Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Move initializing gap shapes to a separate static function

Agata Cacko2b4440efb516
diff --git a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp b/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp
index df9811cdd4..f89fe356f1 100644
--- a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp
+++ b/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp
@@ -156,6 +156,35 @@ void CutThroughShapeStrategy::initializeOutlineObjects(const QTransform &boolean
}
}
+void CutThroughShapeStrategy::initializeGapShapes(QRectF outlineRect, QLineF leftLine, QLineF rightLine, QPainterPath& outLeft, QPainterPath& outRight, QPainterPath &outLeftOpposite, QPainterPath &outRightOpposite,
+ QRectF& outGapLineRect, QPolygonF& outGapLinePolygon)
+{
+
+
+ QRect outlineRectBiggerInt = kisGrowRect(outlineRect, 10).toRect();
+ QLineF leftLineLong = leftLine;
+ QLineF rightLineLong = rightLine;
+
+
+ KisAlgebra2D::cropLineToRect(leftLineLong, outlineRectBiggerInt, true, true);
+ KisAlgebra2D::cropLineToRect(rightLineLong, outlineRectBiggerInt, true, true);
+
+
+ QList<QPainterPath> paths = KisAlgebra2D::getPathsFromRectangleCutThrough(QRectF(outlineRectBiggerInt), leftLineLong, rightLineLong);
+ outLeft = paths[0];
+ outRight = paths[1];
+
+ QList<QPainterPath> pathsOpposite = KisAlgebra2D::getPathsFromRectangleCutThrough(QRectF(outlineRectBiggerInt), rightLineLong, leftLineLong);
+ outLeftOpposite = pathsOpposite[0];
+ outRightOpposite = pathsOpposite[1];
+
+
+ outGapLineRect = KisAlgebra2D::createRectFromCorners(leftLine) | KisAlgebra2D::createRectFromCorners(rightLine); // will not be empty if the gutterWidth > 0
+
+ outGapLinePolygon = QPolygonF({leftLine.p1(), leftLine.p2(), rightLine.p2(), rightLine.p1(), leftLine.p1()});
+
+}
+
void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
{
tool()->canvas()->updateCanvas(m_previousLineDirtyRect);
@@ -182,8 +211,6 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
return;
}
- QRectF outlineRectBigger = kisGrowRect(outlineRect, 10);
- QRect outlineRectBiggerInt = outlineRectBigger.toRect();
QLineF gapLine = QLineF(m_startPoint, m_endPoint);
qreal eps = 0.0000001;
@@ -202,13 +229,9 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
QLineF leftLine = gapLines[0];
QLineF rightLine = gapLines[1];
- QLineF leftLineLong = leftLine;
- QLineF rightLineLong = rightLine;
- KisAlgebra2D::cropLineToRect(leftLineLong, outlineRectBiggerInt, true, true);
- KisAlgebra2D::cropLineToRect(rightLineLong, outlineRectBiggerInt, true, true);
std::unique_ptr<KUndo2Command> cmd = std::unique_ptr<KUndo2Command>(new KUndo2Command(kundo2_i18n("Knife tool: cut through shapes")));
@@ -222,25 +245,19 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
}
- QList<QPainterPath> paths = KisAlgebra2D::getPathsFromRectangleCutThrough(QRectF(outlineRectBiggerInt), leftLineLong, rightLineLong);
- QPainterPath left = paths[0];
- QPainterPath right = paths[1];
+ QPainterPath left, right, leftOpposite, rightOpposite;
- QList<QPainterPath> pathsOpposite = KisAlgebra2D::getPathsFromRectangleCutThrough(QRectF(outlineRectBiggerInt), rightLineLong, leftLineLong);
- QPainterPath leftOpposite = pathsOpposite[0];
- QPainterPath rightOpposite = pathsOpposite[1];
+ QRectF gapLineRect;
+ QPolygonF gapLinePolygon;
+ initializeGapShapes(outlineRect, leftLine, rightLine, left, right, leftOpposite, rightOpposite, gapLineRect, gapLinePolygon);
QList<KoShape*> newSelectedShapes;
QList<KoShape*> shapesToRemove;
+ bool checkGapLineRect = !gapLineRect.isEmpty();
QTransform booleanWorkaroundTransformInverted = booleanWorkaroundTransform.inverted();
- QRectF gapLineLeftRect = KisAlgebra2D::createRectFromCorners(leftLine); // warning! can be empty for perfectly horizontal/vertical lines
- QRectF gapLineRightRect = KisAlgebra2D::createRectFromCorners(rightLine);
- QRectF gapLineRect = gapLineLeftRect | gapLineRightRect; // will not be empty if the gutterWidth > 0
- bool checkGapLineRect = !gapLineRect.isEmpty();
- QPolygonF gapLinePolygon = QPolygonF({leftLine.p1(), leftLine.p2(), rightLine.p2(), rightLine.p1(), leftLine.p1()});
int affectedShapes = 0;
diff --git a/plugins/tools/tool_knife/CutThroughShapeStrategy.h b/plugins/tools/tool_knife/CutThroughShapeStrategy.h
index 2b56079d21..f9af77f7f2 100644
--- a/plugins/tools/tool_knife/CutThroughShapeStrategy.h
+++ b/plugins/tools/tool_knife/CutThroughShapeStrategy.h
@@ -42,6 +42,9 @@ private:
bool willShapeBeCutGeneral(KoShape* referenceShape, const QPainterPath &srcOutline, const QRectF &leftOppositeRect, const QRectF &rightOppositeRect, bool checkGapLineRect, const QRectF &gapLineRect);
bool willShapeBeCutPrecise(const QPainterPath& srcOutline, const QLineF gapLine, const QLineF& leftLine, const QLineF& rightLine, const QPolygonF& gapLinePolygon);
static void initializeOutlineObjects(const QTransform &booleanWorkaroundTransform, QList<KoShape *> allShapes, QList<QPainterPath> &outSrcOutlines, QRectF &outOutlineRect);
+ static void initializeGapShapes(QRectF outlineRect, QLineF leftLine, QLineF rightLine, QPainterPath& outLeft, QPainterPath& outRight,
+ QPainterPath& outLeftOpposite, QPainterPath& outRightOpposite, QRectF& outGapLineRect, QPolygonF& outGapLinePolygon);
+
private: