Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextReorderShapeInsideCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7#include <KoSvgTextShape.h>
9
10
13 : textShape(_text)
14 , memento(textShape->getMemento())
15 , shapes(_shapes)
16 , type(_type)
17 {
18 std::sort(shapes.begin(), shapes.end(), [this](KoShape *a, KoShape *b)
19 {
20 return this->textShape->shapesInside().indexOf(a) < this->textShape->shapesInside().indexOf(b);
21 });
22 Q_FOREACH(KoShape *shape, shapes) {
23 oldIndices.append(textShape->shapesInside().indexOf(shape));
24 }
25 }
26
32};
33
35 : KUndo2Command(parent)
36 , d(new Private(textShape, shapes, type))
37{
38
39}
40
45
47{
48 KoShapeBulkActionLock lock(d->textShape);
49
50 int newIndex = d->textShape->shapesInside().indexOf(d->shapes.first());
51 const int max = (d->textShape->shapesInside().size() -1);
52 if (d->type == MoveEarlier || d->type == BringToFront) {
53 if (d->type == MoveEarlier) {
54 newIndex = qMax(0, newIndex - 1);
55 } else {
56 newIndex = 0;
57 }
58 Q_FOREACH(KoShape *shape, d->shapes) {
59 const int index = d->textShape->shapesInside().indexOf(shape);
60 if (index == newIndex) continue;
61
62 d->textShape->moveShapeInsideToIndex(shape, newIndex);
63 newIndex += 1;
64 }
65 } else {
66 if (d->type == MoveLater) {
67 newIndex = qMin(max, newIndex + d->shapes.size());
68 } else {
69 newIndex = max;
70 }
71 auto end = std::make_reverse_iterator(d->shapes.begin());
72 auto begin = std::make_reverse_iterator(d->shapes.end());
73 for (auto it = begin; it != end; it++) {
74 KoShape *shape = *it;
75
76 const int index = d->textShape->shapesInside().indexOf(shape);
77 if (index == newIndex) continue;
78 if (newIndex < 0) continue;
79
80 d->textShape->moveShapeInsideToIndex(shape, newIndex);
81 newIndex -= 1;
82 }
83 }
84
86}
87
89{
90 KoShapeBulkActionLock lock(d->textShape);
91
92 if (d->type == MoveEarlier || d->type == BringToFront) {
93 for (int i = d->oldIndices.size() -1 ; i>= 0; i--) {
94 d->textShape->moveShapeInsideToIndex(d->shapes.at(i), d->oldIndices.at(i));
95 }
96 } else {
97 for (int i = 0; i< d->oldIndices.size(); i++) {
98 d->textShape->moveShapeInsideToIndex(d->shapes.at(i), d->oldIndices.at(i));
99 }
100 }
101 d->textShape->setMemento(d->memento);
102
104}
static void bulkShapesUpdate(const UpdatesList &updates)
KoSvgTextReorderShapeInsideCommand(KoSvgTextShape *textShape, QList< KoShape * > shape, MoveShapeType type, KUndo2Command *parent=nullptr)
QList< KoShape * > shapesInside
KoSvgTextReorderShapeInsideCommand::MoveShapeType type
Private(KoSvgTextShape *_text, QList< KoShape * > _shapes, KoSvgTextReorderShapeInsideCommand::MoveShapeType _type)