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

The undo / redo command for path point moving. More...

#include <KoPathControlPointMoveCommand.h>

+ Inheritance diagram for KoPathControlPointMoveCommand:

Public Member Functions

int id () const override
 
 KoPathControlPointMoveCommand (const KoPathPointData &pointData, const QPointF &offset, KoPathPoint::PointType pointType, KUndo2Command *parent=0)
 
bool mergeWith (const KUndo2Command *command) override
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
- 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 bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
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 Attributes

QPointF m_offset
 
KoPathPointData m_pointData
 
KoPathPoint::PointType m_pointType
 

Detailed Description

The undo / redo command for path point moving.

Definition at line 19 of file KoPathControlPointMoveCommand.h.

Constructor & Destructor Documentation

◆ KoPathControlPointMoveCommand()

KoPathControlPointMoveCommand::KoPathControlPointMoveCommand ( const KoPathPointData & pointData,
const QPointF & offset,
KoPathPoint::PointType pointType,
KUndo2Command * parent = 0 )

Command to move one control path point.

Parameters
pointDatathe data of the point to move
offsetthe offset by which the point is moved in shape coordinates
pointTypethe type of the point to move
parentthe parent command used for macro commands

Definition at line 13 of file KoPathControlPointMoveCommand.cpp.

18 : KUndo2Command(parent)
19 , m_pointData(pointData)
20 , m_pointType(pointType)
21{
22 Q_ASSERT(offset.x() < 1e14 && offset.y() < 1e14);
23 KoPathShape * pathShape = m_pointData.pathShape;
24 KoPathPoint * point = pathShape->pointByIndex(m_pointData.pointIndex);
25 if (point) {
26 m_offset = offset;
27 }
28
29 setText(kundo2_i18n("Move control point"));
30}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
A KoPathPoint represents a point in a path.
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
KUndo2MagicString kundo2_i18n(const char *text)

References kundo2_i18n(), m_offset, m_pointData, KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, and KUndo2Command::setText().

Member Function Documentation

◆ id()

int KoPathControlPointMoveCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 85 of file KoPathControlPointMoveCommand.cpp.

References KisCommandUtils::ChangePathShapeControlPointId.

◆ mergeWith()

bool KoPathControlPointMoveCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 90 of file KoPathControlPointMoveCommand.cpp.

91{
92 const KoPathControlPointMoveCommand *other = dynamic_cast<const KoPathControlPointMoveCommand*>(command);
93
94 if (!other ||
95 other->m_pointData != m_pointData ||
96 other->m_pointType != m_pointType) {
97
98 return false;
99 }
100
101 m_offset += other->m_offset;
102
103 return true;
104}
The undo / redo command for path point moving.

References m_offset, m_pointData, and m_pointType.

◆ redo()

void KoPathControlPointMoveCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 32 of file KoPathControlPointMoveCommand.cpp.

33{
35 KoPathShape * pathShape = m_pointData.pathShape;
36 KoPathPoint * point = pathShape->pointByIndex(m_pointData.pointIndex);
37 if (point) {
38 const QRectF oldDirtyRect = pathShape->boundingRect();
39
41 point->setControlPoint1(point->controlPoint1() + m_offset);
42 if (point->properties() & KoPathPoint::IsSymmetric) {
43 // set the other control point so that it lies on the line between the moved
44 // control point and the point, with the same distance to the point as the moved point
45 point->setControlPoint2(2.0 * point->point() - point->controlPoint1());
46 } else if (point->properties() & KoPathPoint::IsSmooth) {
47 // move the other control point so that it lies on the line through point and control point
48 // keeping its distance to the point
49 QPointF direction = point->point() - point->controlPoint1();
50 direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y());
51 QPointF distance = point->point() - point->controlPoint2();
52 qreal length = sqrt(distance.x() * distance.x() + distance.y() * distance.y());
53 point->setControlPoint2(point->point() + length * direction);
54 }
56 point->setControlPoint2(point->controlPoint2() + m_offset);
57 if (point->properties() & KoPathPoint::IsSymmetric) {
58 // set the other control point so that it lies on the line between the moved
59 // control point and the point, with the same distance to the point as the moved point
60 point->setControlPoint1(2.0 * point->point() - point->controlPoint2());
61 } else if (point->properties() & KoPathPoint::IsSmooth) {
62 // move the other control point so that it lies on the line through point and control point
63 // keeping its distance to the point
64 QPointF direction = point->point() - point->controlPoint2();
65 direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y());
66 QPointF distance = point->point() - point->controlPoint1();
67 qreal length = sqrt(distance.x() * distance.x() + distance.y() * distance.y());
68 point->setControlPoint1(point->point() + length * direction);
69 }
70 }
71
72 pathShape->normalize();
73 pathShape->updateAbsolute(oldDirtyRect | pathShape->boundingRect());
74 }
75}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
qreal distance(const QPointF &p1, const QPointF &p2)
virtual void redo()
PointProperties properties
void setControlPoint1(const QPointF &point)
Set the control point 1.
QPointF point
void setControlPoint2(const QPointF &point)
Set the control point 2.
QPointF controlPoint1
@ IsSmooth
it is smooth, both control points on a line through the point
Definition KoPathPoint.h:41
@ IsSymmetric
it is symmetric, like smooth but control points have same distance to point
Definition KoPathPoint.h:42
@ ControlPoint2
the second control point
Definition KoPathPoint.h:51
@ ControlPoint1
the first control point
Definition KoPathPoint.h:50
QPointF controlPoint2
virtual QPointF normalize()
Normalizes the path data.
QRectF boundingRect() const override
reimplemented
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616

References KoPathShape::boundingRect(), KoPathPoint::controlPoint1, KoPathPoint::ControlPoint1, KoPathPoint::controlPoint2, KoPathPoint::ControlPoint2, distance(), KoPathPoint::IsSmooth, KoPathPoint::IsSymmetric, length(), m_offset, m_pointData, m_pointType, KoPathShape::normalize(), KoPathPointData::pathShape, KoPathPoint::point, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, KoPathPoint::properties, KUndo2Command::redo(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), and KoShape::updateAbsolute().

◆ undo()

void KoPathControlPointMoveCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 77 of file KoPathControlPointMoveCommand.cpp.

78{
80 m_offset *= -1.0;
81 redo();
82 m_offset *= -1.0;
83}
virtual void undo()

References m_offset, redo(), and KUndo2Command::undo().

Member Data Documentation

◆ m_offset

QPointF KoPathControlPointMoveCommand::m_offset
private

Definition at line 42 of file KoPathControlPointMoveCommand.h.

◆ m_pointData

KoPathPointData KoPathControlPointMoveCommand::m_pointData
private

Definition at line 40 of file KoPathControlPointMoveCommand.h.

◆ m_pointType

KoPathPoint::PointType KoPathControlPointMoveCommand::m_pointType
private

Definition at line 43 of file KoPathControlPointMoveCommand.h.


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