Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeMoveCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
3 * SPDX-FileCopyrightText: 2006 Jan Hambrecht <jaham@gmx.net>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
9
10#include <KoShape.h>
11#include <klocalizedstring.h>
12#include "kis_command_ids.h"
13#include <kis_assert.h>
14
22
24 : KUndo2Command(kundo2_i18n("Move shapes"), parent),
25 d(new Private())
26{
27 d->shapes = shapes;
28 d->previousPositions = previousPositions;
29 d->newPositions = newPositions;
30 d->anchor = anchor;
31 Q_ASSERT(d->shapes.count() == d->previousPositions.count());
32 Q_ASSERT(d->shapes.count() == d->newPositions.count());
33}
34
35KoShapeMoveCommand::KoShapeMoveCommand(const QList<KoShape *> &shapes, const QPointF &offset, KUndo2Command *parent)
36 : KUndo2Command(kundo2_i18n("Move shapes"), parent),
37 d(new Private())
38{
39 d->shapes = shapes;
40 d->anchor = KoFlake::Center;
41
42 Q_FOREACH (KoShape *shape, d->shapes) {
43 const QPointF pos = shape->absolutePosition();
44
45 d->previousPositions << pos;
46 d->newPositions << pos + offset;
47 }
48}
49
54
56{
58
59 for (int i = 0; i < d->shapes.count(); i++) {
60 KoShape *shape = d->shapes.at(i);
61
62 const QRectF oldDirtyRect = shape->boundingRect();
63 shape->setAbsolutePosition(d->newPositions.at(i), d->anchor);
64 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
65 }
66}
67
69{
71 for (int i = 0; i < d->shapes.count(); i++) {
72 KoShape *shape = d->shapes.at(i);
73
74 const QRectF oldDirtyRect = shape->boundingRect();
75 shape->setAbsolutePosition(d->previousPositions.at(i), d->anchor);
76 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
77 }
78}
79
84
86{
87 const KoShapeMoveCommand *other = dynamic_cast<const KoShapeMoveCommand*>(command);
88 KIS_ASSERT(other);
89
90 if (other->d->shapes != d->shapes ||
91 other->d->anchor != d->anchor) {
92
93 return false;
94 }
95
96 d->newPositions = other->d->newPositions;
97 return true;
98}
virtual void undo()
virtual void redo()
The undo / redo command for shape moving.
void undo() override
revert the actions done in redo
QList< KoShape * > shapes
KoFlake::AnchorPosition anchor
bool mergeWith(const KUndo2Command *command) override
int id() const override
void redo() override
redo the command
KoShapeMoveCommand(const QList< KoShape * > &shapes, QList< QPointF > &previousPositions, QList< QPointF > &newPositions, KoFlake::AnchorPosition anchor=KoFlake::Center, KUndo2Command *parent=0)
QList< QPointF > newPositions
QList< QPointF > previousPositions
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:668
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90