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 <QScopedPointer>
25class QDomElement;
26
34class KRITATOOLTRANSFORM_EXPORT ToolTransformArgs : public KisToolChangesTrackerData
35{
36public:
37 enum TransformMode {FREE_TRANSFORM = 0,
43 N_MODES};
44
50
55
56 KisToolChangesTrackerData *clone() const override;
57
62 ToolTransformArgs(TransformMode mode,
63 QPointF transformedCenter,
64 QPointF originalCenter,
65 QPointF rotationCenterOffset, bool transformAroundRotationCenter,
66 double aX, double aY, double aZ,
67 double scaleX, double scaleY,
68 double shearX, double shearY,
69 double boundsRotation,
71 double alpha,
72 bool defaultPoints,
73 const QString &filterId,
74 int pixelPrecision, int previewPixelPrecision,
75 KisPaintDeviceSP externalSource);
77 ToolTransformArgs& operator=(const ToolTransformArgs& args);
78
79 bool operator==(const ToolTransformArgs& other) const;
80 bool isSameMode(const ToolTransformArgs& other) const;
81
82 inline TransformMode mode() const {
83 return m_mode;
84 }
85 inline void setMode(TransformMode mode) {
86 m_mode = mode;
87 }
88
89 inline int pixelPrecision() const {
90 return m_pixelPrecision;
91 }
92
93 inline void setPixelPrecision(int precision) {
94 m_pixelPrecision = precision;
95 }
96
97 inline int previewPixelPrecision() const {
98 return m_previewPixelPrecision;
99 }
100
101 inline void setPreviewPixelPrecision(int precision) {
102 m_previewPixelPrecision = precision;
103 }
104
106 return m_externalSource;
107 }
108
109 inline void setExternalSource(KisPaintDeviceSP externalSource) {
110 m_externalSource = externalSource;
111 }
112
113 //warp-related
114 inline int numPoints() const {
115 KIS_ASSERT_RECOVER_NOOP(m_origPoints.size() == m_transfPoints.size());
116 return m_origPoints.size();
117 }
118 inline QPointF &origPoint(int i) {
119 return m_origPoints[i];
120 }
121 inline QPointF &transfPoint(int i) {
122 return m_transfPoints[i];
123 }
124 inline const QVector<QPointF> &origPoints() const {
125 return m_origPoints;
126 }
127 inline const QVector<QPointF> &transfPoints() const {
128 return m_transfPoints;
129 }
130
132 return m_origPoints;
133 }
135 return m_transfPoints;
136 }
137
139 return m_warpType;
140 }
141 inline double alpha() const {
142 return m_alpha;
143 }
144 inline bool defaultPoints() const {
145 return m_defaultPoints;
146 }
147 inline void setPoints(QVector<QPointF> origPoints, QVector<QPointF> transfPoints) {
148 m_origPoints = QVector<QPointF>(origPoints);
149 m_transfPoints = QVector<QPointF>(transfPoints);
150 }
152 m_warpType = warpType;
153 }
155 m_warpCalculation = warpCalc;
156 }
158 return m_warpCalculation;
159 }
160
161 inline void setAlpha(double alpha) {
162 m_alpha = alpha;
163 }
164 inline void setDefaultPoints(bool defaultPoints) {
165 m_defaultPoints = defaultPoints;
166 }
167
168 //"free transform"-related
169 inline QPointF transformedCenter() const {
170 return m_transformedCenter;
171 }
172 inline QPointF originalCenter() const {
173 return m_originalCenter;
174 }
175 inline QPointF rotationCenterOffset() const {
176 return m_rotationCenterOffset;
177 }
178 inline bool transformAroundRotationCenter() const {
179 return m_transformAroundRotationCenter;
180 }
181 inline double aX() const {
182 return m_aX;
183 }
184 inline double aY() const {
185 return m_aY;
186 }
187 inline double aZ() const {
188 return m_aZ;
189 }
190 inline QVector3D cameraPos() const {
191 return m_cameraPos;
192 }
193 inline double scaleX() const {
194 return m_scaleX;
195 }
196 inline double scaleY() const {
197 return m_scaleY;
198 }
199 inline bool keepAspectRatio() const {
200 return m_keepAspectRatio;
201 }
202 inline double shearX() const {
203 return m_shearX;
204 }
205 inline double shearY() const {
206 return m_shearY;
207 }
208 inline double boundsRotation() const {
209 return m_boundsRotation;
210 }
211
212 inline void setTransformedCenter(QPointF transformedCenter) {
213 m_transformedCenter = transformedCenter;
214 }
215 inline void setOriginalCenter(QPointF originalCenter) {
216 m_originalCenter = originalCenter;
217 }
218 inline void setRotationCenterOffset(QPointF rotationCenterOffset) {
219 m_rotationCenterOffset = rotationCenterOffset;
220 }
221 void setTransformAroundRotationCenter(bool value);
222
223 inline void setAX(double aX) {
224 m_aX = aX;
225 }
226 inline void setAY(double aY) {
227 m_aY = aY;
228 }
229 inline void setAZ(double aZ) {
230 m_aZ = aZ;
231 }
232 inline void setCameraPos(const QVector3D &pos) {
233 m_cameraPos = pos;
234 }
235 inline void setScaleX(double scaleX) {
236 m_scaleX = scaleX;
237 }
238 inline void setScaleY(double scaleY) {
239 m_scaleY = scaleY;
240 }
241 inline void setKeepAspectRatio(bool value) {
242 m_keepAspectRatio = value;
243 }
244 inline void setShearX(double shearX) {
245 m_shearX = shearX;
246 }
247 inline void setShearY(double shearY) {
248 m_shearY = shearY;
249 }
250 inline void setBoundsRotation(double boundsRotation) {
251 m_boundsRotation = boundsRotation;
252 }
253
254 inline QString filterId() const {
255 return m_filter->id();
256 }
257
258 void setFilterId(const QString &id);
259
260 inline KisFilterStrategy* filter() const {
261 return m_filter;
262 }
263
264 // True if the transformation does not differ from the initial one. The
265 // target device may still need changing if we are placing an external source.
266 bool isIdentity() const;
267
268 // True if the target device does not need changing as a result of this
269 // transformation, because the transformation does not differ from the initial
270 // one and the source image is not external.
271 bool isUnchanging() const;
272
273 inline QTransform flattenedPerspectiveTransform() const {
274 return m_flattenedPerspectiveTransform;
275 }
276
277 inline void setFlattenedPerspectiveTransform(const QTransform &value) {
278 m_flattenedPerspectiveTransform = value;
279 }
280
282 return m_editTransformPoints;
283 }
284
286 m_editTransformPoints = value;
287 }
288
290 return m_liquifyProperties.data();
291 }
292
294 return m_liquifyProperties.data();
295 }
296
297 void initLiquifyTransformMode(const QRect &srcRect);
298 void saveLiquifyTransformMode() const;
299
301 return m_liquifyWorker.data();
302 }
303
304 void toXML(QDomElement *e) const;
305 static ToolTransformArgs fromXML(const QDomElement &e);
306
307 void translateSrcAndDst(const QPointF &offset);
308 void transformSrcAndDst(const QTransform &t);
309 void translateDstSpace(const QPointF &offset);
310
311 void saveContinuedState();
312 void restoreContinuedState();
313 const ToolTransformArgs* continuedTransform() const;
314
315 const KisBezierTransformMesh* meshTransform() const;
316 KisBezierTransformMesh* meshTransform();
317
318 bool meshShowHandles() const;
319 void setMeshShowHandles(bool value);
320
321 bool meshSymmetricalHandles() const;
322 void setMeshSymmetricalHandles(bool meshSymmetricalHandles);
323
324 bool meshScaleHandles() const;
325 void setMeshScaleHandles(bool meshScaleHandles);
326
327 void scale3dSrcAndDst(qreal scale);
328
329private:
330 void clear();
331 void init(const ToolTransformArgs& args);
333
334 // warp-related arguments
335 // these are basically the arguments taken by the warp transform worker
336 bool m_defaultPoints {true}; // true : the original points are set to make a grid
337 // which density is given by numPoints()
341 KisWarpTransformWorker::WarpCalculation m_warpCalculation {KisWarpTransformWorker::WarpCalculation::DRAW}; // DRAW or GRID
342 double m_alpha {1.0};
343
344 //'free transform'-related
345 // basically the arguments taken by the transform worker
348 QPointF m_rotationCenterOffset; // the position of the rotation center relative to
349 // the original top left corner of the selection
350 // before any transformation
351 bool m_transformAroundRotationCenter {false}; // In freehand mode makes the scaling and other transformations
352 // be anchored to the rotation center point.
353
354 double m_aX {0};
355 double m_aY {0};
356 double m_aZ {0};
357 QVector3D m_cameraPos {QVector3D(0,0,1024)};
358 double m_scaleX {1.0};
359 double m_scaleY {1.0};
360 double m_shearX {0.0};
361 double m_shearY {0.0};
362 double m_boundsRotation {0.0};
363 bool m_keepAspectRatio {false};
364
365 // perspective transform related
367
368 KisFilterStrategy *m_filter {0};
369 bool m_editTransformPoints {false};
371 QScopedPointer<KisLiquifyTransformWorker> m_liquifyWorker;
372
374 bool m_meshShowHandles = true;
375 bool m_meshSymmetricalHandles = true;
376 bool m_meshScaleHandles = false;
377
383 QScopedPointer<ToolTransformArgs> m_continuedTransformation;
384
385 //PixelPrecision should always be in powers of 2
386 int m_pixelPrecision {8};
387 int m_previewPixelPrecision {16};
388
394};
395
396#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()
QScopedPointer< ToolTransformArgs > m_continuedTransformation
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)
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