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

The undo / redo command for changing segments to curves/lines. More...

#include <KoPathSegmentTypeCommand.h>

+ Inheritance diagram for KoPathSegmentTypeCommand:

Classes

struct  SegmentTypeData
 

Public Types

enum  SegmentType { Curve = 1 , Line = 2 }
 Segment Types. More...
 

Public Member Functions

 KoPathSegmentTypeCommand (const KoPathPointData &pointData, SegmentType segmentType, KUndo2Command *parent=0)
 
 KoPathSegmentTypeCommand (const QList< KoPathPointData > &pointDataList, SegmentType segmentType, KUndo2Command *parent=0)
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoPathSegmentTypeCommand () override
 
- 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 ()
 

Private Member Functions

void initialize (const QList< KoPathPointData > &pointDataList)
 

Private Attributes

QList< KoPathPointDatam_pointDataList
 
QList< SegmentTypeDatam_segmentData
 
SegmentType m_segmentType
 

Detailed Description

The undo / redo command for changing segments to curves/lines.

Definition at line 19 of file KoPathSegmentTypeCommand.h.

Member Enumeration Documentation

◆ SegmentType

Segment Types.

Enumerator
Curve 
Line 

Definition at line 23 of file KoPathSegmentTypeCommand.h.

Constructor & Destructor Documentation

◆ KoPathSegmentTypeCommand() [1/2]

KoPathSegmentTypeCommand::KoPathSegmentTypeCommand ( const KoPathPointData & pointData,
SegmentType segmentType,
KUndo2Command * parent = 0 )

Command for changing the segment type ( curve/line )

Parameters
pointDatapoint data identifying the segment that should be changed.
segmentTypeto which the segment should be changed to
parentthe parent command used for macro commands

Definition at line 13 of file KoPathSegmentTypeCommand.cpp.

14: KUndo2Command(parent)
15, m_segmentType(segmentType)
16{
17 QList<KoPathPointData> pointDataList;
18 pointDataList.append(pointData);
19 initialize(pointDataList);
20}
KUndo2Command(KUndo2Command *parent=0)
void initialize(const QList< KoPathPointData > &pointDataList)

References initialize().

◆ KoPathSegmentTypeCommand() [2/2]

KoPathSegmentTypeCommand::KoPathSegmentTypeCommand ( const QList< KoPathPointData > & pointDataList,
SegmentType segmentType,
KUndo2Command * parent = 0 )

Command for changing the segment type ( curve/line )

Parameters
pointDataListList of point data identifying the segments that should be changed.
segmentTypeto which the segments should be changed to
parentthe parent command used for macro commands

Definition at line 22 of file KoPathSegmentTypeCommand.cpp.

24 : KUndo2Command(parent)
25 , m_segmentType(segmentType)
26{
27 initialize(pointDataList);
28}

References initialize().

◆ ~KoPathSegmentTypeCommand()

KoPathSegmentTypeCommand::~KoPathSegmentTypeCommand ( )
override

Definition at line 30 of file KoPathSegmentTypeCommand.cpp.

31{
32}

Member Function Documentation

◆ initialize()

void KoPathSegmentTypeCommand::initialize ( const QList< KoPathPointData > & pointDataList)
private

Definition at line 87 of file KoPathSegmentTypeCommand.cpp.

88{
89 QList<KoPathPointData>::const_iterator it(pointDataList.begin());
90 for (; it != pointDataList.end(); ++it) {
91 KoPathSegment segment = it->pathShape->segmentByIndex(it->pointIndex);
92 if (segment.isValid()) {
93 if (m_segmentType == Curve) {
94 // don not change segment if already a curve
95 if (segment.first()->activeControlPoint2() || segment.second()->activeControlPoint1())
96 continue;
97 } else {
98 // do not change segment if already a line
99 if (! segment.first()->activeControlPoint2() && ! segment.second()->activeControlPoint1())
100 continue;
101 }
102
103 m_pointDataList.append(*it);
104 SegmentTypeData segmentData;
105
106 KoPathShape * pathShape = segment.first()->parent();
107
108 // we are changing a curve to a line -> save control point positions
109 if (m_segmentType == Line) {
110 segmentData.m_controlPoint2 = pathShape->shapeToDocument(segment.first()->controlPoint2());
111 segmentData.m_controlPoint1 = pathShape->shapeToDocument(segment.second()->controlPoint1());
112 }
113 // save point properties
114 segmentData.m_properties2 = segment.first()->properties();
115 segmentData.m_properties1 = segment.second()->properties();
116 m_segmentData.append(segmentData);
117 }
118 }
119
120 if (m_segmentType == Curve) {
121 setText(kundo2_i18n("Change segments to curves"));
122 } else {
123 setText(kundo2_i18n("Change segments to lines"));
124 }
125}
void setText(const KUndo2MagicString &text)
PointProperties properties
QPointF controlPoint1
KoPathShape * parent() const
Get the path shape the point belongs to.
bool activeControlPoint1
bool activeControlPoint2
QPointF controlPoint2
QList< KoPathPointData > m_pointDataList
QList< SegmentTypeData > m_segmentData
A KoPathSegment consist of two neighboring KoPathPoints.
KoPathPoint * first
KoPathPoint * second
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
The position of a path point within a path shape.
Definition KoPathShape.h:63
QPointF shapeToDocument(const QPointF &point) const
Transforms point from shape coordinates to document coordinates.
Definition KoShape.cpp:1201
KUndo2MagicString kundo2_i18n(const char *text)

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, Curve, KoPathSegment::first, KoPathSegment::isValid(), kundo2_i18n(), Line, KoPathSegmentTypeCommand::SegmentTypeData::m_controlPoint1, KoPathSegmentTypeCommand::SegmentTypeData::m_controlPoint2, m_pointDataList, KoPathSegmentTypeCommand::SegmentTypeData::m_properties1, KoPathSegmentTypeCommand::SegmentTypeData::m_properties2, m_segmentData, m_segmentType, KoPathPoint::parent(), KoPathPoint::properties, KoPathSegment::second, KUndo2Command::setText(), and KoShape::shapeToDocument().

◆ redo()

void KoPathSegmentTypeCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 34 of file KoPathSegmentTypeCommand.cpp.

35{
38 for (; it != m_pointDataList.constEnd(); ++it) {
39 KoPathShape * pathShape = it->pathShape;
40 pathShape->update();
41
42 KoPathSegment segment = pathShape->segmentByIndex(it->pointIndex);
43
44 if (m_segmentType == Curve) {
45 // we change type to curve -> set control point positions
46 QPointF pointDiff = segment.second()->point() - segment.first()->point();
47 segment.first()->setControlPoint2(segment.first()->point() + pointDiff / 3.0);
48 segment.second()->setControlPoint1(segment.first()->point() + pointDiff * 2.0 / 3.0);
49 } else {
50 // we are changing type to line -> remove control points
51 segment.first()->removeControlPoint2();
52 segment.second()->removeControlPoint1();
53 }
54
55 pathShape->normalize();
56 pathShape->update();
57 }
58}
virtual void redo()
void setControlPoint1(const QPointF &point)
Set the control point 1.
QPointF point
void setControlPoint2(const QPointF &point)
Set the control point 2.
void removeControlPoint1()
Removes the first control point.
void removeControlPoint2()
Removes the second control point.
virtual QPointF normalize()
Normalizes the path data.
KoPathSegment segmentByIndex(const KoPathPointIndex &pointIndex) const
Returns the segment specified by a path point index.
void update() const override
reimplemented

References Curve, KoPathSegment::first, m_pointDataList, m_segmentType, KoPathShape::normalize(), KoPathPoint::point, KUndo2Command::redo(), KoPathPoint::removeControlPoint1(), KoPathPoint::removeControlPoint2(), KoPathSegment::second, KoPathShape::segmentByIndex(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), and KoShapeContainer::update().

◆ undo()

void KoPathSegmentTypeCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 60 of file KoPathSegmentTypeCommand.cpp.

61{
63 for (int i = 0; i < m_pointDataList.size(); ++i) {
64 const KoPathPointData & pd = m_pointDataList.at(i);
65 pd.pathShape->update();
67 const SegmentTypeData segmentData(m_segmentData.at(i));
68
69 if (m_segmentType == Line) {
70 // change type back to curve -> reactivate control points and their positions
71 segment.first()->setControlPoint2(pd.pathShape->documentToShape(segmentData.m_controlPoint2));
72 segment.second()->setControlPoint1(pd.pathShape->documentToShape(segmentData.m_controlPoint1));
73 } else {
74 // change back to line -> remove control points
75 segment.first()->removeControlPoint2();
76 segment.second()->removeControlPoint1();
77 }
78
79 segment.first()->setProperties(segmentData.m_properties2);
80 segment.second()->setProperties(segmentData.m_properties1);
81
82 pd.pathShape->normalize();
83 pd.pathShape->update();
84 }
85}
virtual void undo()
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
void setProperties(PointProperties properties)
Set the properties of a point.
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211

References KoShape::documentToShape(), KoPathSegment::first, Line, KoPathSegmentTypeCommand::SegmentTypeData::m_controlPoint1, KoPathSegmentTypeCommand::SegmentTypeData::m_controlPoint2, m_pointDataList, KoPathSegmentTypeCommand::SegmentTypeData::m_properties1, KoPathSegmentTypeCommand::SegmentTypeData::m_properties2, m_segmentData, m_segmentType, KoPathShape::normalize(), KoPathPointData::pathShape, KoPathPointData::pointIndex, KoPathPoint::removeControlPoint1(), KoPathPoint::removeControlPoint2(), KoPathSegment::second, KoPathShape::segmentByIndex(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), KoPathPoint::setProperties(), KUndo2Command::undo(), and KoShapeContainer::update().

Member Data Documentation

◆ m_pointDataList

QList<KoPathPointData> KoPathSegmentTypeCommand::m_pointDataList
private

Definition at line 62 of file KoPathSegmentTypeCommand.h.

◆ m_segmentData

QList<SegmentTypeData> KoPathSegmentTypeCommand::m_segmentData
private

Definition at line 63 of file KoPathSegmentTypeCommand.h.

◆ m_segmentType

SegmentType KoPathSegmentTypeCommand::m_segmentType
private

Definition at line 64 of file KoPathSegmentTypeCommand.h.


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