Count mirror line as part of shape.

This commit is contained in:
Roman Telezhynskyi 2024-07-18 19:42:06 +03:00
parent 1a2ba7233d
commit b4f7f6378f
2 changed files with 50 additions and 46 deletions

View file

@ -182,6 +182,7 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF
shape.addPath(m_stickyPath); shape.addPath(m_stickyPath);
shape.addPath(m_foldLineMarkPath); shape.addPath(m_foldLineMarkPath);
shape.addPath(m_foldLineLabelPath); shape.addPath(m_foldLineLabelPath);
shape.addPath(m_mirrorLinePath);
VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
const qreal halfPenWidth = settings->GetLayoutLineWidth() / 2.; const qreal halfPenWidth = settings->GetLayoutLineWidth() / 2.;
@ -598,6 +599,7 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter)
m_stickyPath = QPainterPath(); m_stickyPath = QPainterPath();
m_foldLineMarkPath = QPainterPath(); m_foldLineMarkPath = QPainterPath();
m_foldLineLabelPath = QPainterPath(); m_foldLineLabelPath = QPainterPath();
m_mirrorLinePath = QPainterPath();
VPPiecePtr const piece = m_piece.toStrongRef(); VPPiecePtr const piece = m_piece.toStrongRef();
if (piece.isNull()) 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; return;
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<QPointF> seamAllowance;
CastTo(piece->GetMappedContourPoints(), seamAllowance);
if (!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p1()) || bool mirrorFlag = false;
!VAbstractCurve::IsPointOnCurve(seamAllowance, seamAllowanceMirrorLine.p2())) if (not piece->IsSeamAllowance() || piece->IsSeamAllowanceBuiltIn())
{ {
seamAllowanceMirrorLine = QLineF const seamMirrorLine = piece->GetMappedSeamMirrorLine();
piece->SeamAllowanceMirrorLine(piece->GetMappedSeamMirrorLine(), seamAllowance); 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<QPointF> 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) QPainterPath mirrorPath;
{ mirrorPath.moveTo(seamAllowanceMirrorLine.p1());
painter->save(); mirrorPath.lineTo(seamAllowanceMirrorLine.p2());
QPen pen = painter->pen(); m_mirrorLinePath.addPath(mirrorPath);
pen.setStyle(Qt::DashDotLine); mirrorFlag = true;
painter->setPen(pen);
painter->drawPath(mirrorLinePath);
painter->restore();
} }
} }
if (mirrorFlag && painter != nullptr)
{
painter->save();
QPen pen = painter->pen();
pen.setStyle(Qt::DashDotLine);
painter->setPen(pen);
painter->drawPath(m_mirrorLinePath);
painter->restore();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -96,6 +96,7 @@ private:
QPainterPath m_internalPaths{}; QPainterPath m_internalPaths{};
QPainterPath m_passmarks{}; QPainterPath m_passmarks{};
QPainterPath m_placeLabels{}; QPainterPath m_placeLabels{};
QPainterPath m_mirrorLinePath{};
QPointF m_moveStartPoint{}; QPointF m_moveStartPoint{};
QPointF m_rotationStartPoint{}; QPointF m_rotationStartPoint{};
@ -133,7 +134,7 @@ private:
void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece); void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece);
void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece); void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece);
void PaintStickyPath(QPainter *painter); 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 PaintFoldLine(QPainter *painter, const VPPiecePtr &piece);
void GroupMove(const QPointF &pos); void GroupMove(const QPointF &pos);