18#include <QPainterPath>
51 const qreal
eps = 1e-6;
53 if (segment.
degree() < 3) {
59 QPointF vec1 = points[1] - points[0];
60 QPointF vec2 = points[3] - points[2];
62 if (vec1.manhattanLength() <
eps) {
64 vec1 = points[1] - points[0];
67 if (vec2.manhattanLength() <
eps) {
69 vec2 = points[3] - points[2];
72 const qreal angle1 = std::atan2(vec1.y(), vec1.x());
73 const qreal angle2 = std::atan2(vec2.y(), vec2.x());
74 return qMakePair(angle1, angle2);
78void KoShapeStroke::Private::paintBorder(
const KoShape *shape, QPainter &painter,
const QPen &pen)
const
80 if (!pen.isCosmetic() && pen.style() != Qt::NoPen) {
83 QPainterPath path = pathShape->
pathStroke(pen);
85 painter.fillPath(path, pen.brush());
90 painter.strokePath(shape->
outline(), pen);
93void KoShapeStroke::Private::paintMarkers(
const KoShape *shape, QPainter &painter,
const QPen &pen)
const
95 if (!pen.isCosmetic() && pen.style() != Qt::NoPen) {
108 if (numSubPoints < 2)
continue;
112 qreal firstAngle = 0.0;
115 firstAngle= anglesForSegment(segment).
first;
118 const int numSegments = isClosedSubpath ? numSubPoints : numSubPoints - 1;
120 qreal lastAngle = 0.0;
123 lastAngle = anglesForSegment(segment).
second;
126 qreal previousAngle = 0.0;
128 for (
int j = 0; j < numSegments; j++) {
130 QPair<qreal, qreal> angles = anglesForSegment(segment);
132 const qreal angle1 = angles.first;
133 const qreal angle2 = angles.second;
135 if (j == 0 && startMarker) {
136 const qreal angle = isClosedSubpath ?
bisectorAngle(firstAngle, lastAngle) : firstAngle;
137 if (autoFillMarkers) {
143 if (j > 0 && midMarker) {
145 if (autoFillMarkers) {
151 if (j == numSegments - 1 && endMarker) {
152 const qreal angle = isClosedSubpath ?
bisectorAngle(firstAngle, lastAngle) : lastAngle;
153 if (autoFillMarkers) {
159 previousAngle = angle2;
169 d->color = QColor(Qt::black);
172 d->pen.setWidthF(1.0);
178 d->color = other.
d->color;
179 d->pen = other.
d->pen;
180 d->brush = other.
d->brush;
186 d->pen.setWidthF(qMax(qreal(0.0),
lineWidth));
187 d->pen.setJoinStyle(Qt::MiterJoin);
202 d->color = rhs.
d->color;
203 d->brush = rhs.
d->brush;
213 qreal extent = 0.5 * (
d->pen.widthF() >= 0 ?
d->pen.widthF() : 1.0);
223 extent = qMax(extent,
d->pen.widthF() *
miterLimit());
228 insets.
left = extent;
229 insets.
right = extent;
245 Q_FOREACH (
const KoMarker *marker, markers) {
257 return d->color.alpha() > 0;
264 if (
d->brush.gradient()) {
265 pen.setBrush(
d->brush);
267 pen.setColor(
d->color.isValid() ?
d->color : Qt::transparent);
289 if (!other)
return false;
292 if (!stroke)
return false;
294 return (
d->brush.gradient() &&
d->brush == stroke->
d->brush) ||
295 (!
d->brush.gradient() &&
d->color == stroke->
d->color);
300 if (!other)
return false;
303 if (!stroke)
return false;
306 QPen pen2 = stroke->
d->pen;
309 pen1.setColor(Qt::magenta);
310 pen2.setColor(Qt::magenta);
317 return d->pen.widthF() > 0 &&
318 (
d->brush.gradient() ||
d->color.alpha() > 0);
323 d->pen.setCapStyle(style);
328 return d->pen.capStyle();
333 d->pen.setJoinStyle(style);
338 return d->pen.joinStyle();
343 d->pen.setWidthF(qMax(qreal(0.0),
lineWidth));
348 return d->pen.widthF();
358 return d->pen.miterLimit();
373 if (style < Qt::CustomDashLine) {
374 d->pen.setStyle(style);
376 d->pen.setDashPattern(dashes);
382 return d->pen.style();
387 return d->pen.dashPattern();
397 return d->pen.dashOffset();
QPair< int, int > KoPathPointIndex
void paintAtPosition(QPainter *painter, const QPointF &pos, qreal strokeWidth, qreal nodeAngle)
paintAtOrigin paints the marker at the position pos. Scales and rotates the marker if needed.
void applyShapeStroke(const KoShape *shape, KoShapeStroke *stroke, const QPointF &pos, qreal strokeWidth, qreal nodeAngle)
qreal maxInset(qreal strokeWidth) const
A KoPathSegment consist of two neighboring KoPathPoints.
int degree() const
Returns the degree of the segment: 1 = line, 2 = quadratic, 3 = cubic, -1 = invalid.
QPointF pointAt(qreal t) const
Returns point at given t.
QList< QPointF > controlPoints() const
Returns ordered list of control points.
KoPathSegment toCubic() const
Returns cubic bezier curve segment of this segment.
The position of a path point within a path shape.
bool autoFillMarkers() const
int subpathPointCount(int subpathIndex) const
Returns the number of points in a subpath.
bool isClosedSubpath(int subpathIndex) const
Checks if a subpath is closed.
KoMarker * marker(KoFlake::MarkerPosition pos) const
QPainterPath pathStroke(const QPen &pen) const
int subpathCount() const
Returns the number of subpaths in the path.
KoPathSegment segmentByIndex(const KoPathPointIndex &pointIndex) const
Returns the segment specified by a path point index.
QBrush lineBrush() const
Returns the strokes brush.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the lines join style.
void setMiterLimit(qreal miterLimit)
Sets the miter limit.
bool compareFillTo(const KoShapeStrokeModel *other) override
void setLineStyle(Qt::PenStyle style, const QVector< qreal > &dashes)
Sets the line style.
qreal strokeMaxMarkersInset(const KoShape *shape) const override
void paint(const KoShape *shape, QPainter &painter) const override
qreal miterLimit() const
Returns the miter limit.
KoShapeStroke()
Constructor for a thin line in black.
QPen resultLinePen() const
KoShapeStroke & operator=(const KoShapeStroke &rhs)
Assignment operator.
qreal lineWidth() const
Returns the line width.
void paintBorder(const KoShape *shape, QPainter &painter, const QPen &pen) const
qreal dashOffset() const
Returns the dash offset.
Qt::PenStyle lineStyle() const
Returns the line style.
void setColor(const QColor &color)
Sets the color.
Private(KoShapeStroke *_q)
Qt::PenCapStyle capStyle() const
Returns the lines cap style.
bool hasTransparency() const override
void setDashOffset(qreal dashOffset)
Sets the dash offset.
bool isVisible() const override
bool compareStyleTo(const KoShapeStrokeModel *other) override
~KoShapeStroke() override
void setLineBrush(const QBrush &brush)
Sets the strokes brush used to fill strokes of this border.
void strokeInsets(const KoShape *shape, KoInsets &insets) const override
Qt::PenJoinStyle joinStyle() const
Returns the lines join style.
void setLineWidth(qreal lineWidth)
Sets the line width.
void setCapStyle(Qt::PenCapStyle style)
Sets the lines cap style.
QVector< qreal > lineDashes() const
Returns the line dashes.
void paintMarkers(const KoShape *shape, QPainter &painter, const QPen &pen) const
virtual QPainterPath outline() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
qreal bisectorAngle(qreal a, qreal b)
qreal bottom
Bottom inset.