Krita Source Code Documentation
Loading...
Searching...
No Matches
tool_transform_args.h
Go to the documentation of this file.
1/*
2 * tool_transform_args.h - part of Krita
3 *
4 * SPDX-FileCopyrightText: 2010 Marc Pegon <pe.marc@free.fr>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef TOOL_TRANSFORM_ARGS_H_
10#define TOOL_TRANSFORM_ARGS_H_
11
12#include <QPointF>
13#include <QVector3D>
15#include <kis_filter_strategy.h>
17#include "kritatooltransform_export.h"
18#include "kis_global.h"
21#include "kis_paint_device.h"
22
23#include <memory>
24
25#include <QScopedPointer>
27class QDomElement;
28
36class KRITATOOLTRANSFORM_EXPORT ToolTransformArgs : public KisToolChangesTrackerData
37{
38public:
39 enum TransformMode {FREE_TRANSFORM = 0,
45 N_MODES};
46
52
57
58 KisToolChangesTrackerData *clone() const override;
59
64 ToolTransformArgs(TransformMode mode,
65 QPointF transformedCenter,
66 QPointF originalCenter,
67 QPointF rotationCenterOffset, bool transformAroundRotationCenter,
68 double aX, double aY, double aZ,
69 double scaleX, double scaleY,
70 double shearX, double shearY,
71 double boundsRotation,
73 double alpha,
74 bool defaultPoints,
75 const QString &filterId,
76 int pixelPrecision, int previewPixelPrecision,
77 KisPaintDeviceSP externalSource);
79 ToolTransformArgs& operator=(const ToolTransformArgs& args);
80
81 bool operator==(const ToolTransformArgs& other) const;
82 bool isSameMode(const ToolTransformArgs& other) const;
83
84 inline TransformMode mode() const {
85 return m_mode;
86 }
87 inline void setMode(TransformMode mode) {
88 m_mode = mode;
89 }
90
91 inline int pixelPrecision() const {
92 return m_pixelPrecision;
93 }
94
95 inline void setPixelPrecision(int precision) {
96 m_pixelPrecision = precision;
97 }
98
99 inline int previewPixelPrecision() const {
100 return m_previewPixelPrecision;
101 }
102
103 inline void setPreviewPixelPrecision(int precision) {
104 m_previewPixelPrecision = precision;
105 }
106
108 return m_externalSource;
109 }
110
111 inline void setExternalSource(KisPaintDeviceSP externalSource) {
112 m_externalSource = externalSource;
113 }
114
115 //warp-related
116 inline int numPoints() const {
117 KIS_ASSERT_RECOVER_NOOP(m_origPoints.size() == m_transfPoints.size());
118 return m_origPoints.size();
119 }
120 inline QPointF &origPoint(int i) {
121 return m_origPoints[i];
122 }
123 inline QPointF &transfPoint(int i) {
124 return m_transfPoints[i];
125 }
126 inline const QVector<QPointF> &origPoints() const {
127 return m_origPoints;
128 }
129 inline const QVector<QPointF> &transfPoints() const {
130 return m_transfPoints;
131 }
132
134 return m_origPoints;
135 }
137 return m_transfPoints;
138 }
139
141 return m_warpType;
142 }
143 inline double alpha() const {
144 return m_alpha;
145 }
146 inline bool defaultPoints() const {
147 return m_defaultPoints;
148 }
149 inline void setPoints(QVector<QPointF> origPoints, QVector<QPointF> transfPoints) {
150 m_origPoints = QVector<QPointF>(origPoints);
151 m_transfPoints = QVector<QPointF>(transfPoints);
152 }
154 m_warpType = warpType;
155 }
157 m_warpCalculation = warpCalc;
158 }
160 return m_warpCalculation;
161 }
162
163 inline void setAlpha(double alpha) {
164 m_alpha = alpha;
165 }
166 inline void setDefaultPoints(bool defaultPoints) {
167 m_defaultPoints = defaultPoints;
168 }
169
170 //"free transform"-related
171 inline QPointF transformedCenter() const {
172 return m_transformedCenter;
173 }
174 inline QPointF originalCenter() const {
175 return m_originalCenter;
176 }
177 inline QPointF rotationCenterOffset() const {
178 return m_rotationCenterOffset;
179 }
180 inline bool transformAroundRotationCenter() const {
181 return m_transformAroundRotationCenter;
182 }
183 inline double aX() const {
184 return m_aX;
185 }
186 inline double aY() const {
187 return m_aY;
188 }
189 inline double aZ() const {
190 return m_aZ;
191 }
192 inline QVector3D cameraPos() const {
193 return m_cameraPos;
194 }
195 inline double scaleX() const {
196 return m_scaleX;
197 }
198 inline double scaleY() const {
199 return m_scaleY;
200 }
201 inline bool keepAspectRatio() const {
202 return m_keepAspectRatio;
203 }
204 inline double shearX() const {
205 return m_shearX;
206 }
207 inline double shearY() const {
208 return m_shearY;
209 }
210 inline double boundsRotation() const {
211 return m_boundsRotation;
212 }
213
214 inline void setTransformedCenter(QPointF transformedCenter) {
215 m_transformedCenter = transformedCenter;
216 }
217 inline void setOriginalCenter(QPointF originalCenter) {
218 m_originalCenter = originalCenter;
219 }
220 inline void setRotationCenterOffset(QPointF rotationCenterOffset) {
221 m_rotationCenterOffset = rotationCenterOffset;
222 }
223 void setTransformAroundRotationCenter(bool value);
224
225 inline void setAX(double aX) {
226 m_aX = aX;
227 }
228 inline void setAY(double aY) {
229 m_aY = aY;
230 }
231 inline void setAZ(double aZ) {
232 m_aZ = aZ;
233 }
234 inline void setCameraPos(const QVector3D &pos) {
235 m_cameraPos = pos;
236 }
237 inline void setScaleX(double scaleX) {
238 m_scaleX = scaleX;
239 }
240 inline void setScaleY(double scaleY) {
241 m_scaleY = scaleY;
242 }
243 inline void setKeepAspectRatio(bool value) {
244 m_keepAspectRatio = value;
245 }
246 inline void setShearX(double shearX) {
247 m_shearX = shearX;
248 }
249 inline void setShearY(double shearY) {
250 m_shearY = shearY;
251 }
252 inline void setBoundsRotation(double boundsRotation) {
253 m_boundsRotation = boundsRotation;
254 }
255
256 inline QString filterId() const {
257 return m_filter->id();
258 }
259
260 void setFilterId(const QString &id);
261
262 inline KisFilterStrategy* filter() const {
263 return m_filter;
264 }
265
266 // True if the transformation does not differ from the initial one. The
267 // target device may still need changing if we are placing an external source.
268 bool isIdentity() const;
269
270 // True if the target device does not need changing as a result of this
271 // transformation, because the transformation does not differ from the initial
272 // one and the source image is not external.
273 bool isUnchanging() const;
274
275 inline QTransform flattenedPerspectiveTransform() const {
276 return m_flattenedPerspectiveTransform;
277 }
278
279 inline void setFlattenedPerspectiveTransform(const QTransform &value) {
280 m_flattenedPerspectiveTransform = value;
281 }
282
284 return m_editTransformPoints;
285 }
286
288 m_editTransformPoints = value;
289 }
290
292 return m_liquifyProperties.data();
293 }
294
296 return m_liquifyProperties.data();
297 }
298
299 void initLiquifyTransformMode(const QRect &srcRect);
300 void saveLiquifyTransformMode() const;
301
303 return m_liquifyWorker.data();
304 }
305
306 void toXML(QDomElement *e) const;
307 static ToolTransformArgs fromXML(const QDomElement &e);
308
309 void translateSrcAndDst(const QPointF &offset);
310 void transformSrcAndDst(const QTransform &t);
311 void translateDstSpace(const QPointF &offset);
312
313 void saveContinuedState();
314 void restoreContinuedState();
315 const ToolTransformArgs* continuedTransform() const;
316
317 const KisBezierTransformMesh* meshTransform() const;
318 KisBezierTransformMesh* meshTransform();
319
320 bool meshShowHandles() const;
321 void setMeshShowHandles(bool value);
322
323 bool meshSymmetricalHandles() const;
324 void setMeshSymmetricalHandles(bool meshSymmetricalHandles);
325
326 bool meshScaleHandles() const;
327 void setMeshScaleHandles(bool meshScaleHandles);
328
329 void scale3dSrcAndDst(qreal scale);
330
331private:
332 void clear();
333 void init(const ToolTransformArgs& args);
335
336 // warp-related arguments
337 // these are basically the arguments taken by the warp transform worker
338 bool m_defaultPoints {true}; // true : the original points are set to make a grid
339 // which density is given by numPoints()
343 KisWarpTransformWorker::WarpCalculation m_warpCalculation {KisWarpTransformWorker::WarpCalculation::DRAW}; // DRAW or GRID
344 double m_alpha {1.0};
345
346 //'free transform'-related
347 // basically the arguments taken by the transform worker
350 QPointF m_rotationCenterOffset; // the position of the rotation center relative to
351 // the original top left corner of the selection
352 // before any transformation
353 bool m_transformAroundRotationCenter {false}; // In freehand mode makes the scaling and other transformations
354 // be anchored to the rotation center point.
355
356 double m_aX {0};
357 double m_aY {0};
358 double m_aZ {0};
359 QVector3D m_cameraPos {QVector3D(0,0,1024)};
360 double m_scaleX {1.0};
361 double m_scaleY {1.0};
362 double m_shearX {0.0};
363 double m_shearY {0.0};
364 double m_boundsRotation {0.0};
365 bool m_keepAspectRatio {false};
366
367 // perspective transform related
369
370 KisFilterStrategy *m_filter {0};
371 bool m_editTransformPoints {false};
373 QScopedPointer<KisLiquifyTransformWorker> m_liquifyWorker;
374
376 bool m_meshShowHandles = true;
377 bool m_meshSymmetricalHandles = true;
378 bool m_meshScaleHandles = false;
379
385 std::unique_ptr<ToolTransformArgs> m_continuedTransformation;
386
387 //PixelPrecision should always be in powers of 2
388 int m_pixelPrecision {8};
389 int m_previewPixelPrecision {16};
390
396};
397
398#endif // TOOL_TRANSFORM_ARGS_H_
float value(const T *src, size_t ch)
bool operator==(const KisRegion &lhs, const KisRegion &rhs)
virtual KisToolChangesTrackerData * clone() const
enum KisWarpTransformWorker::WarpType_ WarpType
enum KisWarpTransformWorker::WarpCalculation_ WarpCalculation
void setCameraPos(const QVector3D &pos)
void setShearX(double shearX)
QPointF transformedCenter() const
void setWarpCalculation(KisWarpTransformWorker::WarpCalculation warpCalc)
const QVector< QPointF > & origPoints() const
QTransform flattenedPerspectiveTransform() const
void setKeepAspectRatio(bool value)
KisPaintDeviceSP m_externalSource
KisWarpTransformWorker::WarpCalculation warpCalculation()
QPointF & origPoint(int i)
QVector< QPointF > & refTransformedPoints()
bool transformAroundRotationCenter() const
void setRotationCenterOffset(QPointF rotationCenterOffset)
void setBoundsRotation(double boundsRotation)
int previewPixelPrecision() const
QVector< QPointF > m_transfPoints
bool isEditingTransformPoints() const
KisFilterStrategy * filter() const
KisLiquifyTransformWorker * liquifyWorker() const
void setAlpha(double alpha)
void setScaleX(double scaleX)
KisWarpTransformWorker::WarpType warpType() const
void setPoints(QVector< QPointF > origPoints, QVector< QPointF > transfPoints)
void setTransformedCenter(QPointF transformedCenter)
void setPreviewPixelPrecision(int precision)
const KisLiquifyProperties * liquifyProperties() const
void setScaleY(double scaleY)
void setOriginalCenter(QPointF originalCenter)
std::unique_ptr< ToolTransformArgs > m_continuedTransformation
QVector< QPointF > m_origPoints
QPointF originalCenter() const
QPointF rotationCenterOffset() const
void setDefaultPoints(bool defaultPoints)
KisLiquifyProperties * liquifyProperties()
void setShearY(double shearY)
const QVector< QPointF > & transfPoints() const
void setFlattenedPerspectiveTransform(const QTransform &value)
void setEditingTransformPoints(bool value)
void setMode(TransformMode mode)
QPointF & transfPoint(int i)
void setPixelPrecision(int precision)
double boundsRotation() const
QSharedPointer< KisLiquifyProperties > m_liquifyProperties
QTransform m_flattenedPerspectiveTransform
QString filterId() const
void setExternalSource(KisPaintDeviceSP externalSource)
void setWarpType(KisWarpTransformWorker::WarpType warpType)
TransformMode mode() const
QVector3D cameraPos() const
QScopedPointer< KisLiquifyTransformWorker > m_liquifyWorker
KisPaintDeviceSP externalSource() const
KisBezierTransformMesh m_meshTransform
QVector< QPointF > & refOriginalPoints()
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97