Krita Source Code Documentation
Loading...
Searching...
No Matches
KoParameterShape.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org>
3 SPDX-FileCopyrightText: 2007, 2009 Thomas Zander <zander@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "KoParameterShape.h"
10
12
13#include <QPainter>
14#include <FlakeDebug.h>
15
16KoParameterShape::Private::Private()
17 : QSharedData()
18 , parametric(true)
19{
20}
21
22KoParameterShape::Private::Private(const Private &rhs)
23 : QSharedData()
24 , parametric(rhs.parametric)
25 , handles(rhs.handles)
26{
27}
28
34
36 : KoPathShape(rhs)
37 , d(rhs.d)
38{
39}
40
44
45void KoParameterShape::moveHandle(int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers)
46{
47
48 if (handleId >= d->handles.size()) {
49 warnFlake << "handleId out of bounds";
50 return;
51 }
52
53 update();
54 // function to do special stuff
55 moveHandleAction(handleId, documentToShape(point), modifiers);
56
58 update();
59}
60
61
62int KoParameterShape::handleIdAt(const QRectF & rect) const
63{
64
65 int handle = -1;
66
67 for (int i = 0; i < d->handles.size(); ++i) {
68 if (rect.contains(d->handles.at(i))) {
69 handle = i;
70 break;
71 }
72 }
73 return handle;
74}
75
76QPointF KoParameterShape::handlePosition(int handleId) const
77{
78
79 return d->handles.value(handleId);
80}
81
83{
84
85
86 QList<QPointF>::const_iterator it(d->handles.constBegin());
87 for (; it != d->handles.constEnd(); ++it) {
88 handlesHelper.drawGradientHandle(*it);
89 }
90}
91
92void KoParameterShape::paintHandle(KisHandlePainterHelper &handlesHelper, int handleId)
93{
94
95 handlesHelper.drawGradientHandle(d->handles[handleId]);
96}
97
98void KoParameterShape::setSize(const QSizeF &newSize)
99{
100
101 QTransform matrix(resizeMatrix(newSize));
102
103 for (int i = 0; i < d->handles.size(); ++i) {
104 d->handles[i] = matrix.map(d->handles[i]);
105 }
106
107 KoPathShape::setSize(newSize);
108}
109
111{
112
113 QPointF offset(KoPathShape::normalize());
114 QTransform matrix;
115 matrix.translate(-offset.x(), -offset.y());
116
117 for (int i = 0; i < d->handles.size(); ++i) {
118 d->handles[i] = matrix.map(d->handles[i]);
119 }
120
121 return offset;
122}
123
125{
126
127 return d->parametric;
128}
129
131{
132
133 d->parametric = parametric;
134 update();
135}
136
138{
139
140 return d->handles;
141}
142
144{
145
146 d->handles = handles;
147
149}
150
152{
153
154 return d->handles.count();
155}
#define warnFlake
Definition FlakeDebug.h:16
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void drawGradientHandle(const QPointF &center, qreal radius)
QSharedDataPointer< Private > d
QPointF normalize() override
Normalizes the path data.
void paintHandles(KisHandlePainterHelper &handlesHelper)
Paint the handles.
void paintHandle(KisHandlePainterHelper &handlesHelper, int handleId)
Paint the given handles.
void moveHandle(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
Move handle to point.
QList< QPointF > handles
the handles that the user can grab and change
~KoParameterShape() override
int handleCount() const
return the number of handles set on the shape
void setSize(const QSizeF &size) override
reimplemented from KoShape
QPointF handlePosition(int handleId) const
Get the handle position.
void setHandles(const QList< QPointF > &handles)
void setParametricShape(bool parametric)
Set if the shape can be modified using parameters.
virtual void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier)=0
Updates the internal state of a KoParameterShape.
virtual void updatePath(const QSizeF &size)=0
Update the path of the parameter shape.
bool isParametricShape() const
Check if object is a parametric shape.
int handleIdAt(const QRectF &rect) const
Get the id of the handle within the given rect.
The position of a path point within a path shape.
Definition KoPathShape.h:63
QTransform resizeMatrix(const QSizeF &newSize) const
virtual QPointF normalize()
Normalizes the path data.
QSizeF size() const override
reimplemented
void setSize(const QSizeF &size) override
QScopedPointer< Private > d
void update() const override
reimplemented
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211
void shapeChangedPriv(KoShape::ChangeType type)
Definition KoShape.cpp:132
@ ParameterChanged
the shapes parameter has changed (KoParameterShape only)
Definition KoShape.h:109