From 497cb65cb244fb0bed57881674d292ff06820608 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 2 May 2020 12:17:06 +0200 Subject: [PATCH] Optimizing the piece carrousel --- src/app/puzzle/puzzlemainwindow.cpp | 10 ++++++++++ src/app/puzzle/vpiececarrousel.cpp | 18 ++++++++++++------ src/app/puzzle/vpiececarrousel.h | 13 +++++++++++++ src/app/puzzle/vpiececarrouselpiece.cpp | 9 ++++++--- src/app/puzzle/vpuzzlepiece.cpp | 11 +++++++++++ src/app/puzzle/vpuzzlepiece.h | 21 +++++++++++++++++++++ 6 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index 8f8252a76..f318a9a0d 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -144,6 +144,14 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() + + // TODO / FIXME: make a few tests, on the data to check for validity. If not + // + // If seam allowance enabled, but the path is empty — invalid. + // If seam line path not hidden, but the path is empty — invalid. + // If seam allowance is built-in, but the seam line path is empty — invalid. + + VPuzzlePiece *piece = CreatePiece(rawPiece); m_layout->GetUnplacedPiecesLayer()->AddPiece(piece); } @@ -165,10 +173,12 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) //--------------------------------------------------------------------------------------------------------------------- VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece) { + VPuzzlePiece *piece = new VPuzzlePiece(); piece->SetName(rawPiece.GetName()); piece->SetUuid(rawPiece.GetUUID()); piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints()); + piece->SetSeamLine(rawPiece.GetMappedContourPoints()); // TODO : set all the information we need for the piece! diff --git a/src/app/puzzle/vpiececarrousel.cpp b/src/app/puzzle/vpiececarrousel.cpp index 06741ffb7..ff659ca80 100644 --- a/src/app/puzzle/vpiececarrousel.cpp +++ b/src/app/puzzle/vpiececarrousel.cpp @@ -75,8 +75,10 @@ void VPieceCarrousel::Init() QVBoxLayout *layersContainerLayout = new QVBoxLayout(); layersContainerLayout->setMargin(0); m_layersContainer->setLayout(layersContainerLayout); + m_layersContainer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding); + layersContainerWrapperLayout->addWidget(m_layersContainer); layersContainerWrapperLayout->addSpacerItem(spacer); @@ -92,9 +94,6 @@ void VPieceCarrousel::Init() // ------ then we fill the carrousel with the layout content Refresh(); - - // ------ and make sure the calculation for the qlayout is right - SetOrientation(Qt::Vertical); } //--------------------------------------------------------------------------------------------------------------------- @@ -126,6 +125,8 @@ void VPieceCarrousel::Refresh() } on_ActiveLayerChanged(0); + + RefreshOrientation(); } //--------------------------------------------------------------------------------------------------------------------- @@ -188,8 +189,14 @@ void VPieceCarrousel::on_ActiveLayerChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) { + m_orientation = orientation; + RefreshOrientation(); +} - QBoxLayout::Direction direction = (orientation == Qt::Horizontal)? +//--------------------------------------------------------------------------------------------------------------------- +void VPieceCarrousel::RefreshOrientation() +{ + QBoxLayout::Direction direction = (m_orientation == Qt::Horizontal)? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom; @@ -207,7 +214,7 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) } // then update the scrollarea min height / width and scrollbar behaviour - if(orientation == Qt::Horizontal) + if(m_orientation == Qt::Horizontal) { m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -232,7 +239,6 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) m_scrollArea->setMinimumWidth(124 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2); // FIXME: find a nicer way than putting directly the 120 width of the piece } - } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpiececarrousel.h b/src/app/puzzle/vpiececarrousel.h index 9e90c56d7..54b9e786e 100644 --- a/src/app/puzzle/vpiececarrousel.h +++ b/src/app/puzzle/vpiececarrousel.h @@ -43,8 +43,19 @@ public: explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr); virtual ~VPieceCarrousel(); + /** + * @brief SetOrientation Sets the orientation to the given value and refreshes + * the orientation of the carrousel. + * @param orientation the orientation to set the carrousel to. + */ void SetOrientation(Qt::Orientation orientation); + /** + * @brief RefreshOrientation Refreshes the orientation of the carrousel with the + * m_orientation value; + */ + void RefreshOrientation(); + /** * @brief Inits the carroussel */ @@ -85,6 +96,8 @@ private: QList m_carrouselLayers; + Qt::Orientation m_orientation{Qt::Vertical}; + private slots: void on_ActiveLayerChanged(int index); diff --git a/src/app/puzzle/vpiececarrouselpiece.cpp b/src/app/puzzle/vpiececarrouselpiece.cpp index 3ce4771a1..78f02c9e5 100644 --- a/src/app/puzzle/vpiececarrouselpiece.cpp +++ b/src/app/puzzle/vpiececarrouselpiece.cpp @@ -72,6 +72,7 @@ void VPieceCarrouselPiece::Init() m_graphicsView->setScene(graphicsScene); m_graphicsView->setFixedSize(120,100); m_graphicsView->setStyleSheet("border: 4px solid transparent;"); + m_graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); // define the label m_label = new QLabel(); @@ -98,9 +99,11 @@ void VPieceCarrouselPiece::Refresh() { // update the graphic view / the scene - // TODO / FIXME : not perfect and maybe not the right way, still need to work on this - // for instance: use a painter to habve a better quality, less pixeled. - QVector points = m_piece->GetCuttingLine(); + QVector points = m_piece->GetSeamLine(); + if(points.isEmpty()) + { + points = m_piece->GetCuttingLine(); + } QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); pen.setCosmetic(true); diff --git a/src/app/puzzle/vpuzzlepiece.cpp b/src/app/puzzle/vpuzzlepiece.cpp index 21daa67a2..b01f9b59b 100644 --- a/src/app/puzzle/vpuzzlepiece.cpp +++ b/src/app/puzzle/vpuzzlepiece.cpp @@ -79,6 +79,17 @@ void VPuzzlePiece::SetCuttingLine(const QVector &cuttingLine) m_cuttingLine = cuttingLine; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPuzzlePiece::GetSeamLine() const +{ + return m_seamLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzlePiece::SetSeamLine(const QVector &seamLine) +{ + m_seamLine = seamLine; +} //--------------------------------------------------------------------------------------------------------------------- bool VPuzzlePiece::GetShowSeamLine() diff --git a/src/app/puzzle/vpuzzlepiece.h b/src/app/puzzle/vpuzzlepiece.h index 55d0f3fd8..735707e1c 100644 --- a/src/app/puzzle/vpuzzlepiece.h +++ b/src/app/puzzle/vpuzzlepiece.h @@ -61,10 +61,30 @@ public: */ void SetUuid(const QUuid &uuid); + /** + * @brief GetCuttingLine Returns the vector points of the cutting line + * @return the vector points of the cutting line + */ QVector GetCuttingLine() const; + /** + * @brief SetCuttingLine Sets the vector points of the cutting line to the given value + * @param cuttingLine the new vector points for the cutting line + */ void SetCuttingLine(const QVector &cuttingLine); + /** + * @brief GetSeamLine Returns the vector points of the seam line + * @return the vector points of the seam line + */ + QVector GetSeamLine() const; + + /** + * @brief SetSeamLine Sets the vector points of the seam line to the given value + * @param seamLine the new vector points for the seam line + */ + void SetSeamLine(const QVector &seamLine); + /** * @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not * @return true if the seamline has to be shown @@ -94,6 +114,7 @@ private: QUuid m_uuid{QUuid()}; QString m_name{QString()}; QVector m_cuttingLine{QVector()}; + QVector m_seamLine{QVector()}; bool m_showSeamline{true}; bool m_mirrorPiece{false}; };