Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSubpathJoinCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Jan Hambrecht <jaham@gmx.net>
3 * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
9#include <klocalizedstring.h>
10#include "kis_assert.h"
11#include "KoPathMergeUtils.h"
12
13
15 : KUndo2Command(parent)
16 , m_pointData1(pointData1)
17 , m_pointData2(pointData2)
18 , m_splitIndex(KoPathPointIndex(-1, -1))
19 , m_oldProperties1(KoPathPoint::Normal)
20 , m_oldProperties2(KoPathPoint::Normal)
21 , m_reverse(0)
22{
27 m_pointData1.pointIndex.second == pathShape->subpathPointCount(m_pointData1.pointIndex.first) - 1);
30 m_pointData2.pointIndex.second == pathShape->subpathPointCount(m_pointData2.pointIndex.first) - 1);
31 //TODO check that points are not the same
32
34 std::swap(m_pointData1, m_pointData2);
35 }
36
37 if (!closeSubpathMode()) {
38 if (m_pointData1.pointIndex.second == 0 &&
39 pathShape->subpathPointCount(m_pointData1.pointIndex.first) > 1)
41 if (m_pointData2.pointIndex.second != 0)
43 setText(kundo2_i18n("Join subpaths"));
44 } else {
45 setText(kundo2_i18n("Close subpath"));
46 }
47
48 KoPathPoint * point1 = pathShape->pointByIndex(m_pointData1.pointIndex);
49 KoPathPoint * point2 = pathShape->pointByIndex(m_pointData2.pointIndex);
50
53
54 m_oldProperties1 = point1->properties();
55 m_oldProperties2 = point2->properties();
56}
57
61
62
63
65{
68
69 KoPathPoint * point1 = pathShape->pointByIndex(m_pointData1.pointIndex);
70 KoPathPoint * point2 = pathShape->pointByIndex(m_pointData2.pointIndex);
71
74
75 // if the endpoint has a control point create a control point for the new segment to be
76 // at the symmetric position to the exiting one
77
78 if (closeSubpathMode()) {
79 KritaUtils::makeSymmetric(point1, false);
80 KritaUtils::makeSymmetric(point2, true);
81 } else {
84 }
85
86 if (closeSubpathMode()) {
88 } else {
89 if (m_reverse & ReverseFirst) {
90 pathShape->reverseSubpath(m_pointData1.pointIndex.first);
91 }
93 pathShape->reverseSubpath(m_pointData2.pointIndex.first);
94 }
95 pathShape->moveSubpath(m_pointData2.pointIndex.first, m_pointData1.pointIndex.first + 1);
97 m_splitIndex.second = pathShape->subpathPointCount(m_pointData1.pointIndex.first) - 1;
98 pathShape->join(m_pointData1.pointIndex.first);
99 }
100
101 QList<KoPathPointIndex> pointIndexes;
102 pointIndexes << pathShape->pathPointIndex(point1);
103 pointIndexes << pathShape->pathPointIndex(point2);
104 pathShape->recommendPointSelectionChange(pointIndexes);
105
106 pathShape->normalize();
107 pathShape->update();
108}
109
111{
113 KoPathShape * pathShape = m_pointData1.pathShape;
114 pathShape->update();
115
116 if (closeSubpathMode()) {
118 } else {
119 pathShape->breakAfter(m_splitIndex);
120 pathShape->moveSubpath(m_pointData1.pointIndex.first + 1, m_pointData2.pointIndex.first);
121
122 if (m_reverse & ReverseSecond) {
123 pathShape->reverseSubpath(m_pointData2.pointIndex.first);
124 }
125 if (m_reverse & ReverseFirst) {
126 pathShape->reverseSubpath(m_pointData1.pointIndex.first);
127 }
128 }
129 KoPathPoint * point1 = pathShape->pointByIndex(m_pointData1.pointIndex);
130 KoPathPoint * point2 = pathShape->pointByIndex(m_pointData2.pointIndex);
131
134
135 // restore the old end points
136 if (closeSubpathMode()) {
139 } else {
142 }
143
146
147 QList<KoPathPointIndex> pointIndexes;
148 pointIndexes << pathShape->pathPointIndex(point1);
149 pointIndexes << pathShape->pathPointIndex(point2);
150 pathShape->recommendPointSelectionChange(pointIndexes);
151
152 pathShape->normalize();
153 pathShape->update();
154}
155
160
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
A KoPathPoint represents a point in a path.
PointProperties properties
void setProperties(PointProperties properties)
Set the properties of a point.
The position of a path point within a path shape.
Definition KoPathShape.h:63
bool breakAfter(const KoPathPointIndex &pointIndex)
Breaks the path after the point index.
int subpathPointCount(int subpathIndex) const
Returns the number of points in a subpath.
bool isClosedSubpath(int subpathIndex) const
Checks if a subpath is closed.
bool reverseSubpath(int subpathIndex)
Reverse subpath.
void recommendPointSelectionChange(const QList< KoPathPointIndex > &newSelection)
virtual QPointF normalize()
Normalizes the path data.
bool moveSubpath(int oldSubpathIndex, int newSubpathIndex)
Moves the position of a subpath within a path.
bool join(int subpathIndex)
Joins the given subpath with the following one.
KoPathPointIndex closeSubpath(const KoPathPointIndex &pointIndex)
Close a open subpath.
KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex)
Opens a closed subpath.
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
void update() const override
reimplemented
KoPathPoint::PointProperties m_oldProperties1
KoSubpathJoinCommand(const KoPathPointData &pointData1, const KoPathPointData &pointData2, KUndo2Command *parent=0)
KoPathPointIndex m_splitIndex
boost::optional< QPointF > m_savedControlPoint1
boost::optional< QPointF > m_savedControlPoint2
void undo() override
revert the actions done in redo
void redo() override
redo the command
KoPathPoint::PointProperties m_oldProperties2
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)
void makeSymmetric(KoPathPoint *pt, bool copyFromFirst)
void restoreControlPoint(KoPathPoint *pt, bool restoreFirst, boost::optional< QPointF > savedPoint)
boost::optional< QPointF > fetchControlPoint(KoPathPoint *pt, bool takeFirst)