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

Strategy for deforming a segment of a path shape. More...

#include <KoPathSegmentChangeStrategy.h>

+ Inheritance diagram for KoPathSegmentChangeStrategy:

Public Member Functions

KUndo2CommandcreateCommand () override
 
void finishInteraction (Qt::KeyboardModifiers modifiers) override
 
void handleMouseMove (const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
 
 KoPathSegmentChangeStrategy (KoPathTool *tool, const QPointF &pos, const KoPathPointData &segment, qreal segmentParam)
 
 ~KoPathSegmentChangeStrategy () override
 
- Public Member Functions inherited from KoInteractionStrategy
virtual void cancelInteraction ()
 
 KoInteractionStrategy (KoToolBase *parent)
 constructor
 
virtual void paint (QPainter &painter, const KoViewConverter &converter)
 
KoToolBasetool () const
 
virtual ~KoInteractionStrategy ()
 Destructor.
 

Private Attributes

QPointF m_ctrlPoint1Move
 
QPointF m_ctrlPoint2Move
 
QPointF m_lastPosition
 
QPointF m_move
 the accumulated point move amount
 
QPointF m_originalPosition
 
int m_originalSegmentDegree
 
KoPathShapem_path
 
KoPathPointData m_pointData1
 
KoPathPointData m_pointData2
 
KoPathSegment m_segment
 
qreal m_segmentParam
 
KoPathToolm_tool
 pointer to the path tool
 

Additional Inherited Members

- Protected Member Functions inherited from KoInteractionStrategy
uint decorationThickness () const
 
uint grabSensitivity () const
 Convenience function to get the global grab sensitivity.
 
uint handleRadius () const
 Convenience function to get the global handle radius.
 
 KoInteractionStrategy (KoInteractionStrategyPrivate &)
 constructor
 
- Protected Attributes inherited from KoInteractionStrategy
KoInteractionStrategyPrivated_ptr
 

Detailed Description

Strategy for deforming a segment of a path shape.

Definition at line 21 of file KoPathSegmentChangeStrategy.h.

Constructor & Destructor Documentation

◆ KoPathSegmentChangeStrategy()

KoPathSegmentChangeStrategy::KoPathSegmentChangeStrategy ( KoPathTool * tool,
const QPointF & pos,
const KoPathPointData & segment,
qreal segmentParam )

Definition at line 21 of file KoPathSegmentChangeStrategy.cpp.

24, m_lastPosition(pos)
25, m_tool(tool)
26, m_segmentParam(segmentParam)
27, m_pointData1(segment)
28, m_pointData2(segment)
29{
30 // The following value is a bit arbitrary, it would be more mathematically correct to use
31 // "std::numeric_limits<qreal>::epsilon()", but if the value is too small, when the user
32 // click near a control point it is relatively easy to create a path shape of almost
33 // infinite size, which blocks the application for a long period of time. A bigger value
34 // is mathematically incorrect, but it avoids to block application, it also avoid to create
35 // an huge path shape by accident, and anyway, but it does not prevent the user to create one
36 // if they choose so.
37 const qreal eps = 1e-2;
38 // force segment parameter range to avoid division by zero
39 m_segmentParam = qBound(eps, m_segmentParam, qreal(1.0)-eps);
40
41 m_path = segment.pathShape;
45}
KoInteractionStrategy(KoToolBase *parent)
constructor
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
KoPathTool * m_tool
pointer to the path tool
int degree() const
Returns the degree of the segment: 1 = line, 2 = quadratic, 3 = cubic, -1 = invalid.
KoPathPoint * second
KoPathSegment segmentByIndex(const KoPathPointIndex &pointIndex) const
Returns the segment specified by a path point index.
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.
const qreal eps

References KoPathSegment::degree(), eps, m_originalSegmentDegree, m_path, m_pointData2, m_segment, m_segmentParam, KoPathShape::pathPointIndex(), KoPathPointData::pathShape, KoPathPointData::pointIndex, KoPathSegment::second, and KoPathShape::segmentByIndex().

◆ ~KoPathSegmentChangeStrategy()

KoPathSegmentChangeStrategy::~KoPathSegmentChangeStrategy ( )
override

Definition at line 47 of file KoPathSegmentChangeStrategy.cpp.

48{
49}

Member Function Documentation

◆ createCommand()

KUndo2Command * KoPathSegmentChangeStrategy::createCommand ( )
overridevirtual

For interactions that are undo-able this method should be implemented to return such a command. Implementations should return 0 otherwise.

Returns
a command, or 0.

Implements KoInteractionStrategy.

Definition at line 104 of file KoPathSegmentChangeStrategy.cpp.

105{
106 bool hasControlPoint1 = m_segment.second()->activeControlPoint1();
107 bool hasControlPoint2 = m_segment.first()->activeControlPoint2();
108
109 KUndo2Command * cmd = new KUndo2Command(kundo2_i18n("Change Segment"));
110 if (m_originalSegmentDegree == 1) {
112 }
113
114 if (hasControlPoint2) {
116 }
117 if (hasControlPoint1) {
119 }
120
121 if (cmd) {
123 }
124 return nullptr;
125}
The undo / redo command for path point moving.
@ ControlPoint2
the second control point
Definition KoPathPoint.h:51
@ ControlPoint1
the first control point
Definition KoPathPoint.h:50
bool activeControlPoint1
bool activeControlPoint2
The undo / redo command for changing segments to curves/lines.
KoPathPoint * first
KUndo2MagicString kundo2_i18n(const char *text)

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::ControlPoint1, KoPathPoint::ControlPoint2, KoPathSegmentTypeCommand::Curve, KoPathSegment::first, kundo2_i18n(), m_ctrlPoint1Move, m_ctrlPoint2Move, m_originalSegmentDegree, m_pointData1, m_pointData2, m_segment, and KoPathSegment::second.

◆ finishInteraction()

void KoPathSegmentChangeStrategy::finishInteraction ( Qt::KeyboardModifiers modifiers)
overridevirtual

Override to make final changes to the data on the end of an interaction.

Implements KoInteractionStrategy.

Definition at line 99 of file KoPathSegmentChangeStrategy.cpp.

100{
101 Q_UNUSED(modifiers);
102}

◆ handleMouseMove()

void KoPathSegmentChangeStrategy::handleMouseMove ( const QPointF & mouseLocation,
Qt::KeyboardModifiers modifiers )
overridevirtual

Extending classes should implement this method to update the selectedShapes based on the new mouse position.

Parameters
mouseLocationthe new location in pt
modifiersOR-ed set of keys pressed.

Implements KoInteractionStrategy.

Definition at line 51 of file KoPathSegmentChangeStrategy.cpp.

52{
53 QPointF snappedPosition = m_tool->canvas()->snapGuide()->snap(mouseLocation, modifiers);
54 QPointF localPos = m_path->documentToShape(snappedPosition);
55
56 if (m_segment.degree() == 1) {
57 // line segment is converted to a curve
59 cmd.redo();
60 }
61
62 QPointF move1, move2;
63
64 if (m_segment.degree() == 2) {
65 // interpolate quadratic segment between segment start, mouse position and segment end
67 localPos,
70 if (ipol.isValid()) {
71 move1 = move2 = ipol.controlPoints()[1] - m_segment.controlPoints()[1];
72 }
73 }
74 else if (m_segment.degree() == 3) {
75 QPointF lastLocalPos = m_path->documentToShape(m_lastPosition);
76 QPointF delta = localPos - lastLocalPos;
77
78 std::tie(move2, move1) =
80 }
81
84 cmd.redo();
85 }
88 cmd.redo();
89 }
91
92 m_ctrlPoint1Move += move1;
93 m_ctrlPoint2Move += move2;
94
95 // save last mouse position
96 m_lastPosition = snappedPosition;
97}
KoSnapGuide * snapGuide
QPointF point
A KoPathSegment consist of two neighboring KoPathPoints.
static KoPathSegment interpolate(const QPointF &p0, const QPointF &p1, const QPointF &p2, qreal t)
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
QList< QPointF > controlPoints() const
Returns ordered list of control points.
virtual QPointF normalize()
Normalizes the path data.
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
std::pair< QPointF, QPointF > offsetSegment(qreal t, const QPointF &offset)
moves point t of the curve by offset offset

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoToolBase::canvas(), KoPathPoint::ControlPoint1, KoPathPoint::ControlPoint2, KoPathSegment::controlPoints(), KoPathSegmentTypeCommand::Curve, KoPathSegment::degree(), KoShape::documentToShape(), KoPathSegment::first, KoPathSegment::interpolate(), KoPathSegment::isValid(), m_ctrlPoint1Move, m_ctrlPoint2Move, m_lastPosition, m_path, m_pointData1, m_pointData2, m_segment, m_segmentParam, m_tool, KoPathShape::normalize(), KisBezierUtils::offsetSegment(), KoPathPoint::point, KoPathControlPointMoveCommand::redo(), KoPathSegmentTypeCommand::redo(), KoPathSegment::second, KoSnapGuide::snap(), and KoCanvasBase::snapGuide.

Member Data Documentation

◆ m_ctrlPoint1Move

QPointF KoPathSegmentChangeStrategy::m_ctrlPoint1Move
private

Definition at line 40 of file KoPathSegmentChangeStrategy.h.

◆ m_ctrlPoint2Move

QPointF KoPathSegmentChangeStrategy::m_ctrlPoint2Move
private

Definition at line 41 of file KoPathSegmentChangeStrategy.h.

◆ m_lastPosition

QPointF KoPathSegmentChangeStrategy::m_lastPosition
private

Definition at line 32 of file KoPathSegmentChangeStrategy.h.

◆ m_move

QPointF KoPathSegmentChangeStrategy::m_move
private

the accumulated point move amount

Definition at line 34 of file KoPathSegmentChangeStrategy.h.

◆ m_originalPosition

QPointF KoPathSegmentChangeStrategy::m_originalPosition
private

Definition at line 31 of file KoPathSegmentChangeStrategy.h.

◆ m_originalSegmentDegree

int KoPathSegmentChangeStrategy::m_originalSegmentDegree
private

Definition at line 44 of file KoPathSegmentChangeStrategy.h.

◆ m_path

KoPathShape* KoPathSegmentChangeStrategy::m_path
private

Definition at line 37 of file KoPathSegmentChangeStrategy.h.

◆ m_pointData1

KoPathPointData KoPathSegmentChangeStrategy::m_pointData1
private

Definition at line 42 of file KoPathSegmentChangeStrategy.h.

◆ m_pointData2

KoPathPointData KoPathSegmentChangeStrategy::m_pointData2
private

Definition at line 43 of file KoPathSegmentChangeStrategy.h.

◆ m_segment

KoPathSegment KoPathSegmentChangeStrategy::m_segment
private

Definition at line 38 of file KoPathSegmentChangeStrategy.h.

◆ m_segmentParam

qreal KoPathSegmentChangeStrategy::m_segmentParam
private

Definition at line 39 of file KoPathSegmentChangeStrategy.h.

◆ m_tool

KoPathTool* KoPathSegmentChangeStrategy::m_tool
private

pointer to the path tool

Definition at line 36 of file KoPathSegmentChangeStrategy.h.


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