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>
15
16
24
26 : KUndo2Command(kundo2_i18n("Move shapes"), parent),
27 d(new Private())
28{
29 d->shapes = shapes;
30 d->previousPositions = previousPositions;
31 d->newPositions = newPositions;
32 d->anchor = anchor;
33 Q_ASSERT(d->shapes.count() == d->previousPositions.count());
34 Q_ASSERT(d->shapes.count() == d->newPositions.count());
35}
36
37KoShapeMoveCommand::KoShapeMoveCommand(const QList<KoShape *> &shapes, const QPointF &offset, KUndo2Command *parent)
38 : KUndo2Command(kundo2_i18n("Move shapes"), parent),
39 d(new Private())
40{
41 d->shapes = shapes;
42 d->anchor = KoFlake::Center;
43
44 Q_FOREACH (KoShape *shape, d->shapes) {
45 const QPointF pos = shape->absolutePosition();
46
47 d->previousPositions << pos;
48 d->newPositions << pos + offset;
49 }
50}
51
56
58{
60
61 KoShapeBulkActionLock lock(d->shapes);
62
63 for (int i = 0; i < d->shapes.count(); i++) {
64 KoShape *shape = d->shapes.at(i);
65 shape->setAbsolutePosition(d->newPositions.at(i), d->anchor);
66 }
67
69}
70
72{
74
75 KoShapeBulkActionLock lock(d->shapes);
76
77 for (int i = 0; i < d->shapes.count(); i++) {
78 KoShape *shape = d->shapes.at(i);
79 shape->setAbsolutePosition(d->previousPositions.at(i), d->anchor);
80 }
81
83}
84
89
91{
92 const KoShapeMoveCommand *other = dynamic_cast<const KoShapeMoveCommand*>(command);
93 KIS_ASSERT(other);
94
95 if (other->d->shapes != d->shapes ||
96 other->d->anchor != d->anchor) {
97
98 return false;
99 }
100
101 d->newPositions = other->d->newPositions;
102 return true;
103}
virtual void undo()
virtual void redo()
static void bulkShapesUpdate(const UpdatesList &updates)
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:573
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:588
#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