Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeClipCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2011 Jan Hambrecht <jaham@gmx.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8#include "KoClipPath.h"
9#include "KoShape.h"
10#include "KoShapeContainer.h"
11#include "KoPathShape.h"
13
14#include <klocalizedstring.h>
15
16#include "kis_pointer_utils.h"
17
18class Q_DECL_HIDDEN KoShapeClipCommand::Private
19{
20public:
22 : controller(c), executed(false) {
23 }
24
26 if (executed) {
27 qDeleteAll(oldClipPaths);
28 } else {
29 qDeleteAll(newClipPaths);
30 }
31 }
32
40};
41
43 : KUndo2Command(parent), d(new Private(controller))
44{
45 d->shapesToClip = shapes;
46 d->clipPathShapes = clipPathShapes;
47
48 Q_FOREACH (KoShape *shape, d->shapesToClip) {
49 d->oldClipPaths.append(shape->clipPath());
50 d->newClipPaths.append(new KoClipPath(implicitCastList<KoShape*>(clipPathShapes), KoFlake::UserSpaceOnUse));
51 }
52
53 Q_FOREACH (KoPathShape *path, clipPathShapes) {
54 d->oldParents.append(path->parent());
55 }
56
57 setText(kundo2_i18n("Clip Shape"));
58}
59
61 : KUndo2Command(parent), d(new Private(controller))
62{
63 d->shapesToClip.append(shape);
64 d->clipPathShapes = clipPathShapes;
65 d->oldClipPaths.append(shape->clipPath());
66 d->newClipPaths.append(new KoClipPath(implicitCastList<KoShape*>(clipPathShapes), KoFlake::UserSpaceOnUse));
67
68 Q_FOREACH (KoPathShape *path, clipPathShapes) {
69 d->oldParents.append(path->parent());
70 }
71
72 setText(kundo2_i18n("Clip Shape"));
73}
74
79
81{
82 const uint shapeCount = d->shapesToClip.count();
83 for (uint i = 0; i < shapeCount; ++i) {
84 d->shapesToClip[i]->setClipPath(d->newClipPaths[i]);
85 d->shapesToClip[i]->update();
86 }
87
88 const uint clipPathCount = d->clipPathShapes.count();
89 for (uint i = 0; i < clipPathCount; ++i) {
90 if (d->oldParents.at(i)) {
91 d->oldParents.at(i)->removeShape(d->clipPathShapes[i]);
92 }
93 }
94
95 d->executed = true;
96
98}
99
101{
103
104 const uint shapeCount = d->shapesToClip.count();
105 for (uint i = 0; i < shapeCount; ++i) {
106 d->shapesToClip[i]->setClipPath(d->oldClipPaths[i]);
107 d->shapesToClip[i]->update();
108 }
109
110 const uint clipPathCount = d->clipPathShapes.count();
111 for (uint i = 0; i < clipPathCount; ++i) {
112 if (d->oldParents.at(i)) {
113 d->oldParents.at(i)->addShape(d->clipPathShapes[i]);
114 }
115 }
116
117 d->executed = false;
118}
unsigned int uint
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
Clip path used to clip shapes.
The position of a path point within a path shape.
Definition KoPathShape.h:63
The undo / redo command for setting the shape clip path.
QList< KoShape * > shapesToClip
QList< KoClipPath * > oldClipPaths
~KoShapeClipCommand() override
Destroys the command.
QList< KoShapeContainer * > oldParents
KoShapeClipCommand(KoShapeControllerBase *controller, const QList< KoShape * > &shapes, const QList< KoPathShape * > &clipPathShapes, KUndo2Command *parent=0)
void undo() override
revert the actions done in redo
QList< KoClipPath * > newClipPaths
void redo() override
redo the command
QList< KoPathShape * > clipPathShapes
Private(KoShapeControllerBase *c)
KoShapeControllerBase * controller
KoClipPath * clipPath() const
Returns the currently set clip path or 0 if there is no clip path set.
Definition KoShape.cpp:1128
KUndo2MagicString kundo2_i18n(const char *text)