12#include <klocalizedstring.h>
22 : pathShape(pointData1.pathShape)
23 , pointIndex1(pointData1.pointIndex)
24 , pointIndex2(pointData2.pointIndex)
26 , mergedPointIndex(-1, -1)
27 , reverse(ReverseNone)
37 savedNodePoint1 = point->
point();
50 QPointF mergePosition = 0.5 * (
p1->point() +
p2->point());
52 boost::optional<QPointF> mergedControlPoint1;
53 boost::optional<QPointF> mergedControlPoint2;
55 if (
p1->activeControlPoint1()) {
56 mergedControlPoint1 = mergePosition + (
p1->controlPoint1() -
p1->point());
59 if (
p2->activeControlPoint2()) {
60 mergedControlPoint2 = mergePosition + (
p2->controlPoint2() -
p2->point());
69 return pointIndex2.first == pointIndex1.first;
105 KIS_ASSERT(!
d->pathShape->isClosedSubpath(
d->pointIndex1.first));
106 KIS_ASSERT(!
d->pathShape->isClosedSubpath(
d->pointIndex2.first));
109 d->pointIndex1.second ==
d->pathShape->subpathPointCount(
d->pointIndex1.first) - 1);
112 d->pointIndex2.second ==
d->pathShape->subpathPointCount(
d->pointIndex2.first) - 1);
116 if (
d->pointIndex2 <
d->pointIndex1) {
117 std::swap(
d->pointIndex2,
d->pointIndex1);
121 if (!
d->closeSubpathMode()) {
122 if (
d->pointIndex1.second == 0 &&
123 d->pathShape->subpathPointCount(
d->pointIndex1.first) > 1) {
125 d->reverse |= Private::ReverseFirst;
128 if (
d->pointIndex2.second != 0 &&
129 d->pathShape->subpathPointCount(
d->pointIndex2.first) > 1) {
131 d->reverse |= Private::ReverseSecond;
149 KoPathPoint * point1 =
d->pathShape->pointByIndex(
d->pointIndex1);
150 KoPathPoint * point2 =
d->pathShape->pointByIndex(
d->pointIndex2);
152 d->pathShape->update();
154 if (
d->closeSubpathMode()) {
155 d->savePointState(point1);
156 d->mergePoints(point2, point1, point1);
157 d->removedPoint =
d->pathShape->removePoint(
d->pointIndex2);
161 d->pathShape->closeSubpath(newStartIndex);
162 d->mergedPointIndex = newStartIndex;
165 if (
d->reverse & Private::ReverseFirst) {
166 d->pathShape->reverseSubpath(
d->pointIndex1.first);
169 if (
d->reverse & Private::ReverseSecond) {
170 d->pathShape->reverseSubpath(
d->pointIndex2.first);
173 d->pathShape->moveSubpath(
d->pointIndex2.first,
d->pointIndex1.first + 1);
174 d->mergedPointIndex =
d->pathShape->pathPointIndex(point1);
175 d->pathShape->join(
d->pointIndex1.first);
177 d->savePointState(point1);
178 d->mergePoints(point1, point2, point1);
181 d->removedPoint =
d->pathShape->removePoint(removeIndex);
184 d->pathShape->recommendPointSelectionChange({
d->mergedPointIndex});
185 d->pathShape->update();
192 d->pathShape->update();
196 if (
d->closeSubpathMode()) {
197 d->pathShape->openSubpath(
d->mergedPointIndex);
198 d->pathShape->insertPoint(
d->removedPoint,
d->pointIndex2);
199 d->restorePointState(
d->pathShape->pointByIndex(
d->pointIndex1));
201 d->pathShape->breakAfter(
d->mergedPointIndex);
202 d->pathShape->insertPoint(
d->removedPoint,
KoPathPointIndex(
d->mergedPointIndex.first+1,0));
203 d->restorePointState(
d->pathShape->pointByIndex(
d->mergedPointIndex));
204 d->pathShape->moveSubpath(
d->mergedPointIndex.first+1,
d->pointIndex2.first);
207 if (
d->reverse & Private::ReverseFirst) {
208 d->pathShape->reverseSubpath(
d->pointIndex1.first);
211 if (
d->reverse & Private::ReverseSecond) {
212 d->pathShape->reverseSubpath(
d->pointIndex2.first);
220 d->pathShape->recommendPointSelectionChange({
d->pointIndex1,
d->pointIndex2});
221 d->pathShape->update();
QPair< int, int > KoPathPointIndex
void setText(const KUndo2MagicString &text)
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathShape * pathShape
path shape the path point belongs too
The undo / redo command for merging two subpath end points.
Private(const KoPathPointData &pointData1, const KoPathPointData &pointData2)
KoPathPointIndex pointIndex1
void restorePointState(KoPathPoint *point)
void savePointState(KoPathPoint *point)
~KoPathPointMergeCommand() override
KoPathPointIndex pointIndex2
KoPathPointIndex mergedPointIndex
KoPathPoint * removedPoint
void mergePoints(KoPathPoint *p1, KoPathPoint *p2, KoPathPoint *dstPoint)
void undo() override
revert the actions done in redo
void redo() override
redo the command
KoPathPointMergeCommand(const KoPathPointData &pointData1, const KoPathPointData &pointData2, KUndo2Command *parent=0)
boost::optional< QPointF > savedControlPoint12
boost::optional< QPointF > savedControlPoint11
KoPathPointData mergedPointData() const
bool closeSubpathMode() const
A KoPathPoint represents a point in a path.
void setPoint(const QPointF &point)
alter the point
The position of a path point within a path shape.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
KUndo2MagicString kundo2_i18n(const char *text)
void restoreControlPoint(KoPathPoint *pt, bool restoreFirst, boost::optional< QPointF > savedPoint)
boost::optional< QPointF > fetchControlPoint(KoPathPoint *pt, bool takeFirst)