Krita Source Code Documentation
Loading...
Searching...
No Matches
KoPathToolHandle.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006, 2008 Jan Hambrecht <jaham@gmx.net>
3 * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
4 * SPDX-FileCopyrightText: 2007, 2010 Thomas Zander <zander@kde.org>
5 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
6 *
7 * SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
10#include "KoPathToolHandle.h"
11#include "KoPathTool.h"
14#include "KoSelection.h"
17#include "KoParameterShape.h"
18#include "KoCanvasBase.h"
19#include "KoViewConverter.h"
20#include "KoPointerEvent.h"
21#include "KoShapeController.h"
22#include <QPainter>
24
25
27 : m_tool(tool)
28{
29}
30
34
35
37 : KoPathToolHandle(tool)
38 , m_activePoint(activePoint)
39 , m_activePointType(activePointType)
40{
41}
42
43void PointHandle::paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness)
44{
45 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
46
47 KoPathPoint::PointTypes allPaintedTypes = KoPathPoint::Node;
48 if (selection && selection->contains(m_activePoint)) {
49 allPaintedTypes = KoPathPoint::All;
50 }
51
52
53 KisHandlePainterHelper helper = KoShape::createHandlePainterHelperView(&painter, m_activePoint->parent(), converter, handleRadius, decorationThickness);
54
55
56 if (allPaintedTypes != m_activePointType) {
57 KoPathPoint::PointTypes nonHighlightedType = allPaintedTypes & ~m_activePointType;
58 KoPathPoint::PointTypes nonNodeType = nonHighlightedType & ~KoPathPoint::Node;
59
60 if (nonNodeType != KoPathPoint::None) {
62 m_activePoint->paint(helper, nonHighlightedType);
63 }
64
65 if (nonHighlightedType & KoPathPoint::Node) {
68 }
69 }
70
73}
74
76{
77 bool active = false;
78 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
79 if (selection && selection->contains(m_activePoint))
80 active = true;
81 return m_activePoint->boundingRect(!active);
82}
83
85{
86 if ((event->button() & Qt::LeftButton) == 0)
87 return 0;
88 if ((event->modifiers() & Qt::ControlModifier) == 0) { // no shift pressed.
89 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
91
92 // control select adds/removes points to/from the selection
93 if (event->modifiers() & Qt::ShiftModifier) {
94 if (selection->contains(m_activePoint)) {
95 selection->remove(m_activePoint);
96 } else {
97 selection->add(m_activePoint, false);
98 }
99 } else {
100 // no control modifier, so clear selection and select active point
101 if (!selection->contains(m_activePoint)) {
102 selection->add(m_activePoint, true);
103 }
104 }
105 // TODO remove canvas from call ?
107 QPointF movedPointPosition = m_activePoint->parent()->shapeToDocument(m_activePoint->point());
108 return new KoPathPointMoveStrategy(m_tool, event->point, movedPointPosition);
109 } else {
110 KoPathShape * pathShape = m_activePoint->parent();
111 KoPathPointData pd(pathShape, pathShape->pathPointIndex(m_activePoint));
113 }
114 } else {
115 KoPathPoint::PointProperties props = m_activePoint->properties();
117 return 0;
118
120 // cycle the smooth->symmetric->unsmooth state of the path point
121 if (props & KoPathPoint::IsSmooth)
123 else if (props & KoPathPoint::IsSymmetric)
125
126 QList<KoPathPointData> pointData;
128 m_tool->canvas()->addCommand(new KoPathPointTypeCommand(pointData, pointType));
129 }
130 return 0;
131}
132
133bool PointHandle::check(const QList<KoPathShape*> &selectedShapes)
134{
135 if (selectedShapes.contains(m_activePoint->parent())) {
137 }
138 return false;
139}
140
142{
143 return m_activePoint;
144}
145
150
152{
153 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
155
157 selection->clear();
158 selection->add(m_activePoint, false);
159 }
160}
161
163 : KoPathToolHandle(tool)
164 , m_parameterShape(parameterShape)
165 , m_handleId(handleId)
166{
167}
168
169void ParameterHandle::paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness)
170{
171 KisHandlePainterHelper helper = KoShape::createHandlePainterHelperView(&painter, m_parameterShape, converter, handleRadius, decorationThickness);
174}
175
180
182{
183 if (event->button() & Qt::LeftButton) {
184 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
185 if (selection)
186 selection->clear();
188 }
189 return 0;
190}
191
193{
194 return selectedShapes.contains(m_parameterShape);
195}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void setHandleStyle(const KisHandleStyle &style)
static KisHandleStyle & highlightedPrimaryHandles()
static KisHandleStyle & selectedPrimaryHandles()
static KisHandleStyle & partiallyHighlightedPrimaryHandles()
virtual void addCommand(KUndo2Command *command)=0
Strategy for changing control points of parametric shapes.
void paintHandle(KisHandlePainterHelper &handlesHelper, int handleId)
Paint the given handles.
QPointF handlePosition(int handleId) const
Get the handle position.
Strategy for moving points of a path shape.
Describe a KoPathPoint by a KoPathShape and its indices.
Strategy for moving points of a path shape.
The undo / redo command for changing the path point type.
PointType
The type of the point.
A KoPathPoint represents a point in a path.
PointProperties properties
QRectF boundingRect(bool active=true) const
Get the bounding rect of the point.
QPointF point
KoPathShape * parent() const
Get the path shape the point belongs to.
@ 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
PointType
the type for identifying part of a KoPathPoint
Definition KoPathPoint.h:47
@ Node
the node point
Definition KoPathPoint.h:49
bool activeControlPoint1
void paint(KisHandlePainterHelper &handlesHelper, PointTypes types, bool active=true)
bool activeControlPoint2
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.
KoPathToolHandle(KoPathTool *tool)
KoPathTool * m_tool
Handle the selection of points.
bool contains(KoPathPoint *point)
Check if a point is in the selection.
void clear()
Clear the selection.
void add(KoPathPoint *point, bool clear)
Add a point to the selection.
void remove(KoPathPoint *point)
Remove a point form the selection.
KoToolSelection * selection() override
Qt::MouseButton button() const
return button pressed (see QMouseEvent::button());
Qt::KeyboardModifiers modifiers() const
QPointF point
The point in document coordinates.
QPointF shapeToDocument(const QPointF &point) const
Transforms point from shape coordinates to document coordinates.
Definition KoShape.cpp:1201
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:1177
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
Definition Node.h:24
KoParameterShape * m_parameterShape
ParameterHandle(KoPathTool *tool, KoParameterShape *parameterShape, int handleId)
void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness) override
QRectF boundingRect() const override
KoInteractionStrategy * handleMousePress(KoPointerEvent *event) override
bool check(const QList< KoPathShape * > &selectedShapes) override
bool check(const QList< KoPathShape * > &selectedShapes) override
void trySelectHandle() override
PointHandle(KoPathTool *tool, KoPathPoint *activePoint, KoPathPoint::PointType activePointType)
KoPathPoint::PointType m_activePointType
QRectF boundingRect() const override
KoInteractionStrategy * handleMousePress(KoPointerEvent *event) override
KoPathPoint * activePoint() const
void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness) override
KoPathPoint * m_activePoint
KoPathPoint::PointType activePointType() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128