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"
15
17{
18public:
20 void applyOffset(qreal factor);
21
22 QMap<KoPathPointData, QPointF > points;
23 QSet<KoPathShape*> paths;
24};
25
26
28 : KUndo2Command(parent),
30{
31 setText(kundo2_i18n("Move points"));
32
33 foreach (const KoPathPointData &data, pointData) {
34 if (!d->points.contains(data)) {
35 d->points[data] = offset;
36 d->paths.insert(data.pathShape);
37 }
38 }
39}
40
42 : KUndo2Command(parent),
44{
45 Q_ASSERT(pointData.count() == offsets.count());
46
47 setText(kundo2_i18n("Move points"));
48
49 uint dataCount = pointData.count();
50 for (uint i = 0; i < dataCount; ++i) {
51 const KoPathPointData & data = pointData[i];
52 if (!d->points.contains(data)) {
53 d->points[data] = offsets[i];
54 d->paths.insert(data.pathShape);
55 }
56 }
57}
58
63
69
75
80
82{
83 const KoPathPointMoveCommand *other = dynamic_cast<const KoPathPointMoveCommand*>(command);
84
85 if (!other ||
86 other->d->paths != d->paths ||
87 !KritaUtils::compareListsUnordered(other->d->points.keys(), d->points.keys())) {
88
89 return false;
90 }
91
92 auto it = d->points.begin();
93 while (it != d->points.end()) {
94 it.value() += other->d->points[it.key()];
95 ++it;
96 }
97
98 return true;
99}
100
102{
103 QList<KoShape*> shapes;
104 std::copy(paths.begin(), paths.end(), std::back_inserter(shapes));
105
106 KoShapeBulkActionLock lock(shapes);
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 }
124
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
static void bulkShapesUpdate(const UpdatesList &updates)
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1016
KUndo2MagicString kundo2_i18n(const char *text)
bool compareListsUnordered(const QList< T > &a, const QList< T > &b)