From 4edcbfd0c5258c846cdcebbc6e0f209852db543f Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 26 Apr 2020 15:36:20 +0200 Subject: [PATCH] work on the piece and carrousel --- src/app/puzzle/puzzlemainwindow.cpp | 4 ++ src/app/puzzle/vpiececarrouselpiece.cpp | 50 ++++++++++++++++++------- src/app/puzzle/vpiececarrouselpiece.h | 3 ++ src/app/puzzle/vpuzzlepiece.cpp | 13 +++++++ src/app/puzzle/vpuzzlepiece.h | 7 ++++ 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index 245149e7e..1fa45c60e 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -142,6 +142,9 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) for (int i = 0; i < data.pieces.size(); ++i) { VLayoutPiece rawPiece = data.pieces.at(i); + + // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() + VPuzzlePiece *piece = CreatePiece(rawPiece); m_layout->GetUnplacedPiecesLayer()->AddPiece(piece); } @@ -166,6 +169,7 @@ VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece) VPuzzlePiece *piece = new VPuzzlePiece(); piece->SetName(rawPiece.GetName()); piece->SetUuid(rawPiece.GetUUID()); + piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints()); // TODO : set all the information we need for the piece! diff --git a/src/app/puzzle/vpiececarrouselpiece.cpp b/src/app/puzzle/vpiececarrouselpiece.cpp index 7c1085f3e..f31f4f963 100644 --- a/src/app/puzzle/vpiececarrouselpiece.cpp +++ b/src/app/puzzle/vpiececarrouselpiece.cpp @@ -29,6 +29,8 @@ #include "vpiececarrouselpiece.h" #include #include +#include +#include #include @@ -44,27 +46,34 @@ VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- VPieceCarrouselPiece::~VPieceCarrouselPiece() { - + delete m_graphicsView; } //--------------------------------------------------------------------------------------------------------------------- void VPieceCarrouselPiece::Init() { - // first define the structure - + //m_label->setStyleSheet("background-color:cornflowerblue"); + + // Define the structure + setFixedSize(120,120); QVBoxLayout *pieceLayout = new QVBoxLayout(); pieceLayout->setMargin(0); setLayout(pieceLayout); - // NOTE: this label structure is for test purpuses, it has to be changed when we see the piece preview - m_label = new QLabel(); - m_label->setFixedSize(120,120); - m_label->sizePolicy(); - m_label->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); - m_label->setStyleSheet("background-color:cornflowerblue"); + // define the preview of the piece + m_graphicsView = new QGraphicsView(this); + QGraphicsScene *graphicsScene = new QGraphicsScene(this); + m_graphicsView->setScene(graphicsScene); + m_graphicsView->setFixedSize(120,100); + // define the label + m_label = new QLabel(); + m_label->sizePolicy(); + m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + m_label->setFixedSize(120,20); + + pieceLayout->addWidget(m_graphicsView); pieceLayout->addWidget(m_label); - setMinimumSize(120,120); // then refresh the data Refresh(); @@ -73,8 +82,24 @@ void VPieceCarrouselPiece::Init() //--------------------------------------------------------------------------------------------------------------------- void VPieceCarrouselPiece::Refresh() { - // update the label of the piece + // update the graphic view / the scene + // TODO / FIXME : not perfect and maybe not the right way, still need to work on this + QVector points = m_piece->GetCuttingLine(); + + QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + pen.setCosmetic(true); + QBrush noBrush(Qt::NoBrush); + + QPainterPath path; + path.moveTo(points.first()); + for (int i = 1; i < points.size(); ++i) + path.lineTo(points.at(i)); + m_graphicsView->scene()->addPath(path, pen, noBrush); + + m_graphicsView->fitInView(m_graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); + + // update the label of the piece QFontMetrics metrix(m_label->font()); int width = m_label->width() - 8; QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width); @@ -82,7 +107,4 @@ void VPieceCarrouselPiece::Refresh() m_label->setToolTip(m_piece->GetName()); - - // update the graphic preview of the piece - // TODO } diff --git a/src/app/puzzle/vpiececarrouselpiece.h b/src/app/puzzle/vpiececarrouselpiece.h index 29e8cdc28..845e3902c 100644 --- a/src/app/puzzle/vpiececarrouselpiece.h +++ b/src/app/puzzle/vpiececarrouselpiece.h @@ -30,9 +30,11 @@ #include #include +#include #include "vpuzzlepiece.h" + class VPieceCarrouselPiece : public QWidget { Q_OBJECT @@ -52,6 +54,7 @@ private: VPuzzlePiece *m_piece; QLabel *m_label; + QGraphicsView *m_graphicsView; private slots: diff --git a/src/app/puzzle/vpuzzlepiece.cpp b/src/app/puzzle/vpuzzlepiece.cpp index cd3df00c4..e4c8558eb 100644 --- a/src/app/puzzle/vpuzzlepiece.cpp +++ b/src/app/puzzle/vpuzzlepiece.cpp @@ -65,3 +65,16 @@ void VPuzzlePiece::SetUuid(const QUuid &uuid) { m_uuid = uuid; } + + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPuzzlePiece::GetCuttingLine() const +{ + return m_cuttingLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetCuttingLine(const QVector &cuttingLine) +{ + m_cuttingLine = cuttingLine; +} diff --git a/src/app/puzzle/vpuzzlepiece.h b/src/app/puzzle/vpuzzlepiece.h index beef8072c..6504e6d66 100644 --- a/src/app/puzzle/vpuzzlepiece.h +++ b/src/app/puzzle/vpuzzlepiece.h @@ -29,6 +29,8 @@ #define VPUZZLEPIECE_H #include +#include +#include class VPuzzlePiece { @@ -60,10 +62,15 @@ public: */ void SetUuid(const QUuid &uuid); + QVector GetCuttingLine() const; + + void SetCuttingLine(const QVector &cuttingLine); + private: QUuid m_uuid{QUuid()}; QString m_name{QString()}; + QVector m_cuttingLine{QVector()}; }; #endif // VPUZZLEPIECE_H