Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMultiPathPointMergeCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include <KoPathPointData.h>
9
12#include <KoSelection.h>
13
14#include "kis_assert.h"
15
16
18{
19 Private(const KoPathPointData &_pointData1, const KoPathPointData &_pointData2, KoShapeControllerBase *_controller, KoSelection *_selection)
20 : pointData1(_pointData1),
21 pointData2(_pointData2),
22 controller(_controller),
23 selection(_selection)
24 {
25 }
26
31
32
33 QScopedPointer<KoPathCombineCommand> combineCommand;
34 QScopedPointer<KUndo2Command> mergeCommand;
35};
36
38 : KUndo2Command(kundo2_i18n("Merge points"), parent),
39 m_d(new Private(pointData1, pointData2, controller, selection))
40{
41}
42
46
51
53{
54 KoShape *mergedShape = 0;
55
56 if (m_d->pointData1.pathShape != m_d->pointData2.pathShape) {
58
59 QList<KoPathShape*> shapes = {m_d->pointData1.pathShape, m_d->pointData2.pathShape};
60 m_d->combineCommand.reset(new KoPathCombineCommand(m_d->controller, shapes));
61 m_d->combineCommand->redo();
62
63 KoPathPointData newPD1 = m_d->combineCommand->originalToCombined(m_d->pointData1);
64 KoPathPointData newPD2 = m_d->combineCommand->originalToCombined(m_d->pointData2);
65
66 m_d->mergeCommand.reset(createMergeCommand(newPD1, newPD2));
67 m_d->mergeCommand->redo();
68
69 mergedShape = m_d->combineCommand->combinedPath();
70
71 } else {
72 m_d->mergeCommand.reset(createMergeCommand(m_d->pointData1, m_d->pointData2));
73 m_d->mergeCommand->redo();
74
75 mergedShape = m_d->pointData1.pathShape;
76 }
77
78 if (m_d->selection) {
79 m_d->selection->select(mergedShape);
80 }
81
83}
84
86{
87 return m_d->combineCommand ? m_d->combineCommand->combinedPath() : 0;
88}
89
91{
93
94 if (m_d->mergeCommand) {
95 m_d->mergeCommand->undo();
96 m_d->mergeCommand.reset();
97 }
98
99 if (m_d->combineCommand) {
100 m_d->combineCommand->undo();
101 m_d->combineCommand.reset();
102 }
103
104 if (m_d->selection) {
105 m_d->selection->select(m_d->pointData1.pathShape);
106 if (m_d->pointData1.pathShape != m_d->pointData2.pathShape) {
107 m_d->selection->select(m_d->pointData2.pathShape);
108 }
109 }
110}
111
virtual void undo()
virtual void redo()
The undo / redo command for combining two or more paths into one.
Describe a KoPathPoint by a KoPathShape and its indices.
The undo / redo command for merging two subpath end points.
The position of a path point within a path shape.
Definition KoPathShape.h:63
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
KUndo2MagicString kundo2_i18n(const char *text)
const QScopedPointer< Private > m_d
virtual KUndo2Command * createMergeCommand(const KoPathPointData &pointData1, const KoPathPointData &pointData2)
QScopedPointer< KoPathCombineCommand > combineCommand
KoMultiPathPointMergeCommand(const KoPathPointData &pointData1, const KoPathPointData &pointData2, KoShapeControllerBase *controller, KoSelection *selection, KUndo2Command *parent=0)
QScopedPointer< KUndo2Command > mergeCommand
Private(const KoPathPointData &_pointData1, const KoPathPointData &_pointData2, KoShapeControllerBase *_controller, KoSelection *_selection)