Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMarker Class Reference

#include <KoMarker.h>

+ Inheritance diagram for KoMarker:

Public Types

enum  MarkerCoordinateSystem { StrokeWidth , UserSpaceOnUse }
 

Public Member Functions

void applyShapeStroke (const KoShape *shape, KoShapeStroke *stroke, const QPointF &pos, qreal strokeWidth, qreal nodeAngle)
 
QRectF boundingRect (qreal strokeWidth, qreal nodeAngle) const
 
bool compareShapesTo (const QList< KoShape * > other) const
 
MarkerCoordinateSystem coordinateSystem () const
 
void drawPreview (QPainter *painter, const QRectF &previewRect, const QPen &pen, KoFlake::MarkerPosition position)
 
qreal explicitOrientation () const
 
bool hasAutoOrientation () const
 
 KoMarker ()
 
 KoMarker (const KoMarker &rhs)
 
QTransform markerTransform (qreal strokeWidth, qreal nodeAngle, const QPointF &pos=QPointF())
 
qreal maxInset (qreal strokeWidth) const
 
QString name () const
 
bool operator== (const KoMarker &other) const
 
bool operator== (const KoMarker::Private &other) const
 
QPainterPath outline (qreal strokeWidth, qreal nodeAngle) const
 
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.
 
 Private ()
 
 Private (const Private &rhs)
 
QPointF referencePoint () const
 
QSizeF referenceSize () const
 
void setAutoOrientation (bool value)
 
void setCoordinateSystem (MarkerCoordinateSystem value)
 
void setExplicitOrientation (qreal value)
 
void setReferencePoint (const QPointF &value)
 
void setReferenceSize (const QSizeF &size)
 
void setShapes (const QList< KoShape * > &shapes)
 
QList< KoShape * > shapes () const
 
 ~KoMarker ()
 
 ~Private ()
 

Static Public Member Functions

static MarkerCoordinateSystem coordinateSystemFromString (const QString &value)
 
static QString coordinateSystemToString (MarkerCoordinateSystem value)
 

Public Attributes

MarkerCoordinateSystem coordinateSystem
 
qreal explicitOrientation
 
bool hasAutoOrientation
 
QString name
 
QPointF referencePoint
 
QSizeF referenceSize
 
QScopedPointer< KoShapePaintershapePainter
 
QList< KoShape * > shapes
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

Definition at line 28 of file KoMarker.cpp.

Member Enumeration Documentation

◆ MarkerCoordinateSystem

Enumerator
StrokeWidth 
UserSpaceOnUse 

Definition at line 42 of file KoMarker.h.

42 {
45 };
@ StrokeWidth
Definition KoMarker.h:43
@ UserSpaceOnUse
Definition KoMarker.h:44

Constructor & Destructor Documentation

◆ ~Private()

KoMarker::~Private ( )
inline

Definition at line 38 of file KoMarker.cpp.

38 {
39 // shape manager that is stored in the painter should be destroyed
40 // before the shapes themselves
41 shapePainter.reset();
42 qDeleteAll(shapes);
43 }
QScopedPointer< KoShapePainter > shapePainter
Definition KoMarker.cpp:81
QList< KoShape * > shapes
Definition KoMarker.cpp:80

◆ KoMarker() [1/2]

KoMarker::KoMarker ( )

Definition at line 119 of file KoMarker.cpp.

120: d(new Private())
121{
122}
Private *const d
Definition KoMarker.h:105

◆ ~KoMarker()

KoMarker::~KoMarker ( )

Definition at line 124 of file KoMarker.cpp.

125{
126 delete d;
127}

References d.

◆ KoMarker() [2/2]

KoMarker::KoMarker ( const KoMarker & rhs)

Definition at line 134 of file KoMarker.cpp.

135 : QSharedData(rhs),
136 d(new Private(*rhs.d))
137{
138}

Member Function Documentation

◆ applyShapeStroke()

void KoMarker::applyShapeStroke ( const KoShape * shape,
KoShapeStroke * stroke,
const QPointF & pos,
qreal strokeWidth,
qreal nodeAngle )

Definition at line 316 of file KoMarker.cpp.

317{
318 const QGradient *originalGradient = stroke->lineBrush().gradient();
319
320 if (!originalGradient) {
321 QList<KoShape*> linearizedShapes = KoShape::linearizeSubtree(d->shapes);
322 Q_FOREACH(KoShape *shape, linearizedShapes) {
323 // update the stroke
324 KoShapeStrokeSP shapeStroke = shape->stroke() ?
325 qSharedPointerDynamicCast<KoShapeStroke>(shape->stroke()) :
327
328 if (shapeStroke) {
329 shapeStroke = toQShared(new KoShapeStroke(*shapeStroke));
330
331 shapeStroke->setLineBrush(QBrush());
332 shapeStroke->setColor(stroke->color());
333
334 shape->setStroke(shapeStroke);
335 }
336
337 // update the background
338 if (shape->background()) {
340 shape->setBackground(bg);
341 }
342 }
343 } else {
344 QScopedPointer<QGradient> g(KoFlake::cloneGradient(originalGradient));
346
347 const QTransform markerTransformInverted =
348 d->markerTransform(strokeWidth, nodeAngle, pos).inverted();
349
350 QTransform gradientToUser;
351
352 // Unwrap the gradient to work in global mode
353 if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
354 QRectF boundingRect =
355 parentShape ?
356 parentShape->outline().boundingRect() :
357 this->boundingRect(strokeWidth, nodeAngle);
358
360
361 gradientToUser = QTransform(boundingRect.width(), 0, 0, boundingRect.height(),
362 boundingRect.x(), boundingRect.y());
363
364 g->setCoordinateMode(QGradient::LogicalMode);
365 }
366
367 QList<KoShape*> linearizedShapes = KoShape::linearizeSubtree(d->shapes);
368 Q_FOREACH(KoShape *shape, linearizedShapes) {
369 // shape-unwinding transform
370 QTransform t = gradientToUser * markerTransformInverted * shape->absoluteTransformation().inverted();
371
372 // update the stroke
373 KoShapeStrokeSP shapeStroke = shape->stroke() ?
374 qSharedPointerDynamicCast<KoShapeStroke>(shape->stroke()) :
376
377 if (shapeStroke) {
378 shapeStroke = toQShared(new KoShapeStroke(*shapeStroke));
379
380 QBrush brush(*g);
381 brush.setTransform(t);
382 shapeStroke->setLineBrush(brush);
383 shapeStroke->setColor(Qt::transparent);
384 shape->setStroke(shapeStroke);
385 }
386
387 // update the background
388 if (shape->background()) {
389
391 shape->setBackground(bg);
392 }
393 }
394 }
395}
A simple solid color shape background.
A gradient shape background.
QRectF boundingRect(qreal strokeWidth, qreal nodeAngle) const
Definition KoMarker.cpp:256
QBrush lineBrush() const
Returns the strokes brush.
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
QTransform absoluteTransformation() const
Definition KoShape.cpp:382
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1381
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:926
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
QSharedPointer< T > toQShared(T *ptr)
Rect ensureRectNotSmaller(Rect rc, const decltype(Rect().size()) &size)
KRITAFLAKE_EXPORT QGradient * cloneGradient(const QGradient *gradient)
clones the given gradient
Definition KoFlake.cpp:17

References KoShape::absoluteTransformation(), KoShape::background(), boundingRect(), KoFlake::cloneGradient(), KoShapeStroke::color, d, KisAlgebra2D::ensureRectNotSmaller(), KIS_ASSERT_RECOVER_RETURN, KoShape::linearizeSubtree(), KoShapeStroke::lineBrush(), KoShape::outline(), KoShape::setBackground(), KoShape::setStroke(), KoShape::stroke(), and toQShared().

◆ boundingRect()

QRectF KoMarker::boundingRect ( qreal strokeWidth,
qreal nodeAngle ) const

Bounding rect of the marker in local coordinates. It is assumed that the marker is painted with the reference point placed at position (0,0)

Definition at line 256 of file KoMarker.cpp.

257{
258 QRectF shapesBounds = KoShape::boundingRect(d->shapes);
259
260 const QTransform t = d->markerTransform(strokeWidth, nodeAngle);
261
262 if (!t.isIdentity()) {
263 shapesBounds = t.mapRect(shapesBounds);
264 }
265
266 return shapesBounds;
267}
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335

References KoShape::boundingRect(), and d.

◆ compareShapesTo()

bool KoMarker::compareShapesTo ( const QList< KoShape * > other) const
inline

Definition at line 83 of file KoMarker.cpp.

83 {
84 if (shapes.size() != other.size()) return false;
85
86 for (int i = 0; i < shapes.size(); i++) {
87 if (shapes[i]->outline() != other[i]->outline() ||
88 shapes[i]->absoluteTransformation() != other[i]->absoluteTransformation()) {
89
90 return false;
91 }
92 }
93
94 return true;
95 }
QPainterPath outline(qreal strokeWidth, qreal nodeAngle) const
Definition KoMarker.cpp:269

◆ coordinateSystem()

MarkerCoordinateSystem KoMarker::coordinateSystem ( ) const

◆ coordinateSystemFromString()

KoMarker::MarkerCoordinateSystem KoMarker::coordinateSystemFromString ( const QString & value)
static

Definition at line 155 of file KoMarker.cpp.

156{
158
159 if (value == "userSpaceOnUse") {
160 result = UserSpaceOnUse;
161 }
162
163 return result;
164}
float value(const T *src, size_t ch)
MarkerCoordinateSystem
Definition KoMarker.h:42

References StrokeWidth, UserSpaceOnUse, and value().

◆ coordinateSystemToString()

QString KoMarker::coordinateSystemToString ( KoMarker::MarkerCoordinateSystem value)
static

Definition at line 166 of file KoMarker.cpp.

167{
168 return
169 value == StrokeWidth ?
170 "strokeWidth" :
171 "userSpaceOnUse";
172}

References StrokeWidth, and value().

◆ drawPreview()

void KoMarker::drawPreview ( QPainter * painter,
const QRectF & previewRect,
const QPen & pen,
KoFlake::MarkerPosition position )

Draws a preview of the marker in previewRect of painter

Definition at line 285 of file KoMarker.cpp.

286{
287 const QRectF outlineRect = outline(pen.widthF(), 0).boundingRect(); // normalized to 0,0
288 QPointF marker;
289 QPointF start;
290 QPointF end;
291
292 if (position == KoFlake::StartMarker) {
293 marker = QPointF(-outlineRect.left() + previewRect.left(), previewRect.center().y());
294 start = marker;
295 end = QPointF(previewRect.right(), start.y());
296 } else if (position == KoFlake::MidMarker) {
297 start = QPointF(previewRect.left(), previewRect.center().y());
298 marker = QPointF(-outlineRect.center().x() + previewRect.center().x(), start.y());
299 end = QPointF(previewRect.right(), start.y());
300 } else if (position == KoFlake::EndMarker) {
301 start = QPointF(previewRect.left(), previewRect.center().y());
302 marker = QPointF(-outlineRect.right() + previewRect.right(), start.y());
303 end = marker;
304 }
305
306 painter->save();
307 painter->setPen(pen);
308 painter->setClipRect(previewRect);
309
310 painter->drawLine(start, end);
311 paintAtPosition(painter, marker, pen.widthF(), 0);
312
313 painter->restore();
314}
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.
Definition KoMarker.cpp:228
@ EndMarker
Definition KoFlake.h:44
@ StartMarker
Definition KoFlake.h:42
@ MidMarker
Definition KoFlake.h:43

References KoFlake::EndMarker, KoFlake::MidMarker, outline(), paintAtPosition(), and KoFlake::StartMarker.

◆ explicitOrientation()

qreal KoMarker::explicitOrientation ( ) const

◆ hasAutoOrientation()

bool KoMarker::hasAutoOrientation ( ) const

◆ markerTransform()

QTransform KoMarker::markerTransform ( qreal strokeWidth,
qreal nodeAngle,
const QPointF & pos = QPointF() )
inline

Definition at line 97 of file KoMarker.cpp.

97 {
98 const QTransform translate = QTransform::fromTranslate(-referencePoint.x(), -referencePoint.y());
99
100 QTransform t = translate;
101
103 t *= QTransform::fromScale(strokeWidth, strokeWidth);
104 }
105
106 const qreal angle = hasAutoOrientation ? nodeAngle : explicitOrientation;
107 if (angle != 0.0) {
108 QTransform r;
109 r.rotateRadians(angle);
110 t *= r;
111 }
112
113 t *= QTransform::fromTranslate(pos.x(), pos.y());
114
115 return t;
116 }
qreal explicitOrientation
Definition KoMarker.cpp:78
bool hasAutoOrientation
Definition KoMarker.cpp:77
MarkerCoordinateSystem coordinateSystem
Definition KoMarker.cpp:73
QPointF referencePoint
Definition KoMarker.cpp:74

◆ maxInset()

qreal KoMarker::maxInset ( qreal strokeWidth) const

Return maximum distance that the marker can take outside the shape itself

Definition at line 243 of file KoMarker.cpp.

244{
245 QRectF shapesBounds = boundingRect(strokeWidth, 0.0); // normalized to 0,0
246 qreal result = 0.0;
247
248 result = qMax(KisAlgebra2D::norm(shapesBounds.topLeft()), result);
249 result = qMax(KisAlgebra2D::norm(shapesBounds.topRight()), result);
250 result = qMax(KisAlgebra2D::norm(shapesBounds.bottomLeft()), result);
251 result = qMax(KisAlgebra2D::norm(shapesBounds.bottomRight()), result);
252
253 return result;
254}
qreal norm(const T &a)

References boundingRect(), and KisAlgebra2D::norm().

◆ name()

QString KoMarker::name ( ) const

Display name of the marker

Returns
Display name of the marker

◆ operator==() [1/2]

bool KoMarker::operator== ( const KoMarker & other) const

Definition at line 140 of file KoMarker.cpp.

141{
142 return *d == *other.d;
143}

References d.

◆ operator==() [2/2]

bool KoMarker::operator== ( const KoMarker::Private & other) const
inline

Definition at line 45 of file KoMarker.cpp.

46 {
47 // WARNING: comparison of shapes is extremely fuzzy! Don't
48 // trust it in life-critical cases!
49
50 return name == other.name &&
51 coordinateSystem == other.coordinateSystem &&
52 referencePoint == other.referencePoint &&
53 referenceSize == other.referenceSize &&
54 hasAutoOrientation == other.hasAutoOrientation &&
55 explicitOrientation == other.explicitOrientation &&
56 compareShapesTo(other.shapes);
57 }
bool compareShapesTo(const QList< KoShape * > other) const
Definition KoMarker.cpp:83
QString name
Definition KoMarker.cpp:72
QSizeF referenceSize
Definition KoMarker.cpp:75

◆ outline()

QPainterPath KoMarker::outline ( qreal strokeWidth,
qreal nodeAngle ) const

Outline of the marker in local coordinates. It is assumed that the marker is painted with the reference point placed at position (0,0)

Definition at line 269 of file KoMarker.cpp.

270{
271 QPainterPath outline;
272 Q_FOREACH (KoShape *shape, d->shapes) {
273 outline |= shape->absoluteTransformation().map(shape->outline());
274 }
275
276 const QTransform t = d->markerTransform(strokeWidth, nodeAngle);
277
278 if (!t.isIdentity()) {
279 outline = t.map(outline);
280 }
281
282 return outline;
283}
virtual QPainterPath outline() const
Definition KoShape.cpp:630

References KoShape::absoluteTransformation(), d, KoShape::outline(), and outline().

◆ paintAtPosition()

void KoMarker::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.

Definition at line 228 of file KoMarker.cpp.

229{
230 QTransform oldTransform = painter->transform();
231
232 if (!d->shapePainter) {
233 d->shapePainter.reset(new KoShapePainter());
234 d->shapePainter->setShapes(d->shapes);
235 }
236
237 painter->setTransform(d->markerTransform(strokeWidth, nodeAngle, pos), true);
238 d->shapePainter->paint(*painter);
239
240 painter->setTransform(oldTransform);
241}

References d.

◆ Private() [1/2]

KoMarker::Private ( )
inline

Definition at line 31 of file KoMarker.cpp.

◆ Private() [2/2]

KoMarker::Private ( const Private & rhs)
inline

Definition at line 59 of file KoMarker.cpp.

60 : name(rhs.name),
61 coordinateSystem(rhs.coordinateSystem),
62 referencePoint(rhs.referencePoint),
63 referenceSize(rhs.referenceSize),
64 hasAutoOrientation(rhs.hasAutoOrientation),
65 explicitOrientation(rhs.explicitOrientation)
66 {
67 Q_FOREACH (KoShape *shape, rhs.shapes) {
68 shapes << shape->cloneShape();
69 }
70 }
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200

References KoShape::cloneShape().

◆ referencePoint()

QPointF KoMarker::referencePoint ( ) const

◆ referenceSize()

QSizeF KoMarker::referenceSize ( ) const

◆ setAutoOrientation()

void KoMarker::setAutoOrientation ( bool value)

Definition at line 199 of file KoMarker.cpp.

200{
201 d->hasAutoOrientation = value;
202}

References d, and value().

◆ setCoordinateSystem()

void KoMarker::setCoordinateSystem ( KoMarker::MarkerCoordinateSystem value)

Definition at line 145 of file KoMarker.cpp.

146{
147 d->coordinateSystem = value;
148}

References d, and value().

◆ setExplicitOrientation()

void KoMarker::setExplicitOrientation ( qreal value)

Definition at line 209 of file KoMarker.cpp.

210{
211 d->explicitOrientation = value;
212}

References d, and value().

◆ setReferencePoint()

void KoMarker::setReferencePoint ( const QPointF & value)

Definition at line 174 of file KoMarker.cpp.

175{
176 d->referencePoint = value;
177}

References d, and value().

◆ setReferenceSize()

void KoMarker::setReferenceSize ( const QSizeF & size)

Definition at line 184 of file KoMarker.cpp.

185{
186 d->referenceSize = size;
187}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d.

◆ setShapes()

void KoMarker::setShapes ( const QList< KoShape * > & shapes)

Definition at line 214 of file KoMarker.cpp.

215{
216 d->shapes = shapes;
217
218 if (d->shapePainter) {
219 d->shapePainter->setShapes(shapes);
220 }
221}

References d, and shapes.

◆ shapes()

QList< KoShape * > KoMarker::shapes ( ) const

Member Data Documentation

◆ coordinateSystem

KoMarker::MarkerCoordinateSystem KoMarker::coordinateSystem

Definition at line 73 of file KoMarker.cpp.

◆ d

Private* const KoMarker::d
private

Definition at line 105 of file KoMarker.h.

◆ explicitOrientation

qreal KoMarker::explicitOrientation

Definition at line 78 of file KoMarker.cpp.

◆ hasAutoOrientation

bool KoMarker::hasAutoOrientation

Definition at line 77 of file KoMarker.cpp.

◆ name

QString KoMarker::name

Definition at line 72 of file KoMarker.cpp.

◆ referencePoint

QPointF KoMarker::referencePoint

Definition at line 74 of file KoMarker.cpp.

◆ referenceSize

QSizeF KoMarker::referenceSize

Definition at line 75 of file KoMarker.cpp.

◆ shapePainter

QScopedPointer<KoShapePainter> KoMarker::shapePainter

Definition at line 81 of file KoMarker.cpp.

◆ shapes

QList< KoShape * > KoMarker::shapes

Definition at line 80 of file KoMarker.cpp.


The documentation for this class was generated from the following files: