Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeUnclipCommand.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#include <kis_assert.h>
14
15#include <klocalizedstring.h>
16
18{
19public:
23
25 if (executed) {
26 qDeleteAll(oldClipPaths);
27 } else {
28 qDeleteAll(clipPathShapes);
29 }
30 }
31
33 // check if we have already created the clip path shapes
34 if (!clipPathShapes.isEmpty())
35 return;
36
37 Q_FOREACH (KoShape *shape, shapesToUnclip) {
38 KoClipPath *clipPath = shape->clipPath();
39 if (!clipPath)
40 continue;
41
42 Q_FOREACH (KoShape *clipShape, clipPath->clipPathShapes()) {
43 KoShape *clone = clipShape->cloneShape();
44
45 KoPathShape *pathShape = dynamic_cast<KoPathShape*>(clone);
46 KIS_SAFE_ASSERT_RECOVER(pathShape) {
47 delete clone;
48 continue;
49 }
50
51 clipPathShapes.append(pathShape);
52 }
53
54 // apply transformations
55 Q_FOREACH (KoPathShape *pathShape, clipPathShapes) {
56 // apply transformation so that it matches the current clipped shapes clip path
57 pathShape->applyAbsoluteTransformation(clipPath->clipDataTransformation(shape));
58 pathShape->setZIndex(shape->zIndex() + 1);
59 clipPathParents.append(shape->parent());
60 }
61 }
62 }
63
68
69 // TODO: damn! this is not a controller, this is a document! Needs refactoring!
71
73};
74
76 : KUndo2Command(parent), d(new Private(controller))
77{
78 d->shapesToUnclip = shapes;
79 Q_FOREACH (KoShape *shape, d->shapesToUnclip) {
80 d->oldClipPaths.append(shape->clipPath());
81 }
82
83 setText(kundo2_i18n("Unclip Shape"));
84}
85
87 : KUndo2Command(parent), d(new Private(controller))
88{
89 d->shapesToUnclip.append(shape);
90 d->oldClipPaths.append(shape->clipPath());
91
92 setText(kundo2_i18n("Unclip Shapes"));
93}
94
99
101{
103
104 const uint shapeCount = d->shapesToUnclip.count();
105 for (uint i = 0; i < shapeCount; ++i) {
106 d->shapesToUnclip[i]->setClipPath(0);
107 d->shapesToUnclip[i]->update();
108 }
109
110 const uint clipPathCount = d->clipPathShapes.count();
111 for (uint i = 0; i < clipPathCount; ++i) {
112 if (d->clipPathParents.at(i)) {
113 d->clipPathParents.at(i)->addShape(d->clipPathShapes[i]);
114 }
115 }
116
117 d->executed = true;
118
120}
121
123{
125
126 const uint shapeCount = d->shapesToUnclip.count();
127 for (uint i = 0; i < shapeCount; ++i) {
128 d->shapesToUnclip[i]->setClipPath(d->oldClipPaths[i]);
129 d->shapesToUnclip[i]->update();
130 }
131
132 const uint clipPathCount = d->clipPathShapes.count();
133 for (uint i = 0; i < clipPathCount; ++i) {
134 if (d->clipPathParents.at(i)) {
135 d->clipPathParents.at(i)->removeShape(d->clipPathShapes[i]);
136 }
137 }
138
139 d->executed = false;
140}
unsigned int uint
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
Clip path used to clip shapes.
QList< KoPathShape * > clipPathShapes() const
Returns the clip path shapes.
QTransform clipDataTransformation(KoShape *clippedShape) const
The position of a path point within a path shape.
Definition KoPathShape.h:63
QList< KoPathShape * > clipPathShapes
Private(KoShapeControllerBase *c)
QList< KoShapeContainer * > clipPathParents
KoShapeUnclipCommand(KoShapeControllerBase *controller, const QList< KoShape * > &shapes, KUndo2Command *parent=0)
~KoShapeUnclipCommand() override
Destroys the command.
void redo() override
redo the command
void undo() override
revert the actions done in redo
void setZIndex(qint16 zIndex)
Definition KoShape.cpp:954
void applyAbsoluteTransformation(const QTransform &matrix)
Definition KoShape.cpp:400
KoClipPath * clipPath() const
Returns the currently set clip path or 0 if there is no clip path set.
Definition KoShape.cpp:1128
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
qint16 zIndex() const
Definition KoShape.cpp:600
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
KUndo2MagicString kundo2_i18n(const char *text)