Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeAlignCommand.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#include "KoShape.h"
10#include "KoShapeGroup.h"
12
13#include <klocalizedstring.h>
14// #include <FlakeDebug.h>
15
16class Q_DECL_HIDDEN KoShapeAlignCommand::Private
17{
18public:
19 Private() : command(0) {}
21 delete command;
22 }
24};
25
26KoShapeAlignCommand::KoShapeAlignCommand(const QList<KoShape*> &shapes, Align align, const QRectF &boundingRect, KUndo2Command *parent)
27 : KUndo2Command(parent),
28 d(new Private())
29{
30 QList<QPointF> previousPositions;
31 QList<QPointF> newPositions;
32 QPointF position;
33 QPointF delta;
34 QRectF bRect;
35 Q_FOREACH (KoShape *shape, shapes) {
36// if (dynamic_cast<KoShapeGroup*> (shape))
37// debugFlake <<"Found Group";
38// else if (dynamic_cast<KoShapeContainer*> (shape))
39// debugFlake <<"Found Container";
40// else
41// debugFlake <<"Found shape";
42 position = shape->absolutePosition();
43 previousPositions << position;
44 bRect = shape->absoluteOutlineRect();
45 switch (align) {
47 delta = QPointF(boundingRect.left(), bRect.y()) - bRect.topLeft();
48 break;
50 delta = QPointF(boundingRect.center().x() - bRect.width() / 2, bRect.y()) - bRect.topLeft();
51 break;
53 delta = QPointF(boundingRect.right() - bRect.width(), bRect.y()) - bRect.topLeft();
54 break;
56 delta = QPointF(bRect.x(), boundingRect.top()) - bRect.topLeft();
57 break;
59 delta = QPointF(bRect.x(), boundingRect.center().y() - bRect.height() / 2) - bRect.topLeft();
60 break;
62 delta = QPointF(bRect.x(), boundingRect.bottom() - bRect.height()) - bRect.topLeft();
63 break;
64 };
65 newPositions << position + delta;
66//debugFlake <<"-> moving" << position.x() <<"," << position.y() <<" to" <<
67// (position + delta).x() << ", " << (position+delta).y() << Qt::endl;
68 }
69 d->command = new KoShapeMoveCommand(shapes, previousPositions, newPositions);
70
71 setText(kundo2_i18n("Align shapes"));
72}
73
78
80{
82 d->command->redo();
83}
84
86{
88 d->command->undo();
89}
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
The undo / redo command for aligning shapes.
void undo() override
revert the actions done in redo
KoShapeMoveCommand * command
void redo() override
redo the command
Align
The different alignment options for this command.
@ VerticalCenterAlignment
Align centered vertically.
@ HorizontalLeftAlignment
Align left.
@ HorizontalCenterAlignment
Align Centered horizontally.
@ VerticalBottomAlignment
Align bottom.
@ HorizontalRightAlignment
Align Right.
KoShapeAlignCommand(const QList< KoShape * > &shapes, Align align, const QRectF &boundingRect, KUndo2Command *parent=0)
The undo / redo command for shape moving.
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
QRectF absoluteOutlineRect() const
Definition KoShape.cpp:368
KUndo2MagicString kundo2_i18n(const char *text)