From b4f7f6378f52822f19a8ffe4e84656897f1ef6fa Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 18 Jul 2024 19:42:06 +0300 Subject: [PATCH] Count mirror line as part of shape. --- src/app/puzzle/scene/vpgraphicspiece.cpp | 93 ++++++++++++------------ src/app/puzzle/scene/vpgraphicspiece.h | 3 +- 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index c258705c1..9a51289c5 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -182,6 +182,7 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF shape.addPath(m_stickyPath); shape.addPath(m_foldLineMarkPath); shape.addPath(m_foldLineLabelPath); + shape.addPath(m_mirrorLinePath); VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); const qreal halfPenWidth = settings->GetLayoutLineWidth() / 2.; @@ -598,6 +599,7 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter) m_stickyPath = QPainterPath(); m_foldLineMarkPath = QPainterPath(); m_foldLineLabelPath = QPainterPath(); + m_mirrorLinePath = QPainterPath(); VPPiecePtr const piece = m_piece.toStrongRef(); if (piece.isNull()) @@ -907,59 +909,60 @@ void VPGraphicsPiece::PaintStickyPath(QPainter *painter) } //--------------------------------------------------------------------------------------------------------------------- -void VPGraphicsPiece::PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) const +void VPGraphicsPiece::PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) { - if (piece->IsShowFullPiece()) + if (!piece->IsShowFullPiece()) { - bool mirrorFlag = false; - QPainterPath mirrorLinePath; - if (not piece->IsSeamAllowance() || piece->IsSeamAllowanceBuiltIn()) - { - QLineF const seamMirrorLine = piece->GetMappedSeamMirrorLine(); - if (!seamMirrorLine.isNull() && piece->IsShowMirrorLine()) - { - QPainterPath mirrorPath; - mirrorPath.moveTo(seamMirrorLine.p1()); - mirrorPath.lineTo(seamMirrorLine.p2()); - mirrorLinePath.addPath(mirrorPath); - mirrorFlag = true; - } - } - else if (not piece->IsSeamAllowanceBuiltIn()) - { - QLineF seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine(); - if (!seamAllowanceMirrorLine.isNull() && piece->IsShowMirrorLine()) - { - { // Trying to correct a seam allowance mirror line based on seam mirror line - QVector seamAllowance; - CastTo(piece->GetMappedContourPoints(), seamAllowance); + return; + } - if (!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p1()) || - !VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p2())) - { - seamAllowanceMirrorLine = - piece->SeamAllowanceMirrorLine(piece->GetMappedSeamMirrorLine(), seamAllowance); - } + bool mirrorFlag = false; + if (not piece->IsSeamAllowance() || piece->IsSeamAllowanceBuiltIn()) + { + QLineF const seamMirrorLine = piece->GetMappedSeamMirrorLine(); + if (!seamMirrorLine.isNull() && piece->IsShowMirrorLine()) + { + QPainterPath mirrorPath; + mirrorPath.moveTo(seamMirrorLine.p1()); + mirrorPath.lineTo(seamMirrorLine.p2()); + m_mirrorLinePath.addPath(mirrorPath); + mirrorFlag = true; + } + } + else if (not piece->IsSeamAllowanceBuiltIn()) + { + QLineF seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine(); + if (!seamAllowanceMirrorLine.isNull() && piece->IsShowMirrorLine()) + { + { // Trying to correct a seam allowance mirror line based on seam mirror line + QVector seamAllowance; + CastTo(piece->GetMappedContourPoints(), seamAllowance); + + if (!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p1()) || + !VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p2())) + { + seamAllowanceMirrorLine = + piece->SeamAllowanceMirrorLine(piece->GetMappedSeamMirrorLine(), seamAllowance); } - - QPainterPath mirrorPath; - mirrorPath.moveTo(seamAllowanceMirrorLine.p1()); - mirrorPath.lineTo(seamAllowanceMirrorLine.p2()); - mirrorLinePath.addPath(mirrorPath); - mirrorFlag = true; } - } - if (mirrorFlag && painter != nullptr) - { - painter->save(); - QPen pen = painter->pen(); - pen.setStyle(Qt::DashDotLine); - painter->setPen(pen); - painter->drawPath(mirrorLinePath); - painter->restore(); + QPainterPath mirrorPath; + mirrorPath.moveTo(seamAllowanceMirrorLine.p1()); + mirrorPath.lineTo(seamAllowanceMirrorLine.p2()); + m_mirrorLinePath.addPath(mirrorPath); + mirrorFlag = true; } } + + if (mirrorFlag && painter != nullptr) + { + painter->save(); + QPen pen = painter->pen(); + pen.setStyle(Qt::DashDotLine); + painter->setPen(pen); + painter->drawPath(m_mirrorLinePath); + painter->restore(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/scene/vpgraphicspiece.h b/src/app/puzzle/scene/vpgraphicspiece.h index 1138d820c..1869ae119 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.h +++ b/src/app/puzzle/scene/vpgraphicspiece.h @@ -96,6 +96,7 @@ private: QPainterPath m_internalPaths{}; QPainterPath m_passmarks{}; QPainterPath m_placeLabels{}; + QPainterPath m_mirrorLinePath{}; QPointF m_moveStartPoint{}; QPointF m_rotationStartPoint{}; @@ -133,7 +134,7 @@ private: void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece); void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece); void PaintStickyPath(QPainter *painter); - void PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) const; + void PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece); void PaintFoldLine(QPainter *painter, const VPPiecePtr &piece); void GroupMove(const QPointF &pos);