From 61a2e17a789837c3a4fcfdad815b2d7179a33294 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 23 May 2020 17:47:04 +0200 Subject: [PATCH] Introducing VPSheet and refactoring part 2 --- src/app/puzzle/puzzle.pri | 2 + src/app/puzzle/vpcarrousel.cpp | 9 +- src/app/puzzle/vpcarrouselpiece.cpp | 8 +- src/app/puzzle/vpgraphicspiece.cpp | 12 +- src/app/puzzle/vpgraphicssheet.cpp | 18 +- src/app/puzzle/vpgraphicssheet.h | 8 +- src/app/puzzle/vplayout.cpp | 214 +++------------- src/app/puzzle/vplayout.h | 188 +++----------- src/app/puzzle/vpmaingraphicsview.cpp | 7 +- src/app/puzzle/vpmainwindow.cpp | 178 +++++++------ src/app/puzzle/vpmainwindow.h | 30 ++- src/app/puzzle/vpmainwindow.ui | 292 ++++++++++++++++------ src/app/puzzle/vppiece.h | 2 +- src/app/puzzle/vpsheet.cpp | 202 ++++++++++++++- src/app/puzzle/vpsheet.h | 218 +++++++++++++++- src/app/puzzle/xml/vplayoutfilereader.cpp | 60 ++--- src/app/puzzle/xml/vplayoutfilereader.h | 4 +- src/app/puzzle/xml/vplayoutfilewriter.cpp | 54 ++-- src/app/puzzle/xml/vplayoutfilewriter.h | 5 +- src/app/puzzle/xml/vplayoutliterals.cpp | 2 + src/app/puzzle/xml/vplayoutliterals.h | 2 + 21 files changed, 921 insertions(+), 594 deletions(-) diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index f1ad4bdf2..d3a03826c 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -20,6 +20,7 @@ SOURCES += \ $$PWD/vppiece.cpp \ $$PWD/vppiecelist.cpp \ $$PWD/vpsettings.cpp \ + $$PWD/vpsheet.cpp \ $$PWD/xml/vplayoutfilereader.cpp \ $$PWD/xml/vplayoutfilewriter.cpp \ $$PWD/xml/vplayoutliterals.cpp @@ -44,6 +45,7 @@ HEADERS += \ $$PWD/vppiece.h \ $$PWD/vppiecelist.h \ $$PWD/vpsettings.h \ + $$PWD/vpsheet.h \ $$PWD/vpstable.h \ $$PWD/xml/vplayoutfilereader.h \ $$PWD/xml/vplayoutfilewriter.h \ diff --git a/src/app/puzzle/vpcarrousel.cpp b/src/app/puzzle/vpcarrousel.cpp index f57bf2cb9..8423a67ab 100644 --- a/src/app/puzzle/vpcarrousel.cpp +++ b/src/app/puzzle/vpcarrousel.cpp @@ -33,6 +33,7 @@ #include "../vmisc/backport/qoverload.h" #include "vppiecelist.h" +#include "vpsheet.h" #include #include @@ -68,8 +69,12 @@ void VPCarrousel::Refresh() // --- add the content saved in the layout to the carrousel. // Do not rely on m_layout because we do not control it. - m_pieceLists = m_layout->GetPiecesLists(); - m_pieceLists.prepend(m_layout->GetUnplacedPieceList()); + m_pieceLists = QList(); + m_pieceLists.append(m_layout->GetUnplacedPieceList()); + for(auto sheet : m_layout->GetSheets()) + { + m_pieceLists.append(sheet->GetPieceList()); + } for (auto pieceList : m_pieceLists) { diff --git a/src/app/puzzle/vpcarrouselpiece.cpp b/src/app/puzzle/vpcarrouselpiece.cpp index 165553482..82b401cf8 100644 --- a/src/app/puzzle/vpcarrouselpiece.cpp +++ b/src/app/puzzle/vpcarrouselpiece.cpp @@ -40,6 +40,7 @@ #include "vpmimedatapiece.h" #include "vpcarrouselpiecelist.h" #include "vpcarrousel.h" +#include "vpsheet.h" #include @@ -240,7 +241,12 @@ void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event) QMenu contextMenu; VPPieceList* unplacedPieces = m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList(); - QList pieceLists = m_piece->GetPieceList()->GetLayout()->GetPiecesLists(); + QList sheets = m_piece->GetPieceList()->GetLayout()->GetSheets(); + QList pieceLists = QList(); + for (auto sheet : sheets) + { + pieceLists.append(sheet->GetPieceList()); + } // move to piece list actions -- TODO : To be tested properly when we have several piece lists pieceLists.removeAll(m_piece->GetPieceList()); diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index 0fb07e083..7daa4f20e 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -42,6 +42,7 @@ #include "vppiece.h" #include "vppiecelist.h" #include "vplayout.h" +#include "vpsheet.h" #include Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") @@ -294,10 +295,19 @@ void VPGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + + + // TODO/FIXME context menu needs to be refactored + QMenu contextMenu; // move to piece list actions -- TODO : To be tested properly when we have several piece lists - QList pieceLists = m_piece->GetPieceList()->GetLayout()->GetPiecesLists(); + QList pieceLists = QList(); + for(auto sheet : m_piece->GetPieceList()->GetLayout()->GetSheets()) + { + pieceLists.append(sheet->GetPieceList()); + } + pieceLists.removeAll(m_piece->GetPieceList()); if(pieceLists.count() > 0) diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index 9919679b1..77b496a4c 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -29,10 +29,10 @@ #include "vpgraphicssheet.h" //--------------------------------------------------------------------------------------------------------------------- -VPGraphicsSheet::VPGraphicsSheet(VPLayout *layout, QGraphicsItem *parent): +VPGraphicsSheet::VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent): QGraphicsItem(parent), - m_layout(layout), - m_boundingRect(GetLayoutRect()) + m_sheet(sheet), + m_boundingRect(GetSheetRect()) { } @@ -60,23 +60,23 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o pen.setColor(Qt::black); painter->setPen(pen); - painter->drawRect(GetLayoutRect()); + painter->drawRect(GetSheetRect()); - m_boundingRect = GetLayoutRect(); + m_boundingRect = GetSheetRect(); } //--------------------------------------------------------------------------------------------------------------------- -QRectF VPGraphicsSheet::GetLayoutRect() const +QRectF VPGraphicsSheet::GetSheetRect() const { - QRectF rect = QRectF(QPointF(0,0), m_layout->GetLayoutSize()); + QRectF rect = QRectF(QPointF(0,0), m_sheet->GetSheetSize()); return rect; } //--------------------------------------------------------------------------------------------------------------------- QRectF VPGraphicsSheet::GetMarginsRect() const { - QMarginsF margins = m_layout->GetLayoutMargins(); - QSizeF size = m_layout->GetLayoutSize(); + QMarginsF margins = m_sheet->GetSheetMargins(); + QSizeF size = m_sheet->GetSheetSize(); QRectF rect = QRectF( QPointF(margins.left(),margins.top()), QPointF(size.width()-margins.right(), size.height()-margins.bottom()) diff --git a/src/app/puzzle/vpgraphicssheet.h b/src/app/puzzle/vpgraphicssheet.h index 01183d97c..0c20ea2ec 100644 --- a/src/app/puzzle/vpgraphicssheet.h +++ b/src/app/puzzle/vpgraphicssheet.h @@ -32,26 +32,26 @@ #include #include -#include "vplayout.h" +#include "vpsheet.h" class VPGraphicsSheet : public QGraphicsItem { public: - explicit VPGraphicsSheet(VPLayout *layout, QGraphicsItem *parent = nullptr); + explicit VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent = nullptr); ~VPGraphicsSheet(); QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) override; - QRectF GetLayoutRect() const; + QRectF GetSheetRect() const; QRectF GetMarginsRect() const; private: Q_DISABLE_COPY(VPGraphicsSheet) - VPLayout *m_layout{nullptr}; + VPSheet *m_sheet{nullptr}; QRectF m_boundingRect; }; diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index 1f9087836..5c7052d95 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -28,26 +28,19 @@ #include "vplayout.h" #include "vppiecelist.h" #include "vppiece.h" +#include "vpsheet.h" //--------------------------------------------------------------------------------------------------------------------- VPLayout::VPLayout() : m_unplacedPieceList(new VPPieceList(this)) { m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); - - // create a standard default piecelist: - VPPieceList *pieceList = new VPPieceList(this); - pieceList->SetName(QObject::tr("Layout")); - AddPieceList(pieceList); - - // sets the default active piece list - SetFocusedPieceList(); } //--------------------------------------------------------------------------------------------------------------------- VPLayout::~VPLayout() { - qDeleteAll(m_pieceLists); + qDeleteAll(m_sheets); delete m_unplacedPieceList; } @@ -58,24 +51,24 @@ VPPieceList* VPLayout::GetUnplacedPieceList() } //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPLayout::AddPieceList() +VPSheet* VPLayout::AddSheet() { - VPPieceList *newPieceList = new VPPieceList(this); - m_pieceLists.append(newPieceList); - return newPieceList; + VPSheet *newSheet = new VPSheet(this); + m_sheets.append(newSheet); + return newSheet; } //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPLayout::AddPieceList(VPPieceList *pieceList) +VPSheet* VPLayout::AddSheet(VPSheet *sheet) { - m_pieceLists.append(pieceList); - return pieceList; + m_sheets.append(sheet); + return sheet; } //--------------------------------------------------------------------------------------------------------------------- -QList VPLayout::GetPiecesLists() +QList VPLayout::GetSheets() { - return m_pieceLists; + return m_sheets; } //--------------------------------------------------------------------------------------------------------------------- @@ -83,8 +76,12 @@ QList VPLayout::GetSelectedPieces() { QList result = QList(); - QList pieceLists = m_pieceLists; - pieceLists.prepend(m_unplacedPieceList); + QList pieceLists = QList(); + pieceLists.append(m_unplacedPieceList); + for (auto sheet : m_sheets) + { + pieceLists.append(sheet->GetPieceList()); + } for (auto pieceList : pieceLists) { @@ -113,128 +110,6 @@ Unit VPLayout::GetUnit() const return m_unit; } -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutSize(qreal width, qreal height) -{ - m_size.setWidth(width); - m_size.setHeight(height); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutSizeConverted(qreal width, qreal height) -{ - m_size.setWidth(UnitConvertor(width, m_unit, Unit::Px)); - m_size.setHeight(UnitConvertor(height, m_unit, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutSize(const QSizeF &size) -{ - m_size = size; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutSizeConverted(const QSizeF &size) -{ - m_size = QSizeF( - UnitConvertor(size.width(), m_unit, Unit::Px), - UnitConvertor(size.height(), m_unit, Unit::Px) - ); -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayout::GetLayoutSize() const -{ - return m_size; -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayout::GetLayoutSizeConverted() const -{ - QSizeF convertedSize = QSizeF( - UnitConvertor(m_size.width(), Unit::Px, m_unit), - UnitConvertor(m_size.height(), Unit::Px, m_unit) - ); - - return convertedSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom) -{ - m_margins.setLeft(left); - m_margins.setTop(top); - m_margins.setRight(right); - m_margins.setBottom(bottom); -} -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) -{ - m_margins.setLeft(UnitConvertor(left, m_unit, Unit::Px)); - m_margins.setTop(UnitConvertor(top, m_unit, Unit::Px)); - m_margins.setRight(UnitConvertor(right, m_unit, Unit::Px)); - m_margins.setBottom(UnitConvertor(bottom, m_unit, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutMargins(const QMarginsF &margins) -{ - m_margins = margins; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetLayoutMarginsConverted(const QMarginsF &margins) -{ - m_margins = UnitConvertor(margins, m_unit, Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayout::GetLayoutMargins() const -{ - return m_margins; -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayout::GetLayoutMarginsConverted() const -{ - return UnitConvertor(m_margins, Unit::Px, m_unit); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetFollowGrainline(FollowGrainline state) -{ - m_followGrainLine = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -FollowGrainline VPLayout::GetFollowGrainline() const -{ - return m_followGrainLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetPiecesGap(qreal value) -{ - m_piecesGap = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetPiecesGapConverted(qreal value) -{ - m_piecesGap = UnitConvertor(value, m_unit, Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPLayout::GetPiecesGap() const -{ - return m_piecesGap; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPLayout::GetPiecesGapConverted() const -{ - return UnitConvertor(m_piecesGap, Unit::Px, m_unit); -} //--------------------------------------------------------------------------------------------------------------------- void VPLayout::SetWarningSuperpositionOfPieces(bool state) @@ -260,48 +135,17 @@ bool VPLayout::GetWarningPiecesOutOfBound() const return m_warningPiecesOutOfBound; } -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetStickyEdges(bool state) -{ - m_stickyEdges = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPLayout::GetStickyEdges() const -{ - return m_stickyEdges; -} - //--------------------------------------------------------------------------------------------------------------------- void VPLayout::ClearSelection() { m_unplacedPieceList->ClearSelection(); - for (auto pieceList : m_pieceLists) + for (auto sheet : m_sheets) { - pieceList->ClearSelection(); + sheet->ClearSelection(); } } -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetFocusedPieceList(VPPieceList* focusedPieceList) -{ - if(focusedPieceList == nullptr) - { - m_focusedPieceList = m_pieceLists.first(); - } - else - { - m_focusedPieceList = focusedPieceList; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPLayout::GetFocusedPieceList() -{ - return m_focusedPieceList; -} - //--------------------------------------------------------------------------------------------------------------------- void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) { @@ -316,3 +160,23 @@ void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) // signal, that a piece was moved emit PieceMovedToPieceList(piece, pieceListBefore,pieceList); } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetFocusedSheet(VPSheet *focusedSheet) +{ + if(focusedSheet == nullptr) + { + m_focusedSheet = m_sheets.first(); + } + else + { + m_focusedSheet = focusedSheet; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet* VPLayout::GetFocusedSheet() +{ + return m_focusedSheet; +} diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index b03668685..5d36fad93 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -28,17 +28,14 @@ #ifndef VPLAYOUT_H #define VPLAYOUT_H -#include -#include + #include #include "def.h" class VPPieceList; class VPPiece; - -// is this the right place for the definition? -enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; +class VPSheet; class VPLayout : public QObject { @@ -53,9 +50,9 @@ public: */ VPPieceList* GetUnplacedPieceList(); - VPPieceList* AddPieceList(); - VPPieceList* AddPieceList(VPPieceList *pieceList); - QList GetPiecesLists(); + VPSheet* AddSheet(); + VPSheet* AddSheet(VPSheet *sheet); + QList GetSheets(); /** * @brief GetSelectedPieces Returns the list of the selected pieces @@ -75,150 +72,18 @@ public: */ Unit GetUnit() const; - /** - * @brief SetLayoutSize sets the size of the layout, the values have to be in Unit::Px - * @param width layout width - * @param height layout height - */ - void SetLayoutSize(qreal width, qreal height); - - /** - * @brief SetLayoutSize sets the size of the layout, the values have to be in the layout's unit - * @param width layout width - * @param height layout height - */ - void SetLayoutSizeConverted(qreal width, qreal height); - - /** - * @brief SetLayoutSize sets the size of the layout, the values have to be in Unit::Px - * @param size layout size - */ - void SetLayoutSize(const QSizeF &size); - /** - * @brief SetLayoutSizeConverted sets the size of the layout, the values have to be in the layout's unit - * @param size layout size - */ - void SetLayoutSizeConverted(const QSizeF &size); - - /** - * @brief GetLayoutSize Returns the size in Unit::Px - * @return layout size in Unit::Px - */ - QSizeF GetLayoutSize() const; - - /** - * @brief GetLayoutSizeConverted Returns the size in the layout's unit - * @return the size in the layout's unit - */ - QSizeF GetLayoutSizeConverted() const; - - /** - * @brief SetLayoutMargins, set the margins of the layout, the values have to be in Unit::Px - * @param left in Unit::Px - * @param top in Unit::Px - * @param right in Unit::Px - * @param bottom in Unit::Px - */ - void SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetLayoutMargins, set the margins of the layout, the values have to be in the unit of the layout - * @param left in Unit::Px - * @param top in Unit::Px - * @param right in Unit::Px - * @param bottom in Unit::Px - */ - void SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetLayoutMargins set the margins of the layout, the values have to be in Unit::Px - * @param margins layout margins - */ - void SetLayoutMargins(const QMarginsF &margins); - - /** - * @brief SetLayoutMargins set the margins of the layout, the values have to be in the unit of the layout - * @param margins layout margins - */ - void SetLayoutMarginsConverted(const QMarginsF &margins); - - /** - * @brief GetLayoutMargins Returns the size in Unit::Px - * @return the size in Unit::Px - */ - QMarginsF GetLayoutMargins() const; - - /** - * @brief GetLayoutMarginsConverted Returns the margins in the layout's unit - * @return the margins in the layout's unit - */ - QMarginsF GetLayoutMarginsConverted() const; - - /** - * @brief SetFollowGrainline Sets the type of grainline for the pieces to follow - * @param state the type of grainline - */ - void SetFollowGrainline(FollowGrainline state); - - /** - * @brief GetFollowGrainline Returns if the layout's pieces follow a grainline or not - * @return wether the pieces follow a grainline and if so, which grainline - */ - FollowGrainline GetFollowGrainline() const; - - /** - * @brief SetPiecesGap sets the pieces gap to the given value, the unit has to be in Unit::Px - * @param value pieces gap - */ - void SetPiecesGap(qreal value); - - /** - * @brief SetPiecesGapConverted sets the pieces gap to the given value, the unit has to be in the layout's unit - * @param value pieces gap - */ - void SetPiecesGapConverted(qreal value); - - /** - * @brief GetPiecesGap returns the pieces gap in Unit::Px - * @return the pieces gap in Unit::Px - */ - qreal GetPiecesGap() const; - - /** - * @brief GetPiecesGapConverted returns the pieces gap in the layout's unit - * @return the pieces gap in the layout's unit - */ - qreal GetPiecesGapConverted() const; - void SetWarningSuperpositionOfPieces(bool state); bool GetWarningSuperpositionOfPieces() const; void SetWarningPiecesOutOfBound(bool state); bool GetWarningPiecesOutOfBound() const; - void SetStickyEdges(bool state); - bool GetStickyEdges() const; - /** - * @brief ClearSelection goes through the piece list and pieces and calls + * @brief ClearSelection goes through the unplaced pieces and through the sheets and calls * SetIsSelected(false) for the pieces that were selected. */ void ClearSelection(); - /** - * @brief SetFocusedPieceList Sets the focused piece klist, to which pieces are added from the carrousel via drag - * and drop - * @param focusedPieceList the new active piece list. If nullptr, then it sets automaticaly the first piece list from m_pieceLists - */ - void SetFocusedPieceList(VPPieceList* focusedPieceList = nullptr); - - /** - * @brief GetFocusedPieceList Returns the focused piece list, to which pieces are added from the carrousel via drag - * and drop - * @return the focused piece list - */ - VPPieceList* GetFocusedPieceList(); - /** * @brief MovePieceToPieceList Moves the given piece to the given piece list * @param piece the piece to move @@ -226,6 +91,21 @@ public: */ void MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList); + /** + * @brief SetFocusedSheet Sets the focused sheet, to which pieces are added from the carrousel via drag + * and drop + * @param focusedSheet the new active sheet. If nullptr, then it sets automaticaly the first sheet from m_sheets + */ + void SetFocusedSheet(VPSheet *focusedSheet = nullptr); + + /** + * @brief GetFocusedSheet Returns the focused sheet, to which pieces are added from the carrousel via drag + * and drop + * @return the focused sheet + */ + VPSheet* GetFocusedSheet(); + + signals: void PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); @@ -234,37 +114,25 @@ private: Q_DISABLE_COPY(VPLayout) VPPieceList *m_unplacedPieceList; - QList m_pieceLists{}; + + QList m_sheets; /** + TODO : To be replaced by m_focusedSheet * @brief m_focusedPieceList pointer the the focused piece list, to which pieces will be * added via drag and drop, or if no piece list is defined. */ VPPieceList *m_focusedPieceList{nullptr}; + + VPSheet *m_focusedSheet{nullptr}; + // format Unit m_unit{Unit::Cm}; - /** - * @brief m_size the Size in Unit::Px - */ - QSizeF m_size{}; - // margins - /** - * @brief m_margins the margins in Unit::Px - */ - QMarginsF m_margins{}; - - // control - FollowGrainline m_followGrainLine{FollowGrainline::No}; - - /** - * @brief m_piecesGap the pieces gap in Unit::Px - */ - qreal m_piecesGap{0}; bool m_warningSuperpositionOfPieces{false}; bool m_warningPiecesOutOfBound{false}; - bool m_stickyEdges{false}; + }; diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 17ec5ee48..a114a8ff0 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -34,6 +34,8 @@ #include "vpmimedatapiece.h" #include "vppiecelist.h" +#include "vplayout.h" +#include "vpsheet.h" #include "../vwidgets/vmaingraphicsscene.h" #include @@ -46,10 +48,11 @@ VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, QWidget *parent) : VMainGraphicsView(parent), m_layout(layout) { + // TODO : list of scenes m_scene = new VMainGraphicsScene(this); setScene(m_scene); - m_graphicsSheet = new VPGraphicsSheet(layout); + m_graphicsSheet = new VPGraphicsSheet(layout->GetFocusedSheet()); m_graphicsSheet->setPos(0, 0); m_scene->addItem(m_graphicsSheet); @@ -123,7 +126,7 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event) piece->SetPosition(mapToScene(point)); // change the piecelist of the piece - VPPieceList *focusedPieceList = m_layout->GetFocusedPieceList(); + VPPieceList *focusedPieceList = m_layout->GetFocusedSheet()->GetPieceList(); if(focusedPieceList != nullptr) { m_layout->MovePieceToPieceList(piece, focusedPieceList); diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index e9afa30f4..c383074db 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -40,6 +40,7 @@ #include "../vmisc/projectversion.h" #include "../ifc/xml/vlayoutconverter.h" #include "../ifc/exception/vexception.h" +#include "vpsheet.h" #include @@ -57,13 +58,19 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : ui(new Ui::VPMainWindow), m_cmd(cmd) { - m_layout = new VPLayout(); + // create a standard sheet + VPSheet *sheet = new VPSheet(m_layout); + sheet->SetName(QObject::tr("Sheet #1")); + m_layout->AddSheet(sheet); + m_layout->SetFocusedSheet(); + // ----- for test purposes, to be removed------------------ - m_layout->SetLayoutMarginsConverted(2, 2, 2, 2); - m_layout->SetLayoutSizeConverted(30.0, 45); - m_layout->SetPiecesGapConverted(1); + sheet->SetSheetMarginsConverted(2, 2, 2, 2); + sheet->SetSheetSizeConverted(30.0, 45); + sheet->SetPiecesGapConverted(1); + m_layout->SetUnit(Unit::Cm); m_layout->SetWarningSuperpositionOfPieces(true); // -------------------------------------------------------- @@ -270,32 +277,32 @@ void VPMainWindow::InitPropertyTabLayout() // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect // -------------------- layout width, length, orientation ------------------------ - connect(ui->doubleSpinBoxLayoutWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &VPMainWindow::on_LayoutSizeChanged); - connect(ui->doubleSpinBoxLayoutLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &VPMainWindow::on_LayoutSizeChanged); - connect(ui->radioButtonLayoutPortrait, QOverload::of(&QRadioButton::clicked), this, - &VPMainWindow::on_LayoutOrientationChanged); - connect(ui->radioButtonLayoutLandscape, QOverload::of(&QRadioButton::clicked), this, - &VPMainWindow::on_LayoutOrientationChanged); + connect(ui->doubleSpinBoxSheetWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetSizeChanged); + connect(ui->doubleSpinBoxSheetLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetSizeChanged); + connect(ui->radioButtonSheetPortrait, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetOrientationChanged); + connect(ui->radioButtonSheetLandscape, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetOrientationChanged); // -------------------- margins ------------------------ - connect(ui->doubleSpinBoxLayoutMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &VPMainWindow::on_LayoutMarginChanged); - connect(ui->doubleSpinBoxLayoutMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &VPMainWindow::on_LayoutMarginChanged); - connect(ui->doubleSpinBoxLayoutMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &VPMainWindow::on_LayoutMarginChanged); - connect(ui->doubleSpinBoxLayoutMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &VPMainWindow::on_LayoutMarginChanged); + connect(ui->doubleSpinBoxSheetMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); + connect(ui->doubleSpinBoxSheetMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); + connect(ui->doubleSpinBoxSheetMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); + connect(ui->doubleSpinBoxSheetMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); // ------------------- follow grainline ----------------------- - connect(ui->radioButtonLayoutFollowGrainlineNo, QOverload::of(&QRadioButton::clicked), this, - &VPMainWindow::on_LayoutFollowGrainlineChanged); - connect(ui->radioButtonLayoutFollowGrainlineVertical, QOverload::of(&QRadioButton::clicked), this, - &VPMainWindow::on_LayoutFollowGrainlineChanged); - connect(ui->radioButtonLayoutFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, - &VPMainWindow::on_LayoutFollowGrainlineChanged); + connect(ui->radioButtonSheetFollowGrainlineNo, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetFollowGrainlineChanged); + connect(ui->radioButtonSheetFollowGrainlineVertical, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetFollowGrainlineChanged); + connect(ui->radioButtonSheetFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetFollowGrainlineChanged); // -------------------- export --------------------------- @@ -332,8 +339,9 @@ void VPMainWindow::SetPropertiesData() else { SetPropertyTabCurrentPieceData(); - SetPropertyTabLayoutData(); + SetPropertyTabSheetData(); SetPropertyTabTilesData(); + SetPropertyTabLayoutData(); } } @@ -384,9 +392,43 @@ void VPMainWindow::SetPropertyTabCurrentPieceData() } } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::SetPropertyTabSheetData() +{ + // set Width / Length + QSizeF size = m_layout->GetFocusedSheet()->GetSheetSizeConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, size.width()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height()); + + // Set Orientation + if(size.width() <= size.height()) + { + ui->radioButtonSheetPortrait->setChecked(true); + } + else + { + ui->radioButtonSheetLandscape->setChecked(true); + } + + // set margins + QMarginsF margins = m_layout->GetFocusedSheet()->GetSheetMarginsConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, margins.left()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, margins.top()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, margins.right()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, margins.bottom()); + + // set pieces gap + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPiecesGap, m_layout->GetFocusedSheet()->GetPiecesGapConverted()); + + // set the checkboxes + SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabLayoutData() { + // TODO FIXME : Set name and description + // set Unit int index = ui->comboBoxLayoutUnit->findData(QVariant(UnitsToStr(m_layout->GetUnit()))); if(index != -1) @@ -396,35 +438,9 @@ void VPMainWindow::SetPropertyTabLayoutData() ui->comboBoxLayoutUnit->blockSignals(false); } - // set Width / Length - QSizeF size = m_layout->GetLayoutSizeConverted(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, size.width()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, size.height()); - - // Set Orientation - if(size.width() <= size.height()) - { - ui->radioButtonLayoutPortrait->setChecked(true); - } - else - { - ui->radioButtonLayoutLandscape->setChecked(true); - } - - // set margins - QMarginsF margins = m_layout->GetLayoutMarginsConverted(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginLeft, margins.left()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginTop, margins.top()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginRight, margins.right()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginBottom, margins.bottom()); - - // set pieces gap - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutPiecesGap, m_layout->GetPiecesGapConverted()); - - // set the checkboxes + // set controls SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, m_layout->GetWarningPiecesOutOfBound()); SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); - SetCheckBoxValue(ui->checkBoxLayoutStickyEdges, m_layout->GetStickyEdges()); } //--------------------------------------------------------------------------------------------------------------------- @@ -763,16 +779,16 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) m_layout->SetUnit(Unit::Inch); } - SetPropertyTabLayoutData(); + SetPropertyTabSheetData(); SetPropertyTabCurrentPieceData(); } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_comboBoxLayoutTemplate_currentIndexChanged(int index) +void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO VPMainWindow::LayoutTemplateChanged"); + msgBox.setText("TODO VPMainWindow::SheetTemplateChanged"); int ret = msgBox.exec(); Q_UNUSED(index); @@ -783,20 +799,20 @@ void VPMainWindow::on_comboBoxLayoutTemplate_currentIndexChanged(int index) } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_LayoutSizeChanged() +void VPMainWindow::on_SheetSizeChanged() { - m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value()); + m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); // updates orientation - no need to block signals because the signal reacts on "clicked" - if(ui->doubleSpinBoxLayoutWidth->value() <= ui->doubleSpinBoxLayoutLength->value()) + if(ui->doubleSpinBoxSheetWidth->value() <= ui->doubleSpinBoxSheetLength->value()) { //portrait - ui->radioButtonLayoutPortrait->setChecked(true); + ui->radioButtonSheetPortrait->setChecked(true); } else { //landscape - ui->radioButtonLayoutLandscape->setChecked(true); + ui->radioButtonSheetLandscape->setChecked(true); } // TODO Undo / Redo @@ -805,16 +821,16 @@ void VPMainWindow::on_LayoutSizeChanged() } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_LayoutOrientationChanged() +void VPMainWindow::on_SheetOrientationChanged() { // swap the width and length - qreal width_before = ui->doubleSpinBoxLayoutWidth->value(); - qreal length_before = ui->doubleSpinBoxLayoutLength->value(); + qreal width_before = ui->doubleSpinBoxSheetWidth->value(); + qreal length_before = ui->doubleSpinBoxSheetLength->value(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, length_before); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, width_before); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, length_before); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, width_before); - m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value()); + m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); // TODO Undo / Redo @@ -822,7 +838,7 @@ void VPMainWindow::on_LayoutOrientationChanged() } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_pushButtonLayoutRemoveUnusedLength_clicked() +void VPMainWindow::on_pushButtonSheetRemoveUnusedLength_clicked() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -836,13 +852,13 @@ void VPMainWindow::on_pushButtonLayoutRemoveUnusedLength_clicked() //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_LayoutMarginChanged() +void VPMainWindow::on_SheetMarginChanged() { - m_layout->SetLayoutMarginsConverted( - ui->doubleSpinBoxLayoutMarginLeft->value(), - ui->doubleSpinBoxLayoutMarginTop->value(), - ui->doubleSpinBoxLayoutMarginRight->value(), - ui->doubleSpinBoxLayoutMarginBottom->value() + m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + ui->doubleSpinBoxSheetMarginLeft->value(), + ui->doubleSpinBoxSheetMarginTop->value(), + ui->doubleSpinBoxSheetMarginRight->value(), + ui->doubleSpinBoxSheetMarginBottom->value() ); // TODO Undo / Redo @@ -852,7 +868,7 @@ void VPMainWindow::on_LayoutMarginChanged() //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_LayoutFollowGrainlineChanged() +void VPMainWindow::on_SheetFollowGrainlineChanged() { // just for test purpuses, to be removed: QMessageBox msgBox; @@ -866,9 +882,9 @@ void VPMainWindow::on_LayoutFollowGrainlineChanged() //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_doubleSpinBoxLayoutPiecesGap_valueChanged(double value) +void VPMainWindow::on_doubleSpinBoxSheetPiecesGap_valueChanged(double value) { - m_layout->SetPiecesGapConverted(value); + m_layout->GetFocusedSheet()->SetPiecesGapConverted(value); // TODO Undo / Redo // TODO update the QGraphicView @@ -893,16 +909,16 @@ void VPMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_checkBoxLayoutStickyEdges_toggled(bool checked) +void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) { - m_layout->SetStickyEdges(checked); + m_layout->GetFocusedSheet()->SetStickyEdges(checked); // TODO Undo / Redo // TODO update the QGraphicView } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_pushButtonLayoutExport_clicked() +void VPMainWindow::on_pushButtonSheetExport_clicked() { // just for test purpuses, to be removed: QMessageBox msgBox; diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 275f2fb00..65380c4dc 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -152,10 +152,10 @@ private: void SetPropertyTabCurrentPieceData(); /** - * @brief SetPropertyTabLayoutData Sets the values of UI elements - * in the Layout Tab to the values saved in m_layout + * @brief SetPropertyTabSheetData Sets the values of UI elements + * in the Sheet Tab to the values saved in focused sheet */ - void SetPropertyTabLayoutData(); + void SetPropertyTabSheetData(); /** * @brief SetPropertyTabTilesData Sets the values of UI elements @@ -163,6 +163,12 @@ private: */ void SetPropertyTabTilesData(); + /** + * @brief SetPropertyTabLayoutData Sets the values of UI elements + * in the Layout Tab to the values saved in m_layout + */ + void SetPropertyTabLayoutData(); + /** * @brief SetDoubleSpinBoxValue sets the given spinbox to the given value. * the signals are blocked before changing the value and unblocked after @@ -248,38 +254,38 @@ private slots: * The slot is automatically connected through name convention. * @param index the index of the selected templated */ - void on_comboBoxLayoutTemplate_currentIndexChanged(int index); + void on_comboBoxSheetTemplate_currentIndexChanged(int index); /** * @brief LayoutSizeChanged When the width or the length has been changed in * the layout property tab */ - void on_LayoutSizeChanged(); + void on_SheetSizeChanged(); /** * @brief LayoutOrientationChanged When one of the radio boxes for the layout * orientation has been clicked */ - void on_LayoutOrientationChanged(); + void on_SheetOrientationChanged(); /** * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button * "Remove unused length" in the layout property tab is clicked. * The slot is automatically connected through name convention. */ - void on_pushButtonLayoutRemoveUnusedLength_clicked(); + void on_pushButtonSheetRemoveUnusedLength_clicked(); /** * @brief on_LayoutMarginChanged When one of the margin values has been changed * in the layout property tab. */ - void on_LayoutMarginChanged(); + void on_SheetMarginChanged(); /** * @brief LayoutFollowGrainlineChanged When one of the radio boxes for the * "Follow grainline" has been clicked in the layout property tab. */ - void on_LayoutFollowGrainlineChanged(); + void on_SheetFollowGrainlineChanged(); /** * @brief on_doubleSpinBoxLayoutPiecesGap_valueChanged When the "pieces gap" @@ -287,7 +293,7 @@ private slots: * The slot is automatically connected through name convention. * @param value the new value of the pieces gap */ - void on_doubleSpinBoxLayoutPiecesGap_valueChanged(double value); + void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); /** * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the @@ -313,14 +319,14 @@ private slots: * The slot is automatically connected through name convention. * @param checked the new checked value */ - void on_checkBoxLayoutStickyEdges_toggled(bool checked); + void on_checkBoxSheetStickyEdges_toggled(bool checked); /** * @brief on_pushButtonLayoutExport_clicked When the button * "Export layout" in the layout property is clicked. * The slot is automatically connected through name convention. */ - void on_pushButtonLayoutExport_clicked(); + void on_pushButtonSheetExport_clicked(); /** * @brief on_checkBoxCurrentPieceShowSeamline_toggled When the diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 677c1286d..927c80787 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -172,7 +172,7 @@ QTabWidget::Rounded - 2 + 1 @@ -458,7 +458,7 @@ - + :/puzzleicon/64x64/iconLayout.png:/puzzleicon/64x64/iconLayout.png @@ -483,7 +483,7 @@ 0 - + QFrame::NoFrame @@ -507,12 +507,12 @@ - + font-weight: bold; - Layout + Current sheet Qt::AlignCenter @@ -520,7 +520,7 @@ - + Format @@ -528,64 +528,54 @@ - - - Unit - - - - - - - - + Template - - + + - - + + Width - - + + 100000.000000000000000 - - + + + + Length + + + + + 100000.000000000000000 - - - Length - - - - - + Orientation - + - + Portrait @@ -608,7 +598,7 @@ - + Landscape @@ -632,7 +622,7 @@ - + Remove unused length @@ -642,13 +632,13 @@ - + Margins - + Right: @@ -658,7 +648,7 @@ - + Top: @@ -668,21 +658,21 @@ - + 0.100000000000000 - + 0.100000000000000 - + Left: @@ -692,7 +682,7 @@ - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -702,14 +692,14 @@ - + 0.100000000000000 - + Bottom: @@ -722,7 +712,7 @@ - + Control @@ -730,7 +720,7 @@ - + Follow grainline @@ -739,7 +729,7 @@ - + No @@ -749,7 +739,7 @@ - + Vertical grainline @@ -769,7 +759,7 @@ - + Horizontal grainline @@ -791,33 +781,19 @@ - + Pieces gap - + - - - Warning superposition of pieces - - - - - - - Warning pieces out of bound - - - - - + Sticky edges @@ -827,7 +803,7 @@ - + Export @@ -835,21 +811,21 @@ - + Format - + - + - Export Layout + Export Sheet @@ -857,7 +833,7 @@ - + Qt::Vertical @@ -929,7 +905,7 @@ font-weight: bold; - Tiles + Tiles of current sheet Qt::AlignCenter @@ -955,6 +931,162 @@ + + + Prop. + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + true + + + + + 0 + 0 + 356 + 760 + + + + + + + font-weight: bold; + + + Layout + + + Qt::AlignCenter + + + + + + + Infos + + + + + + + + Name + + + + + + + My layout + + + + + + + + + Description + + + + + + + + + + + + + Format + + + + + + + + Unit + + + + + + + + + + + + + + + Control + + + + + + Warning superposition of pieces + + + + + + + Warning pieces out of bound + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + @@ -1041,11 +1173,11 @@ - scrollAreaLayout - doubleSpinBoxLayoutMarginTop - doubleSpinBoxLayoutMarginLeft - doubleSpinBoxLayoutMarginRight - doubleSpinBoxLayoutMarginBottom + scrollAreaSheet + doubleSpinBoxSheetMarginTop + doubleSpinBoxSheetMarginLeft + doubleSpinBoxSheetMarginRight + doubleSpinBoxSheetMarginBottom scrollAreaTiles diff --git a/src/app/puzzle/vppiece.h b/src/app/puzzle/vppiece.h index 759909631..d536c569f 100644 --- a/src/app/puzzle/vppiece.h +++ b/src/app/puzzle/vppiece.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpiece.h + ** @file vppiece.h ** @author Ronan Le Tiec ** @date 13 4, 2020 ** diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index a89e4227b..d61f586c7 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -1,6 +1,204 @@ +/************************************************************************ + ** + ** @file vpsheet.cpp + ** @author Ronan Le Tiec + ** @date 23 5, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ #include "vpsheet.h" -VPSheet::VPSheet() -{ +#include "vppiecelist.h" +#include "vplayout.h" +//--------------------------------------------------------------------------------------------------------------------- +VPSheet::VPSheet(VPLayout* layout) : + m_layout(layout) +{ + m_pieceList = new VPPieceList(layout); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet::~VPSheet() +{ + delete m_pieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPPieceList* VPSheet::GetPieceList() +{ + return m_pieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPSheet::GetName() const +{ + return m_name; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetName(const QString &name) +{ + m_name = name; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSize(qreal width, qreal height) +{ + m_size.setWidth(width); + m_size.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSizeConverted(qreal width, qreal height) +{ + m_size.setWidth(UnitConvertor(width, m_layout->GetUnit(), Unit::Px)); + m_size.setHeight(UnitConvertor(height, m_layout->GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSize(const QSizeF &size) +{ + m_size = size; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSizeConverted(const QSizeF &size) +{ + m_size = QSizeF( + UnitConvertor(size.width(), m_layout->GetUnit(), Unit::Px), + UnitConvertor(size.height(), m_layout->GetUnit(), Unit::Px) + ); +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPSheet::GetSheetSize() const +{ + return m_size; +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPSheet::GetSheetSizeConverted() const +{ + QSizeF convertedSize = QSizeF( + UnitConvertor(m_size.width(), Unit::Px, m_layout->GetUnit()), + UnitConvertor(m_size.height(), Unit::Px, m_layout->GetUnit()) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom) +{ + m_margins.setLeft(left); + m_margins.setTop(top); + m_margins.setRight(right); + m_margins.setBottom(bottom); +} +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) +{ + m_margins.setLeft(UnitConvertor(left, m_layout->GetUnit(), Unit::Px)); + m_margins.setTop(UnitConvertor(top, m_layout->GetUnit(), Unit::Px)); + m_margins.setRight(UnitConvertor(right, m_layout->GetUnit(), Unit::Px)); + m_margins.setBottom(UnitConvertor(bottom, m_layout->GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMargins(const QMarginsF &margins) +{ + m_margins = margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMarginsConverted(const QMarginsF &margins) +{ + m_margins = UnitConvertor(margins, m_layout->GetUnit(), Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPSheet::GetSheetMargins() const +{ + return m_margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPSheet::GetSheetMarginsConverted() const +{ + return UnitConvertor(m_margins, Unit::Px, m_layout->GetUnit()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetFollowGrainline(FollowGrainline state) +{ + m_followGrainLine = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +FollowGrainline VPSheet::GetFollowGrainline() const +{ + return m_followGrainLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetPiecesGap(qreal value) +{ + m_piecesGap = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetPiecesGapConverted(qreal value) +{ + m_piecesGap = UnitConvertor(value, m_layout->GetUnit(), Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPSheet::GetPiecesGap() const +{ + return m_piecesGap; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPSheet::GetPiecesGapConverted() const +{ + return UnitConvertor(m_piecesGap, Unit::Px, m_layout->GetUnit()); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetStickyEdges(bool state) +{ + m_stickyEdges = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPSheet::GetStickyEdges() const +{ + return m_stickyEdges; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::ClearSelection() +{ + m_pieceList->ClearSelection(); } diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h index c2cd9dffb..ea9fb58f4 100644 --- a/src/app/puzzle/vpsheet.h +++ b/src/app/puzzle/vpsheet.h @@ -1,11 +1,225 @@ +/************************************************************************ + ** + ** @file vpsheet.h + ** @author Ronan Le Tiec + ** @date 23 5, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ #ifndef VPSHEET_H #define VPSHEET_H +#include +#include +#include +#include -class VPSheet +#include "def.h" + +// is this the right place for the definition? +enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; + +class VPLayout; +class VPPieceList; + +class VPSheet : public QObject { + Q_OBJECT public: - VPSheet(); + VPSheet(VPLayout* layout); + + ~VPSheet(); + + /** + * @brief GetPieceList returns the piece list of the sheet + * @return + */ + VPPieceList* GetPieceList(); + + /** + * @brief GetName Returns the name of the sheet + * @return the name + */ + QString GetName() const; + + /** + * @brief SetName Sets the name of the sheet to the given name + * @param name the new sheet's name + */ + void SetName(const QString &name); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px + * @param width sheet width + * @param height sheet height + */ + void SetSheetSize(qreal width, qreal height); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in the layout's unit + * @param width sheet width + * @param height sheet height + */ + void SetSheetSizeConverted(qreal width, qreal height); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px + * @param size sheet size + */ + void SetSheetSize(const QSizeF &size); + /** + * @brief SetSheetSizeConverted sets the size of the sheet, the values have to be in the layout's unit + * @param size sheet size + */ + void SetSheetSizeConverted(const QSizeF &size); + + /** + * @brief GetSheetSize Returns the size in Unit::Px + * @return sheet size in Unit::Px + */ + QSizeF GetSheetSize() const; + + /** + * @brief GetSheetSizeConverted Returns the size in the layout's unit + * @return the size in the layout's unit + */ + QSizeF GetSheetSizeConverted() const; + + /** + * @brief SetSheetMargins, set the margins of the sheet, the values have to be in Unit::Px + * @param left in Unit::Px + * @param top in Unit::Px + * @param right in Unit::Px + * @param bottom in Unit::Px + */ + void SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins, set the margins of the sheet, the values have to be in the unit of the layout + * @param left in Unit::Px + * @param top in Unit::Px + * @param right in Unit::Px + * @param bottom in Unit::Px + */ + void SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins set the margins of the sheet, the values have to be in Unit::Px + * @param margins sheet margins + */ + void SetSheetMargins(const QMarginsF &margins); + + /** + * @brief SetSheetMargins set the margins of the sheet, the values have to be in the unit of the layout + * @param margins sheet margins + */ + void SetSheetMarginsConverted(const QMarginsF &margins); + + /** + * @brief GetSheetMargins Returns the size in Unit::Px + * @return the size in Unit::Px + */ + QMarginsF GetSheetMargins() const; + + /** + * @brief GetSheetMarginsConverted Returns the margins in the layout's unit + * @return the margins in the sheet's unit + */ + QMarginsF GetSheetMarginsConverted() const; + + /** + * @brief SetFollowGrainline Sets the type of grainline for the pieces to follow + * @param state the type of grainline + */ + void SetFollowGrainline(FollowGrainline state); + + /** + * @brief GetFollowGrainline Returns if the sheet's pieces follow a grainline or not + * @return wether the pieces follow a grainline and if so, which grainline + */ + FollowGrainline GetFollowGrainline() const; + + /** + * @brief SetPiecesGap sets the pieces gap to the given value, the unit has to be in Unit::Px + * @param value pieces gap + */ + void SetPiecesGap(qreal value); + + /** + * @brief SetPiecesGapConverted sets the pieces gap to the given value, the unit has to be in the layout's unit + * @param value pieces gap + */ + void SetPiecesGapConverted(qreal value); + + /** + * @brief GetPiecesGap returns the pieces gap in Unit::Px + * @return the pieces gap in Unit::Px + */ + qreal GetPiecesGap() const; + + /** + * @brief GetPiecesGapConverted returns the pieces gap in the layout's unit + * @return the pieces gap in the layout's unit + */ + qreal GetPiecesGapConverted() const; + + /** + * @brief ClearSelection goes through the piece list and pieces and calls + * SetIsSelected(false) for the pieces that were selected. + */ + void ClearSelection(); + + void SetStickyEdges(bool state); + bool GetStickyEdges() const; + +private: + Q_DISABLE_COPY(VPSheet) + + VPLayout *m_layout; + + VPPieceList *m_pieceList {nullptr}; + + QString m_name{}; + + /** + * @brief m_size the Size in Unit::Px + */ + QSizeF m_size{}; + + // margins + /** + * @brief m_margins the margins in Unit::Px + */ + QMarginsF m_margins{}; + + // control + FollowGrainline m_followGrainLine{FollowGrainline::No}; + + /** + * @brief m_piecesGap the pieces gap in Unit::Px + */ + qreal m_piecesGap{0}; + + bool m_stickyEdges{false}; }; #endif // VPSHEET_H diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 59ce5d1ca..233bf6c65 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -72,7 +72,11 @@ void VPLayoutFileReader::ReadLayout(VPLayout *layout) } else if (name() == ML::TagPieceLists) { - ReadPieceLists(layout); + ReadSheets(layout); + } + else if (name() == ML::TagUnplacedPieceList) + { + ReadUnplacedPieces(layout); } else { @@ -94,8 +98,6 @@ void VPLayoutFileReader::ReadProperties(VPLayout *layout) { ML::TagUnit, ML::TagDescription, - ML::TagSize, - ML::TagMargin, ML::TagControl, ML::TagTiles }); @@ -113,38 +115,17 @@ void VPLayoutFileReader::ReadProperties(VPLayout *layout) // TODO read the description info break; } - case 2:// size - { - qDebug("read size"); - QSizeF size = ReadSize(); - layout->SetLayoutSize(size); - readElementText(); - break; - } - case 3:// margin - { - qDebug("read margin"); - QMarginsF margins = ReadMargins(); - layout->SetLayoutMargins(margins); - readElementText(); - break; - } - case 4:// control + case 2:// control { qDebug("read control"); QXmlStreamAttributes attribs = attributes(); - - // attribs.value("followGrainLine"); // TODO - layout->SetWarningSuperpositionOfPieces(ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr)); layout->SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr)); - layout->SetStickyEdges(ReadAttributeBool(attribs, ML::AttrStickyEdges, trueStr)); - layout->SetPiecesGap(ReadAttributeDouble(attribs, ML::AttrPiecesGap, QChar('0'))); readElementText(); break; } - case 5:// tiles + case 3:// tiles qDebug("read tiles"); ReadTiles(layout); readElementText(); @@ -157,6 +138,12 @@ void VPLayoutFileReader::ReadProperties(VPLayout *layout) } } +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadUnplacedPieces(VPLayout *layout) +{ + ReadPieceList(layout->GetUnplacedPieceList()); +} + //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileReader::ReadTiles(VPLayout *layout) { @@ -193,20 +180,15 @@ void VPLayoutFileReader::ReadTiles(VPLayout *layout) } //--------------------------------------------------------------------------------------------------------------------- -void VPLayoutFileReader::ReadPieceLists(VPLayout *layout) +void VPLayoutFileReader::ReadSheets(VPLayout *layout) { - SCASSERT(isStartElement() && name() == ML::TagPieceLists); + SCASSERT(isStartElement() && name() == ML::TagSheets); while (readNextStartElement()) { - if (name() == ML::TagUnplacedPieceList) + if (name() == ML::TagSheet) { - ReadPieceList(layout->GetUnplacedPieceList()); - } - else if (name() == ML::TagPieceList) - { - VPPieceList *pieceList = layout->AddPieceList(); - ReadPieceList(pieceList); + ReadSheet(layout); } else { @@ -216,6 +198,14 @@ void VPLayoutFileReader::ReadPieceLists(VPLayout *layout) } } +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadSheet(VPLayout *layout) +{ + Q_UNUSED(layout); + // TODO +} + + //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList) { diff --git a/src/app/puzzle/xml/vplayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h index db38265d6..7ed40f1a8 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -50,7 +50,9 @@ private: void ReadLayout(VPLayout *layout); void ReadProperties(VPLayout *layout); void ReadTiles(VPLayout *layout); - void ReadPieceLists(VPLayout *layout); + void ReadUnplacedPieces(VPLayout *layout); + void ReadSheets(VPLayout *layout); + void ReadSheet(VPLayout *layout); void ReadPieceList(VPPieceList *pieceList); void ReadPiece(VPPiece *piece); diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 92832f6c0..327e01aaf 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -28,6 +28,7 @@ #include "vplayoutfilewriter.h" #include "vplayout.h" +#include "vpsheet.h" #include "vppiecelist.h" #include "vppiece.h" #include "vplayoutliterals.h" @@ -65,7 +66,7 @@ void VPLayoutFileWriter::WriteLayout(VPLayout *layout) SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr); WriteProperties(layout); - WritePieceLists(layout); + WriteUnplacePiecesList(layout); writeEndElement(); //layout } @@ -79,16 +80,10 @@ void VPLayoutFileWriter::WriteProperties(VPLayout *layout) writeTextElement(ML::TagDescription, QString()); // TODO : define the value in layout - WriteSize(layout->GetLayoutSize()); - - WriteMargins(layout->GetLayoutMargins()); - writeStartElement(ML::TagControl); - SetAttribute(ML::AttrFollowGrainLine, "no"); // TODO / Fixme get the right value + SetAttribute(ML::AttrWarningSuperposition, layout->GetWarningSuperpositionOfPieces()); SetAttribute(ML::AttrWarningOutOfBound, layout->GetWarningPiecesOutOfBound()); - SetAttribute(ML::AttrStickyEdges, layout->GetStickyEdges()); - SetAttribute(ML::AttrPiecesGap, layout->GetPiecesGap()); writeEndElement(); // control // WriteTiles(layout); TODO: when tile functionality implemented, then uncomment this line @@ -96,6 +91,32 @@ void VPLayoutFileWriter::WriteProperties(VPLayout *layout) writeEndElement(); // properties } +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteUnplacePiecesList(VPLayout *layout) +{ + Q_UNUSED(layout); + // TODO +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteSheets(VPLayout *layout) +{ + Q_UNUSED(layout); + // TODO +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteSheet(VPSheet* sheet) +{ + Q_UNUSED(sheet); + // TODO + + // WritePieceList(pieceList); + +} + + + //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileWriter::WriteTiles(VPLayout *layout) { @@ -115,23 +136,6 @@ void VPLayoutFileWriter::WriteTiles(VPLayout *layout) } -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutFileWriter::WritePieceLists(VPLayout *layout) -{ - writeStartElement(ML::TagPieceLists); - - WritePieceList(layout->GetUnplacedPieceList(), ML::TagUnplacedPieceList); - - QList pieceLists = layout->GetPiecesLists(); - for (auto pieceList : pieceLists) - { - WritePieceList(pieceList); - } - - writeEndElement(); // piece list -} - - //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList) { diff --git a/src/app/puzzle/xml/vplayoutfilewriter.h b/src/app/puzzle/xml/vplayoutfilewriter.h index a63ee4f0b..4498277c4 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.h +++ b/src/app/puzzle/xml/vplayoutfilewriter.h @@ -35,6 +35,7 @@ #include "../vmisc/literals.h" class VPLayout; +class VPSheet; class VPPieceList; class VPPiece; class QFile; @@ -52,8 +53,10 @@ private: void WriteLayout(VPLayout *layout); void WriteProperties(VPLayout *layout); + void WriteUnplacePiecesList(VPLayout *layout); + void WriteSheets(VPLayout *layout); + void WriteSheet(VPSheet* sheet); void WriteTiles(VPLayout *layout); - void WritePieceLists(VPLayout *layout); void WritePieceList(VPPieceList *pieceList); void WritePieceList(VPPieceList *pieceList, const QString &tagName); void WritePiece(VPPiece *piece); diff --git a/src/app/puzzle/xml/vplayoutliterals.cpp b/src/app/puzzle/xml/vplayoutliterals.cpp index 2421577e2..ada2d2f37 100644 --- a/src/app/puzzle/xml/vplayoutliterals.cpp +++ b/src/app/puzzle/xml/vplayoutliterals.cpp @@ -41,6 +41,8 @@ const QString TagTiles = QStringLiteral("tiles"); const QString TagUnplacedPieceList = QStringLiteral("unplacedPieceList"); const QString TagPieceList = QStringLiteral("pieceList"); const QString TagPiece = QStringLiteral("piece"); +const QString TagSheets = QStringLiteral("sheets"); +const QString TagSheet = QStringLiteral("sheet"); const QString AttrVersion = QStringLiteral("version"); const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition"); diff --git a/src/app/puzzle/xml/vplayoutliterals.h b/src/app/puzzle/xml/vplayoutliterals.h index b0b2c970f..0f1278b7d 100644 --- a/src/app/puzzle/xml/vplayoutliterals.h +++ b/src/app/puzzle/xml/vplayoutliterals.h @@ -46,6 +46,8 @@ extern const QString TagTiles; extern const QString TagUnplacedPieceList; extern const QString TagPieceList; extern const QString TagPiece; +extern const QString TagSheets; +extern const QString TagSheet; extern const QString AttrVersion; extern const QString AttrWarningSuperposition;