22#include <QPainterPath>
31 , m_startPoint(startPoint)
32 , m_endPoint(startPoint)
50QPointF
snapEndPoint(
const QPointF &startPoint,
const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) {
54 if (modifiers & Qt::KeyboardModifier::ShiftModifier) {
56 if (qAbs(mouseLocation.x() - startPoint.x()) >= qAbs(mouseLocation.y() - startPoint.y())) {
58 return QPointF(mouseLocation.x(), startPoint.y());
60 return QPointF(startPoint.x(), mouseLocation.y());
63 QLineF line = QLineF(startPoint, mouseLocation);
64 qreal angle = line.angleTo(QLineF(startPoint, nicePoint));
100 qCritical() <<
"No shapes are available";
106 QPainterPath outlineHere =
107 booleanWorkaroundTransform.map(
111 srcOutlines << outlineHere;
112 outlineRect |= outlineHere.boundingRect();
115 if (outlineRect.isEmpty()) {
120 QRectF outlineRectBigger =
kisGrowRect(outlineRect, 10);
121 QRect outlineRectBiggerInt = outlineRectBigger.toRect();
124 qreal
eps = 0.0000001;
125 if (gapLine.length() <
eps) {
133 gapLine = booleanWorkaroundTransform.map(gapLine);
134 gapLines[0] = booleanWorkaroundTransform.map(gapLines[0]);
135 gapLines[1] = booleanWorkaroundTransform.map(gapLines[1]);
137 QLineF leftLine = gapLines[0];
138 QLineF rightLine = gapLines[1];
140 QLineF leftLineLong = leftLine;
141 QLineF rightLineLong = rightLine;
154 if (leftLine.length() == 0 || rightLine.length() == 0) {
155 KIS_SAFE_ASSERT_RECOVER_RETURN(gapLine.length() != 0 && gapLines[0].length() != 0 && gapLines[1].length() != 0 &&
"Original gap lines shouldn't be empty at this point");
165 QPainterPath left = paths[0];
166 QPainterPath right = paths[1];
169 QPainterPath leftOpposite = pathsOpposite[0];
170 QPainterPath rightOpposite = pathsOpposite[1];
176 QTransform booleanWorkaroundTransformInverted = booleanWorkaroundTransform.inverted();
182 for (
int i = 0; i < srcOutlines.size(); i++) {
187 if ((srcOutlines[i].boundingRect() & leftOpposite.boundingRect()).isEmpty()
188 || (srcOutlines[i].boundingRect() & rightOpposite.boundingRect()).isEmpty()) {
194 newSelectedShapes << referenceShape;
199 if ((srcOutlines[i].boundingRect() & gapLineLeftRect).isEmpty()
200 || (srcOutlines[i].boundingRect() & gapLineRightRect).isEmpty()) {
203 newSelectedShapes << referenceShape;
209 bool containsGapLinePoint = srcOutlines[i].contains(leftLine.p1()) || srcOutlines[i].contains(leftLine.p2())
210 || srcOutlines[i].contains(rightLine.p1()) || srcOutlines[i].contains(rightLine.p2());
213 if (!containsGapLinePoint && !crossesGapLine) {
217 newSelectedShapes << referenceShape;
225 QPainterPath leftPath = srcOutlines[i] & left;
226 QPainterPath rightPath = srcOutlines[i] & right;
229 bothSides << leftPath << rightPath;
232 Q_FOREACH(QPainterPath path, bothSides) {
233 if (path.isEmpty()) {
243 path = booleanWorkaroundTransformInverted.map(path);
258 newSelectedShapes << shape;
284 QColor semitransparentGray = QColor(Qt::darkGray);
285 semitransparentGray.setAlphaF(0.6);
286 QPen pen = QPen(QBrush(semitransparentGray), 2);
289 painter.setRenderHint(QPainter::RenderHint::Antialiasing,
true);
294 gutterCenterLine = converter.
documentToView().map(gutterCenterLine);
295 QLineF gutterWidthHelperLine = QLineF(QPointF(0, 0), QPointF(gutterWidth, 0));
296 gutterWidthHelperLine = converter.
documentToView().map(gutterWidthHelperLine);
298 gutterWidth = gutterWidthHelperLine.length();
302 QLineF gutterLine1 = gutterLines.length() > 0 ? gutterLines[0] : gutterCenterLine;
303 QLineF gutterLine2 = gutterLines.length() > 1 ? gutterLines[1] : gutterCenterLine;
306 painter.drawLine(gutterLine1);
307 painter.drawLine(gutterLine2);
309 QRectF arcRect1 = QRectF(gutterCenterLine.p1() - QPointF(gutterWidth/2, gutterWidth/2), gutterCenterLine.p1() + QPointF(gutterWidth/2, gutterWidth/2));
310 QRectF arcRect2 = QRectF(gutterCenterLine.p2() - QPointF(gutterWidth/2, gutterWidth/2), gutterCenterLine.p2() + QPointF(gutterWidth/2, gutterWidth/2));
312 int qtAngleFactor = 16;
313 int qtHalfCircle = qtAngleFactor*180;
320 qreal xLengthEllipse = 2*qSqrt(2);
323 painter.drawLine({QLineF(gutterCenterLine.p1() - QPointF(xLength, xLength), gutterCenterLine.p1() + QPointF(xLength, xLength))});
324 painter.drawLine({QLineF(gutterCenterLine.p2() - QPointF(xLength, xLength), gutterCenterLine.p2() + QPointF(xLength, xLength))});
326 painter.drawLine({QLineF(gutterCenterLine.p1() - QPointF(xLength, -xLength), gutterCenterLine.p1() + QPointF(xLength, -xLength))});
327 painter.drawLine({QLineF(gutterCenterLine.p2() - QPointF(xLength, -xLength), gutterCenterLine.p2() + QPointF(xLength, -xLength))});
331 painter.drawEllipse(gutterCenterLine.p1(), xLengthEllipse, xLengthEllipse);
332 painter.drawEllipse(gutterCenterLine.p2(), xLengthEllipse, xLengthEllipse);
337 semitransparentGray.setAlphaF(0.2);
338 pen.setColor(semitransparentGray);
342 painter.drawLine(gutterCenterLine);
353 return helperGapWidthLineTransformed.length();
358 QPointF vec = end - start;
QPointF snapEndPoint(const QPointF &startPoint, const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers)
~CutThroughShapeStrategy() override
void finishInteraction(Qt::KeyboardModifiers modifiers) override
qreal calculateLineAngle(QPointF start, QPointF end)
QList< KoShape * > m_selectedShapes
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
QRectF m_previousLineDirtyRect
KUndo2Command * createCommand() override
QList< KoShape * > m_allShapes
CutThroughShapeStrategy(KoToolBase *tool, KoSelection *selection, const QList< KoShape * > &allShapes, QPointF startPoint, const GutterWidthsConfig &width)
qreal gutterWidthInDocumentCoordinates(qreal lineAngle)
GutterWidthsConfig m_width
void paint(QPainter &painter, const KoViewConverter &converter) override
qreal widthForAngleInPixels(qreal lineAngleDegrees)
KisSelectedShapesProxy selectedShapesProxy
KisCoordinatesConverter * coordinatesConverter
KisImageWSP image() const
_Private::Traits< T >::Result imageToDocument(const T &obj) const
QPointer< KoShapeController > shapeController
virtual void updateCanvas(const QRectF &rc)=0
virtual void addCommand(KUndo2Command *command)=0
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
KoToolBase * tool() const
The position of a path point within a path shape.
QRectF boundingRect() const override
reimplemented
static KoPathShape * createShapeFromPainterPath(const QPainterPath &path)
Creates path shape from given QPainterPath.
const QList< KoShape * > selectedEditableShapes() const
void setZIndex(qint16 zIndex)
virtual QPainterPath outline() const
virtual KoShapeStrokeModelSP stroke() const
KoShapeContainer * parent() const
virtual void setStroke(KoShapeStrokeModelSP stroke)
QTransform absoluteTransformation() const
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
virtual QSharedPointer< KoShapeBackground > background() const
virtual QPointF documentToView(const QPointF &documentPoint) const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
T kisGrowRect(const T &rect, U offset)
T kisRadiansToDegrees(T radians)
PointType snapToClosestNiceAngle(PointType point, PointType startPoint, qreal angle=(2 *M_PI)/24)
T kisDegreesToRadians(T degrees)
KUndo2MagicString kundo2_i18n(const char *text)
T wrapValue(T value, T wrapBounds)
QList< QPainterPath > getPathsFromRectangleCutThrough(const QRectF &rect, const QLineF &leftLine, const QLineF &rightLine)
getPathsFromRectangleCutThrough get paths defining both sides of a rectangle cut through using two (s...
void accumulateBounds(const Point &pt, Rect *bounds)
qreal directionBetweenPoints(const QPointF &p1, const QPointF &p2, qreal defaultAngle)
void cropLineToRect(QLineF &line, const QRect rect, bool extendFirst, bool extendSecond)
Crop line to rect; if it doesn't intersect, just return an empty line (QLineF()).
QList< QLineF > getParallelLines(const QLineF &line, const qreal distance)
QList< int > getLineSegmentCrossingLineIndexes(const QLineF &line, const QPainterPath &shape)
PointTypeTraits< Point >::rect_type createRectFromCorners(Point corner1, Point corner2)
QTransform pathShapeBooleanSpaceWorkaround(KisImageSP image)