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

A KoPathPoint represents a point in a path. More...

#include <KoPathPoint.h>

+ Inheritance diagram for KoPathPoint:

Public Types

enum  PointProperty {
  Normal = 0 , StartSubpath = 1 , StopSubpath = 2 , CloseSubpath = 8 ,
  IsSmooth = 16 , IsSymmetric = 32
}
 property enum More...
 
enum  PointType {
  None = 0 , Node = 1 , ControlPoint1 = 2 , ControlPoint2 = 4 ,
  All = 7
}
 the type for identifying part of a KoPathPoint More...
 

Public Member Functions

bool activeControlPoint1 () const
 Checks if there is a controlPoint1.
 
bool activeControlPoint2 () const
 Checks if there is a controlPoint2.
 
QRectF boundingRect (bool active=true) const
 Get the bounding rect of the point.
 
QPointF controlPoint1 () const
 get the control point 1
 
QPointF controlPoint2 () const
 get the second control point
 
bool isSmooth (KoPathPoint *previous, KoPathPoint *next) const
 
 KoPathPoint ()
 Default constructor.
 
 KoPathPoint (const KoPathPoint &pathPoint)
 Copy Constructor.
 
 KoPathPoint (const KoPathPoint &pathPoint, KoPathShape *newParent)
 
 KoPathPoint (KoPathShape *path, const QPointF &point, PointProperties properties=Normal)
 Constructor.
 
void map (const QTransform &matrix)
 apply matrix on the point
 
KoPathPointoperator= (const KoPathPoint &other)
 Assignment operator.
 
bool operator== (const KoPathPoint &other) const
 Compare operator.
 
void paint (KisHandlePainterHelper &handlesHelper, PointTypes types, bool active=true)
 
KoPathShapeparent () const
 Get the path shape the point belongs to.
 
QPointF point () const
 return the position relative to the shape origin
 
 Private ()
 
PointProperties properties () const
 Get the properties of a point.
 
void removeControlPoint1 ()
 Removes the first control point.
 
void removeControlPoint2 ()
 Removes the second control point.
 
void reverse ()
 Reverses the path point.
 
void setControlPoint1 (const QPointF &point)
 Set the control point 1.
 
void setControlPoint2 (const QPointF &point)
 Set the control point 2.
 
void setParent (KoPathShape *parent)
 Sets the parent path shape.
 
void setPoint (const QPointF &point)
 alter the point
 
void setProperties (PointProperties properties)
 Set the properties of a point.
 
void setProperty (PointProperty property)
 Sets a single property of a point.
 
void unsetProperty (PointProperty property)
 Removes a property from the point.
 
 ~KoPathPoint ()
 Destructor.
 

Public Attributes

bool activeControlPoint1
 
bool activeControlPoint2
 
QPointF controlPoint1
 
QPointF controlPoint2
 
QPointF point
 
PointProperties properties
 
KoPathShapeshape
 

Private Attributes

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

Friends

class KoPathShapePrivate
 

Additional Inherited Members

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

Detailed Description

A KoPathPoint represents a point in a path.

A KoPathPoint stores a point in a path. Additional to this point 2 control points are stored. controlPoint1 is used to describe the second point of a cubic bezier ending at the point. controlPoint2 is used to describe the first point of a cubic bezier curve starting at the point.

Definition at line 24 of file KoPathPoint.cpp.

Member Enumeration Documentation

◆ PointProperty

property enum

Enumerator
Normal 

it has no control points

StartSubpath 

it starts a new subpath by a moveTo command

StopSubpath 

it stops a subpath (last point of subpath)

CloseSubpath 

it closes a subpath (only applicable on StartSubpath and StopSubpath)

IsSmooth 

it is smooth, both control points on a line through the point

IsSymmetric 

it is symmetric, like smooth but control points have same distance to point

Definition at line 36 of file KoPathPoint.h.

36 {
37 Normal = 0,
38 StartSubpath = 1,
39 StopSubpath = 2,
40 CloseSubpath = 8,
41 IsSmooth = 16,
42 IsSymmetric = 32
43 };
@ IsSmooth
it is smooth, both control points on a line through the point
Definition KoPathPoint.h:41
@ StartSubpath
it starts a new subpath by a moveTo command
Definition KoPathPoint.h:38
@ Normal
it has no control points
Definition KoPathPoint.h:37
@ IsSymmetric
it is symmetric, like smooth but control points have same distance to point
Definition KoPathPoint.h:42
@ CloseSubpath
it closes a subpath (only applicable on StartSubpath and StopSubpath)
Definition KoPathPoint.h:40
@ StopSubpath
it stops a subpath (last point of subpath)
Definition KoPathPoint.h:39

◆ PointType

the type for identifying part of a KoPathPoint

Enumerator
None 
Node 

the node point

ControlPoint1 

the first control point

ControlPoint2 

the second control point

All 

Definition at line 47 of file KoPathPoint.h.

47 {
48 None = 0,
49 Node = 1,
50 ControlPoint1 = 2,
51 ControlPoint2 = 4,
52 All = 7
53 };
@ ControlPoint2
the second control point
Definition KoPathPoint.h:51
@ ControlPoint1
the first control point
Definition KoPathPoint.h:50
Definition Node.h:24

Constructor & Destructor Documentation

◆ KoPathPoint() [1/4]

KoPathPoint::KoPathPoint ( )

Default constructor.

Definition at line 57 of file KoPathPoint.cpp.

58 : d(new Private())
59{
60}
Private *const d

◆ KoPathPoint() [2/4]

KoPathPoint::KoPathPoint ( KoPathShape * path,
const QPointF & point,
PointProperties properties = Normal )

Constructor.

Parameters
pathis a pointer to the path shape this point is used in
pointthe position relative to the shape origin
propertiesdescribing the point

Definition at line 62 of file KoPathPoint.cpp.

63 : d(new Private())
64{
65 d->shape = path;
66 d->point = point;
67 d->controlPoint1 = point;
68 d->controlPoint2 = point;
69 d->properties = properties;
70}
PointProperties properties
QPointF point

References d, point, and properties.

◆ KoPathPoint() [3/4]

KoPathPoint::KoPathPoint ( const KoPathPoint & pathPoint)

Copy Constructor.

Definition at line 39 of file KoPathPoint.cpp.

40 : d(new Private())
41{
42 d->shape = 0;
43 d->point = pathPoint.d->point;
44 d->controlPoint1 = pathPoint.d->controlPoint1;
45 d->controlPoint2 = pathPoint.d->controlPoint2;
46 d->properties = pathPoint.d->properties;
47 d->activeControlPoint1 = pathPoint.d->activeControlPoint1;
48 d->activeControlPoint2 = pathPoint.d->activeControlPoint2;
49}

References d.

◆ KoPathPoint() [4/4]

KoPathPoint::KoPathPoint ( const KoPathPoint & pathPoint,
KoPathShape * newParent )

Definition at line 51 of file KoPathPoint.cpp.

52 : KoPathPoint(pathPoint)
53{
54 d->shape = newParent;
55}
KoPathPoint()
Default constructor.

References d.

◆ ~KoPathPoint()

KoPathPoint::~KoPathPoint ( )

Destructor.

Definition at line 72 of file KoPathPoint.cpp.

73{
74 delete d;
75}

References d.

Member Function Documentation

◆ activeControlPoint1()

bool KoPathPoint::activeControlPoint1 ( ) const

Checks if there is a controlPoint1.

The control point is active if a control point was set by calling setControlPoint1. However a start point of a subpath (StartSubpath) can only have an active control 1 if the subpath is closed (CloseSubpath on first and last point).

Returns
true if control point is active, false otherwise

◆ activeControlPoint2()

bool KoPathPoint::activeControlPoint2 ( ) const

Checks if there is a controlPoint2.

The control point is active if a control point was set by calling setControlPoint2. However a end point of a subpath (StopSubpath) can only have an active control point 2 if there subpath is closed (CloseSubpath on first and last point).

Returns
true if control point is active, false otherwise

◆ boundingRect()

QRectF KoPathPoint::boundingRect ( bool active = true) const

Get the bounding rect of the point.

This takes into account if there are control points

Parameters
activeIf true only the active points are used in calculation of the bounding rectangle. If false all points are used.
Returns
bounding rect in document coordinates

Definition at line 295 of file KoPathPoint.cpp.

296{
297 QRectF rect(d->point, QSize(1, 1));
298 if (!active && activeControlPoint1()) {
299 QRectF r1(d->point, QSize(1, 1));
300 r1.setBottomRight(d->controlPoint1);
301 rect = rect.united(r1);
302 }
303 if (!active && activeControlPoint2()) {
304 QRectF r2(d->point, QSize(1, 1));
305 r2.setBottomRight(d->controlPoint2);
306 rect = rect.united(r2);
307 }
308 if (d->shape)
309 return d->shape->shapeToDocument(rect);
310 else
311 return rect;
312}
QPointF r2
QPointF r1
bool activeControlPoint1
bool activeControlPoint2

References activeControlPoint1, activeControlPoint2, d, r1, and r2.

◆ controlPoint1()

QPointF KoPathPoint::controlPoint1 ( ) const

get the control point 1

This points is used for controlling a curve ending at this point

Returns
control point 1 of this point

◆ controlPoint2()

QPointF KoPathPoint::controlPoint2 ( ) const

get the second control point

This points is used for controlling a curve starting at this point

Returns
control point 2 of this point

◆ isSmooth()

bool KoPathPoint::isSmooth ( KoPathPoint * previous,
KoPathPoint * next ) const

Returns if this point is a smooth join of adjacent path segments.

The smoothness is defined by the parallelness of the tangents emanating from the knot point, i.e. the normalized vectors from the knot to the first and second control point. The previous and next path points are used to determine the smoothness in case this path point has not two control points.

Parameters
previousthe previous path point
nextthe next path point

Definition at line 327 of file KoPathPoint.cpp.

328{
329 QPointF t1, t2;
330
331 if (activeControlPoint1()) {
332 t1 = point() - controlPoint1();
333 } else {
334 // we need the previous path point but there is none provided
335 if (! prev)
336 return false;
337 if (prev->activeControlPoint2())
338 t1 = point() - prev->controlPoint2();
339 else
340 t1 = point() - prev->point();
341 }
342
343 if (activeControlPoint2()) {
344 t2 = controlPoint2() - point();
345 } else {
346 // we need the next path point but there is none provided
347 if (! next)
348 return false;
349 if (next->activeControlPoint1())
350 t2 = next->controlPoint1() - point();
351 else
352 t2 = next->point() - point();
353 }
354
355 // normalize tangent vectors
356 qreal l1 = sqrt(t1.x() * t1.x() + t1.y() * t1.y());
357 qreal l2 = sqrt(t2.x() * t2.x() + t2.y() * t2.y());
358 if (qFuzzyCompare(l1 + 1, qreal(1.0)) || qFuzzyCompare(l2 + 1, qreal(1.0)))
359 return true;
360
361 t1 /= l1;
362 t2 /= l2;
363
364 qreal scalar = t1.x() * t2.x() + t1.y() * t2.y();
365 // tangents are parallel if t1*t2 = |t1|*|t2|
366 return qFuzzyCompare(scalar, qreal(1.0));
367}
QPointF controlPoint1
QPointF controlPoint2
static bool qFuzzyCompare(half p1, half p2)
QAction * next(const QObject *recvr, const char *slot, QObject *parent)

References activeControlPoint1, activeControlPoint2, controlPoint1, controlPoint2, point, and qFuzzyCompare().

◆ map()

void KoPathPoint::map ( const QTransform & matrix)

apply matrix on the point

This does a matrix multiplication on all points of the point

Parameters
matrixwhich will be applied to all points

Definition at line 242 of file KoPathPoint.cpp.

243{
244 d->point = matrix.map(d->point);
245 d->controlPoint1 = matrix.map(d->controlPoint1);
246 d->controlPoint2 = matrix.map(d->controlPoint2);
247
248 if (d->shape)
249 d->shape->notifyChanged();
250}

References d.

◆ operator=()

KoPathPoint & KoPathPoint::operator= ( const KoPathPoint & other)

Assignment operator.

Definition at line 77 of file KoPathPoint.cpp.

78{
79 if (this == &rhs)
80 return (*this);
81
82 d->shape = rhs.d->shape;
83 d->point = rhs.d->point;
84 d->controlPoint1 = rhs.d->controlPoint1;
85 d->controlPoint2 = rhs.d->controlPoint2;
86 d->properties = rhs.d->properties;
87 d->activeControlPoint1 = rhs.d->activeControlPoint1;
88 d->activeControlPoint2 = rhs.d->activeControlPoint2;
89
90 return (*this);
91}

References d.

◆ operator==()

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

Compare operator.

Definition at line 93 of file KoPathPoint.cpp.

94{
95 if (d->point != rhs.d->point)
96 return false;
97 if (d->controlPoint1 != rhs.d->controlPoint1)
98 return false;
99 if (d->controlPoint2 != rhs.d->controlPoint2)
100 return false;
101 if (d->properties != rhs.d->properties)
102 return false;
103 if (d->activeControlPoint1 != rhs.d->activeControlPoint1)
104 return false;
105 if (d->activeControlPoint2 != rhs.d->activeControlPoint2)
106 return false;
107 return true;
108}

References d.

◆ paint()

void KoPathPoint::paint ( KisHandlePainterHelper & handlesHelper,
PointTypes types,
bool active = true )

Paints the path point with the actual brush and pen

Parameters
painterused for painting the shape point
handleRadiussize of point handles in pixel
typesthe points which should be painted
activeIf true only the given active points are painted If false all given points are used.

Definition at line 252 of file KoPathPoint.cpp.

253{
254 bool drawControlPoint1 = types & ControlPoint1 && (!active || activeControlPoint1());
255 bool drawControlPoint2 = types & ControlPoint2 && (!active || activeControlPoint2());
256
257 // draw lines at the bottom
258 if (drawControlPoint2) {
259 handlesHelper.drawConnectionLine(point(), controlPoint2());
260 }
261
262 if (drawControlPoint1) {
263 handlesHelper.drawConnectionLine(point(), controlPoint1());
264 }
265
266 // the point is lowest
267 if (types & Node) {
268 if (properties() & IsSmooth) {
269 handlesHelper.drawHandleCircle(point());
270 } else if (properties() & IsSymmetric) {
271 handlesHelper.drawHandleRect(point());
272 } else {
273 handlesHelper.drawGradientHandle(point());
274 }
275 }
276
277 // then comes control point 2
278 if (drawControlPoint2) {
279 handlesHelper.drawHandleSmallCircle(controlPoint2());
280 }
281
282 // then comes control point 1
283 if (drawControlPoint1) {
284 handlesHelper.drawHandleSmallCircle(controlPoint1());
285 }
286}
void drawHandleSmallCircle(const QPointF &center)
void drawHandleRect(const QPointF &center, qreal radius)
void drawConnectionLine(const QLineF &line)
void drawGradientHandle(const QPointF &center, qreal radius)
void drawHandleCircle(const QPointF &center, qreal radius)

References activeControlPoint1, activeControlPoint2, controlPoint1, ControlPoint1, controlPoint2, ControlPoint2, KisHandlePainterHelper::drawConnectionLine(), KisHandlePainterHelper::drawGradientHandle(), KisHandlePainterHelper::drawHandleCircle(), KisHandlePainterHelper::drawHandleRect(), KisHandlePainterHelper::drawHandleSmallCircle(), IsSmooth, IsSymmetric, point, and properties.

◆ parent()

KoPathShape * KoPathPoint::parent ( ) const

Get the path shape the point belongs to.

Returns
the path shape the point belongs to

Definition at line 389 of file KoPathPoint.cpp.

390{
391 return d->shape;
392}

References d.

◆ point()

QPointF KoPathPoint::point ( ) const

return the position relative to the shape origin

Returns
point

◆ Private()

KoPathPoint::Private ( )
inline

Definition at line 27 of file KoPathPoint.cpp.

KoPathShape * shape

◆ properties()

PointProperties KoPathPoint::properties ( ) const

Get the properties of a point.

Returns
properties of the point

◆ removeControlPoint1()

void KoPathPoint::removeControlPoint1 ( )

Removes the first control point.

Definition at line 137 of file KoPathPoint.cpp.

138{
139 d->activeControlPoint1 = false;
140 d->properties &= ~IsSmooth;
141 d->properties &= ~IsSymmetric;
142 if (d->shape)
143 d->shape->notifyChanged();
144}

References d.

◆ removeControlPoint2()

void KoPathPoint::removeControlPoint2 ( )

Removes the second control point.

Definition at line 146 of file KoPathPoint.cpp.

147{
148 d->activeControlPoint2 = false;
149 d->properties &= ~IsSmooth;
150 d->properties &= ~IsSymmetric;
151 if (d->shape)
152 d->shape->notifyChanged();
153}

References d.

◆ reverse()

void KoPathPoint::reverse ( )

Reverses the path point.

The control points are swapped and the point properties are adjusted. The position dependent properties like StartSubpath and CloseSubpath are not changed.

Definition at line 314 of file KoPathPoint.cpp.

315{
316 std::swap(d->controlPoint1, d->controlPoint2);
317 std::swap(d->activeControlPoint1, d->activeControlPoint2);
318 PointProperties newProps = Normal;
319 newProps |= d->properties & IsSmooth;
320 newProps |= d->properties & IsSymmetric;
321 newProps |= d->properties & StartSubpath;
322 newProps |= d->properties & StopSubpath;
323 newProps |= d->properties & CloseSubpath;
324 d->properties = newProps;
325}

References CloseSubpath, d, IsSmooth, IsSymmetric, Normal, StartSubpath, and StopSubpath.

◆ setControlPoint1()

void KoPathPoint::setControlPoint1 ( const QPointF & point)

Set the control point 1.

Parameters
pointto set

Definition at line 117 of file KoPathPoint.cpp.

118{
119 if (qIsNaNPoint(point)) return;
120
121 d->controlPoint1 = point;
122 d->activeControlPoint1 = true;
123 if (d->shape)
124 d->shape->notifyChanged();
125}
static bool qIsNaNPoint(const QPointF &p)

References d, point, and qIsNaNPoint().

◆ setControlPoint2()

void KoPathPoint::setControlPoint2 ( const QPointF & point)

Set the control point 2.

Parameters
pointto set

Definition at line 127 of file KoPathPoint.cpp.

128{
129 if (qIsNaNPoint(point)) return;
130
131 d->controlPoint2 = point;
132 d->activeControlPoint2 = true;
133 if (d->shape)
134 d->shape->notifyChanged();
135}

References d, point, and qIsNaNPoint().

◆ setParent()

void KoPathPoint::setParent ( KoPathShape * parent)

Sets the parent path shape.

Parameters
parentthe new parent path shape

Definition at line 288 of file KoPathPoint.cpp.

289{
290 // don't set to zero
291 //Q_ASSERT(parent);
292 d->shape = parent;
293}
KoPathShape * parent() const
Get the path shape the point belongs to.

References d, and parent().

◆ setPoint()

void KoPathPoint::setPoint ( const QPointF & point)

alter the point

Parameters
pointto set

Definition at line 110 of file KoPathPoint.cpp.

111{
112 d->point = point;
113 if (d->shape)
114 d->shape->notifyChanged();
115}

References d, and point.

◆ setProperties()

void KoPathPoint::setProperties ( PointProperties properties)

Set the properties of a point.

Parameters
propertiesthe new properties

Definition at line 155 of file KoPathPoint.cpp.

156{
157 d->properties = properties;
158 // CloseSubpath only allowed with StartSubpath or StopSubpath
159 if ((d->properties & StartSubpath) == 0 && (d->properties & StopSubpath) == 0)
160 d->properties &= ~CloseSubpath;
161
163 // strip smooth and symmetric flags if point has not two control points
164 d->properties &= ~IsSmooth;
165 d->properties &= ~IsSymmetric;
166 }
167
168 if (d->shape)
169 d->shape->notifyChanged();
170}

References activeControlPoint1, activeControlPoint2, d, properties, StartSubpath, and StopSubpath.

◆ setProperty()

void KoPathPoint::setProperty ( PointProperty property)

Sets a single property of a point.

Parameters
propertythe property to set

Definition at line 172 of file KoPathPoint.cpp.

173{
174 switch (property) {
175 case StartSubpath:
176 case StopSubpath:
177 case CloseSubpath:
178 // nothing special to do here
179 break;
180 case IsSmooth:
181 d->properties &= ~IsSymmetric;
182 break;
183 case IsSymmetric:
184 d->properties &= ~IsSmooth;
185 break;
186 default: return;
187 }
188
189 d->properties |= property;
190
192 // strip smooth and symmetric flags if point has not two control points
193 d->properties &= ~IsSymmetric;
194 d->properties &= ~IsSmooth;
195 }
196}

References activeControlPoint1, activeControlPoint2, CloseSubpath, d, IsSmooth, IsSymmetric, StartSubpath, and StopSubpath.

◆ unsetProperty()

void KoPathPoint::unsetProperty ( PointProperty property)

Removes a property from the point.

Parameters
propertythe property to remove

Definition at line 198 of file KoPathPoint.cpp.

199{
200 switch (property) {
201 case StartSubpath:
202 if (d->properties & StartSubpath && (d->properties & StopSubpath) == 0)
203 d->properties &= ~CloseSubpath;
204 break;
205 case StopSubpath:
206 if (d->properties & StopSubpath && (d->properties & StartSubpath) == 0)
207 d->properties &= ~CloseSubpath;
208 break;
209 case CloseSubpath:
210 if (d->properties & StartSubpath || d->properties & StopSubpath) {
211 d->properties &= ~IsSmooth;
212 d->properties &= ~IsSymmetric;
213 }
214 break;
215 case IsSmooth:
216 case IsSymmetric:
217 // no others depend on these
218 break;
219 default: return;
220 }
221 d->properties &= ~property;
222}

References CloseSubpath, d, IsSmooth, IsSymmetric, StartSubpath, and StopSubpath.

Friends And Related Symbol Documentation

◆ KoPathShapePrivate

friend class KoPathShapePrivate
friend

Definition at line 255 of file KoPathPoint.h.

Member Data Documentation

◆ activeControlPoint1

bool KoPathPoint::activeControlPoint1

Definition at line 35 of file KoPathPoint.cpp.

◆ activeControlPoint2

bool KoPathPoint::activeControlPoint2

Definition at line 36 of file KoPathPoint.cpp.

◆ controlPoint1

QPointF KoPathPoint::controlPoint1

Definition at line 32 of file KoPathPoint.cpp.

◆ controlPoint2

QPointF KoPathPoint::controlPoint2

Definition at line 33 of file KoPathPoint.cpp.

◆ d

Private* const KoPathPoint::d
private

Definition at line 258 of file KoPathPoint.h.

◆ point

QPointF KoPathPoint::point

Definition at line 31 of file KoPathPoint.cpp.

◆ properties

KoPathPoint::PointProperties KoPathPoint::properties

Definition at line 34 of file KoPathPoint.cpp.

◆ shape

KoPathShape* KoPathPoint::shape

Definition at line 30 of file KoPathPoint.cpp.


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