Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeResizeCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <KoShape.h>
10#include "kis_command_ids.h"
12
13
27
28
30 qreal scaleX, qreal scaleY,
31 const QPointF &absoluteStillPoint,
32 bool useGLobalMode,
33 bool usePostScaling,
34 const QTransform &postScalingCoveringTransform,
35 KUndo2Command *parent)
36 : SkipFirstRedoBase(false, kundo2_i18n("Resize"), parent),
37 m_d(new Private)
38{
39 m_d->shapes = shapes;
40 m_d->scaleX = scaleX;
41 m_d->scaleY = scaleY;
42 m_d->absoluteStillPoint = absoluteStillPoint;
43 m_d->useGlobalMode = useGLobalMode;
44 m_d->usePostScaling = usePostScaling;
45 m_d->postScalingCoveringTransform = postScalingCoveringTransform;
46
47 Q_FOREACH (KoShape *shape, m_d->shapes) {
48 m_d->oldSizes << shape->size();
49 m_d->oldTransforms << shape->transformation();
50 }
51}
52
56
65
74
76{
77 Q_FOREACH (KoShape *shape, m_d->shapes) {
79 m_d->scaleX, m_d->scaleY,
80 m_d->absoluteStillPoint,
81 m_d->useGlobalMode,
82 m_d->usePostScaling,
83 m_d->postScalingCoveringTransform);
84 }
85}
86
88{
89 for (int i = 0; i < m_d->shapes.size(); i++) {
90 KoShape *shape = m_d->shapes[i];
91
92 shape->setSize(m_d->oldSizes[i]);
93 shape->setTransformation(m_d->oldTransforms[i]);
94 }
95}
96
101
103{
104 const KoShapeResizeCommand *other = dynamic_cast<const KoShapeResizeCommand*>(command);
105
106 if (!other ||
107 other->m_d->absoluteStillPoint != m_d->absoluteStillPoint ||
108 other->m_d->shapes != m_d->shapes ||
109 other->m_d->useGlobalMode != m_d->useGlobalMode ||
110 other->m_d->usePostScaling != m_d->usePostScaling) {
111
112 return false;
113 }
114
115 // check if the significant orientations coincide
116 if (m_d->useGlobalMode && !m_d->usePostScaling) {
117 Qt::Orientation our = KoFlake::significantScaleOrientation(m_d->scaleX, m_d->scaleY);
118 Qt::Orientation their = KoFlake::significantScaleOrientation(other->m_d->scaleX, other->m_d->scaleY);
119
120 if (our != their) {
121 return false;
122 }
123 }
124
125 m_d->scaleX *= other->m_d->scaleX;
126 m_d->scaleY *= other->m_d->scaleY;
127 return true;
128}
129
130void KoShapeResizeCommand::replaceResizeAction(qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint)
131{
132 KoShapeBulkActionLock lock(m_d->shapes);
133
134 undoNoUpdate();
135
136 m_d->scaleX = scaleX;
137 m_d->scaleY = scaleY;
138 m_d->absoluteStillPoint = absoluteStillPoint;
139
140 redoNoUpdate();
141
143}
static void bulkShapesUpdate(const UpdatesList &updates)
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:740
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:374
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:383
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:248
KUndo2MagicString kundo2_i18n(const char *text)
KRITAFLAKE_EXPORT Qt::Orientation significantScaleOrientation(qreal scaleX, qreal scaleY)
Definition KoFlake.cpp:168
KRITAFLAKE_EXPORT void resizeShapeCommon(KoShape *shape, qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint, bool useGlobalMode, bool usePostScaling, const QTransform &postScalingCoveringTransform)
Definition KoFlake.cpp:313
bool mergeWith(const KUndo2Command *command) override
QList< QTransform > oldTransforms
KoShapeResizeCommand(const QList< KoShape * > &shapes, qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint, bool useGLobalMode, bool usePostScaling, const QTransform &postScalingCoveringTransform, KUndo2Command *parent=0)
void replaceResizeAction(qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint)
QScopedPointer< Private > const m_d
int id() const override