Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeStrokeCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
4 * SPDX-FileCopyrightText: 2006-2008 Jan Hambrecht <jaham@gmx.net>
5 * SPDX-FileCopyrightText: 2012 Inge Wallin <inge@lysator.liu.se>
6 *
7 * SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
11#include "KoShape.h"
12#include "KoShapeStrokeModel.h"
13
14#include <klocalizedstring.h>
15
16#include "kis_command_ids.h"
17
18
19class Q_DECL_HIDDEN KoShapeStrokeCommand::Private
20{
21public:
24 {
25 }
26
28 {
29 oldStrokes.append(oldStroke);
30 }
31
33 {
34 newStrokes.append(newStroke);
35 }
36
40};
41
43 : KUndo2Command(parent)
44 , d(new Private())
45{
46 d->shapes = shapes;
47
48 // save old strokes
49 Q_FOREACH (KoShape *shape, d->shapes) {
50 d->addOldStroke(shape->stroke());
51 d->addNewStroke(stroke);
52 }
53
54 setText(kundo2_i18n("Set stroke"));
55}
56
58 const QList<KoShapeStrokeModelSP> &strokes,
59 KUndo2Command *parent)
60 : KUndo2Command(parent)
61 , d(new Private())
62{
63 Q_ASSERT(shapes.count() == strokes.count());
64
65 d->shapes = shapes;
66
67 // save old strokes
68 Q_FOREACH (KoShape *shape, shapes)
69 d->addOldStroke(shape->stroke());
70 foreach (KoShapeStrokeModelSP stroke, strokes)
71 d->addNewStroke(stroke);
72
73 setText(kundo2_i18n("Set stroke"));
74}
75
77 : KUndo2Command(parent)
78 , d(new Private())
79{
80 d->shapes.append(shape);
81 d->addNewStroke(stroke);
82 d->addOldStroke(shape->stroke());
83
84 setText(kundo2_i18n("Set stroke"));
85}
86
91
93{
95 QList<KoShapeStrokeModelSP>::iterator strokeIt = d->newStrokes.begin();
96 Q_FOREACH (KoShape *shape, d->shapes) {
97 const QRectF oldDirtyRect = shape->boundingRect();
98 shape->setStroke(*strokeIt);
99 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
100 ++strokeIt;
101 }
102}
103
105{
107 QList<KoShapeStrokeModelSP>::iterator strokeIt = d->oldStrokes.begin();
108 Q_FOREACH (KoShape *shape, d->shapes) {
109 const QRectF oldDirtyRect = shape->boundingRect();
110 shape->setStroke(*strokeIt);
111 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
112 ++strokeIt;
113 }
114}
115
120
122{
123 const KoShapeStrokeCommand *other = dynamic_cast<const KoShapeStrokeCommand*>(command);
124
125 if (!other ||
126 other->d->shapes != d->shapes) {
127
128 return false;
129 }
130
131 d->newStrokes = other->d->newStrokes;
132 return true;
133}
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
The undo / redo command for setting the shape stroke.
QList< KoShapeStrokeModelSP > newStrokes
the new strokes to set
void undo() override
revert the actions done in redo
void addOldStroke(KoShapeStrokeModelSP oldStroke)
void redo() override
redo the command
QList< KoShape * > shapes
the shapes to set stroke for
void addNewStroke(KoShapeStrokeModelSP newStroke)
KoShapeStrokeCommand(const QList< KoShape * > &shapes, KoShapeStrokeModelSP stroke, KUndo2Command *parent=0)
QList< KoShapeStrokeModelSP > oldStrokes
the old strokes, one for each shape
bool mergeWith(const KUndo2Command *command) override
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
KUndo2MagicString kundo2_i18n(const char *text)