Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeShadowCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2008 Jan Hambrecht <jaham@gmx.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8#include "KoShape.h"
9#include "KoShapeShadow.h"
10
11#include <klocalizedstring.h>
12
13class Q_DECL_HIDDEN KoShapeShadowCommand::Private
14{
15public:
18 Q_FOREACH (KoShapeShadow* shadow, oldShadows) {
19 if (shadow && !shadow->deref())
20 delete shadow;
21 }
22 }
23
24 void addOldShadow(KoShapeShadow * oldShadow)
25 {
26 if (oldShadow)
27 oldShadow->ref();
28 oldShadows.append(oldShadow);
29 }
30
31 void addNewShadow(KoShapeShadow * newShadow)
32 {
33 if (newShadow)
34 newShadow->ref();
35 newShadows.append(newShadow);
36 }
37
41};
42
44 : KUndo2Command(parent)
45 , d(new Private())
46{
47 d->shapes = shapes;
48 // save old shadows
49 Q_FOREACH (KoShape *shape, d->shapes) {
50 d->addOldShadow(shape->shadow());
51 d->addNewShadow(shadow);
52 }
53
54 setText(kundo2_i18n("Set Shadow"));
55}
56
58 : KUndo2Command(parent)
59 , d(new Private())
60{
61 Q_ASSERT(shapes.count() == shadows.count());
62
63 d->shapes = shapes;
64
65 // save old shadows
66 Q_FOREACH (KoShape *shape, shapes)
67 d->addOldShadow(shape->shadow());
68 Q_FOREACH (KoShapeShadow * shadow, shadows)
69 d->addNewShadow(shadow);
70
71 setText(kundo2_i18n("Set Shadow"));
72}
73
75 : KUndo2Command(parent)
76 , d(new Private())
77{
78 d->shapes.append(shape);
79 d->addNewShadow(shadow);
80 d->addOldShadow(shape->shadow());
81
82 setText(kundo2_i18n("Set Shadow"));
83}
84
89
91{
93 int shapeCount = d->shapes.count();
94 for (int i = 0; i < shapeCount; ++i) {
95 KoShape *shape = d->shapes[i];
96
97 // TODO: implement comparison operator for KoShapeShadow
98 // (or just deprecate it entirely)
99 if (shape->shadow() || d->newShadows[i]) {
100 const QRectF oldBoundingRect = shape->boundingRect();
101 shape->setShadow(d->newShadows[i]);
102 shape->updateAbsolute(oldBoundingRect | shape->boundingRect());
103 }
104 }
105}
106
108{
110 int shapeCount = d->shapes.count();
111 for (int i = 0; i < shapeCount; ++i) {
112 KoShape *shape = d->shapes[i];
113
114 // TODO: implement comparison operator for KoShapeShadow
115 // (or just deprecate it entirely)
116 if (shape->shadow() || d->oldShadows[i]) {
117 const QRectF oldBoundingRect = shape->boundingRect();
118 shape->setShadow(d->oldShadows[i]);
119 shape->updateAbsolute(oldBoundingRect | shape->boundingRect());
120 }
121 }
122}
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
The undo / redo command for setting the shape shadow.
QList< KoShapeShadow * > oldShadows
the old shadows, one for each shape
void redo() override
redo the command
QList< KoShape * > shapes
the shapes to set shadow for
void undo() override
revert the actions done in redo
QList< KoShapeShadow * > newShadows
the new shadows to set
void addNewShadow(KoShapeShadow *newShadow)
void addOldShadow(KoShapeShadow *oldShadow)
KoShapeShadowCommand(const QList< KoShape * > &shapes, KoShapeShadow *shadow, KUndo2Command *parent=0)
void setShadow(KoShapeShadow *shadow)
Sets the new shadow, removing the old one.
Definition KoShape.cpp:1103
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
KoShapeShadow * shadow() const
Returns the currently set shadow or 0 if there is no shadow set.
Definition KoShape.cpp:1116
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
KUndo2MagicString kundo2_i18n(const char *text)