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

The position of a path point within a path shape. More...

#include <KoPathShape.h>

+ Inheritance diagram for KoPathShape:

Classes

struct  PointSelectionChangeListener
 
class  Private
 

Public Member Functions

bool addSubpath (KoSubpath *subpath, int subpathIndex)
 Adds a subpath at the given index to the path.
 
KoPathPointarcTo (qreal rx, qreal ry, qreal startAngle, qreal sweepAngle)
 Add an arc.
 
bool autoFillMarkers () const
 
QRectF boundingRect () const override
 reimplemented
 
bool breakAfter (const KoPathPointIndex &pointIndex)
 Breaks the path after the point index.
 
void clear ()
 Removes all subpaths and their points from the path.
 
KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
void close ()
 Closes the current subpath.
 
void closeMerge ()
 Closes the current subpath.
 
KoPathPointIndex closeSubpath (const KoPathPointIndex &pointIndex)
 Close a open subpath.
 
int combine (KoPathShape *path)
 Combines two path shapes by appending the data of the specified path.
 
KoPathPointcurveTo (const QPointF &c, const QPointF &p)
 Adds a new quadratic Bezier curve segment.
 
KoPathPointcurveTo (const QPointF &c1, const QPointF &c2, const QPointF &p)
 Adds a new cubic Bezier curve segment.
 
Qt::FillRule fillRule () const
 Returns the fill rule for the path object.
 
bool hasMarkers () const
 
bool hitTest (const QPointF &position) const override
 reimplemented
 
bool insertPoint (KoPathPoint *point, const KoPathPointIndex &pointIndex)
 Inserts a new point into the given subpath at the specified position.
 
bool isClosedSubpath (int subpathIndex) const
 Checks if a subpath is closed.
 
bool join (int subpathIndex)
 Joins the given subpath with the following one.
 
 KoPathShape ()
 constructor
 
KoPathPointlineTo (const QPointF &p)
 Adds a new line segment.
 
void loadNodeTypes (const QString &nodeTypes)
 Loads node types.
 
KoMarkermarker (KoFlake::MarkerPosition pos) const
 
bool moveSubpath (int oldSubpathIndex, int newSubpathIndex)
 Moves the position of a subpath within a path.
 
KoPathPointmoveTo (const QPointF &p)
 Starts a new Subpath.
 
QString nodeTypes () const
 Saves the node types.
 
virtual QPointF normalize ()
 Normalizes the path data.
 
KoPathPointIndex openSubpath (const KoPathPointIndex &pointIndex)
 Opens a closed subpath.
 
QPainterPath outline () const override
 reimplemented
 
QRectF outlineRect () const override
 reimplemented
 
void paint (QPainter &painter) const override
 reimplemented
 
virtual void paintPoints (KisHandlePainterHelper &handlesHelper)
 
KoPathPointIndex pathPointIndex (const KoPathPoint *point) const
 Returns the path point index of a given path point.
 
virtual QString pathShapeId () const
 
QPainterPath pathStroke (const QPen &pen) const
 
KoPathPointpointByIndex (const KoPathPointIndex &pointIndex) const
 Returns the path point specified by a path point index.
 
int pointCount () const
 Returns the number of points in the path.
 
QList< KoPathPoint * > pointsAt (const QRectF &rect, const bool useControlPoints=false) const
 Returns the path points within the given rectangle.
 
void recommendPointSelectionChange (const QList< KoPathPointIndex > &newSelection)
 
KoPathPointremovePoint (const KoPathPointIndex &pointIndex)
 Removes a point from the path.
 
KoSubpathremoveSubpath (int subpathIndex)
 Removes subpath from the path.
 
bool reverseSubpath (int subpathIndex)
 Reverse subpath.
 
KoPathSegment segmentAtPoint (const QPointF &point, const QRectF &grabRoi) const
 
KoPathSegment segmentByIndex (const KoPathPointIndex &pointIndex) const
 Returns the segment specified by a path point index.
 
QList< KoPathSegmentsegmentsAt (const QRectF &rect) const
 Returns the list of path segments within the given rectangle.
 
bool separate (QList< KoPathShape * > &separatedPaths)
 Creates separate path shapes, one for each existing subpath.
 
void setAutoFillMarkers (bool value)
 
void setFillRule (Qt::FillRule fillRule)
 Sets the fill rule to be used for painting the background.
 
void setMarker (KoMarker *marker, KoFlake::MarkerPosition pos)
 
void setSize (const QSizeF &size) override
 
QSizeF size () const override
 reimplemented
 
int subpathCount () const
 Returns the number of subpaths in the path.
 
int subpathPointCount (int subpathIndex) const
 Returns the number of points in a subpath.
 
QString toString (const QTransform &matrix=QTransform()) const
 Returns a odf/svg string representation of the path data with the given matrix applied.
 
 ~KoPathShape () override
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
void setSelectable (bool selectable)
 
void setShapeId (const QString &id)
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void update () const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 

Static Public Member Functions

static KoPathShapecreateShapeFromPainterPath (const QPainterPath &path)
 Creates path shape from given QPainterPath.
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 

Protected Member Functions

int arcToCurve (qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF &offset, QPointF *curvePoints) const
 Add an arc.
 
 KoPathShape (const KoPathShape &rhs)
 
void map (const QTransform &matrix)
 
void notifyPointsChanged ()
 
QTransform resizeMatrix (const QSizeF &newSize) const
 
KoSubpathListsubpaths ()
 XXX: refactor this using setter?
 
const KoSubpathListsubpaths () const
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
virtual void shapeChanged (ChangeType type, KoShape *shape=0)
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Private Member Functions

void closeMergeSubpathPriv (KoSubpath *subpath)
 close-merges specified subpath
 
void closeSubpathPriv (KoSubpath *subpath)
 closes specified subpath
 
void updateLastPriv (KoPathPoint **lastPoint)
 

Private Attributes

QScopedPointer< Privated
 

Additional Inherited Members

- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , BorderChanged ,
  ParameterChanged , ContentChanged , TextContourMarginChanged , ChildChanged ,
  ConnectionPointChanged , ClipPathChanged , ClipMaskChanged , TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 

Detailed Description

The position of a path point within a path shape.

This is the base for all graphical objects.

All graphical objects are based on this object e.g. lines, rectangles, pies and so on.

The KoPathShape uses KoPathPoint's to describe the path of the shape.

Here a short example: 3 points connected by a curveTo's described by the following svg: M 100,200 C 100,100 250,100 250,200 C 250,200 400,300 400,200.

This will be stored in 3 KoPathPoint's as The first point contains in point 100,200 controlPoint2 100,100 The second point contains in point 250,200 controlPoint1 250,100 controlPoint2 250,300 The third point contains in point 400,300 controlPoint1 400,200

Not the segments are stored but the points. Out of the points the segments are generated. See the outline method. The reason for storing it like that is that it is the points that are modified by the user and not the segments.

Definition at line 62 of file KoPathShape.h.

Constructor & Destructor Documentation

◆ KoPathShape() [1/2]

KoPathShape::KoPathShape ( )

constructor

Definition at line 59 of file KoPathShape.cpp.

60 : KoShape()
61 , d(new Private)
62{
63}
QScopedPointer< Private > d
KoShape()
Constructor.
Definition KoShape.cpp:135

◆ ~KoPathShape()

KoPathShape::~KoPathShape ( )
override

Definition at line 84 of file KoPathShape.cpp.

85{
86 clear();
87}
void clear()
Removes all subpaths and their points from the path.

References clear().

◆ KoPathShape() [2/2]

KoPathShape::KoPathShape ( const KoPathShape & rhs)
protected

constructor: to be used in cloneShape(), not in descendants!

Definition at line 65 of file KoPathShape.cpp.

66 : KoShape(rhs)
67 , d(new Private(*rhs.d))
68{
69 // local data cannot be shared via QSharedData because
70 // every path point holds a pointer to the parent shape
72 Q_FOREACH (KoSubpath *subPath, rhs.d->subpaths) {
73 KoSubpath *clonedSubPath = new KoSubpath();
74
75 Q_FOREACH (KoPathPoint *point, *subPath) {
76 *clonedSubPath << new KoPathPoint(*point, this);
77 }
78
79 subpaths << clonedSubPath;
80 }
81 d->subpaths = subpaths;
82}
QList< KoPathPoint * > KoSubpath
a KoSubpath contains a path from a moveTo until a close or a new moveTo
Definition KoPathShape.h:31
A KoPathPoint represents a point in a path.
const KoSubpathList & subpaths() const

References d, and subpaths().

Member Function Documentation

◆ addSubpath()

bool KoPathShape::addSubpath ( KoSubpath * subpath,
int subpathIndex )

Adds a subpath at the given index to the path.

Parameters
subpaththe subpath to add
subpathIndexthe index at which the new subpath should be inserted
Returns
true on success, false otherwise e.g. subpathIndex out of bounds

Definition at line 925 of file KoPathShape.cpp.

926{
927 if (subpathIndex < 0 || subpathIndex > d->subpaths.size())
928 return false;
929
930 Q_FOREACH (KoPathPoint* point, *subpath) {
931 point->setParent(this);
932 }
933
934 d->subpaths.insert(subpathIndex, subpath);
936
937
938 return true;
939}
void setParent(KoPathShape *parent)
Sets the parent path shape.
void notifyPointsChanged()

References d, notifyPointsChanged(), and KoPathPoint::setParent().

◆ arcTo()

KoPathPoint * KoPathShape::arcTo ( qreal rx,
qreal ry,
qreal startAngle,
qreal sweepAngle )

Add an arc.

Adds an arc starting at the current point. The arc will be converted to bezier curves.

Parameters
rxx radius of the ellipse
ryy radius of the ellipse
startAnglethe angle where the arc will be started
sweepAnglethe length of the angle TODO add param to have angle of the ellipse
Returns
The newly created point

Definition at line 384 of file KoPathShape.cpp.

385{
386 if (d->subpaths.empty()) {
387 moveTo(QPointF(0, 0));
388 }
389
390 KoPathPoint * lastPoint = d->subpaths.last()->last();
391 if (lastPoint->properties() & KoPathPoint::CloseSubpath) {
392 lastPoint = d->subpaths.last()->first();
393 }
394 QPointF startpoint(lastPoint->point());
395
396 KoPathPoint * newEndPoint = lastPoint;
397
398 QPointF curvePoints[12];
399 int pointCnt = arcToCurve(rx, ry, startAngle, sweepAngle, startpoint, curvePoints);
400 for (int i = 0; i < pointCnt; i += 3) {
401 newEndPoint = curveTo(curvePoints[i], curvePoints[i+1], curvePoints[i+2]);
402 }
403 return newEndPoint;
404}
PointProperties properties
QPointF point
@ CloseSubpath
it closes a subpath (only applicable on StartSubpath and StopSubpath)
Definition KoPathPoint.h:40
KoPathPoint * moveTo(const QPointF &p)
Starts a new Subpath.
int arcToCurve(qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF &offset, QPointF *curvePoints) const
Add an arc.
KoPathPoint * curveTo(const QPointF &c1, const QPointF &c2, const QPointF &p)
Adds a new cubic Bezier curve segment.

References arcToCurve(), KoPathPoint::CloseSubpath, curveTo(), d, moveTo(), KoPathPoint::point, and KoPathPoint::properties.

◆ arcToCurve()

int KoPathShape::arcToCurve ( qreal rx,
qreal ry,
qreal startAngle,
qreal sweepAngle,
const QPointF & offset,
QPointF * curvePoints ) const
protected

Add an arc.

Adds an arc starting at the current point. The arc will be converted to bezier curves.

Parameters
rxx radius of the ellipse
ryy radius of the ellipse
startAnglethe angle where the arc will be started
sweepAnglethe length of the angle TODO add param to have angle of the ellipse
offsetto the first point in the arc
curvePointsan array which take the curve points, pass a 'QPointF curvePoints[12]';
Returns
number of points created by the curve

Definition at line 406 of file KoPathShape.cpp.

407{
408 int pointCnt = 0;
409
410 // check Parameters
411 if (sweepAngle == 0.0)
412 return pointCnt;
413
414 sweepAngle = qBound(-360.0, sweepAngle, 360.0);
415
416 if (rx == 0 || ry == 0) {
417 //TODO
418 }
419
420 // split angles bigger than 90° so that it gives a good approximation to the circle
421 qreal parts = ceil(qAbs(sweepAngle / 90.0));
422
423 qreal sa_rad = startAngle * M_PI / 180.0;
424 qreal partangle = sweepAngle / parts;
425 qreal endangle = startAngle + partangle;
426 qreal se_rad = endangle * M_PI / 180.0;
427 qreal sinsa = sin(sa_rad);
428 qreal cossa = cos(sa_rad);
429 qreal kappa = 4.0 / 3.0 * tan((se_rad - sa_rad) / 4);
430
431 // startpoint is at the last point is the path but when it is closed
432 // it is at the first point
433 QPointF startpoint(offset);
434
435 //center berechnen
436 QPointF center(startpoint - QPointF(cossa * rx, -sinsa * ry));
437
438 //debugFlake <<"kappa" << kappa <<"parts" << parts;
439
440 for (int part = 0; part < parts; ++part) {
441 // start tangent
442 curvePoints[pointCnt++] = QPointF(startpoint - QPointF(sinsa * rx * kappa, cossa * ry * kappa));
443
444 qreal sinse = sin(se_rad);
445 qreal cosse = cos(se_rad);
446
447 // end point
448 QPointF endpoint(center + QPointF(cosse * rx, -sinse * ry));
449 // end tangent
450 curvePoints[pointCnt++] = QPointF(endpoint - QPointF(-sinse * rx * kappa, -cosse * ry * kappa));
451 curvePoints[pointCnt++] = endpoint;
452
453 // set the endpoint as next start point
454 startpoint = endpoint;
455 sinsa = sinse;
456 cossa = cosse;
457 endangle += partangle;
458 se_rad = endangle * M_PI / 180.0;
459 }
460
461 return pointCnt;
462}
quint64 part(quint64 n1, quint64 n2, int p)
#define M_PI
Definition kis_global.h:111

References M_PI, and part().

◆ autoFillMarkers()

bool KoPathShape::autoFillMarkers ( ) const

Definition at line 1310 of file KoPathShape.cpp.

1311{
1312 return d->autoFillMarkers;
1313}

References d.

◆ boundingRect()

QRectF KoPathShape::boundingRect ( ) const
overridevirtual

reimplemented

First we approximate the insets of the stroke by rendering a fat bezier curve with width set to the maximum inset of miters and markers. The are swept by this curve will be a good approximation of the real curve bounding rect.

NOTE: stroking the entire shape might be too expensive, so try to estimate the bounds using insets only...

Reimplemented from KoShape.

Definition at line 249 of file KoPathShape.cpp.

250{
251 const QTransform transform = absoluteTransformation();
252
258 qreal outlineSweepWidth = 0;
259
260 const QSharedPointer<KoShapeStroke> lineBorder = qSharedPointerDynamicCast<KoShapeStroke>(stroke());
261 if (lineBorder) {
262 outlineSweepWidth = lineBorder->lineWidth();
263 }
264
265 if (stroke()) {
266 KoInsets inset;
267 stroke()->strokeInsets(this, inset);
268 const qreal maxInset = std::max({inset.left, inset.top, inset.right, inset.bottom});
269
270 // insets extend outside the shape, but width extends both inside and outside,
271 // so we should multiply insets by 2.0
272 outlineSweepWidth = std::max({outlineSweepWidth,
273 2.0 * maxInset,
274 2.0 * stroke()->strokeMaxMarkersInset(this)});
275 }
276
277
278
281
282#if 0
283 QPen pen(Qt::black, outlineSweepWidth);
284
285 // select round joins and caps to ensure it sweeps exactly
286 // 'outlineSweepWidth' pixels in every possible
287 pen.setJoinStyle(Qt::RoundJoin);
288 pen.setCapStyle(Qt::RoundCap);
289 QRectF bb = transform.map(pathStroke(pen)).boundingRect();
290#endif
291
292 // add 10% extra update area around the doubled insets
293 return transform.mapRect(kisGrowRect(outline().boundingRect(), 1.1 * 0.5 * outlineSweepWidth));
294}
QPainterPath pathStroke(const QPen &pen) const
QPainterPath outline() const override
reimplemented
QRectF boundingRect() const override
reimplemented
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:890
QTransform absoluteTransformation() const
Definition KoShape.cpp:335
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
Definition KoShape.cpp:950
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
qreal bottom
Bottom inset.
Definition KoInsets.h:50
qreal right
Right inset.
Definition KoInsets.h:52
qreal top
Top inset.
Definition KoInsets.h:49
qreal left
Left inset.
Definition KoInsets.h:51

References KoShape::absoluteTransformation(), KoInsets::bottom, boundingRect(), kisGrowRect(), KoInsets::left, outline(), pathStroke(), KoInsets::right, KoShape::stroke(), KoInsets::top, and KoShape::transform().

◆ breakAfter()

bool KoPathShape::breakAfter ( const KoPathPointIndex & pointIndex)

Breaks the path after the point index.

The new subpath will be behind the one that was broken. The segment between the given point and the one behind will be removed. If you want to split at one point insert first a copy of the point behind it. This does not work when the subpath is closed. Use openSubpath for this. It does not break at the last position of a subpath or if there is only one point in the subpath.

Parameters
pointIndexindex of the point after which the path should be broken
Returns
true if the subpath was broken, otherwise false

Definition at line 743 of file KoPathShape.cpp.

744{
745 KoSubpath *subpath = d->subPath(pointIndex.first);
746
747 if (!subpath || pointIndex.second < 0 || pointIndex.second > subpath->size() - 2
748 || isClosedSubpath(pointIndex.first))
749 return false;
750
751 KoSubpath * newSubpath = new KoSubpath;
752
753 int size = subpath->size();
754 for (int i = pointIndex.second + 1; i < size; ++i) {
755 newSubpath->append(subpath->takeAt(pointIndex.second + 1));
756 }
757 // now make the first point of the new subpath a starting node
758 newSubpath->first()->setProperty(KoPathPoint::StartSubpath);
759 // the last point of the old subpath is now an ending node
760 subpath->last()->setProperty(KoPathPoint::StopSubpath);
761
762 // insert the new subpath after the broken one
763 d->subpaths.insert(pointIndex.first + 1, newSubpath);
765
766 return true;
767}
@ StartSubpath
it starts a new subpath by a moveTo command
Definition KoPathPoint.h:38
@ StopSubpath
it stops a subpath (last point of subpath)
Definition KoPathPoint.h:39
bool isClosedSubpath(int subpathIndex) const
Checks if a subpath is closed.
QSizeF size() const override
reimplemented

References d, isClosedSubpath(), notifyPointsChanged(), size(), KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ clear()

void KoPathShape::clear ( )

Removes all subpaths and their points from the path.

Definition at line 94 of file KoPathShape.cpp.

95{
96 Q_FOREACH (KoSubpath *subpath, d->subpaths) {
97 Q_FOREACH (KoPathPoint *point, *subpath)
98 delete point;
99 delete subpath;
100 }
101 d->subpaths.clear();
102
104}

References d, and notifyPointsChanged().

◆ cloneShape()

KoShape * KoPathShape::cloneShape ( ) const
overridevirtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented from KoShape.

Reimplemented in RectangleShape, SpiralShape, and StarShape.

Definition at line 89 of file KoPathShape.cpp.

90{
91 return new KoPathShape(*this);
92}
KoPathShape()
constructor

References KoPathShape().

◆ close()

void KoPathShape::close ( )

Closes the current subpath.

Definition at line 464 of file KoPathShape.cpp.

465{
466 if (d->subpaths.empty()) {
467 return;
468 }
469 closeSubpathPriv(d->subpaths.last());
470}
void closeSubpathPriv(KoSubpath *subpath)
closes specified subpath

References closeSubpathPriv(), and d.

◆ closeMerge()

void KoPathShape::closeMerge ( )

Closes the current subpath.

It tries to merge the last and first point of the subpath to one point and then closes the subpath. If merging is not possible as the two point are to far from each other a close will be done. TODO define a maximum distance between the two points until this is working

Definition at line 472 of file KoPathShape.cpp.

473{
474 if (d->subpaths.empty()) {
475 return;
476 }
477 closeMergeSubpathPriv(d->subpaths.last());
478}
void closeMergeSubpathPriv(KoSubpath *subpath)
close-merges specified subpath

References closeMergeSubpathPriv(), and d.

◆ closeMergeSubpathPriv()

void KoPathShape::closeMergeSubpathPriv ( KoSubpath * subpath)
private

close-merges specified subpath

Definition at line 1013 of file KoPathShape.cpp.

1014{
1015 if (! subpath || subpath->size() < 2)
1016 return;
1017
1018 KoPathPoint * lastPoint = subpath->last();
1019 KoPathPoint * firstPoint = subpath->first();
1020
1021 // check if first and last points are coincident
1022 if (lastPoint->point() == firstPoint->point()) {
1023 // we are removing the current last point and
1024 // reuse its first control point if active
1027 if (lastPoint->activeControlPoint1())
1028 firstPoint->setControlPoint1(lastPoint->controlPoint1());
1029 // remove last point
1030 delete subpath->takeLast();
1031 // the new last point closes the subpath now
1032 lastPoint = subpath->last();
1035
1037 } else {
1038 closeSubpathPriv(subpath);
1039 }
1040}
void setControlPoint1(const QPointF &point)
Set the control point 1.
void setProperty(PointProperty property)
Sets a single property of a point.
QPointF controlPoint1
bool activeControlPoint1

References KoPathPoint::activeControlPoint1, KoPathPoint::CloseSubpath, closeSubpathPriv(), KoPathPoint::controlPoint1, notifyPointsChanged(), KoPathPoint::point, KoPathPoint::setControlPoint1(), KoPathPoint::setProperty(), KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ closeSubpath()

KoPathPointIndex KoPathShape::closeSubpath ( const KoPathPointIndex & pointIndex)

Close a open subpath.

The subpath is closed be inserting a segment between the start and end point, making the given point the new start point of the subpath.

Returns
the new position of the old first point in the subpath otherwise KoPathPointIndex( -1, -1 )

Definition at line 844 of file KoPathShape.cpp.

845{
846 KoSubpath *subpath = d->subPath(pointIndex.first);
847
848 if (!subpath || pointIndex.second < 0 || pointIndex.second >= subpath->size()
849 || isClosedSubpath(pointIndex.first))
850 return KoPathPointIndex(-1, -1);
851
852 KoPathPoint * oldStartPoint = subpath->first();
853 // the old starting node no longer starts the subpath
855 // the old end node no longer ends the subpath
856 subpath->last()->unsetProperty(KoPathPoint::StopSubpath);
857
858 // reorder the subpath
859 for (int i = 0; i < pointIndex.second; ++i) {
860 subpath->append(subpath->takeFirst());
861 }
862 subpath->first()->setProperty(KoPathPoint::StartSubpath);
863 subpath->last()->setProperty(KoPathPoint::StopSubpath);
864
865 closeSubpathPriv(subpath);
866
868
869 return pathPointIndex(oldStartPoint);
870}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
void unsetProperty(PointProperty property)
Removes a property from the point.
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.

References closeSubpathPriv(), d, isClosedSubpath(), notifyPointsChanged(), pathPointIndex(), KoPathPoint::StartSubpath, KoPathPoint::StopSubpath, and KoPathPoint::unsetProperty().

◆ closeSubpathPriv()

void KoPathShape::closeSubpathPriv ( KoSubpath * subpath)
private

closes specified subpath

Definition at line 1002 of file KoPathShape.cpp.

1003{
1004 if (! subpath)
1005 return;
1006
1007 subpath->last()->setProperty(KoPathPoint::CloseSubpath);
1008 subpath->first()->setProperty(KoPathPoint::CloseSubpath);
1009
1011}

References KoPathPoint::CloseSubpath, and notifyPointsChanged().

◆ combine()

int KoPathShape::combine ( KoPathShape * path)

Combines two path shapes by appending the data of the specified path.

Parameters
paththe path to combine with
Returns
index of the first segment inserted or -1 on failure

Definition at line 940 of file KoPathShape.cpp.

941{
942 int insertSegmentPosition = -1;
943 if (!path) return insertSegmentPosition;
944
945 QTransform pathMatrix = path->absoluteTransformation();
946 QTransform myMatrix = absoluteTransformation().inverted();
947
948 Q_FOREACH (KoSubpath* subpath, path->d->subpaths) {
949 KoSubpath *newSubpath = new KoSubpath();
950
951 Q_FOREACH (KoPathPoint* point, *subpath) {
952 KoPathPoint *newPoint = new KoPathPoint(*point, this);
953 newPoint->map(pathMatrix);
954 newPoint->map(myMatrix);
955 newSubpath->append(newPoint);
956 }
957 d->subpaths.append(newSubpath);
958
959 if (insertSegmentPosition < 0) {
960 insertSegmentPosition = d->subpaths.size() - 1;
961 }
962 }
963 normalize();
964
966 return insertSegmentPosition;
967}
void map(const QTransform &matrix)
apply matrix on the point
virtual QPointF normalize()
Normalizes the path data.

References KoShape::absoluteTransformation(), d, KoPathPoint::map(), normalize(), and notifyPointsChanged().

◆ createShapeFromPainterPath()

KoPathShape * KoPathShape::createShapeFromPainterPath ( const QPainterPath & path)
static

Creates path shape from given QPainterPath.

Definition at line 1235 of file KoPathShape.cpp.

1236{
1237 KoPathShape * shape = new KoPathShape();
1238
1239 int elementCount = path.elementCount();
1240 for (int i = 0; i < elementCount; i++) {
1241 QPainterPath::Element element = path.elementAt(i);
1242 switch (element.type) {
1243 case QPainterPath::MoveToElement:
1244 shape->moveTo(QPointF(element.x, element.y));
1245 break;
1246 case QPainterPath::LineToElement:
1247 shape->lineTo(QPointF(element.x, element.y));
1248 break;
1249 case QPainterPath::CurveToElement:
1250 shape->curveTo(QPointF(element.x, element.y),
1251 QPointF(path.elementAt(i + 1).x, path.elementAt(i + 1).y),
1252 QPointF(path.elementAt(i + 2).x, path.elementAt(i + 2).y));
1253 break;
1254 default:
1255 continue;
1256 }
1257 }
1258
1259 shape->setShapeId(KoPathShapeId);
1260
1261 //shape->normalize();
1262 return shape;
1263}
#define KoPathShapeId
Definition KoPathShape.h:20
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoPathPoint * lineTo(const QPointF &p)
Adds a new line segment.
void setShapeId(const QString &id)
Definition KoShape.cpp:885

References curveTo(), KoPathShape(), KoPathShapeId, lineTo(), moveTo(), and KoShape::setShapeId().

◆ curveTo() [1/2]

KoPathPoint * KoPathShape::curveTo ( const QPointF & c,
const QPointF & p )

Adds a new quadratic Bezier curve segment.

Adds a quadratic Bezier curve between the last point and the given point p, using the control point specified by c.

Parameters
ccontrol point
pthe endpoint of this curve segment
Returns
The newly created point

Definition at line 370 of file KoPathShape.cpp.

371{
372 if (d->subpaths.empty())
373 moveTo(QPointF(0, 0));
374
375 KoPathPoint * lastPoint = d->subpaths.last()->last();
376 updateLastPriv(&lastPoint);
377 lastPoint->setControlPoint2(c);
379 d->subpaths.last()->push_back(point);
381 return point;
382}
const Params2D p
void setControlPoint2(const QPointF &point)
Set the control point 2.
void updateLastPriv(KoPathPoint **lastPoint)

References d, moveTo(), notifyPointsChanged(), p, KoPathPoint::setControlPoint2(), KoPathPoint::StopSubpath, and updateLastPriv().

◆ curveTo() [2/2]

KoPathPoint * KoPathShape::curveTo ( const QPointF & c1,
const QPointF & c2,
const QPointF & p )

Adds a new cubic Bezier curve segment.

Adds a cubic Bezier curve between the last point and the given point p, using the control points specified by c1 and c2.

Parameters
c1control point1
c2control point2
pthe endpoint of this curve segment
Returns
The newly created point

Definition at line 355 of file KoPathShape.cpp.

356{
357 if (d->subpaths.empty()) {
358 moveTo(QPointF(0, 0));
359 }
360 KoPathPoint * lastPoint = d->subpaths.last()->last();
361 updateLastPriv(&lastPoint);
362 lastPoint->setControlPoint2(c1);
364 point->setControlPoint1(c2);
365 d->subpaths.last()->push_back(point);
367 return point;
368}

References d, moveTo(), notifyPointsChanged(), p, KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), KoPathPoint::StopSubpath, and updateLastPriv().

◆ fillRule()

Qt::FillRule KoPathShape::fillRule ( ) const

Returns the fill rule for the path object.

Definition at line 1225 of file KoPathShape.cpp.

1226{
1227 return d->fillRule;
1228}

References d.

◆ hasMarkers()

bool KoPathShape::hasMarkers ( ) const

Definition at line 1305 of file KoPathShape.cpp.

1306{
1307 return !d->markersNew.isEmpty();
1308}

References d.

◆ hitTest()

bool KoPathShape::hitTest ( const QPointF & position) const
overridevirtual

reimplemented

Reimplemented from KoShape.

Definition at line 1265 of file KoPathShape.cpp.

1266{
1267 if (parent() && parent()->isClipped(this) && ! parent()->hitTest(position))
1268 return false;
1269
1270 QPointF point = absoluteTransformation().inverted().map(position);
1271 const QPainterPath outlinePath = outline();
1272 if (stroke()) {
1273 KoInsets insets;
1274 stroke()->strokeInsets(this, insets);
1275 QRectF roi(QPointF(-insets.left, -insets.top), QPointF(insets.right, insets.bottom));
1276
1277 roi.moveCenter(point);
1278 if (outlinePath.intersects(roi) || outlinePath.contains(roi))
1279 return true;
1280 } else {
1281 if (outlinePath.contains(point))
1282 return true;
1283 }
1284
1285 return false;
1286}
bool hitTest(const QPointF &position) const override
reimplemented
KoShapeContainer * parent() const
Definition KoShape.cpp:862
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:745

References KoShape::absoluteTransformation(), KoInsets::bottom, hitTest(), KoInsets::left, map(), outline(), KoShape::parent(), KoShape::position(), KoInsets::right, KoShape::stroke(), and KoInsets::top.

◆ insertPoint()

bool KoPathShape::insertPoint ( KoPathPoint * point,
const KoPathPointIndex & pointIndex )

Inserts a new point into the given subpath at the specified position.

This method keeps the subpath closed if it is closed, and open when it was open. So it can change the properties of the point inserted. You might need to update the point before/after to get the desired result e.g. when you insert the point into a curve.

Parameters
pointto insert
pointIndexindex at which the point should be inserted
Returns
true on success, false when pointIndex is out of bounds

Definition at line 661 of file KoPathShape.cpp.

662{
663 KoSubpath *subpath = d->subPath(pointIndex.first);
664
665 if (subpath == 0 || pointIndex.second < 0 || pointIndex.second > subpath->size())
666 return false;
667
668 KoPathPoint::PointProperties properties = point->properties();
669 properties &= ~KoPathPoint::StartSubpath;
670 properties &= ~KoPathPoint::StopSubpath;
671 properties &= ~KoPathPoint::CloseSubpath;
672 // check if new point starts subpath
673 if (pointIndex.second == 0) {
674 properties |= KoPathPoint::StartSubpath;
675 // subpath was closed
676 if (subpath->last()->properties() & KoPathPoint::CloseSubpath) {
677 // keep the path closed
678 properties |= KoPathPoint::CloseSubpath;
679 }
680 // old first point does not start the subpath anymore
681 subpath->first()->unsetProperty(KoPathPoint::StartSubpath);
682 }
683 // check if new point stops subpath
684 else if (pointIndex.second == subpath->size()) {
685 properties |= KoPathPoint::StopSubpath;
686 // subpath was closed
687 if (subpath->last()->properties() & KoPathPoint::CloseSubpath) {
688 // keep the path closed
689 properties = properties | KoPathPoint::CloseSubpath;
690 }
691 // old last point does not end subpath anymore
692 subpath->last()->unsetProperty(KoPathPoint::StopSubpath);
693 }
694
695 point->setProperties(properties);
696 point->setParent(this);
697 subpath->insert(pointIndex.second , point);
699
700 return true;
701}
void setProperties(PointProperties properties)
Set the properties of a point.

References KoPathPoint::CloseSubpath, d, notifyPointsChanged(), KoPathPoint::properties, KoPathPoint::setParent(), KoPathPoint::setProperties(), KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ isClosedSubpath()

bool KoPathShape::isClosedSubpath ( int subpathIndex) const

Checks if a subpath is closed.

Parameters
subpathIndexindex of the subpath to check
Returns
true when the subpath is closed, false otherwise

Definition at line 648 of file KoPathShape.cpp.

649{
650 KoSubpath *subpath = d->subPath(subpathIndex);
651
652 if (subpath == 0)
653 return false;
654
655 const bool firstClosed = subpath->first()->properties() & KoPathPoint::CloseSubpath;
656 const bool lastClosed = subpath->last()->properties() & KoPathPoint::CloseSubpath;
657
658 return firstClosed && lastClosed;
659}

References KoPathPoint::CloseSubpath, and d.

◆ join()

bool KoPathShape::join ( int subpathIndex)

Joins the given subpath with the following one.

Joins the given subpath with the following one by inserting a segment between the two subpaths. This does nothing if the specified subpath is the last subpath or one of both subpaths is closed.

Parameters
subpathIndexindex of the subpath being joined with the following subpath
Returns
true if the subpath was joined, otherwise false

Definition at line 769 of file KoPathShape.cpp.

770{
771 KoSubpath *subpath = d->subPath(subpathIndex);
772 KoSubpath *nextSubpath = d->subPath(subpathIndex + 1);
773
774 if (!subpath || !nextSubpath || isClosedSubpath(subpathIndex)
775 || isClosedSubpath(subpathIndex+1))
776 return false;
777
778 // the last point of the subpath does not end the subpath anymore
779 subpath->last()->unsetProperty(KoPathPoint::StopSubpath);
780 // the first point of the next subpath does not start a subpath anymore
781 nextSubpath->first()->unsetProperty(KoPathPoint::StartSubpath);
782
783 // append the second subpath to the first
784 Q_FOREACH (KoPathPoint * p, *nextSubpath)
785 subpath->append(p);
786
787 // remove the nextSubpath from path
788 d->subpaths.removeAt(subpathIndex + 1);
789
790 // delete it as it is no longer possible to use it
791 delete nextSubpath;
792
794
795 return true;
796}

References d, isClosedSubpath(), notifyPointsChanged(), p, KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ lineTo()

KoPathPoint * KoPathShape::lineTo ( const QPointF & p)

Adds a new line segment.

Adds a straight line between the last point and the given point p.

Returns
the newly created point

Definition at line 342 of file KoPathShape.cpp.

343{
344 if (d->subpaths.empty()) {
345 moveTo(QPointF(0, 0));
346 }
348 KoPathPoint * lastPoint = d->subpaths.last()->last();
349 updateLastPriv(&lastPoint);
350 d->subpaths.last()->push_back(point);
352 return point;
353}

References d, moveTo(), notifyPointsChanged(), p, KoPathPoint::StopSubpath, and updateLastPriv().

◆ loadNodeTypes()

void KoPathShape::loadNodeTypes ( const QString & nodeTypes)

Loads node types.

Definition at line 1199 of file KoPathShape.cpp.

1200{
1201 QString::const_iterator nIt(nodeTypes.constBegin());
1202 KoSubpathList::const_iterator pathIt(d->subpaths.constBegin());
1203 for (; pathIt != d->subpaths.constEnd(); ++pathIt) {
1204 KoSubpath::const_iterator it((*pathIt)->constBegin());
1205 for (; it != (*pathIt)->constEnd(); ++it, nIt++) {
1206 // be sure not to crash if there are not enough nodes in nodeTypes
1207 if (nIt == nodeTypes.constEnd()) {
1208 warnFlake << "not enough nodes in sodipodi:nodetypes";
1209 return;
1210 }
1211 // the first node is always of type 'c'
1212 if (it != (*pathIt)->constBegin()) {
1213 updateNodeType(*it, *nIt);
1214 }
1215
1216 if ((*it)->properties() & KoPathPoint::StopSubpath
1217 && (*it)->properties() & KoPathPoint::CloseSubpath) {
1218 ++nIt;
1219 updateNodeType((*pathIt)->first(), *nIt);
1220 }
1221 }
1222 }
1223}
#define warnFlake
Definition FlakeDebug.h:16
void updateNodeType(KoPathPoint *point, const QChar &nodeType)
QString nodeTypes() const
Saves the node types.

References KoPathPoint::CloseSubpath, d, nodeTypes(), KoPathPoint::StopSubpath, updateNodeType(), and warnFlake.

◆ map()

void KoPathShape::map ( const QTransform & matrix)
protected

Definition at line 1052 of file KoPathShape.cpp.

1053{
1054 return d->map(matrix);
1055}

References d.

◆ marker()

KoMarker * KoPathShape::marker ( KoFlake::MarkerPosition pos) const

Definition at line 1300 of file KoPathShape.cpp.

1301{
1302 return d->markersNew[pos].data();
1303}

References d.

◆ moveSubpath()

bool KoPathShape::moveSubpath ( int oldSubpathIndex,
int newSubpathIndex )

Moves the position of a subpath within a path.

Parameters
oldSubpathIndexold index of the subpath
newSubpathIndexnew index of the subpath
Returns
true if the subpath was moved, otherwise false e.g. if an index is out of bounds

Definition at line 798 of file KoPathShape.cpp.

799{
800 KoSubpath *subpath = d->subPath(oldSubpathIndex);
801
802 if (subpath == 0 || newSubpathIndex >= d->subpaths.size())
803 return false;
804
805 if (oldSubpathIndex == newSubpathIndex)
806 return true;
807
808 d->subpaths.removeAt(oldSubpathIndex);
809 d->subpaths.insert(newSubpathIndex, subpath);
810
812
813 return true;
814}

References d, and notifyPointsChanged().

◆ moveTo()

KoPathPoint * KoPathShape::moveTo ( const QPointF & p)

Starts a new Subpath.

Moves the pen to p and starts a new subpath.

Returns
the newly created point

Definition at line 332 of file KoPathShape.cpp.

333{
335 KoSubpath * path = new KoSubpath;
336 path->push_back(point);
337 d->subpaths.push_back(path);
339 return point;
340}

References d, notifyPointsChanged(), p, KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ nodeTypes()

QString KoPathShape::nodeTypes ( ) const

Saves the node types.

This is inspired by inkscape and uses the same mechanism as they do. This attribute contains of a string which has the node type of each point in it. The following node types exist:

c corner s smooth z symmetric

The first point of a path is always of the type c. If the path is closed the type of the first point is saved in the last element E.g. you have a closed path with 2 points in it. The first one (start/end of path) is symmetric and the second one is smooth that will result in the nodeType="czs" So if there is a closed sub path the nodeTypes contain one more entry then there are points. That is due to the first and the last point of a closed sub path get merged into one when they are on the same position.

Returns
The node types as string

Definition at line 1165 of file KoPathShape.cpp.

1166{
1167 QString types;
1168 KoSubpathList::const_iterator pathIt(d->subpaths.constBegin());
1169 for (; pathIt != d->subpaths.constEnd(); ++pathIt) {
1170 KoSubpath::const_iterator it((*pathIt)->constBegin());
1171 for (; it != (*pathIt)->constEnd(); ++it) {
1172 if (it == (*pathIt)->constBegin()) {
1173 types.append('c');
1174 }
1175 else {
1176 types.append(nodeType(*it));
1177 }
1178
1179 if ((*it)->properties() & KoPathPoint::StopSubpath
1180 && (*it)->properties() & KoPathPoint::CloseSubpath) {
1181 KoPathPoint * firstPoint = (*pathIt)->first();
1182 types.append(nodeType(firstPoint));
1183 }
1184 }
1185 }
1186 return types;
1187}
char nodeType(const KoPathPoint *point)

References KoPathPoint::CloseSubpath, d, nodeType(), and KoPathPoint::StopSubpath.

◆ normalize()

QPointF KoPathShape::normalize ( )
virtual

Normalizes the path data.

The path points are transformed so that the top-left corner of the bounding rect is at (0,0). This should be called after adding points to the path or changing positions of path points.

Returns
the offset by which the points are moved in shape coordinates.

Reimplemented in KoParameterShape, EllipseShape, SpiralShape, and KarbonCalligraphicShape.

Definition at line 480 of file KoPathShape.cpp.

481{
482 QPointF tl(outline().boundingRect().topLeft());
483 QTransform matrix;
484 matrix.translate(-tl.x(), -tl.y());
485 d->map(matrix);
486
487 // keep the top left point of the object
488 applyTransformation(matrix.inverted());
490 return tl;
491}
void applyTransformation(const QTransform &matrix)
Definition KoShape.cpp:363
void shapeChangedPriv(KoShape::ChangeType type)
Definition KoShape.cpp:104
@ ContentChanged
the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
Definition KoShape.h:106

References KoShape::applyTransformation(), boundingRect(), KoShape::ContentChanged, d, outline(), and KoShape::shapeChangedPriv().

◆ notifyPointsChanged()

void KoPathShape::notifyPointsChanged ( )
protected

Definition at line 1362 of file KoPathShape.cpp.

1363{
1364 Q_FOREACH (KoShape::ShapeChangeListener *listener, listeners()) {
1365 PointSelectionChangeListener *pointListener = dynamic_cast<PointSelectionChangeListener*>(listener);
1366 if (pointListener) {
1367 pointListener->notifyPathPointsChanged(this);
1368 }
1369 }
1370}
QList< ShapeChangeListener * > listeners() const
Definition KoShape.cpp:1173

References KoShape::listeners(), and KoPathShape::PointSelectionChangeListener::notifyPathPointsChanged().

◆ openSubpath()

KoPathPointIndex KoPathShape::openSubpath ( const KoPathPointIndex & pointIndex)

Opens a closed subpath.

The subpath is opened by removing the segment before the given point, making the given point the new start point of the subpath.

Parameters
pointIndexthe index of the point at which to open the closed subpath
Returns
the new position of the old first point in the subpath otherwise KoPathPointIndex( -1, -1 )

Definition at line 816 of file KoPathShape.cpp.

817{
818 KoSubpath *subpath = d->subPath(pointIndex.first);
819
820 if (!subpath || pointIndex.second < 0 || pointIndex.second >= subpath->size()
821 || !isClosedSubpath(pointIndex.first))
822 return KoPathPointIndex(-1, -1);
823
824 KoPathPoint * oldStartPoint = subpath->first();
825 // the old starting node no longer starts the subpath
827 // the old end node no longer closes the subpath
828 subpath->last()->unsetProperty(KoPathPoint::StopSubpath);
829
830 // reorder the subpath
831 for (int i = 0; i < pointIndex.second; ++i) {
832 subpath->append(subpath->takeFirst());
833 }
834 // make the first point a start node
835 subpath->first()->setProperty(KoPathPoint::StartSubpath);
836 // make the last point an end node
837 subpath->last()->setProperty(KoPathPoint::StopSubpath);
838
840
841 return pathPointIndex(oldStartPoint);
842}

References d, isClosedSubpath(), notifyPointsChanged(), pathPointIndex(), KoPathPoint::StartSubpath, KoPathPoint::StopSubpath, and KoPathPoint::unsetProperty().

◆ outline()

QPainterPath KoPathShape::outline ( ) const
overridevirtual

reimplemented

Reimplemented from KoShape.

Definition at line 184 of file KoPathShape.cpp.

185{
186 QPainterPath path;
187 for (auto subpathIt = d->subpaths.constBegin(); subpathIt != d->subpaths.constEnd(); ++subpathIt) {
188 const KoSubpath * subpath = *subpathIt;
189 const KoPathPoint * lastPoint = subpath->constFirst();
190 bool activeCP = false;
191 for (auto pointIt = subpath->constBegin(); pointIt != subpath->constEnd(); ++pointIt) {
192 const KoPathPoint * currPoint = *pointIt;
193 KoPathPoint::PointProperties currProperties = currPoint->properties();
194 if (currPoint == subpath->constFirst()) {
195 if (currProperties & KoPathPoint::StartSubpath) {
196 Q_ASSERT(!qIsNaNPoint(currPoint->point()));
197 path.moveTo(currPoint->point());
198 }
199 } else if (activeCP && currPoint->activeControlPoint1()) {
200 Q_ASSERT(!qIsNaNPoint(lastPoint->controlPoint2()));
201 Q_ASSERT(!qIsNaNPoint(currPoint->controlPoint1()));
202 Q_ASSERT(!qIsNaNPoint(currPoint->point()));
203 path.cubicTo(
204 lastPoint->controlPoint2(),
205 currPoint->controlPoint1(),
206 currPoint->point());
207 } else if (activeCP || currPoint->activeControlPoint1()) {
208 Q_ASSERT(!qIsNaNPoint(lastPoint->controlPoint2()));
209 Q_ASSERT(!qIsNaNPoint(currPoint->controlPoint1()));
210 path.quadTo(
211 activeCP ? lastPoint->controlPoint2() : currPoint->controlPoint1(),
212 currPoint->point());
213 } else {
214 Q_ASSERT(!qIsNaNPoint(currPoint->point()));
215 path.lineTo(currPoint->point());
216 }
217 if (currProperties & KoPathPoint::CloseSubpath && currProperties & KoPathPoint::StopSubpath) {
218 // add curve when there is a curve on the way to the first point
219 KoPathPoint * firstPoint = subpath->first();
220 Q_ASSERT(!qIsNaNPoint(firstPoint->point()));
221 if (currPoint->activeControlPoint2() && firstPoint->activeControlPoint1()) {
222 path.cubicTo(
223 currPoint->controlPoint2(),
224 firstPoint->controlPoint1(),
225 firstPoint->point());
226 }
227 else if (currPoint->activeControlPoint2() || firstPoint->activeControlPoint1()) {
228 Q_ASSERT(!qIsNaNPoint(currPoint->point()));
229 Q_ASSERT(!qIsNaNPoint(currPoint->controlPoint1()));
230 path.quadTo(
231 currPoint->activeControlPoint2() ? currPoint->controlPoint2() : firstPoint->controlPoint1(),
232 firstPoint->point());
233 }
234 path.closeSubpath();
235 }
236
237 if (currPoint->activeControlPoint2()) {
238 activeCP = true;
239 } else {
240 activeCP = false;
241 }
242 lastPoint = currPoint;
243 }
244 }
245
246 return path;
247}
static bool qIsNaNPoint(const QPointF &p)
bool activeControlPoint2
QPointF controlPoint2

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::CloseSubpath, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, d, KoPathPoint::point, KoPathPoint::properties, qIsNaNPoint(), KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ outlineRect()

QRectF KoPathShape::outlineRect ( ) const
overridevirtual

reimplemented

Reimplemented from KoShape.

Definition at line 179 of file KoPathShape.cpp.

180{
181 return outline().boundingRect();
182}

References outline().

◆ paint()

void KoPathShape::paint ( QPainter & painter) const
overridevirtual

reimplemented

Implements KoShape.

Definition at line 106 of file KoPathShape.cpp.

107{
108 KisQPainterStateSaver saver(&painter);
109 Q_UNUSED(saver);
110
111 QPainterPath path(outline());
112 path.setFillRule(d->fillRule);
113
114 if (background()) {
115 background()->paint(painter, path);
116 }
117 //d->paintDebug(painter);
118}
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:759

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

◆ paintPoints()

void KoPathShape::paintPoints ( KisHandlePainterHelper & handlesHelper)
virtual

Definition at line 168 of file KoPathShape.cpp.

169{
170 KoSubpathList::const_iterator pathIt(d->subpaths.constBegin());
171
172 for (; pathIt != d->subpaths.constEnd(); ++pathIt) {
173 KoSubpath::const_iterator it((*pathIt)->constBegin());
174 for (; it != (*pathIt)->constEnd(); ++it)
175 (*it)->paint(handlesHelper, KoPathPoint::Node);
176 }
177}
@ Node
the node point
Definition KoPathPoint.h:49

References d, and KoPathPoint::Node.

◆ pathPointIndex()

KoPathPointIndex KoPathShape::pathPointIndex ( const KoPathPoint * point) const

Returns the path point index of a given path point.

Parameters
pointthe point for which you want to get the index
Returns
path point index of the point if it exists otherwise KoPathPointIndex( -1, -1 )

Definition at line 577 of file KoPathShape.cpp.

578{
579 for (int subpathIndex = 0; subpathIndex < d->subpaths.size(); ++subpathIndex) {
580 KoSubpath * subpath = d->subpaths.at(subpathIndex);
581 for (int pointPos = 0; pointPos < subpath->size(); ++pointPos) {
582 if (subpath->at(pointPos) == point) {
583 return KoPathPointIndex(subpathIndex, pointPos);
584 }
585 }
586 }
587 return KoPathPointIndex(-1, -1);
588}

References d.

◆ pathShapeId()

QString KoPathShape::pathShapeId ( ) const
virtual

Returns the specific path shape id.

Path shape derived shapes have a different shape id which link them to their respective shape factories. In most cases they do not have a special tool for editing them. This function returns the specific shape id for finding the shape factory from KoShapeRegistry. The default KoPathShapeId is returned from KoShape::shapeId() so that the generic path editing tool gets activated when the shape is selected.

Returns
the specific shape id

Reimplemented in EllipseShape, RectangleShape, SpiralShape, StarShape, and KarbonCalligraphicShape.

Definition at line 1065 of file KoPathShape.cpp.

1066{
1067 return KoPathShapeId;
1068}

References KoPathShapeId.

◆ pathStroke()

QPainterPath KoPathShape::pathStroke ( const QPen & pen) const

Definition at line 1372 of file KoPathShape.cpp.

1373{
1374 if (d->subpaths.isEmpty()) {
1375 return QPainterPath();
1376 }
1377 QPainterPath pathOutline;
1378
1379 QPainterPathStroker stroker;
1380 stroker.setWidth(0);
1381 stroker.setJoinStyle(Qt::MiterJoin);
1382 stroker.setWidth(pen.widthF());
1383 stroker.setJoinStyle(pen.joinStyle());
1384 stroker.setMiterLimit(pen.miterLimit());
1385 stroker.setCapStyle(pen.capStyle());
1386 stroker.setDashOffset(pen.dashOffset());
1387 stroker.setDashPattern(pen.dashPattern());
1388
1389 QPainterPath path = stroker.createStroke(outline());
1390
1391 pathOutline.addPath(path);
1392 pathOutline.setFillRule(Qt::WindingFill);
1393
1394 return pathOutline;
1395}

References d, and outline().

◆ pointByIndex()

KoPathPoint * KoPathShape::pointByIndex ( const KoPathPointIndex & pointIndex) const

Returns the path point specified by a path point index.

Parameters
pointIndexindex of the point to get
Returns
KoPathPoint on success, 0 otherwise e.g. out of bounds

Definition at line 590 of file KoPathShape.cpp.

591{
592 KoSubpath *subpath = d->subPath(pointIndex.first);
593
594 if (subpath == 0 || pointIndex.second < 0 || pointIndex.second >= subpath->size())
595 return 0;
596
597 return subpath->at(pointIndex.second);
598}

References d.

◆ pointCount()

int KoPathShape::pointCount ( ) const

Returns the number of points in the path.

Returns
The number of points in the path

Definition at line 622 of file KoPathShape.cpp.

623{
624 int i = 0;
625 KoSubpathList::const_iterator pathIt(d->subpaths.constBegin());
626 for (; pathIt != d->subpaths.constEnd(); ++pathIt) {
627 i += (*pathIt)->size();
628 }
629
630 return i;
631}

References d.

◆ pointsAt()

QList< KoPathPoint * > KoPathShape::pointsAt ( const QRectF & rect,
const bool useControlPoints = false ) const

Returns the path points within the given rectangle.

Parameters
rectthe rectangle the requested points are in
useControlPointswhether to add control points to result or not
Returns
list of points within the rectangle

Definition at line 531 of file KoPathShape.cpp.

532{
533 QList<KoPathPoint*> result;
534
535 KoSubpathList::const_iterator pathIt(d->subpaths.constBegin());
536 for (; pathIt != d->subpaths.constEnd(); ++pathIt) {
537 KoSubpath::const_iterator it((*pathIt)->constBegin());
538 for (; it != (*pathIt)->constEnd(); ++it) {
539 if (r.contains((*it)->point()))
540 result.append(*it);
541 else if (useControlPoints) {
542 if ((*it)->activeControlPoint1() && r.contains((*it)->controlPoint1()))
543 result.append(*it);
544 else if ((*it)->activeControlPoint2() && r.contains((*it)->controlPoint2()))
545 result.append(*it);
546 }
547 }
548 }
549 return result;
550}

References d.

◆ recommendPointSelectionChange()

void KoPathShape::recommendPointSelectionChange ( const QList< KoPathPointIndex > & newSelection)

Definition at line 1352 of file KoPathShape.cpp.

1353{
1354 Q_FOREACH (KoShape::ShapeChangeListener *listener, listeners()) {
1355 PointSelectionChangeListener *pointListener = dynamic_cast<PointSelectionChangeListener*>(listener);
1356 if (pointListener) {
1357 pointListener->recommendPointSelectionChange(this, newSelection);
1358 }
1359 }
1360}

References KoShape::listeners(), and KoPathShape::PointSelectionChangeListener::recommendPointSelectionChange().

◆ removePoint()

KoPathPoint * KoPathShape::removePoint ( const KoPathPointIndex & pointIndex)

Removes a point from the path.

Note that the ownership of the point will pass to the caller.

Parameters
pointIndexindex of the point which should be removed
Returns
The removed point on success, otherwise 0

Definition at line 703 of file KoPathShape.cpp.

704{
705 KoSubpath *subpath = d->subPath(pointIndex.first);
706
707 if (subpath == 0 || pointIndex.second < 0 || pointIndex.second >= subpath->size())
708 return 0;
709
710 KoPathPoint * point = subpath->takeAt(pointIndex.second);
711 point->setParent(0);
712
713 //don't do anything (not even crash), if there was only one point
714 if (pointCount()==0) {
715 return point;
716 }
717 // check if we removed the first point
718 else if (pointIndex.second == 0) {
719 // first point removed, set new StartSubpath
720 subpath->first()->setProperty(KoPathPoint::StartSubpath);
721 // check if path was closed
722 if (subpath->last()->properties() & KoPathPoint::CloseSubpath) {
723 // keep path closed
724 subpath->first()->setProperty(KoPathPoint::CloseSubpath);
725 }
726 }
727 // check if we removed the last point
728 else if (pointIndex.second == subpath->size()) { // use size as point is already removed
729 // last point removed, set new StopSubpath
730 subpath->last()->setProperty(KoPathPoint::StopSubpath);
731 // check if path was closed
732 if (point->properties() & KoPathPoint::CloseSubpath) {
733 // keep path closed
734 subpath->last()->setProperty(KoPathPoint::CloseSubpath);
735 }
736 }
737
739
740 return point;
741}
int pointCount() const
Returns the number of points in the path.

References KoPathPoint::CloseSubpath, d, notifyPointsChanged(), pointCount(), KoPathPoint::properties, KoPathPoint::setParent(), KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ removeSubpath()

KoSubpath * KoPathShape::removeSubpath ( int subpathIndex)

Removes subpath from the path.

Parameters
subpathIndexthe index of the subpath to remove
Returns
the removed subpath on success, 0 otherwise.

Definition at line 909 of file KoPathShape.cpp.

910{
911 KoSubpath *subpath = d->subPath(subpathIndex);
912
913 if (subpath != 0) {
914 Q_FOREACH (KoPathPoint* point, *subpath) {
915 point->setParent(this);
916 }
917 d->subpaths.removeAt(subpathIndex);
918 }
919
921
922 return subpath;
923}

References d, notifyPointsChanged(), and KoPathPoint::setParent().

◆ resizeMatrix()

QTransform KoPathShape::resizeMatrix ( const QSizeF & newSize) const
protected

Get the resize matrix

This makes sure that also if the newSize isNull that there will be a very small size of 0.000001 pixels

Definition at line 311 of file KoPathShape.cpp.

312{
313 QSizeF oldSize = size();
314 if (oldSize.width() == 0.0) {
315 oldSize.setWidth(0.000001);
316 }
317 if (oldSize.height() == 0.0) {
318 oldSize.setHeight(0.000001);
319 }
320
321 QSizeF sizeNew(newSize);
322 if (sizeNew.width() == 0.0) {
323 sizeNew.setWidth(0.000001);
324 }
325 if (sizeNew.height() == 0.0) {
326 sizeNew.setHeight(0.000001);
327 }
328
329 return QTransform(sizeNew.width() / oldSize.width(), 0, 0, sizeNew.height() / oldSize.height(), 0, 0);
330}

References size().

◆ reverseSubpath()

bool KoPathShape::reverseSubpath ( int subpathIndex)

Reverse subpath.

The last point becomes the first point and the first one becomes the last one.

Parameters
subpathIndexthe index of the subpath to reverse

Definition at line 872 of file KoPathShape.cpp.

873{
874 KoSubpath *subpath = d->subPath(subpathIndex);
875
876 if (subpath == 0)
877 return false;
878
879 int size = subpath->size();
880 for (int i = 0; i < size; ++i) {
881 KoPathPoint *p = subpath->takeAt(i);
882 p->reverse();
883 subpath->prepend(p);
884 }
885
886 // adjust the position dependent properties
887 KoPathPoint *first = subpath->first();
888 KoPathPoint *last = subpath->last();
889
890 KoPathPoint::PointProperties firstProps = first->properties();
891 KoPathPoint::PointProperties lastProps = last->properties();
892
893 firstProps |= KoPathPoint::StartSubpath;
894 firstProps &= ~KoPathPoint::StopSubpath;
895 lastProps |= KoPathPoint::StopSubpath;
896 lastProps &= ~KoPathPoint::StartSubpath;
897 if (firstProps & KoPathPoint::CloseSubpath) {
898 firstProps |= KoPathPoint::CloseSubpath;
899 lastProps |= KoPathPoint::CloseSubpath;
900 }
901 first->setProperties(firstProps);
902 last->setProperties(lastProps);
903
905
906 return true;
907}

References KoPathPoint::CloseSubpath, d, notifyPointsChanged(), p, KoPathPoint::properties, KoPathPoint::setProperties(), size(), KoPathPoint::StartSubpath, and KoPathPoint::StopSubpath.

◆ segmentAtPoint()

KoPathSegment KoPathShape::segmentAtPoint ( const QPointF & point,
const QRectF & grabRoi ) const

Definition at line 1320 of file KoPathShape.cpp.

1321{
1322 const qreal distanceThreshold = 0.5 * KisAlgebra2D::maxDimension(grabRoi);
1323 KoPathSegment segment;
1324
1325 // convert document point to shape coordinates
1326 const QPointF p = documentToShape(point);
1327 // our region of interest, i.e. a region around our mouse position
1328 const QRectF roi = documentToShape(grabRoi);
1329
1330 qreal minDistance = std::numeric_limits<qreal>::max();
1331
1332 // check all segments of this shape which intersect the region of interest
1333 const QList<KoPathSegment> segments = segmentsAt(roi);
1334
1335 foreach (KoPathSegment s, segments) {
1336 const qreal nearestPointParam = s.nearestPoint(p);
1337 const QPointF nearestPoint = s.pointAt(nearestPointParam);
1338 const qreal distance = kisDistance(p, nearestPoint);
1339
1340 // are we within the allowed distance ?
1341 if (distance > distanceThreshold)
1342 continue;
1343 // are we closer to the last closest point ?
1344 if (distance < minDistance) {
1345 segment = s;
1346 }
1347 }
1348
1349 return segment;
1350}
qreal distance(const QPointF &p1, const QPointF &p2)
A KoPathSegment consist of two neighboring KoPathPoints.
QList< KoPathSegment > segmentsAt(const QRectF &rect) const
Returns the list of path segments within the given rectangle.
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1016
QSharedDataPointer< SharedData > s
Definition KoShape.h:977
qreal kisDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:190
auto maxDimension(Size size) -> decltype(size.width())
qreal nearestPoint(const QList< QPointF > controlPoints, const QPointF &point, qreal *resultDistance, QPointF *resultPoint)

References distance(), KoShape::documentToShape(), kisDistance(), KisAlgebra2D::maxDimension(), p, KoShape::s, and segmentsAt().

◆ segmentByIndex()

KoPathSegment KoPathShape::segmentByIndex ( const KoPathPointIndex & pointIndex) const

Returns the segment specified by a path point index.

A segment is defined by the point index of the first point in the segment. A segment contains the defined point and its following point. If the subpath is closed and the and the pointIndex point to the last point in the subpath, the following point is the first point in the subpath.

Parameters
pointIndexindex of the first point of the segment
Returns
Segment containing both points of the segment or KoPathSegment( 0, 0 ) on error e.g. out of bounds

Definition at line 600 of file KoPathShape.cpp.

601{
602 KoPathSegment segment(0, 0);
603
604 KoSubpath *subpath = d->subPath(pointIndex.first);
605
606 if (subpath != 0 && pointIndex.second >= 0 && pointIndex.second < subpath->size()) {
607 KoPathPoint * point = subpath->at(pointIndex.second);
608 int index = pointIndex.second;
609 // check if we have a (closing) segment starting from the last point
610 if ((index == subpath->size() - 1) && point->properties() & KoPathPoint::CloseSubpath)
611 index = 0;
612 else
613 ++index;
614
615 if (index < subpath->size()) {
616 segment = KoPathSegment(point, subpath->at(index));
617 }
618 }
619 return segment;
620}

References KoPathPoint::CloseSubpath, d, KoPathPoint::properties, and size().

◆ segmentsAt()

QList< KoPathSegment > KoPathShape::segmentsAt ( const QRectF & rect) const

Returns the list of path segments within the given rectangle.

Parameters
rectthe rectangle the requested segments are in
Returns
list of segments within the rectangle

Definition at line 552 of file KoPathShape.cpp.

553{
554 QList<KoPathSegment> segments;
555 int subpathCount = d->subpaths.count();
556 for (int subpathIndex = 0; subpathIndex < subpathCount; ++subpathIndex) {
557 KoSubpath * subpath = d->subpaths[subpathIndex];
558 int pointCount = subpath->count();
559 bool subpathClosed = isClosedSubpath(subpathIndex);
560 for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex) {
561 if (pointIndex == (pointCount - 1) && ! subpathClosed)
562 break;
563 KoPathSegment s(subpath->at(pointIndex), subpath->at((pointIndex + 1) % pointCount));
564 QRectF controlRect = s.controlPointRect();
565 if (! r.intersects(controlRect) && ! controlRect.contains(r))
566 continue;
567 QRectF bound = s.boundingRect();
568 if (! r.intersects(bound) && ! bound.contains(r))
569 continue;
570
571 segments.append(s);
572 }
573 }
574 return segments;
575}
int subpathCount() const
Returns the number of subpaths in the path.

References d, isClosedSubpath(), pointCount(), KoShape::s, and subpathCount().

◆ separate()

bool KoPathShape::separate ( QList< KoPathShape * > & separatedPaths)

Creates separate path shapes, one for each existing subpath.

Parameters
separatedPathsthe list which contains the separated path shapes
Returns
true if separating the path was successful, false otherwise

Definition at line 969 of file KoPathShape.cpp.

970{
971 if (! d->subpaths.size())
972 return false;
973
974 QTransform myMatrix = absoluteTransformation();
975
976 Q_FOREACH (KoSubpath* subpath, d->subpaths) {
977 KoPathShape *shape = new KoPathShape();
978
979 shape->setStroke(stroke());
980 shape->setBackground(background());
981 shape->setShapeId(shapeId());
982 shape->setZIndex(zIndex());
983
984 KoSubpath *newSubpath = new KoSubpath();
985
986 Q_FOREACH (KoPathPoint* point, *subpath) {
987 KoPathPoint *newPoint = new KoPathPoint(*point, shape);
988 newPoint->map(myMatrix);
989 newSubpath->append(newPoint);
990 }
991 shape->d->subpaths.append(newSubpath);
992 shape->normalize();
993
994 // NOTE: shape cannot have any listeners yet, so no notification about
995 // points modification is needed
996
997 separatedPaths.append(shape);
998 }
999 return true;
1000}
void setZIndex(qint16 zIndex)
Definition KoShape.cpp:787
QString shapeId() const
Definition KoShape.cpp:880
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:904
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:751
qint16 zIndex() const
Definition KoShape.cpp:529

References KoShape::absoluteTransformation(), KoShape::background(), d, KoPathShape(), KoPathPoint::map(), normalize(), KoShape::setBackground(), KoShape::setShapeId(), KoShape::setStroke(), KoShape::setZIndex(), KoShape::shapeId(), KoShape::stroke(), and KoShape::zIndex().

◆ setAutoFillMarkers()

void KoPathShape::setAutoFillMarkers ( bool value)

Definition at line 1315 of file KoPathShape.cpp.

1316{
1317 d->autoFillMarkers = value;
1318}
float value(const T *src, size_t ch)

References d, and value().

◆ setFillRule()

void KoPathShape::setFillRule ( Qt::FillRule fillRule)

Sets the fill rule to be used for painting the background.

Definition at line 1230 of file KoPathShape.cpp.

1231{
1232 d->fillRule = fillRule;
1233}
Qt::FillRule fillRule() const
Returns the fill rule for the path object.

References d, and fillRule().

◆ setMarker()

void KoPathShape::setMarker ( KoMarker * marker,
KoFlake::MarkerPosition pos )

Definition at line 1288 of file KoPathShape.cpp.

1289{
1290 if (!marker && d->markersNew.contains(pos)) {
1291 d->markersNew.remove(pos);
1292 } else {
1293 d->markersNew[pos] = marker;
1294 }
1295
1296 notifyChanged();
1298}
KoMarker * marker(KoFlake::MarkerPosition pos) const
@ StrokeChanged
the shapes stroke has changed
Definition KoShape.h:102
void notifyChanged()
Definition KoShape.cpp:618

References d, marker(), KoShape::notifyChanged(), KoShape::shapeChangedPriv(), and KoShape::StrokeChanged.

◆ setSize()

void KoPathShape::setSize ( const QSizeF & size)
overridevirtual

Resize the shape

This makes sure that the pathshape will not be resized to 0 if the new size is null as that makes it impossible to undo the change.

All functions that overwrite this function should also use the resizeMatrix function to get and use the same data in resizing.

See also
resizeMatrix()

Reimplemented from KoShape.

Reimplemented in SpiralShape, and StarShape.

Definition at line 303 of file KoPathShape.cpp.

304{
305 QTransform matrix(resizeMatrix(newSize));
306
307 KoShape::setSize(newSize);
308 d->map(matrix);
309}
QTransform resizeMatrix(const QSizeF &newSize) const
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:248

References d, resizeMatrix(), and KoShape::setSize().

◆ size()

QSizeF KoPathShape::size ( ) const
overridevirtual

reimplemented

Reimplemented from KoShape.

Definition at line 296 of file KoPathShape.cpp.

297{
298 // don't call boundingRect here as it uses absoluteTransformation
299 // which itself uses size() -> leads to infinite recursion
300 return outlineRect().size();
301}
QRectF outlineRect() const override
reimplemented

References outlineRect().

◆ subpathCount()

int KoPathShape::subpathCount ( ) const

Returns the number of subpaths in the path.

Returns
The number of subpaths in the path

Definition at line 633 of file KoPathShape.cpp.

634{
635 return d->subpaths.count();
636}

References d.

◆ subpathPointCount()

int KoPathShape::subpathPointCount ( int subpathIndex) const

Returns the number of points in a subpath.

Returns
The number of points in the subpath or -1 if subpath out of bounds

Definition at line 638 of file KoPathShape.cpp.

639{
640 KoSubpath *subpath = d->subPath(subpathIndex);
641
642 if (subpath == 0)
643 return -1;
644
645 return subpath->size();
646}

References d.

◆ subpaths() [1/2]

KoSubpathList & KoPathShape::subpaths ( )
protected

XXX: refactor this using setter?

Definition at line 1047 of file KoPathShape.cpp.

1048{
1049 return d->subpaths;
1050}

References d.

◆ subpaths() [2/2]

const KoSubpathList & KoPathShape::subpaths ( ) const
protected

Definition at line 1042 of file KoPathShape.cpp.

1043{
1044 return d->subpaths;
1045}

References d.

◆ toString()

QString KoPathShape::toString ( const QTransform & matrix = QTransform()) const

Returns a odf/svg string representation of the path data with the given matrix applied.

Definition at line 1070 of file KoPathShape.cpp.

1071{
1072 QString pathString;
1073
1074 // iterate over all subpaths
1075 KoSubpathList::const_iterator pathIt(d->subpaths.constBegin());
1076 for (; pathIt != d->subpaths.constEnd(); ++pathIt) {
1077 KoSubpath::const_iterator pointIt((*pathIt)->constBegin());
1078 // keep a pointer to the first point of the subpath
1079 KoPathPoint *firstPoint(*pointIt);
1080 // keep a pointer to the previous point of the subpath
1081 KoPathPoint *lastPoint = firstPoint;
1082 // keep track if the previous point has an active control point 2
1083 bool activeControlPoint2 = false;
1084
1085 // iterate over all points of the current subpath
1086 for (; pointIt != (*pathIt)->constEnd(); ++pointIt) {
1087 KoPathPoint *currPoint(*pointIt);
1088 if (!currPoint) {
1089 qWarning() << "Found a zero point in the shape's path!";
1090 continue;
1091 }
1092 // first point of subpath ?
1093 if (currPoint == firstPoint) {
1094 // are we starting a subpath ?
1095 if (currPoint->properties() & KoPathPoint::StartSubpath) {
1096 const QPointF p = matrix.map(currPoint->point());
1097 pathString += QString("M%1 %2").arg(p.x()).arg(p.y());
1098 }
1099 }
1100 // end point of curve segment ?
1101 else if (activeControlPoint2 || currPoint->activeControlPoint1()) {
1102 // check if we have a cubic or quadratic curve
1103 const bool isCubic = activeControlPoint2 && currPoint->activeControlPoint1();
1104 KoPathSegment cubicSeg = isCubic ? KoPathSegment(lastPoint, currPoint)
1105 : KoPathSegment(lastPoint, currPoint).toCubic();
1106 if (cubicSeg.first() && cubicSeg.second()) {
1107 const QPointF cp1 = matrix.map(cubicSeg.first()->controlPoint2());
1108 const QPointF cp2 = matrix.map(cubicSeg.second()->controlPoint1());
1109 const QPointF p = matrix.map(cubicSeg.second()->point());
1110 pathString += QString("C%1 %2 %3 %4 %5 %6")
1111 .arg(cp1.x()).arg(cp1.y())
1112 .arg(cp2.x()).arg(cp2.y())
1113 .arg(p.x()).arg(p.y());
1114 }
1115 }
1116 // end point of line segment!
1117 else {
1118 const QPointF p = matrix.map(currPoint->point());
1119 pathString += QString("L%1 %2").arg(p.x()).arg(p.y());
1120 }
1121 // last point closes subpath ?
1122 if (currPoint->properties() & KoPathPoint::StopSubpath
1123 && currPoint->properties() & KoPathPoint::CloseSubpath) {
1124 // add curve when there is a curve on the way to the first point
1125 if (currPoint->activeControlPoint2() || firstPoint->activeControlPoint1()) {
1126 // check if we have a cubic or quadratic curve
1127 const bool isCubic = currPoint->activeControlPoint2() && firstPoint->activeControlPoint1();
1128 KoPathSegment cubicSeg = isCubic ? KoPathSegment(currPoint, firstPoint)
1129 : KoPathSegment(currPoint, firstPoint).toCubic();
1130 if (cubicSeg.first() && cubicSeg.second()) {
1131 const QPointF cp1 = matrix.map(cubicSeg.first()->controlPoint2());
1132 const QPointF cp2 = matrix.map(cubicSeg.second()->controlPoint1());
1133
1134 const QPointF p = matrix.map(cubicSeg.second()->point());
1135 pathString += QString("C%1 %2 %3 %4 %5 %6")
1136 .arg(cp1.x()).arg(cp1.y())
1137 .arg(cp2.x()).arg(cp2.y())
1138 .arg(p.x()).arg(p.y());
1139 }
1140 }
1141 pathString += QString("Z");
1142 }
1143
1144 activeControlPoint2 = currPoint->activeControlPoint2();
1145 lastPoint = currPoint;
1146 }
1147 }
1148
1149 return pathString;
1150}
KoPathPoint * first
KoPathPoint * second

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::CloseSubpath, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, d, KoPathSegment::first, p, KoPathPoint::point, KoPathPoint::properties, KoPathSegment::second, KoPathPoint::StartSubpath, KoPathPoint::StopSubpath, and KoPathSegment::toCubic().

◆ updateLastPriv()

void KoPathShape::updateLastPriv ( KoPathPoint ** lastPoint)
private

Definition at line 507 of file KoPathShape.cpp.

508{
509 // check if we are about to add a new point to a closed subpath
510 if ((*lastPoint)->properties() & KoPathPoint::StopSubpath
511 && (*lastPoint)->properties() & KoPathPoint::CloseSubpath) {
512 // get the first point of the subpath
513 KoPathPoint *subpathStart = d->subpaths.last()->first();
514 // clone the first point of the subpath...
515 KoPathPoint * newLastPoint = new KoPathPoint(*subpathStart, this);
516 // ... and make it a normal point
517 newLastPoint->setProperties(KoPathPoint::Normal);
518 // now start a new subpath with the cloned start point
519 KoSubpath *path = new KoSubpath;
520 path->push_back(newLastPoint);
521 d->subpaths.push_back(path);
522 *lastPoint = newLastPoint;
523 } else {
524 // the subpath was not closed so the formerly last point
525 // of the subpath is no end point anymore
527 }
528 (*lastPoint)->unsetProperty(KoPathPoint::CloseSubpath);
529}
@ Normal
it has no control points
Definition KoPathPoint.h:37

References KoPathPoint::CloseSubpath, d, KoPathPoint::Normal, KoPathPoint::setProperties(), KoPathPoint::StopSubpath, and KoPathPoint::unsetProperty().

Member Data Documentation

◆ d

QScopedPointer<Private> KoPathShape::d
private

Definition at line 526 of file KoPathShape.h.


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