Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeResizeCommand Class Reference

#include <KoShapeResizeCommand.h>

+ Inheritance diagram for KoShapeResizeCommand:

Public Member Functions

int id () const override
 
 KoShapeResizeCommand (const QList< KoShape * > &shapes, qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint, bool useGLobalMode, bool usePostScaling, const QTransform &postScalingCoveringTransform, KUndo2Command *parent=0)
 
bool mergeWith (const KUndo2Command *command) override
 
void redoImpl () override
 
QMap< KoShape *, QRectF > redoNoUpdate ()
 
void replaceResizeAction (qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint)
 
void undoImpl () override
 
QMap< KoShape *, QRectF > undoNoUpdate ()
 
 ~KoShapeResizeCommand () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisCommandUtils::SkipFirstRedoBase
void redo () override final
 
void setSkipOneRedo (bool value)
 
 SkipFirstRedoBase (bool skipFirstRedo, const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 SkipFirstRedoBase (bool skipFirstRedo, KUndo2Command *parent=0)
 
void undo () override final
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Public Attributes

QPointF absoluteStillPoint
 
QList< QSizeF > oldSizes
 
QList< QTransform > oldTransforms
 
QTransform postScalingCoveringTransform
 
qreal scaleX
 
qreal scaleY
 
QList< KoShape * > shapes
 
bool useGlobalMode
 
bool usePostScaling
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Attributes

QScopedPointer< Private > const m_d
 

Additional Inherited Members

Detailed Description

Definition at line 14 of file KoShapeResizeCommand.cpp.

Constructor & Destructor Documentation

◆ KoShapeResizeCommand()

KoShapeResizeCommand::KoShapeResizeCommand ( const QList< KoShape * > & shapes,
qreal scaleX,
qreal scaleY,
const QPointF & absoluteStillPoint,
bool useGLobalMode,
bool usePostScaling,
const QTransform & postScalingCoveringTransform,
KUndo2Command * parent = 0 )

Definition at line 29 of file KoShapeResizeCommand.cpp.

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}
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:820
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
KUndo2MagicString kundo2_i18n(const char *text)
SkipFirstRedoBase(bool skipFirstRedo, KUndo2Command *parent=0)
QScopedPointer< Private > const m_d

References absoluteStillPoint, m_d, postScalingCoveringTransform, scaleX, scaleY, shapes, KoShape::size(), KoShape::transformation(), and usePostScaling.

◆ ~KoShapeResizeCommand()

KoShapeResizeCommand::~KoShapeResizeCommand ( )
override

Definition at line 53 of file KoShapeResizeCommand.cpp.

54{
55}

Member Function Documentation

◆ id()

int KoShapeResizeCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 112 of file KoShapeResizeCommand.cpp.

References KisCommandUtils::ResizeShapeId.

◆ mergeWith()

bool KoShapeResizeCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 117 of file KoShapeResizeCommand.cpp.

118{
119 const KoShapeResizeCommand *other = dynamic_cast<const KoShapeResizeCommand*>(command);
120
121 if (!other ||
122 other->m_d->absoluteStillPoint != m_d->absoluteStillPoint ||
123 other->m_d->shapes != m_d->shapes ||
124 other->m_d->useGlobalMode != m_d->useGlobalMode ||
125 other->m_d->usePostScaling != m_d->usePostScaling) {
126
127 return false;
128 }
129
130 // check if the significant orientations coincide
131 if (m_d->useGlobalMode && !m_d->usePostScaling) {
132 Qt::Orientation our = KoFlake::significantScaleOrientation(m_d->scaleX, m_d->scaleY);
133 Qt::Orientation their = KoFlake::significantScaleOrientation(other->m_d->scaleX, other->m_d->scaleY);
134
135 if (our != their) {
136 return false;
137 }
138 }
139
140 m_d->scaleX *= other->m_d->scaleX;
141 m_d->scaleY *= other->m_d->scaleY;
142 return true;
143}
KRITAFLAKE_EXPORT Qt::Orientation significantScaleOrientation(qreal scaleX, qreal scaleY)
Definition KoFlake.cpp:168

References m_d, and KoFlake::significantScaleOrientation().

◆ redoImpl()

void KoShapeResizeCommand::redoImpl ( )
overridevirtual

Implements KisCommandUtils::SkipFirstRedoBase.

Definition at line 57 of file KoShapeResizeCommand.cpp.

58{
59 QMap<KoShape*, QRectF> updates = redoNoUpdate();
60
61 for (auto it = updates.begin(); it != updates.end(); ++it) {
62 it.key()->updateAbsolute(it.value());
63 }
64}
QMap< KoShape *, QRectF > redoNoUpdate()

References redoNoUpdate().

◆ redoNoUpdate()

QMap< KoShape *, QRectF > KoShapeResizeCommand::redoNoUpdate ( )

Definition at line 75 of file KoShapeResizeCommand.cpp.

76{
77 QMap<KoShape*,QRectF> updates;
78
79 Q_FOREACH (KoShape *shape, m_d->shapes) {
80 const QRectF oldDirtyRect = shape->boundingRect();
81
83 m_d->scaleX, m_d->scaleY,
84 m_d->absoluteStillPoint,
85 m_d->useGlobalMode,
86 m_d->usePostScaling,
87 m_d->postScalingCoveringTransform);
88
89 updates[shape] = oldDirtyRect | shape->boundingRect();
90 }
91
92 return updates;
93}
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
KRITAFLAKE_EXPORT void resizeShapeCommon(KoShape *shape, qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint, bool useGlobalMode, bool usePostScaling, const QTransform &postScalingCoveringTransform)
Definition KoFlake.cpp:313

References KoShape::boundingRect(), m_d, and KoFlake::resizeShapeCommon().

◆ replaceResizeAction()

void KoShapeResizeCommand::replaceResizeAction ( qreal scaleX,
qreal scaleY,
const QPointF & absoluteStillPoint )

Definition at line 145 of file KoShapeResizeCommand.cpp.

146{
147 const QMap<KoShape*, QRectF> undoUpdates = undoNoUpdate();
148
149 m_d->scaleX = scaleX;
150 m_d->scaleY = scaleY;
151 m_d->absoluteStillPoint = absoluteStillPoint;
152
153 const QMap<KoShape*, QRectF> redoUpdates = redoNoUpdate();
154
155 KIS_SAFE_ASSERT_RECOVER_NOOP(undoUpdates.size() == redoUpdates.size());
156
157 for (auto it = undoUpdates.begin(); it != undoUpdates.end(); ++it) {
158 KIS_SAFE_ASSERT_RECOVER_NOOP(redoUpdates.contains(it.key()));
159 it.key()->updateAbsolute(it.value() | redoUpdates[it.key()]);
160 }
161}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
QMap< KoShape *, QRectF > undoNoUpdate()

References absoluteStillPoint, KIS_SAFE_ASSERT_RECOVER_NOOP, m_d, redoNoUpdate(), scaleX, scaleY, and undoNoUpdate().

◆ undoImpl()

void KoShapeResizeCommand::undoImpl ( )
overridevirtual

Implements KisCommandUtils::SkipFirstRedoBase.

Definition at line 66 of file KoShapeResizeCommand.cpp.

67{
68 QMap<KoShape*, QRectF> updates = undoNoUpdate();
69
70 for (auto it = updates.begin(); it != updates.end(); ++it) {
71 it.key()->updateAbsolute(it.value());
72 }
73}

References undoNoUpdate().

◆ undoNoUpdate()

QMap< KoShape *, QRectF > KoShapeResizeCommand::undoNoUpdate ( )

Definition at line 95 of file KoShapeResizeCommand.cpp.

96{
97 QMap<KoShape*,QRectF> updates;
98
99 for (int i = 0; i < m_d->shapes.size(); i++) {
100 KoShape *shape = m_d->shapes[i];
101
102 const QRectF oldDirtyRect = shape->boundingRect();
103 shape->setSize(m_d->oldSizes[i]);
104 shape->setTransformation(m_d->oldTransforms[i]);
105
106 updates[shape] = oldDirtyRect | shape->boundingRect();
107 }
108
109 return updates;
110}
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:417
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:276

References KoShape::boundingRect(), m_d, KoShape::setSize(), and KoShape::setTransformation().

Member Data Documentation

◆ absoluteStillPoint

QPointF KoShapeResizeCommand::absoluteStillPoint

Definition at line 19 of file KoShapeResizeCommand.cpp.

◆ m_d

QScopedPointer<Private> const KoShapeResizeCommand::m_d
private

Definition at line 47 of file KoShapeResizeCommand.h.

◆ oldSizes

QList<QSizeF> KoShapeResizeCommand::oldSizes

Definition at line 24 of file KoShapeResizeCommand.cpp.

◆ oldTransforms

QList<QTransform> KoShapeResizeCommand::oldTransforms

Definition at line 25 of file KoShapeResizeCommand.cpp.

◆ postScalingCoveringTransform

QTransform KoShapeResizeCommand::postScalingCoveringTransform

Definition at line 22 of file KoShapeResizeCommand.cpp.

◆ scaleX

qreal KoShapeResizeCommand::scaleX

Definition at line 17 of file KoShapeResizeCommand.cpp.

◆ scaleY

qreal KoShapeResizeCommand::scaleY

Definition at line 18 of file KoShapeResizeCommand.cpp.

◆ shapes

QList<KoShape *> KoShapeResizeCommand::shapes

Definition at line 16 of file KoShapeResizeCommand.cpp.

◆ useGlobalMode

bool KoShapeResizeCommand::useGlobalMode

Definition at line 20 of file KoShapeResizeCommand.cpp.

◆ usePostScaling

bool KoShapeResizeCommand::usePostScaling

Definition at line 21 of file KoShapeResizeCommand.cpp.


The documentation for this class was generated from the following files: