Krita Source Code Documentation
Loading...
Searching...
No Matches
KoPathPointMoveCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006, 2008-2009 Jan Hambrecht <jaham@gmx.net>
3 * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
4 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
10#include "KoPathPoint.h"
11#include <klocalizedstring.h>
12#include "kis_command_ids.h"
14
16{
17public:
19 void applyOffset(qreal factor);
20
21 QMap<KoPathPointData, QPointF > points;
22 QSet<KoPathShape*> paths;
23};
24
25
27 : KUndo2Command(parent),
29{
30 setText(kundo2_i18n("Move points"));
31
32 foreach (const KoPathPointData &data, pointData) {
33 if (!d->points.contains(data)) {
34 d->points[data] = offset;
35 d->paths.insert(data.pathShape);
36 }
37 }
38}
39
41 : KUndo2Command(parent),
43{
44 Q_ASSERT(pointData.count() == offsets.count());
45
46 setText(kundo2_i18n("Move points"));
47
48 uint dataCount = pointData.count();
49 for (uint i = 0; i < dataCount; ++i) {
50 const KoPathPointData & data = pointData[i];
51 if (!d->points.contains(data)) {
52 d->points[data] = offsets[i];
53 d->paths.insert(data.pathShape);
54 }
55 }
56}
57
62
68
74
79
81{
82 const KoPathPointMoveCommand *other = dynamic_cast<const KoPathPointMoveCommand*>(command);
83
84 if (!other ||
85 other->d->paths != d->paths ||
86 !KritaUtils::compareListsUnordered(other->d->points.keys(), d->points.keys())) {
87
88 return false;
89 }
90
91 auto it = d->points.begin();
92 while (it != d->points.end()) {
93 it.value() += other->d->points[it.key()];
94 ++it;
95 }
96
97 return true;
98}
99
101{
102 QMap<KoShape*, QRectF> oldDirtyRects;
103
104 foreach (KoPathShape *path, paths) {
105 oldDirtyRects[path] = path->boundingRect();
106 }
107
108 QMap<KoPathPointData, QPointF>::iterator it(points.begin());
109 for (; it != points.end(); ++it) {
110 KoPathShape *path = it.key().pathShape;
111 // transform offset from document to shape coordinate system
112 QPointF shapeOffset = path->documentToShape(factor*it.value()) - path->documentToShape(QPointF());
113 QTransform matrix;
114 matrix.translate(shapeOffset.x(), shapeOffset.y());
115
116 KoPathPoint *p = path->pointByIndex(it.key().pointIndex);
117 if (p)
118 p->map(matrix);
119 }
120
121 foreach (KoPathShape *path, paths) {
122 path->normalize();
123 // repaint new bounding rect
124 path->updateAbsolute(oldDirtyRects[path] | path->boundingRect());
125 }
126}
const Params2D p
unsigned int uint
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathShape * pathShape
path shape the path point belongs too
QMap< KoPathPointData, QPointF > points
The undo / redo command for path point moving.
void undo() override
revert the actions done in redo
bool mergeWith(const KUndo2Command *command) override
KoPathPointMoveCommandPrivate *const d
KoPathPointMoveCommand(const QList< KoPathPointData > &pointData, const QPointF &offset, KUndo2Command *parent=0)
void redo() override
redo the command
A KoPathPoint represents a point in a path.
void map(const QTransform &matrix)
apply matrix on the point
The position of a path point within a path shape.
Definition KoPathShape.h:63
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211
KUndo2MagicString kundo2_i18n(const char *text)
bool compareListsUnordered(const QList< T > &a, const QList< T > &b)