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>
25
26
28 : m_tool(tool)
29{
30}
31
35
36
38 : KoPathToolHandle(tool)
39 , m_activePoint(activePoint)
40 , m_activePointType(activePointType)
41{
42}
43
44void PointHandle::paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness, KoColorDisplayRendererInterface *renderInterface)
45{
46 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
47
48 KoPathPoint::PointTypes allPaintedTypes = KoPathPoint::Node;
49 if (selection && selection->contains(m_activePoint)) {
50 allPaintedTypes = KoPathPoint::All;
51 }
52
54 KisHandlePainterHelper helper = KoShape::createHandlePainterHelperView(&painter, m_activePoint->parent(), converter, handleRadius, decorationThickness);
55
56
57 if (allPaintedTypes != m_activePointType) {
58 KoPathPoint::PointTypes nonHighlightedType = allPaintedTypes & ~m_activePointType;
59 KoPathPoint::PointTypes nonNodeType = nonHighlightedType & ~KoPathPoint::Node;
60
61 if (nonNodeType != KoPathPoint::None) {
63 m_activePoint->paint(helper, nonHighlightedType);
64 }
65
66 if (nonHighlightedType & KoPathPoint::Node) {
69 }
70 }
71
74}
75
77{
78 bool active = false;
79 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
80 if (selection && selection->contains(m_activePoint))
81 active = true;
82 return m_activePoint->boundingRect(!active);
83}
84
86{
87 if ((event->button() & Qt::LeftButton) == 0)
88 return 0;
89 if ((event->modifiers() & Qt::ControlModifier) == 0) { // no shift pressed.
90 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
92
93 // control select adds/removes points to/from the selection
94 if (event->modifiers() & Qt::ShiftModifier) {
95 if (selection->contains(m_activePoint)) {
96 selection->remove(m_activePoint);
97 } else {
98 selection->add(m_activePoint, false);
99 }
100 } else {
101 // no control modifier, so clear selection and select active point
102 if (!selection->contains(m_activePoint)) {
103 selection->add(m_activePoint, true);
104 }
105 }
106 // TODO remove canvas from call ?
108 QPointF movedPointPosition = m_activePoint->parent()->shapeToDocument(m_activePoint->point());
109 return new KoPathPointMoveStrategy(m_tool, event->point, movedPointPosition);
110 } else {
111 KoPathShape * pathShape = m_activePoint->parent();
112 KoPathPointData pd(pathShape, pathShape->pathPointIndex(m_activePoint));
114 }
115 } else {
116 KoPathPoint::PointProperties props = m_activePoint->properties();
118 return 0;
119
121 // cycle the smooth->symmetric->unsmooth state of the path point
122 if (props & KoPathPoint::IsSmooth)
124 else if (props & KoPathPoint::IsSymmetric)
126
127 QList<KoPathPointData> pointData;
129 m_tool->canvas()->addCommand(new KoPathPointTypeCommand(pointData, pointType));
130 }
131 return 0;
132}
133
134bool PointHandle::check(const QList<KoPathShape*> &selectedShapes)
135{
136 if (selectedShapes.contains(m_activePoint->parent())) {
138 }
139 return false;
140}
141
143{
144 return m_activePoint;
145}
146
151
153{
154 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
156
158 selection->clear();
159 selection->add(m_activePoint, false);
160 }
161}
162
164 : KoPathToolHandle(tool)
165 , m_parameterShape(parameterShape)
166 , m_handleId(handleId)
167{
168}
169
170void ParameterHandle::paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness, KoColorDisplayRendererInterface *renderInterface)
171{
172 KisHandlePainterHelper helper = KoShape::createHandlePainterHelperView(&painter, m_parameterShape, converter, handleRadius, decorationThickness);
176}
177
182
184{
185 if (event->button() & Qt::LeftButton) {
186 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
187 if (selection)
188 selection->clear();
190 }
191 return 0;
192}
193
195{
196 return selectedShapes.contains(m_parameterShape);
197}
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 & partiallyHighlightedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & selectedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & highlightedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
virtual void addCommand(KUndo2Command *command)=0
virtual KisHandlePalette handlePaletteForDisplayColorSpace() const =0
handlePaletteForDisplayColorSpace
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:1001
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:977
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, KoColorDisplayRendererInterface *renderInterface) 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
void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness, KoColorDisplayRendererInterface *renderInterface) 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
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
rgba palette[MAX_PALETTE]
Definition palette.c:35