From 4366cbdec9fb4b907c15f447cccdcd5ec5a74659 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 20 Nov 2020 17:05:56 +0100 Subject: [PATCH] Display passmarks and place labels --- src/app/puzzle/vpgraphicspiece.cpp | 46 ++++++++++++++++++++++++++++-- src/app/puzzle/vpgraphicspiece.h | 3 ++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index 7babfa5a3..eb0e4df4b 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -45,6 +45,7 @@ #include "vpsheet.h" #include "vlayoutpiecepath.h" +#include "vplacelabelitem.h" #include Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") @@ -56,8 +57,10 @@ VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) : m_cuttingLine(QPainterPath()), m_seamLine(QPainterPath()), m_grainline(QPainterPath()), + m_passmarks(QPainterPath()), m_internalPaths(QVector()), m_internalPathsPenStyle(QVector()), + m_placeLabels(QVector()), m_rotationStartPoint(QPointF()) { Init(); @@ -117,7 +120,28 @@ void VPGraphicsPiece::Init() m_internalPathsPenStyle.append(piecePath.PenStyle()); } - // TODO : initialises the other elements labels, passmarks etc. + // initialises the passmarks + QVector passmarks = m_piece->GetPassmarks(); + for(auto &passmark : passmarks) + { + for (auto &line : passmark.lines) + { + m_passmarks.moveTo(line.p1()); + m_passmarks.lineTo(line.p2()); + } + } + + // initialises the place labels (buttons etc) + QVector placeLabels = m_piece->GetPlaceLabels(); + for(auto &placeLabel : placeLabels) + { + QPainterPath path = VPlaceLabelItem::LabelShapePath(placeLabel.shape); + m_placeLabels.append(path); + } + + // TODO : initialises the text labels + + // Initialises the connectors connect(m_piece, &VPPiece::SelectionChanged, this, &VPGraphicsPiece::on_PieceSelectionChanged); @@ -213,9 +237,27 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen(m_internalPathsPenStyle.at(i)); painter->drawPath(m_internalPaths.at(i)); } - pen.setStyle(penStyleTmp); + painter->setPen(penStyleTmp); } + // paint the passmarks + if(!m_passmarks.isEmpty()) + { + painter->drawPath(m_passmarks); + } + + // paint the place labels (buttons etc) + if(!m_placeLabels.isEmpty()) + { + for(auto &placeLabel : m_placeLabels) + { + painter->drawPath(placeLabel); + } + } + + + // TODO Detail & Piece Label + // when using m_piece->GetItem(), the results were quite bad diff --git a/src/app/puzzle/vpgraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h index bd0e1fd9d..aefcca155 100644 --- a/src/app/puzzle/vpgraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -97,10 +97,13 @@ private: QPainterPath m_cuttingLine; QPainterPath m_seamLine; QPainterPath m_grainline; + QPainterPath m_passmarks; QVector m_internalPaths; QVector m_internalPathsPenStyle; + QVector m_placeLabels; + QPointF m_rotationStartPoint; };