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

The undo / redo command for changing the path point type. More...

#include <KoPathPointTypeCommand.h>

+ Inheritance diagram for KoPathPointTypeCommand:

Classes

struct  PointData
 

Public Types

enum  PointType {
  Corner , Smooth , Symmetric , Line ,
  Curve
}
 The type of the point. More...
 

Public Member Functions

 KoPathPointTypeCommand (const QList< KoPathPointData > &pointDataList, PointType pointType, KUndo2Command *parent=0)
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoPathPointTypeCommand () override
 
- Public Member Functions inherited from KoPathBaseCommand
 KoPathBaseCommand (KoPathShape *shape, KUndo2Command *parent=0)
 
 KoPathBaseCommand (KUndo2Command *parent=0)
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual int id () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual bool mergeWith (const KUndo2Command *other)
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Static Public Member Functions

static void makeCubicPointSmooth (KoPathPoint *point)
 

Private Member Functions

bool appendPointData (KoPathPointData data)
 
void undoChanges (const QList< PointData > &data)
 

Private Attributes

QList< PointDatam_additionalPointData
 
QList< PointDatam_oldPointData
 
PointType m_pointType
 

Additional Inherited Members

- Protected Member Functions inherited from KoPathBaseCommand
void repaint (bool normalizeShapes)
 
- Protected Attributes inherited from KoPathBaseCommand
QSet< KoPathShape * > m_shapes
 the shapes the command operates on
 

Detailed Description

The undo / redo command for changing the path point type.

Definition at line 19 of file KoPathPointTypeCommand.h.

Member Enumeration Documentation

◆ PointType

The type of the point.

Enumerator
Corner 
Smooth 
Symmetric 
Line 
Curve 

Definition at line 23 of file KoPathPointTypeCommand.h.

Constructor & Destructor Documentation

◆ KoPathPointTypeCommand()

KoPathPointTypeCommand::KoPathPointTypeCommand ( const QList< KoPathPointData > & pointDataList,
PointType pointType,
KUndo2Command * parent = 0 )

Command to change the type of the given points

Parameters
pointDataListList of point for changing the points
pointTypethe new point type to set
parentthe parent command used for macro commands

Definition at line 15 of file KoPathPointTypeCommand.cpp.

19 : KoPathBaseCommand(parent)
20 , m_pointType(pointType)
21{
22 QList<KoPathPointData>::const_iterator it(pointDataList.begin());
23 for (; it != pointDataList.end(); ++it) {
24 KoPathPoint *point = it->pathShape->pointByIndex(it->pointIndex);
25 if (point) {
26 PointData pointData(*it);
27 pointData.m_oldControlPoint1 = it->pathShape->shapeToDocument(point->controlPoint1());
28 pointData.m_oldControlPoint2 = it->pathShape->shapeToDocument(point->controlPoint2());
29 pointData.m_oldProperties = point->properties();
30 pointData.m_hadControlPoint1 = point->activeControlPoint1();
31 pointData.m_hadControlPoint2 = point->activeControlPoint2();
32 m_oldPointData.append(pointData);
33 m_shapes.insert(it->pathShape);
34 }
35 }
36 setText(kundo2_i18n("Set point type"));
37}
void setText(const KUndo2MagicString &text)
KoPathBaseCommand(KUndo2Command *parent=0)
QSet< KoPathShape * > m_shapes
the shapes the command operates on
QList< PointData > m_oldPointData
A KoPathPoint represents a point in a path.
PointProperties properties
QPointF controlPoint1
bool activeControlPoint1
bool activeControlPoint2
QPointF controlPoint2
KUndo2MagicString kundo2_i18n(const char *text)

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, kundo2_i18n(), KoPathPointTypeCommand::PointData::m_hadControlPoint1, KoPathPointTypeCommand::PointData::m_hadControlPoint2, KoPathPointTypeCommand::PointData::m_oldControlPoint1, KoPathPointTypeCommand::PointData::m_oldControlPoint2, m_oldPointData, KoPathPointTypeCommand::PointData::m_oldProperties, KoPathBaseCommand::m_shapes, KoPathPoint::properties, and KUndo2Command::setText().

◆ ~KoPathPointTypeCommand()

KoPathPointTypeCommand::~KoPathPointTypeCommand ( )
override

Definition at line 39 of file KoPathPointTypeCommand.cpp.

40{
41}

Member Function Documentation

◆ appendPointData()

bool KoPathPointTypeCommand::appendPointData ( KoPathPointData data)
private

Definition at line 206 of file KoPathPointTypeCommand.cpp.

207{
208 KoPathPoint *point = data.pathShape->pointByIndex(data.pointIndex);
209 if (! point)
210 return false;
211
212 PointData pointData(data);
213 pointData.m_oldControlPoint1 = data.pathShape->shapeToDocument(point->controlPoint1());
214 pointData.m_oldControlPoint2 = data.pathShape->shapeToDocument(point->controlPoint2());
215 pointData.m_oldProperties = point->properties();
216 pointData.m_hadControlPoint1 = point->activeControlPoint1();
217 pointData.m_hadControlPoint2 = point->activeControlPoint2();
218
219 m_additionalPointData.append(pointData);
220
221 return true;
222}
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
QList< PointData > m_additionalPointData
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
QPointF shapeToDocument(const QPointF &point) const
Transforms point from shape coordinates to document coordinates.
Definition KoShape.cpp:1201

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, m_additionalPointData, KoPathPointTypeCommand::PointData::m_hadControlPoint1, KoPathPointTypeCommand::PointData::m_hadControlPoint2, KoPathPointTypeCommand::PointData::m_oldControlPoint1, KoPathPointTypeCommand::PointData::m_oldControlPoint2, KoPathPointTypeCommand::PointData::m_oldProperties, KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, KoPathPoint::properties, and KoShape::shapeToDocument().

◆ makeCubicPointSmooth()

void KoPathPointTypeCommand::makeCubicPointSmooth ( KoPathPoint * point)
static

Definition at line 164 of file KoPathPointTypeCommand.cpp.

165{
166 KoPathPoint::PointProperties properties = point->properties();
167
168 properties &= ~KoPathPoint::IsSymmetric;
169 properties |= KoPathPoint::IsSmooth;
170
171 // calculate vector from node point to first control point and normalize it
172 QPointF directionC1 = point->controlPoint1() - point->point();
173 qreal dirLengthC1 = sqrt(directionC1.x() * directionC1.x() + directionC1.y() * directionC1.y());
174 directionC1 /= dirLengthC1;
175 // calculate vector from node point to second control point and normalize it
176 QPointF directionC2 = point->controlPoint2() - point->point();
177 qreal dirLengthC2 = sqrt(directionC2.x() * directionC2.x() + directionC2.y() * directionC2.y());
178 directionC2 /= dirLengthC2;
179 // compute position of the control points so that they lie on a line going through the node point
180 // the new distance of the control points is the average distance to the node point
181 point->setControlPoint1(point->point() + 0.5 * dirLengthC1 * (directionC1 - directionC2));
182 point->setControlPoint2(point->point() + 0.5 * dirLengthC2 * (directionC2 - directionC1));
183
184 point->setProperties(properties);
185}
void setProperties(PointProperties properties)
Set the properties of a point.
void setControlPoint1(const QPointF &point)
Set the control point 1.
QPointF point
void setControlPoint2(const QPointF &point)
Set the control point 2.
@ IsSmooth
it is smooth, both control points on a line through the point
Definition KoPathPoint.h:41

References KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, KoPathPoint::IsSmooth, KoPathPoint::point, KoPathPoint::properties, KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), and KoPathPoint::setProperties().

◆ redo()

void KoPathPointTypeCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 43 of file KoPathPointTypeCommand.cpp.

44{
46 repaint(false);
48
50 for (; it != m_oldPointData.end(); ++it) {
51 KoPathPoint *point = it->m_pointData.pathShape->pointByIndex(it->m_pointData.pointIndex);
52 KoPathPoint::PointProperties properties = point->properties();
53
54 switch (m_pointType) {
55 case Line: {
56 point->removeControlPoint1();
57 point->removeControlPoint2();
58 break;
59 }
60 case Curve: {
61 KoPathPointIndex pointIndex = it->m_pointData.pointIndex;
62 KoPathPointIndex prevIndex;
63 KoPathPointIndex nextIndex;
64 KoPathShape * path = it->m_pointData.pathShape;
65 // get previous path node
66 if (pointIndex.second > 0)
67 prevIndex = KoPathPointIndex(pointIndex.first, pointIndex.second - 1);
68 else if (pointIndex.second == 0 && path->isClosedSubpath(pointIndex.first))
69 prevIndex = KoPathPointIndex(pointIndex.first, path->subpathPointCount(pointIndex.first) - 1);
70 // get next node
71 if (pointIndex.second < path->subpathPointCount(pointIndex.first) - 1)
72 nextIndex = KoPathPointIndex(pointIndex.first, pointIndex.second + 1);
73 else if (pointIndex.second < path->subpathPointCount(pointIndex.first) - 1
74 && path->isClosedSubpath(pointIndex.first))
75 nextIndex = KoPathPointIndex(pointIndex.first, 0);
76
77 KoPathPoint * prevPoint = path->pointByIndex(prevIndex);
78 KoPathPoint * nextPoint = path->pointByIndex(nextIndex);
79
80 if (prevPoint && ! point->activeControlPoint1() && appendPointData(KoPathPointData(path, prevIndex))) {
81 KoPathSegment cubic = KoPathSegment(prevPoint, point).toCubic();
82 if (prevPoint->activeControlPoint2()) {
83 prevPoint->setControlPoint2(cubic.first()->controlPoint2());
84 point->setControlPoint1(cubic.second()->controlPoint1());
85 } else
86 point->setControlPoint1(cubic.second()->controlPoint1());
87 }
88 if (nextPoint && ! point->activeControlPoint2() && appendPointData(KoPathPointData(path, nextIndex))) {
89 KoPathSegment cubic = KoPathSegment(point, nextPoint).toCubic();
90 if (nextPoint->activeControlPoint1()) {
91 point->setControlPoint2(cubic.first()->controlPoint2());
92 nextPoint->setControlPoint1(cubic.second()->controlPoint1());
93 } else
94 point->setControlPoint2(cubic.first()->controlPoint2());
95 }
96 point->setProperties(properties);
97 break;
98 }
99 case Symmetric: {
100 properties &= ~KoPathPoint::IsSmooth;
101 properties |= KoPathPoint::IsSymmetric;
102
103 // calculate vector from node point to first control point and normalize it
104 QPointF directionC1 = point->controlPoint1() - point->point();
105 qreal dirLengthC1 = sqrt(directionC1.x() * directionC1.x() + directionC1.y() * directionC1.y());
106 directionC1 /= dirLengthC1;
107 // calculate vector from node point to second control point and normalize it
108 QPointF directionC2 = point->controlPoint2() - point->point();
109 qreal dirLengthC2 = sqrt(directionC2.x() * directionC2.x() + directionC2.y() * directionC2.y());
110 directionC2 /= dirLengthC2;
111 // calculate the average distance of the control points to the node point
112 qreal averageLength = 0.5 * (dirLengthC1 + dirLengthC2);
113 // compute position of the control points so that they lie on a line going through the node point
114 // the new distance of the control points is the average distance to the node point
115 point->setControlPoint1(point->point() + 0.5 * averageLength * (directionC1 - directionC2));
116 point->setControlPoint2(point->point() + 0.5 * averageLength * (directionC2 - directionC1));
117 point->setProperties(properties);
118 }
119 break;
120 case Smooth: {
122 }
123 break;
124 case Corner:
125 default:
126 properties &= ~KoPathPoint::IsSymmetric;
127 properties &= ~KoPathPoint::IsSmooth;
128 point->setProperties(properties);
129 break;
130 }
131 }
132 repaint(true);
133}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
virtual void redo()
void repaint(bool normalizeShapes)
Describe a KoPathPoint by a KoPathShape and its indices.
static void makeCubicPointSmooth(KoPathPoint *point)
bool appendPointData(KoPathPointData data)
void removeControlPoint1()
Removes the first control point.
@ IsSymmetric
it is symmetric, like smooth but control points have same distance to point
Definition KoPathPoint.h:42
void removeControlPoint2()
Removes the second control point.
A KoPathSegment consist of two neighboring KoPathPoints.
KoPathPoint * first
KoPathPoint * second
KoPathSegment toCubic() const
Returns cubic bezier curve segment of this segment.
The position of a path point within a path shape.
Definition KoPathShape.h:63

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, appendPointData(), KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, Corner, Curve, KoPathSegment::first, KoPathPoint::IsSymmetric, Line, m_additionalPointData, m_oldPointData, m_pointType, makeCubicPointSmooth(), KoPathPoint::point, KoPathPoint::properties, KUndo2Command::redo(), KoPathPoint::removeControlPoint1(), KoPathPoint::removeControlPoint2(), KoPathBaseCommand::repaint(), KoPathSegment::second, KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), KoPathPoint::setProperties(), Smooth, Symmetric, and KoPathSegment::toCubic().

◆ undo()

void KoPathPointTypeCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 135 of file KoPathPointTypeCommand.cpp.

136{
138 repaint(false);
139
140 /*
141 QList<PointData>::iterator it(m_oldPointData.begin());
142 for (; it != m_oldPointData.end(); ++it)
143 {
144 KoPathShape *pathShape = it->m_pointData.pathShape;
145 KoPathPoint *point = pathShape->pointByIndex(it->m_pointData.pointIndex);
146
147 point->setProperties(it->m_oldProperties);
148 if (it->m_hadControlPoint1)
149 point->setControlPoint1(pathShape->documentToShape(it->m_oldControlPoint1));
150 else
151 point->removeControlPoint1();
152 if (it->m_hadControlPoint2)
153 point->setControlPoint2(pathShape->documentToShape(it->m_oldControlPoint2));
154 else
155 point->removeControlPoint2();
156 }
157 */
160
161 repaint(true);
162}
virtual void undo()
void undoChanges(const QList< PointData > &data)

References m_additionalPointData, m_oldPointData, KoPathBaseCommand::repaint(), KUndo2Command::undo(), and undoChanges().

◆ undoChanges()

void KoPathPointTypeCommand::undoChanges ( const QList< PointData > & data)
private

Definition at line 187 of file KoPathPointTypeCommand.cpp.

188{
189 QList<PointData>::const_iterator it(data.begin());
190 for (; it != data.end(); ++it) {
191 KoPathShape *pathShape = it->m_pointData.pathShape;
192 KoPathPoint *point = pathShape->pointByIndex(it->m_pointData.pointIndex);
193
194 point->setProperties(it->m_oldProperties);
195 if (it->m_hadControlPoint1)
196 point->setControlPoint1(pathShape->documentToShape(it->m_oldControlPoint1));
197 else
198 point->removeControlPoint1();
199 if (it->m_hadControlPoint2)
200 point->setControlPoint2(pathShape->documentToShape(it->m_oldControlPoint2));
201 else
202 point->removeControlPoint2();
203 }
204}
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211

References KoShape::documentToShape(), KoPathShape::pointByIndex(), KoPathPoint::removeControlPoint1(), KoPathPoint::removeControlPoint2(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), and KoPathPoint::setProperties().

Member Data Documentation

◆ m_additionalPointData

QList<PointData> KoPathPointTypeCommand::m_additionalPointData
private

Definition at line 65 of file KoPathPointTypeCommand.h.

◆ m_oldPointData

QList<PointData> KoPathPointTypeCommand::m_oldPointData
private

Definition at line 64 of file KoPathPointTypeCommand.h.

◆ m_pointType

PointType KoPathPointTypeCommand::m_pointType
private

Definition at line 63 of file KoPathPointTypeCommand.h.


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