From 91a69b83b668b79038c2b4015e4d91a198db1042 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 29 Jul 2021 17:11:18 +0300 Subject: [PATCH] Cleaning and refactoring. --- src/app/puzzle/puzzle.pri | 4 +- src/app/puzzle/vpapplication.cpp | 7 +- src/app/puzzle/vpcarrousel.cpp | 25 +- src/app/puzzle/vpcarrousel.h | 13 +- src/app/puzzle/vpcarrouselpiecelist.cpp | 166 ++---- src/app/puzzle/vpcarrouselpiecelist.h | 34 +- src/app/puzzle/vpexporter.cpp | 4 +- src/app/puzzle/vpgraphicspiece.cpp | 67 +-- src/app/puzzle/vpgraphicspiece.h | 7 - src/app/puzzle/vpgraphicssheet.cpp | 16 +- src/app/puzzle/vpgraphicstilegrid.cpp | 10 +- src/app/puzzle/vplayout.cpp | 319 ++-------- src/app/puzzle/vplayout.h | 255 +------- src/app/puzzle/vplayoutsettings.cpp | 672 ++++++++++++++++++++++ src/app/puzzle/vplayoutsettings.h | 524 +++++++++++++++++ src/app/puzzle/vpmaingraphicsview.cpp | 89 +-- src/app/puzzle/vpmaingraphicsview.h | 16 - src/app/puzzle/vpmainwindow.cpp | 153 ++--- src/app/puzzle/vpmainwindow.h | 2 +- src/app/puzzle/vppiece.cpp | 31 +- src/app/puzzle/vppiece.h | 34 +- src/app/puzzle/vppiecelist.cpp | 120 ---- src/app/puzzle/vppiecelist.h | 102 ---- src/app/puzzle/vpsheet.cpp | 487 +--------------- src/app/puzzle/vpsheet.h | 320 +---------- src/app/puzzle/vptilefactory.cpp | 12 +- src/app/puzzle/vptilefactory.h | 2 +- src/app/puzzle/xml/vplayoutfilereader.cpp | 68 ++- src/app/puzzle/xml/vplayoutfilereader.h | 4 +- src/app/puzzle/xml/vplayoutfilewriter.cpp | 35 +- src/app/puzzle/xml/vplayoutfilewriter.h | 2 +- 31 files changed, 1555 insertions(+), 2045 deletions(-) create mode 100644 src/app/puzzle/vplayoutsettings.cpp create mode 100644 src/app/puzzle/vplayoutsettings.h delete mode 100644 src/app/puzzle/vppiecelist.cpp delete mode 100644 src/app/puzzle/vppiecelist.h diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index d4be14864..9d00cef70 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -18,11 +18,11 @@ SOURCES += \ $$PWD/vpgraphicssheet.cpp \ $$PWD/vpgraphicstilegrid.cpp \ $$PWD/vplayout.cpp \ + $$PWD/vplayoutsettings.cpp \ $$PWD/vpmaingraphicsview.cpp \ $$PWD/vpmainwindow.cpp \ $$PWD/vpmimedatapiece.cpp \ $$PWD/vppiece.cpp \ - $$PWD/vppiecelist.cpp \ $$PWD/vpsettings.cpp \ $$PWD/vpsheet.cpp \ $$PWD/vptilefactory.cpp \ @@ -49,11 +49,11 @@ HEADERS += \ $$PWD/vpgraphicssheet.h \ $$PWD/vpgraphicstilegrid.h \ $$PWD/vplayout.h \ + $$PWD/vplayoutsettings.h \ $$PWD/vpmaingraphicsview.h \ $$PWD/vpmainwindow.h \ $$PWD/vpmimedatapiece.h \ $$PWD/vppiece.h \ - $$PWD/vppiecelist.h \ $$PWD/vpsettings.h \ $$PWD/vpsheet.h \ $$PWD/vptilefactory.h \ diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index 27a257872..ddb7dfdd1 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -446,7 +446,7 @@ void VPApplication::ActivateDarkMode() { f.open(QFile::ReadOnly | QFile::Text); QTextStream ts(&f); - qApp->setStyleSheet(ts.readAll()); + VPApplication::VApp()->setStyleSheet(ts.readAll()); } } } @@ -469,7 +469,7 @@ void VPApplication::ParseCommandLine(const SocketConnection &connection, const Q stream << arguments.join(";;"); stream.flush(); socket.waitForBytesWritten(); - qApp->exit(V_EX_OK); + QCoreApplication::exit(V_EX_OK); return; } @@ -548,14 +548,13 @@ void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd) NewMainWindow(cmd); if (not rawLayouts.isEmpty()) { -// MainWindow()->New(); // prepare layout settings MainWindow()->ImportRawLayouts(rawLayouts); } } if (not cmd->IsGuiEnabled()) { - qApp->exit(V_EX_OK); // close program after processing in console mode + QCoreApplication::exit(V_EX_OK); // close program after processing in console mode } } diff --git a/src/app/puzzle/vpcarrousel.cpp b/src/app/puzzle/vpcarrousel.cpp index d1f8f588f..757ca97af 100644 --- a/src/app/puzzle/vpcarrousel.cpp +++ b/src/app/puzzle/vpcarrousel.cpp @@ -33,7 +33,6 @@ #include #include "../vmisc/backport/qoverload.h" -#include "vppiecelist.h" #include "vpsheet.h" #include @@ -77,7 +76,7 @@ void VPCarrousel::Refresh() VPCarrouselSheet carrouselSheet; carrouselSheet.unplaced = true; carrouselSheet.name = tr("Unplaced pieces"); - carrouselSheet.pieces = m_layout->GetUnplacedPieceList(); + carrouselSheet.pieces = m_layout->GetUnplacedPieces(); m_pieceLists.append(carrouselSheet); } @@ -88,7 +87,7 @@ void VPCarrousel::Refresh() VPCarrouselSheet carrouselSheet; carrouselSheet.unplaced = false; carrouselSheet.name = sheet->GetName(); - carrouselSheet.pieces = sheet->GetPieceList(); + carrouselSheet.pieces = sheet->GetPieces(); m_pieceLists.append(carrouselSheet); } @@ -146,7 +145,7 @@ void VPCarrousel::on_ActivePieceListChanged(int index) } else { - ui->listWidget->SetCurrentPieceList(nullptr); + ui->listWidget->SetCurrentPieceList(QList()); } } @@ -183,24 +182,6 @@ void VPCarrousel::RefreshOrientation() } } -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrousel::ClearSelection() -{ - if (m_layout != nullptr) - { - m_layout->ClearSelection(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrousel::ClearSelectionExceptForCurrentPieceList() -{ - if (m_layout != nullptr) - { - m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList()); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VPCarrousel::changeEvent(QEvent *event) { diff --git a/src/app/puzzle/vpcarrousel.h b/src/app/puzzle/vpcarrousel.h index 581519444..6f431e283 100644 --- a/src/app/puzzle/vpcarrousel.h +++ b/src/app/puzzle/vpcarrousel.h @@ -44,7 +44,7 @@ struct VPCarrouselSheet { bool unplaced{true}; QString name{}; - VPPieceList* pieces{nullptr}; + QList pieces{}; }; class VPCarrousel : public QWidget @@ -79,17 +79,6 @@ public: */ void Clear(); - /** - * @brief ClearSelection Clears the selection of the carrousel. - */ - void ClearSelection(); - - /** - * @brief ClearSelectionExceptForCurrentPieceList Clears the selection of all pieces of - * the layout except for the one in the current piece list - */ - void ClearSelectionExceptForCurrentPieceList(); - protected: virtual void changeEvent(QEvent* event) override; diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index c9ee011eb..a1198a826 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -37,6 +37,7 @@ #include "vpcarrouselpiece.h" #include "../vmisc/backport/qoverload.h" #include "vpmimedatapiece.h" +#include "vpsheet.h" #include @@ -51,8 +52,6 @@ VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) : setContextMenuPolicy(Qt::DefaultContextMenu); setSelectionMode(QAbstractItemView::MultiSelection); setViewMode(QListView::IconMode); - - connect(this, &VPCarrouselPieceList::itemSelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedInternal); } //--------------------------------------------------------------------------------------------------------------------- @@ -72,15 +71,10 @@ void VPCarrouselPieceList::Refresh() { clear(); - if(m_pieceList != nullptr) + if(not m_pieceList.isEmpty()) { - m_pieceList->disconnect(this); - - // Updates the carrousel pieces from the pieces list - QList pieces = m_pieceList->GetPieces(); - // create the corresponding carrousel pieces - for (auto *piece : pieces) + for (auto *piece : m_pieceList) { // update the label of the piece auto* carrouselpiece = new VPCarrouselPiece(piece, this); @@ -88,21 +82,11 @@ void VPCarrouselPieceList::Refresh() connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); } sortItems(); - - connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded); - connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved); } } - //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPCarrouselPieceList::GetCurrentPieceList() -{ - return m_pieceList; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrouselPieceList::SetCurrentPieceList(VPPieceList* pieceList) +void VPCarrouselPieceList::SetCurrentPieceList(const QList &pieceList) { m_pieceList = pieceList; @@ -135,7 +119,7 @@ void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event) if ((event->buttons() & Qt::LeftButton) && ((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) && (selectedItems().count() > 0) && - (m_pieceList->GetSheet() == nullptr)) // only if it's from unplaced pieces + (not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)) // only if it's from unplaced pieces { startDrag(Qt::MoveAction); } @@ -187,115 +171,51 @@ void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) { QListWidgetItem* _item = currentItem(); - if(_item != nullptr) - { - if(_item->type() == 1001) - { - VPCarrouselPiece *pieceItem = static_cast (_item); - - QMenu contextMenu; - - if(m_pieceList->GetSheet() == nullptr) - { - VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList(); - QAction *moveAction = contextMenu.addAction(tr("Move to Sheet")); - QVariant moveData = QVariant::fromValue(sheetPieces); - moveAction->setData(moveData); - - VPPieceList* trashPieceList = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetTrashPieceList(); - QAction *deleteAction = contextMenu.addAction(tr("Delete")); - QVariant deleteData = QVariant::fromValue(trashPieceList); - deleteAction->setData(deleteData); - - connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); - connect(deleteAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); - } - - // remove from piece list action - if(m_pieceList->GetSheet() != nullptr) - { - VPPieceList* unplacedPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetUnplacedPieceList(); - QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet")); - QVariant data = QVariant::fromValue(unplacedPieces); - removeAction->setData(data); - connect(removeAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); - } - - contextMenu.exec(event->globalPos()); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrouselPieceList::on_ActionPieceMovedToPieceList() -{ - QListWidgetItem* _item = currentItem(); - if(_item->type() == 1001) + if(_item != nullptr && _item->type() == 1001) { VPCarrouselPiece *pieceItem = static_cast (_item); - QAction *act = qobject_cast(sender()); - QVariant v = act->data(); - VPPieceList *pieceList = v.value(); - if(pieceList != nullptr) + + QMenu menu; + + QAction *moveAction = menu.addAction(tr("Move to Sheet")); + moveAction->setVisible(false); + + QAction *deleteAction = menu.addAction(tr("Delete")); + deleteAction->setVisible(false); + + QAction *removeAction = menu.addAction(tr("Remove from Sheet")); + removeAction->setVisible(false); + + if(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr) { - pieceList->GetLayout()->MovePieceToPieceList(pieceItem->GetPiece(), pieceList); + moveAction->setVisible(true); + deleteAction->setVisible(true); + } + + if(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() != nullptr) + { + removeAction->setVisible(true); + } + + QAction *selectedAction = menu.exec(event->globalPos()); + + if (selectedAction == moveAction) + { + VPSheet *sheet = pieceItem->GetPiece()->Layout()->GetFocusedSheet(); + pieceItem->GetPiece()->SetSheet(sheet); + } + else if (selectedAction == deleteAction) + { + VPSheet *sheet = pieceItem->GetPiece()->Layout()->GetTrashSheet(); + pieceItem->GetPiece()->SetSheet(sheet); + } + else if (selectedAction == removeAction) + { + pieceItem->GetPiece()->SetSheet(nullptr); } } } -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece) -{ - if(piece->GetPieceList() == m_pieceList) - { - // update the label of the piece - VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this); - carrouselpiece->setSelected(piece->GetIsSelected()); - connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece) -{ - for(int i = 0; i < count(); ++i) - { - QListWidgetItem* _item = item(i); - if(_item->type() == 1001) - { - VPCarrouselPiece *itemPiece = static_cast (_item); - - if(piece == itemPiece->GetPiece()) - { - delete takeItem(row(_item)); - - return; - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPCarrouselPieceList::on_SelectionChangedInternal() -{ - blockSignals(true); - - for(int i = 0; i < count(); ++i) - { - QListWidgetItem* _item = item(i); - if(_item->type() == 1001) - { - VPCarrouselPiece *itemPiece = static_cast (_item); - itemPiece->GetPiece()->SetIsSelected(itemPiece->isSelected()); - } - } - m_carrousel->ClearSelectionExceptForCurrentPieceList(); - // TODO FIXME: when selecting pieces on the sheet, and then selecting a unplaced piece in the piece carrousel - // the selection is cleared in the sheet (good !) but the cliked item in unplaced pieces in not selected (bad!) - - blockSignals(false); -} - //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_SelectionChangedExternal() { diff --git a/src/app/puzzle/vpcarrouselpiecelist.h b/src/app/puzzle/vpcarrouselpiecelist.h index fba5f85af..ba60dbe26 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.h +++ b/src/app/puzzle/vpcarrouselpiecelist.h @@ -30,7 +30,7 @@ #define VPCARROUSELPIECELIST_H #include -#include "vppiecelist.h" + #include "vpcarrousel.h" @@ -46,17 +46,11 @@ public: */ void Refresh(); - /** - * @brief GetPieceList Returns the corresponding VPPieceList - * @return the VPPieceList - */ - VPPieceList* GetCurrentPieceList(); - /** * @brief SetCurrentPieceList Sets the current piece list to the given piece list and redraw * the carrousel. */ - void SetCurrentPieceList(VPPieceList *pieceList); + void SetCurrentPieceList(const QList &pieceList); /** * @brief SetCarrousel Sets the carrousel corresponding to the list @@ -83,31 +77,9 @@ protected: private: Q_DISABLE_COPY(VPCarrouselPieceList) - VPPieceList *m_pieceList{nullptr}; + QList m_pieceList{}; QPoint m_dragStart; VPCarrousel *m_carrousel{nullptr}; - -private slots: - - /** - * @brief on_PieceUpdated This slot is called when a piece was added - */ - void on_PieceAdded(VPPiece* piece); - - /** - * @brief on_PieceUpdated This slot is called when a piece was removed - */ - void on_PieceRemoved(VPPiece* piece); - - /** - * @brief on_SelectionChangedInternal when the selection was changed inside of the carrousel - */ - void on_SelectionChangedInternal(); - - /** - * @brief on_ActionPieceMovedToPieceList when a piece is moved to another piece list via a context menu - */ - void on_ActionPieceMovedToPieceList(); }; #endif // VPCARROUSELPIECELIST_H diff --git a/src/app/puzzle/vpexporter.cpp b/src/app/puzzle/vpexporter.cpp index 60c72d366..2a6def67e 100644 --- a/src/app/puzzle/vpexporter.cpp +++ b/src/app/puzzle/vpexporter.cpp @@ -43,8 +43,8 @@ void VPExporter::Export(VPLayout* layout, LayoutExportFormats format, VPMainGrap SetFileName(fileName); - QSizeF size = QSizeF(layout->GetFocusedSheet()->GetSheetSize()); - if(layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Landscape) + QSizeF size = QSizeF(layout->GetFocusedSheet()->GetLayout()->LayoutSettings().GetSheetSize()); + if(layout->GetFocusedSheet()->GetLayout()->LayoutSettings().GetOrientation() == PageOrientation::Landscape) { size.transpose(); } diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index f8e40a416..741bfd5f2 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -40,7 +40,6 @@ #include #include "vppiece.h" -#include "vppiecelist.h" #include "vplayout.h" #include "vpsheet.h" @@ -394,58 +393,44 @@ void VPGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - // TODO/FIXME context menu needs to be refactored - QMenu contextMenu; +// QMenu menu; - // move to piece list actions -- TODO : To be tested properly when we have several piece lists - QList pieceLists = QList(); - for(auto sheet : m_piece->GetPieceList()->GetLayout()->GetSheets()) - { - pieceLists.append(sheet->GetPieceList()); - } +// // move to piece list actions -- TODO : To be tested properly when we have several piece lists +// QList pieceLists = QList(); +// for(auto sheet : m_piece->GetPieceList()->GetLayout()->GetSheets()) +// { +// pieceLists.append(sheet->GetPieceList()); +// } - pieceLists.removeAll(m_piece->GetPieceList()); +// pieceLists.removeAll(m_piece->GetPieceList()); - if(pieceLists.count() > 0) - { - QMenu *moveMenu = contextMenu.addMenu(tr("Move to")); +// if(pieceLists.count() > 0) +// { +// QMenu *moveMenu = menu.addMenu(tr("Move to")); - // TODO order in alphabetical order +// // TODO order in alphabetical order - for (auto pieceList : pieceLists) - { - QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName()); - QVariant data = QVariant::fromValue(pieceList); - moveToPieceList->setData(data); +// for (auto pieceList : pieceLists) +// { +// QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName()); +// QVariant data = QVariant::fromValue(pieceList); +// moveToPieceList->setData(data); - connect(moveToPieceList, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); - } - } +// connect(moveToPieceList, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); +// } +// } - // remove from layout action - QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet")); - QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList()); - removeAction->setData(data); - connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); +// // remove from layout action +// QAction *removeAction = menu.addAction(tr("Remove from Sheet")); +// QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList()); +// removeAction->setData(data); +// connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); - contextMenu.exec(event->screenPos()); +// menu.exec(event->screenPos()); } -//--------------------------------------------------------------------------------------------------------------------- -void VPGraphicsPiece::on_ActionPieceMovedToPieceList() -{ - QAction *act = qobject_cast(sender()); - QVariant v = act->data(); - VPPieceList *pieceList = v.value(); - if(pieceList != nullptr) - { - pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList); - } -} - - //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::on_PieceSelectionChanged() { diff --git a/src/app/puzzle/vpgraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h index f7238a759..aa04c521d 100644 --- a/src/app/puzzle/vpgraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -84,13 +84,6 @@ protected: void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; -private slots: - /** - * @brief on_ActionPieceMovedToPieceList Slot called when the piece is moved via the - * context menu to anoter piece list - */ - void on_ActionPieceMovedToPieceList(); - private: Q_DISABLE_COPY(VPGraphicsPiece) VPPiece *m_piece; diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index 4734e7e47..1fc91e4e2 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -72,12 +72,12 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->drawRect(sheetRect); } - if(m_sheet->GetShowGrid()) + if(m_sheet->GetLayout()->LayoutSettings().GetShowGrid()) { pen.setColor(QColor(204,204,204)); painter->setPen(pen); - qreal colWidth = m_sheet->GetGridColWidth(); + qreal colWidth = m_sheet->GetLayout()->LayoutSettings().GetGridColWidth(); if(colWidth > 0) { qreal colX = colWidth; @@ -89,7 +89,7 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o } } - qreal rowHeight = m_sheet->GetGridRowHeight(); + qreal rowHeight = m_sheet->GetLayout()->LayoutSettings().GetGridRowHeight(); if(rowHeight > 0) { qreal rowY = rowHeight; @@ -110,8 +110,8 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o QRectF VPGraphicsSheet::GetSheetRect() const { QPoint topLeft = QPoint(0,0); - QSizeF size = m_sheet->GetSheetSize(); - if(m_sheet->GetOrientation() == PageOrientation::Landscape) + QSizeF size = m_sheet->GetLayout()->LayoutSettings().GetSheetSize(); + if(m_sheet->GetLayout()->LayoutSettings().GetOrientation() == PageOrientation::Landscape) { size.transpose(); } @@ -122,10 +122,10 @@ QRectF VPGraphicsSheet::GetSheetRect() const //--------------------------------------------------------------------------------------------------------------------- QRectF VPGraphicsSheet::GetMarginsRect() const { - QMarginsF margins = m_sheet->GetSheetMargins(); - QSizeF size = m_sheet->GetSheetSize(); + QMarginsF margins = m_sheet->GetLayout()->LayoutSettings().GetSheetMargins(); + QSizeF size = m_sheet->GetLayout()->LayoutSettings().GetSheetSize(); - if(m_sheet->GetOrientation() == PageOrientation::Landscape) + if(m_sheet->GetLayout()->LayoutSettings().GetOrientation() == PageOrientation::Landscape) { size.transpose(); } diff --git a/src/app/puzzle/vpgraphicstilegrid.cpp b/src/app/puzzle/vpgraphicstilegrid.cpp index 45e905bd9..22e4c167e 100644 --- a/src/app/puzzle/vpgraphicstilegrid.cpp +++ b/src/app/puzzle/vpgraphicstilegrid.cpp @@ -21,7 +21,7 @@ VPGraphicsTileGrid::~VPGraphicsTileGrid() //--------------------------------------------------------------------------------------------------------------------- QRectF VPGraphicsTileGrid::boundingRect() const { - if(m_layout->GetShowTiles()) + if(m_layout->LayoutSettings().GetShowTiles()) { return QRectF(0, 0, @@ -29,10 +29,8 @@ QRectF VPGraphicsTileGrid::boundingRect() const m_tileFactory->getRowNb()* m_tileFactory->getDrawingAreaHeight() ); } - else - { - return QRectF(0,0,0,0); - } + + return {}; } //--------------------------------------------------------------------------------------------------------------------- @@ -41,7 +39,7 @@ void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem Q_UNUSED(widget); Q_UNUSED(option); - if(m_layout->GetShowTiles()) + if(m_layout->LayoutSettings().GetShowTiles()) { QPen pen(QColor(255,0,0,127), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); pen.setCosmetic(true); diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index cf4dc79b0..e6add2fc3 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -25,8 +25,8 @@ ** along with Valentina. If not, see . ** *************************************************************************/ + #include "vplayout.h" -#include "vppiecelist.h" #include "vppiece.h" #include "vpsheet.h" @@ -36,329 +36,114 @@ Q_LOGGING_CATEGORY(pLayout, "p.layout") //--------------------------------------------------------------------------------------------------------------------- -VPLayout::VPLayout() : - m_unplacedPieceList(new VPPieceList(this)), - m_trashPieceList(new VPPieceList(this)) -{ - m_unplacedPieceList->SetName(tr("Unplaced pieces")); -} +VPLayout::VPLayout(QObject *parent) : + QObject(parent), + m_trashSheet(new VPSheet(this)) +{} //--------------------------------------------------------------------------------------------------------------------- VPLayout::~VPLayout() { - qDeleteAll(m_sheets); - delete m_unplacedPieceList; - delete m_trashPieceList; + qDeleteAll(m_pieces); } //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPLayout::GetUnplacedPieceList() +void VPLayout::AddPiece(VPPiece *piece) { - return m_unplacedPieceList; + if ((piece != nullptr) && not m_pieces.contains(piece)) + { + piece->SetLayout(this); + m_pieces.append(piece); + } } //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPLayout::GetTrashPieceList() +auto VPLayout::GetPieces() const -> QList { - return m_trashPieceList; + return m_pieces; } //--------------------------------------------------------------------------------------------------------------------- -VPSheet* VPLayout::AddSheet() +auto VPLayout::GetUnplacedPieces() const -> QList { - VPSheet *newSheet = new VPSheet(this); + return PiecesForSheet(nullptr); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayout::GetTrashedPieces() const -> QList +{ + return PiecesForSheet(m_trashSheet); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayout::AddSheet() -> VPSheet* +{ + auto *newSheet = new VPSheet(this); m_sheets.append(newSheet); return newSheet; } //--------------------------------------------------------------------------------------------------------------------- -VPSheet* VPLayout::AddSheet(VPSheet *sheet) +auto VPLayout::AddSheet(VPSheet *sheet) -> VPSheet* { - m_sheets.append(sheet); + if ((sheet != nullptr) && not m_sheets.contains(sheet)) + { + sheet->setParent(this); + m_sheets.append(sheet); + } return sheet; } //--------------------------------------------------------------------------------------------------------------------- -QList VPLayout::GetSheets() +auto VPLayout::GetSheets() -> QList { return m_sheets; } -//--------------------------------------------------------------------------------------------------------------------- -QList VPLayout::GetSelectedPieces() -{ - QList result = QList(); - - QList pieceLists = QList(); - pieceLists.append(m_unplacedPieceList); - for (auto *sheet : m_sheets) - { - pieceLists.append(sheet->GetPieceList()); - } - - for (auto *pieceList : pieceLists) - { - for (auto *piece : pieceList->GetPieces()) - { - if(piece->GetIsSelected()) - { - result.append(piece); - } - } - } - - return result; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetUnit(Unit unit) -{ - m_unit = unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -Unit VPLayout::GetUnit() const -{ - return m_unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetWarningSuperpositionOfPieces(bool state) -{ - m_warningSuperpositionOfPieces = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPLayout::GetWarningSuperpositionOfPieces() const -{ - return m_warningSuperpositionOfPieces; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetWarningPiecesOutOfBound(bool state) -{ - m_warningPiecesOutOfBound = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPLayout::GetWarningPiecesOutOfBound() const -{ - return m_warningPiecesOutOfBound; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTitle(const QString &title) -{ - m_title = title; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VPLayout::GetTitle() const -{ - return m_title; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetDescription(const QString &description) -{ - m_description = description; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VPLayout::GetDescription() const -{ - return m_description; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::ClearSelection() -{ - m_unplacedPieceList->ClearSelection(); - - for (auto *sheet : m_sheets) - { - sheet->ClearSelection(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList) -{ - if(m_unplacedPieceList != pieceList) - { - m_unplacedPieceList->ClearSelection(); - } - - for (auto *sheet : m_sheets) - { - if(sheet->GetPieceList() != pieceList) - { - sheet->ClearSelection(); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) -{ - VPPieceList* pieceListBefore = piece->GetPieceList(); - - if(pieceListBefore != nullptr) - { - piece->GetPieceList()->RemovePiece(piece); - } - pieceList->AddPiece(piece); - - // signal, that a piece was moved - emit PieceMovedToPieceList(piece, pieceListBefore, pieceList); -} - - //--------------------------------------------------------------------------------------------------------------------- void VPLayout::SetFocusedSheet(VPSheet *focusedSheet) { - if(focusedSheet == nullptr) + if (m_sheets.isEmpty()) { - m_focusedSheet = m_sheets.first(); + m_focusedSheet = nullptr; } else { - m_focusedSheet = focusedSheet; + m_focusedSheet = focusedSheet == nullptr ? m_sheets.first() : focusedSheet; } } //--------------------------------------------------------------------------------------------------------------------- -VPSheet* VPLayout::GetFocusedSheet() +auto VPLayout::GetFocusedSheet() -> VPSheet* { return m_focusedSheet; } - //--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesSize(qreal width, qreal height) +auto VPLayout::GetTrashSheet() -> VPSheet* { - m_tilesSize.setWidth(width); - m_tilesSize.setHeight(height); + return m_trashSheet; } //--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesSizeConverted(qreal width, qreal height) +auto VPLayout::LayoutSettings() -> VPLayoutSettings & { - m_tilesSize.setWidth(UnitConvertor(width, GetUnit(), Unit::Px)); - m_tilesSize.setHeight(UnitConvertor(height, GetUnit(), Unit::Px)); + return m_layoutSettings; } //--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesSize(const QSizeF &size) +auto VPLayout::PiecesForSheet(const VPSheet *sheet) const -> QList { - m_tilesSize = size; -} + QList list; + list.reserve(m_pieces.size()); -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesSizeConverted(const QSizeF &size) -{ - m_tilesSize = QSizeF( - UnitConvertor(size.width(), GetUnit(), Unit::Px), - UnitConvertor(size.height(), GetUnit(), Unit::Px) - ); -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayout::GetTilesSize() const -{ - return m_tilesSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayout::GetTilesSize(Unit unit) const -{ - QSizeF convertedSize = QSizeF( - UnitConvertor(m_tilesSize.width(), Unit::Px, unit), - UnitConvertor(m_tilesSize.height(), Unit::Px, unit) - ); - - return convertedSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayout::GetTilesSizeConverted() const -{ - return GetTilesSize(GetUnit()); -} - -//--------------------------------------------------------------------------------------------------------------------- -PageOrientation VPLayout::GetTilesOrientation() -{ - return m_tilesOrientation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesOrientation(PageOrientation orientation) -{ - if(orientation != m_tilesOrientation) + for (auto *piece : m_pieces) { - m_tilesOrientation = orientation; + if ((piece != nullptr) && piece->Sheet() == sheet) + { + list.append(piece); + } } -} -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom) -{ - m_tilesMargins.setLeft(left); - m_tilesMargins.setTop(top); - m_tilesMargins.setRight(right); - m_tilesMargins.setBottom(bottom); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) -{ - m_tilesMargins.setLeft(UnitConvertor(left, GetUnit(), Unit::Px)); - m_tilesMargins.setTop(UnitConvertor(top, GetUnit(), Unit::Px)); - m_tilesMargins.setRight(UnitConvertor(right, GetUnit(), Unit::Px)); - m_tilesMargins.setBottom(UnitConvertor(bottom, GetUnit(), Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesMargins(const QMarginsF &margins) -{ - m_tilesMargins = margins; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTilesMarginsConverted(const QMarginsF &margins) -{ - m_tilesMargins = UnitConvertor(margins, GetUnit(), Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayout::GetTilesMargins() const -{ - return m_tilesMargins; -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayout::GetTilesMargins(Unit unit) const -{ - return UnitConvertor(m_tilesMargins, Unit::Px, unit); -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayout::GetTilesMarginsConverted() const -{ - return UnitConvertor(m_tilesMargins, Unit::Px, GetUnit()); -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPLayout::GetShowTiles() -{ - return m_showTiles; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetShowTiles(bool value) -{ - m_showTiles = value; + return list; } diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index bbf875af9..c45b8e7c3 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -28,12 +28,11 @@ #ifndef VPLAYOUT_H #define VPLAYOUT_H - #include #include "def.h" +#include "vplayoutsettings.h" -class VPPieceList; class VPPiece; class VPSheet; @@ -41,93 +40,17 @@ class VPLayout : public QObject { Q_OBJECT public: - VPLayout(); + explicit VPLayout(QObject *parent=nullptr); virtual ~VPLayout(); - /** - * @brief GetUnplacedPieceList Returns the piece list of unplaced pieces - * @return the unplaced pieces list - */ - VPPieceList* GetUnplacedPieceList(); + void AddPiece(VPPiece *piece); + auto GetPieces() const -> QList; + auto GetUnplacedPieces() const -> QList; + auto GetTrashedPieces() const -> QList; - /** - * @brief GetTrashPieceList Returns the piece list of the trash - * @return the pieces list of trashed pieces. - */ - VPPieceList* GetTrashPieceList(); - - VPSheet* AddSheet(); - VPSheet* AddSheet(VPSheet *sheet); - QList GetSheets(); - - /** - * @brief GetSelectedPieces Returns the list of the selected pieces - * @return the selected pieces - */ - QList GetSelectedPieces(); - - /** - * @brief SetUnit Sets the unit of the layout to the given unit - * @param unit the new unit - */ - void SetUnit(Unit unit); - - /** - * @brief GetUnit Returns the current unit of the layout - * @return the unit - */ - Unit GetUnit() const; - - void SetWarningSuperpositionOfPieces(bool state); - bool GetWarningSuperpositionOfPieces() const; - - void SetWarningPiecesOutOfBound(bool state); - bool GetWarningPiecesOutOfBound() const; - - /** - * @brief SetTitle Sets the title of the layout to the given value - * @param title the title of the layout - */ - void SetTitle(const QString &title); - - /** - * @brief GetTitle Returns the title of the layout - * @return title of the layout - */ - QString GetTitle() const; - - /** - * @brief SetDescription Sets the description of the layout to the given value - * @param description the description of the layout - */ - void SetDescription(const QString &description); - - /** - * @brief GetDescription Returns the description of the layout. - * @return description of the layout - */ - QString GetDescription() const; - - /** - * @brief ClearSelection goes through the unplaced pieces and through the sheets and calls - * SetIsSelected(false) for the pieces that were selected. - */ - void ClearSelection(); - - /** - * @brief ClearSelectionExceptForPieceList same as clearSelection but it leaves the selection - * for the given piece list like it ist. - * - * @param pieceList the piece list to let be the way it is. - */ - void ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList); - - /** - * @brief MovePieceToPieceList Moves the given piece to the given piece list - * @param piece the piece to move - * @param pieceList the piece list to move the piece to - */ - void MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList); + auto AddSheet() -> VPSheet*; + auto AddSheet(VPSheet *sheet) -> VPSheet*; + auto GetSheets() -> QList; /** * @brief SetFocusedSheet Sets the focused sheet, to which pieces are added from the carrousel via drag @@ -141,171 +64,25 @@ public: * and drop * @return the focused sheet */ - VPSheet* GetFocusedSheet(); + auto GetFocusedSheet() -> VPSheet*; + auto GetTrashSheet() -> VPSheet*; - /** - * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px - * @param width tiles width - * @param height tiles height - */ - void SetTilesSize(qreal width, qreal height); + auto LayoutSettings() -> VPLayoutSettings &; - /** - * @brief SetTilesSizeConverted sets the size of the sheet, the values have to be in the layout's unit - * @param width tiles width - * @param height tiles height - */ - void SetTilesSizeConverted(qreal width, qreal height); - - /** - * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px - * @param size tiles size - */ - void SetTilesSize(const QSizeF &size); - /** - * @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit - * @param size tiles size - */ - void SetTilesSizeConverted(const QSizeF &size); - - /** - * @brief GetTilesSize Returns the size of the tiles in Unit::Px - * @return tiles size in Unit::Px - */ - QSizeF GetTilesSize() const; - - /** - * @brief GetTilesSize Returns the size of the tiles in given Unit - * @return tiles size - */ - QSizeF GetTilesSize(Unit unit) const; - - /** - * @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit - * @return the size in the layout's unit - */ - QSizeF GetTilesSizeConverted() const; - - /** - * @brief GetOrientation Returns the orientation of the tiles - * @return orientation of the tiles - */ - PageOrientation GetTilesOrientation(); - - /** - * @brief SetOrientation Sets the orientation of the tiles to the given value - * @param orientation the new tiles orientation - */ - void SetTilesOrientation(PageOrientation orientation); - - /** - * @brief SetTilesMargins, set the margins of the tiles, 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 SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetSheetMargins, set the margins of the tiles, 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 SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetTilesMargins set the margins of the tiles, the values have to be in Unit::Px - * @param margins tiles margins - */ - void SetTilesMargins(const QMarginsF &margins); - - /** - * @brief SetTilesMarginsConverted set the margins of the tiles, the values have to be in the unit of the layout - * @param margins tiles margins - */ - void SetTilesMarginsConverted(const QMarginsF &margins); - - /** - * @brief GetTilesMargins Returns margins of the tiles in Unit::Px - * @return the margins in Unit::Px - */ - QMarginsF GetTilesMargins() const; - - /** - * @brief GetTilesMargins Returns margins of the tiles in the given unit - * @param unit the unit in which we want the margins - * @return the margins in the given unit - */ - QMarginsF GetTilesMargins(Unit unit) const; - - /** - * @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit - * @return the margins in the tiles's unit - */ - QMarginsF GetTilesMarginsConverted() const; - - /** - * @brief GetShowTiles Returns true if the tiles has to be shown on the current sheet - * @return true if the tiles has to be shown on the current sheet - */ - bool GetShowTiles(); - - /** - * @brief SetShowTiles Sets wether to show the tiles on the current sheet or not - * @param value true to show the tiles - */ - void SetShowTiles(bool value); - - - -signals: - - void PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); + auto PiecesForSheet(const VPSheet* sheet) const -> QList; private: Q_DISABLE_COPY(VPLayout) - VPPieceList *m_unplacedPieceList; + QList m_pieces{}; - /** - * @brief m_trashPieceList Holds the pieces that were deleted - */ - VPPieceList *m_trashPieceList; + VPSheet* m_trashSheet; QList m_sheets{}; VPSheet *m_focusedSheet{nullptr}; - // format - Unit m_unit{Unit::Cm}; - - bool m_warningSuperpositionOfPieces{false}; - bool m_warningPiecesOutOfBound{false}; - - QString m_title{}; - QString m_description{}; - - - /** - * @brief m_size the Size of the tiles in Unit::Px - */ - QSizeF m_tilesSize{}; - - /** - * @brief holds the orientation of the tiles - */ - PageOrientation m_tilesOrientation {PageOrientation::Portrait}; - - // margins - /** - * @brief m_margins the margins of the tiles in Unit::Px - */ - QMarginsF m_tilesMargins{}; - - bool m_showTiles{false}; + VPLayoutSettings m_layoutSettings{}; }; #endif // VPLAYOUT_H diff --git a/src/app/puzzle/vplayoutsettings.cpp b/src/app/puzzle/vplayoutsettings.cpp new file mode 100644 index 000000000..16b891ddb --- /dev/null +++ b/src/app/puzzle/vplayoutsettings.cpp @@ -0,0 +1,672 @@ +/************************************************************************ + ** + ** @file vplayoutsettings.cpp + ** @author Roman Telezhynskyi + ** @date 29 7, 2021 + ** + ** @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) 2021 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 "vplayoutsettings.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetUnit(Unit unit) +{ + m_unit = unit; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetUnit() const -> Unit +{ + return m_unit; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetWarningSuperpositionOfPieces(bool state) +{ + m_warningSuperpositionOfPieces = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetWarningSuperpositionOfPieces() const -> bool +{ + return m_warningSuperpositionOfPieces; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetWarningPiecesOutOfBound(bool state) +{ + m_warningPiecesOutOfBound = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetWarningPiecesOutOfBound() const -> bool +{ + return m_warningPiecesOutOfBound; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTitle(const QString &title) +{ + m_title = title; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTitle() const -> QString +{ + return m_title; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetDescription(const QString &description) +{ + m_description = description; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetDescription() const -> QString +{ + return m_description; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesSize(qreal width, qreal height) +{ + m_tilesSize.setWidth(width); + m_tilesSize.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesSizeConverted(qreal width, qreal height) +{ + m_tilesSize.setWidth(UnitConvertor(width, GetUnit(), Unit::Px)); + m_tilesSize.setHeight(UnitConvertor(height, GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesSize(const QSizeF &size) +{ + m_tilesSize = size; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesSizeConverted(const QSizeF &size) +{ + m_tilesSize = QSizeF( + UnitConvertor(size.width(), GetUnit(), Unit::Px), + UnitConvertor(size.height(), GetUnit(), Unit::Px) + ); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesSize() const -> QSizeF +{ + return m_tilesSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesSize(Unit unit) const -> QSizeF +{ + QSizeF convertedSize = QSizeF( + UnitConvertor(m_tilesSize.width(), Unit::Px, unit), + UnitConvertor(m_tilesSize.height(), Unit::Px, unit) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesSizeConverted() const -> QSizeF +{ + return GetTilesSize(GetUnit()); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesOrientation() -> PageOrientation +{ + return m_tilesOrientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesOrientation(PageOrientation orientation) +{ + if(orientation != m_tilesOrientation) + { + m_tilesOrientation = orientation; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom) +{ + m_tilesMargins.setLeft(left); + m_tilesMargins.setTop(top); + m_tilesMargins.setRight(right); + m_tilesMargins.setBottom(bottom); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) +{ + m_tilesMargins.setLeft(UnitConvertor(left, GetUnit(), Unit::Px)); + m_tilesMargins.setTop(UnitConvertor(top, GetUnit(), Unit::Px)); + m_tilesMargins.setRight(UnitConvertor(right, GetUnit(), Unit::Px)); + m_tilesMargins.setBottom(UnitConvertor(bottom, GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesMargins(const QMarginsF &margins) +{ + m_tilesMargins = margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetTilesMarginsConverted(const QMarginsF &margins) +{ + m_tilesMargins = UnitConvertor(margins, GetUnit(), Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesMargins() const -> QMarginsF +{ + return m_tilesMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesMargins(Unit unit) const -> QMarginsF +{ + return UnitConvertor(m_tilesMargins, Unit::Px, unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTilesMarginsConverted() const -> QMarginsF +{ + return UnitConvertor(m_tilesMargins, Unit::Px, GetUnit()); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetShowTiles() const -> bool +{ + return m_showTiles; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetShowTiles(bool value) +{ + m_showTiles = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTemplateSize(PaperSizeTemplate tmpl) -> QSizeF +{ + qreal height = 0; + qreal width = 0; + + switch (tmpl) + { + case PaperSizeTemplate::A0: + width = UnitConvertor(841, Unit::Mm, Unit::Px); + height = UnitConvertor(1189, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A1: + width = UnitConvertor(594, Unit::Mm, Unit::Px); + height = UnitConvertor(841, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A2: + width = UnitConvertor(420, Unit::Mm, Unit::Px); + height = UnitConvertor(594, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A3: + width = UnitConvertor(297, Unit::Mm, Unit::Px); + height = UnitConvertor(420, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A4: + width = UnitConvertor(210, Unit::Mm, Unit::Px); + height = UnitConvertor(297, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::Letter: + width = UnitConvertor(8.5, Unit::Inch, Unit::Px); + height = UnitConvertor(11, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Legal: + width = UnitConvertor(8.5, Unit::Inch, Unit::Px); + height = UnitConvertor(14, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Tabloid: + width = UnitConvertor(11, Unit::Inch, Unit::Px); + height = UnitConvertor(17, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll24in: + width = UnitConvertor(24, Unit::Inch, Unit::Px); + height = UnitConvertor(48, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll30in: + width = UnitConvertor(30, Unit::Inch, Unit::Px); + height = UnitConvertor(60, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll36in: + width = UnitConvertor(36, Unit::Inch, Unit::Px); + height = UnitConvertor(72, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll42in: + width = UnitConvertor(42, Unit::Inch, Unit::Px); + height = UnitConvertor(84, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll44in: + width = UnitConvertor(44, Unit::Inch, Unit::Px); + height = UnitConvertor(88, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll48in: + width = UnitConvertor(48, Unit::Inch, Unit::Px); + height = UnitConvertor(96, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll62in: + width = UnitConvertor(62, Unit::Inch, Unit::Px); + height = UnitConvertor(124, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll72in: + width = UnitConvertor(72, Unit::Inch, Unit::Px); + height = UnitConvertor(144, Unit::Inch, Unit::Px); + break; + + default: + break; + } + + return QSizeF(width, height); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTemplateName(PaperSizeTemplate tmpl) -> QString +{ + QString tmplName; + switch (tmpl) + { + case PaperSizeTemplate::A0: + tmplName = QString("A0"); + break; + + case PaperSizeTemplate::A1: + tmplName = QString("A1"); + break; + + case PaperSizeTemplate::A2: + tmplName = QString("A2"); + break; + + case PaperSizeTemplate::A3: + tmplName = QString("A3"); + break; + + case PaperSizeTemplate::A4: + tmplName = QString("A4"); + break; + + case PaperSizeTemplate::Letter: + tmplName = tr("Letter"); + break; + + case PaperSizeTemplate::Legal: + tmplName = tr("Legal"); + break; + + case PaperSizeTemplate::Tabloid: + tmplName = tr("Tabloid"); + break; + + case PaperSizeTemplate::Roll24in: + tmplName = tr("Roll 24in"); + break; + + case PaperSizeTemplate::Roll30in: + tmplName = tr("Roll 30in"); + break; + + case PaperSizeTemplate::Roll36in: + tmplName = tr("Roll 36in"); + break; + + case PaperSizeTemplate::Roll42in: + tmplName = tr("Roll 42in"); + break; + + case PaperSizeTemplate::Roll44in: + tmplName = tr("Roll 44in"); + break; + + case PaperSizeTemplate::Roll48in: + tmplName = tr("Roll 48in"); + break; + + case PaperSizeTemplate::Roll62in: + tmplName = tr("Roll 62in"); + break; + + case PaperSizeTemplate::Roll72in: + tmplName = tr("Roll 72in"); + break; + + case PaperSizeTemplate::Custom: + tmplName = tr("Custom"); + break; + + default: + break; + } + + if(not tmplName.isEmpty()) + { + tmplName += " " + QStringLiteral("(%1ppi)").arg(PrintDPI); + } + + return tmplName; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetTemplate(QSizeF size) -> PaperSizeTemplate +{ + Q_UNUSED(size); + // TODO, float comparision not safe and problems with + // inch / cm + +// const int max = static_cast(PaperSizeTemplate::Custom); + +// for (int i=0; i < max; i++) +// { +// PaperSizeTemplate tmpl = static_cast(i); +// const QSizeF tmplSize = GetTemplateSize(tmpl); + +// if(size.width() == tmplSize.width()) +// { +// if(isRollTemplate(tmpl)) +// { +// return tmpl; +// } +// else if(size.height() == tmplSize.height()) +// { +// return tmpl; +// } +// } +// } + + return PaperSizeTemplate::Custom; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::isRollTemplate(PaperSizeTemplate tmpl) -> bool +{ + switch (tmpl) { + case PaperSizeTemplate::Roll24in: + case PaperSizeTemplate::Roll30in: + case PaperSizeTemplate::Roll36in: + case PaperSizeTemplate::Roll42in: + case PaperSizeTemplate::Roll44in: + case PaperSizeTemplate::Roll48in: + case PaperSizeTemplate::Roll62in: + case PaperSizeTemplate::Roll72in: + return true; + default: + return false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::PopulateComboBox(QVector *tmpls, QComboBox* comboBox) +{ + const QIcon icoPaper("://puzzleicon/16x16/template.png"); + const QIcon icoRoll("://puzzleicon/16x16/roll.png"); + + QIcon icon; + for (auto tmpl : *tmpls) + { + icon = (isRollTemplate(tmpl))? icoRoll : icoPaper; + comboBox->addItem(icon, GetTemplateName(tmpl), QVariant(static_cast(tmpl))); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetSheetSize(qreal width, qreal height) +{ + m_size.setWidth(width); + m_size.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetSheetSizeConverted(qreal width, qreal height) +{ + m_size.setWidth(UnitConvertor(width, m_unit, Unit::Px)); + m_size.setHeight(UnitConvertor(height, m_unit, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetSheetSize(const QSizeF &size) +{ + m_size = size; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetSheetSizeConverted(const QSizeF &size) +{ + m_size = QSizeF( + UnitConvertor(size.width(), m_unit, Unit::Px), + UnitConvertor(size.height(), m_unit, Unit::Px) + ); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetSheetSize() const -> QSizeF +{ + return m_size; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetSheetSizeConverted() const -> QSizeF +{ + QSizeF convertedSize = QSizeF( + UnitConvertor(m_size.width(), Unit::Px, m_unit), + UnitConvertor(m_size.height(), Unit::Px, m_unit) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetOrientation() -> PageOrientation +{ + return m_orientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetOrientation(PageOrientation orientation) +{ + if(orientation != m_orientation) + { + m_orientation = orientation; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::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 VPLayoutSettings::SetSheetMarginsConverted(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 VPLayoutSettings::SetSheetMargins(const QMarginsF &margins) +{ + m_margins = margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetSheetMarginsConverted(const QMarginsF &margins) +{ + m_margins = UnitConvertor(margins, m_unit, Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetSheetMargins() const -> QMarginsF +{ + return m_margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetSheetMarginsConverted() const -> QMarginsF +{ + return UnitConvertor(m_margins, Unit::Px, m_unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetFollowGrainline(FollowGrainline state) +{ + m_followGrainLine = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetFollowGrainline() const -> FollowGrainline +{ + return m_followGrainLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetPiecesGap(qreal value) +{ + m_piecesGap = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetPiecesGapConverted(qreal value) +{ + m_piecesGap = UnitConvertor(value, m_unit, Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetPiecesGap() const -> qreal +{ + return m_piecesGap; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetPiecesGapConverted() const -> qreal +{ + return UnitConvertor(m_piecesGap, Unit::Px, m_unit); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetStickyEdges(bool state) +{ + m_stickyEdges = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetStickyEdges() const -> bool +{ + return m_stickyEdges; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetShowGrid() const -> bool +{ + return m_showGrid; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetShowGrid(bool value) +{ + m_showGrid = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetGridColWidth() const -> qreal +{ + return m_gridColWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetGridColWidthConverted() const -> qreal +{ + return UnitConvertor(m_gridColWidth, Unit::Px, m_unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetGridColWidth(qreal value) +{ + m_gridColWidth = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetGridColWidthConverted(qreal value) +{ + m_gridColWidth = UnitConvertor(value, m_unit, Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetGridRowHeight() const -> qreal +{ + return m_gridRowHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::GetGridRowHeightConverted() const -> qreal +{ + return UnitConvertor(m_gridRowHeight, Unit::Px, m_unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetGridRowHeight(qreal value) +{ + m_gridRowHeight = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetGridRowHeightConverted(qreal value) +{ + m_gridRowHeight = UnitConvertor(value, m_unit, Unit::Px); +} diff --git a/src/app/puzzle/vplayoutsettings.h b/src/app/puzzle/vplayoutsettings.h new file mode 100644 index 000000000..bfe0c6f84 --- /dev/null +++ b/src/app/puzzle/vplayoutsettings.h @@ -0,0 +1,524 @@ +/************************************************************************ + ** + ** @file vplayoutsettings.h + ** @author Roman Telezhynskyi + ** @date 29 7, 2021 + ** + ** @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) 2021 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 VPLAYOUTSETTINGS_H +#define VPLAYOUTSETTINGS_H + +#include +#include +#include +#include + +#include "def.h" + +enum class FollowGrainline : qint8 { + No = 0, + Follow90 = 1, + Follow180 = 2 +}; + +enum class PaperSizeTemplate : qint8 { + A0 = 0, + A1, + A2, + A3, + A4, + Letter, + Legal, + Tabloid, + Roll24in, + Roll30in, + Roll36in, + Roll42in, + Roll44in, + Roll48in, + Roll62in, + Roll72in, + Custom +}; + +class VPLayoutSettings +{ + Q_DECLARE_TR_FUNCTIONS(VPLayoutSettings) +public: + VPLayoutSettings() = default; + + /** + * @brief SetUnit Sets the unit of the layout to the given unit + * @param unit the new unit + */ + void SetUnit(Unit unit); + + /** + * @brief GetUnit Returns the current unit of the layout + * @return the unit + */ + auto GetUnit() const -> Unit; + + void SetWarningSuperpositionOfPieces(bool state); + auto GetWarningSuperpositionOfPieces() const -> bool; + + void SetWarningPiecesOutOfBound(bool state); + auto GetWarningPiecesOutOfBound() const -> bool; + + /** + * @brief SetTitle Sets the title of the layout to the given value + * @param title the title of the layout + */ + void SetTitle(const QString &title); + + /** + * @brief GetTitle Returns the title of the layout + * @return title of the layout + */ + auto GetTitle() const -> QString; + + /** + * @brief SetDescription Sets the description of the layout to the given value + * @param description the description of the layout + */ + void SetDescription(const QString &description); + + /** + * @brief GetDescription Returns the description of the layout. + * @return description of the layout + */ + auto GetDescription() const -> QString; + + /** + * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px + * @param width tiles width + * @param height tiles height + */ + void SetTilesSize(qreal width, qreal height); + + /** + * @brief SetTilesSizeConverted sets the size of the sheet, the values have to be in the layout's unit + * @param width tiles width + * @param height tiles height + */ + void SetTilesSizeConverted(qreal width, qreal height); + + /** + * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px + * @param size tiles size + */ + void SetTilesSize(const QSizeF &size); + /** + * @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit + * @param size tiles size + */ + void SetTilesSizeConverted(const QSizeF &size); + + /** + * @brief GetTilesSize Returns the size of the tiles in Unit::Px + * @return tiles size in Unit::Px + */ + auto GetTilesSize() const -> QSizeF; + + /** + * @brief GetTilesSize Returns the size of the tiles in given Unit + * @return tiles size + */ + auto GetTilesSize(Unit unit) const -> QSizeF; + + /** + * @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit + * @return the size in the layout's unit + */ + auto GetTilesSizeConverted() const -> QSizeF; + + /** + * @brief GetOrientation Returns the orientation of the tiles + * @return orientation of the tiles + */ + auto GetTilesOrientation() -> PageOrientation; + + /** + * @brief SetOrientation Sets the orientation of the tiles to the given value + * @param orientation the new tiles orientation + */ + void SetTilesOrientation(PageOrientation orientation); + + /** + * @brief SetTilesMargins, set the margins of the tiles, 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 SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins, set the margins of the tiles, 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 SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetTilesMargins set the margins of the tiles, the values have to be in Unit::Px + * @param margins tiles margins + */ + void SetTilesMargins(const QMarginsF &margins); + + /** + * @brief SetTilesMarginsConverted set the margins of the tiles, the values have to be in the unit of the layout + * @param margins tiles margins + */ + void SetTilesMarginsConverted(const QMarginsF &margins); + + /** + * @brief GetTilesMargins Returns margins of the tiles in Unit::Px + * @return the margins in Unit::Px + */ + auto GetTilesMargins() const -> QMarginsF; + + /** + * @brief GetTilesMargins Returns margins of the tiles in the given unit + * @param unit the unit in which we want the margins + * @return the margins in the given unit + */ + auto GetTilesMargins(Unit unit) const -> QMarginsF; + + /** + * @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit + * @return the margins in the tiles's unit + */ + auto GetTilesMarginsConverted() const -> QMarginsF; + + /** + * @brief GetShowTiles Returns true if the tiles has to be shown on the current sheet + * @return true if the tiles has to be shown on the current sheet + */ + auto GetShowTiles() const -> bool; + + /** + * @brief SetShowTiles Sets wether to show the tiles on the current sheet or not + * @param value true to show the tiles + */ + void SetShowTiles(bool value); + + /** + * @brief GetTemplateSize Returns the size in Px of the given template + * @param tmpl paper size template + * @return the size in Px + */ + static auto GetTemplateSize(PaperSizeTemplate tmpl) -> QSizeF; + + /** + * @brief GetTemplateName Returns the name of the given template + * @param tmpl paper size template + * @return name of the given template + */ + static auto GetTemplateName(PaperSizeTemplate tmpl) -> QString; + + /** + * @brief GetTemplate GetTemplate Returns the template that corresponds to the given size + * @param size the Size in Px + * @return template that corresponds to the given size + */ + static auto GetTemplate(QSizeF size) -> PaperSizeTemplate; + + /** + * @brief PopulateComboBox Populates the given combo with the given templates + * @param tmpls list of paper size templates + * @param comboBox pointer to the combobox + */ + static void PopulateComboBox(QVector *tmpls, QComboBox* comboBox); + + /** + * @brief isRollTemplate Returns wether the given template is a roll or not. + * @param tmpl paper size template + * @return true if the given template is a roll + */ + static auto isRollTemplate(PaperSizeTemplate tmpl) -> bool; + + /** + * @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 + */ + auto GetSheetSize() const -> QSizeF; + + /** + * @brief GetSheetSizeConverted Returns the size in the layout's unit + * @return the size in the layout's unit + */ + auto GetSheetSizeConverted() const -> QSizeF; + + /** + * @brief GetOrientation Returns the orientation of the sheet + * @return orientation of the sheet + */ + auto GetOrientation() -> PageOrientation; + + /** + * @brief SetOrientation Sets the orientation of the sheet to the given value + * @param orientation the new page orientation + */ + void SetOrientation(PageOrientation orientation); + + /** + * @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 + */ + auto GetSheetMargins() const -> QMarginsF; + + /** + * @brief GetSheetMarginsConverted Returns the margins in the layout's unit + * @return the margins in the sheet's unit + */ + auto GetSheetMarginsConverted() const -> QMarginsF; + + /** + * @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 + */ + auto GetFollowGrainline() const -> FollowGrainline; + + /** + * @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 + */ + auto GetPiecesGap() const -> qreal; + + /** + * @brief GetPiecesGapConverted returns the pieces gap in the layout's unit + * @return the pieces gap in the layout's unit + */ + auto GetPiecesGapConverted() const -> qreal; + + /** + * @brief GetShowGrid Returns true if the placement grid has to be shown on the current sheet + * @return true if the placement grid has to be shown on the current sheet + */ + auto GetShowGrid() const -> bool; + + /** + * @brief SetShowGrid Returns true if the placement grid has to be shown on the current sheet + * @param value whether to show the grid or not + */ + void SetShowGrid(bool value); + + /** + * @brief GetGridColWidth returns the placement grid column width in Unit::Px + * @return the placement grid column width in Unit::Px + */ + auto GetGridColWidth() const -> qreal; + + /** + * @brief GetGridColWidth returns the placement grid column width in the layout's unit + * @return the placement grid column width in the layout's unit + */ + auto GetGridColWidthConverted() const -> qreal; + + /** + * @brief SetGridColWidth sets the placement grid column width to the given value, the unit has to be Unit::Px + * @param value the placement grid column width in Unit::Px + */ + void SetGridColWidth(qreal value); + + /** + * @brief SetGridColWidthConverted sets the placement grid column width to the given value, the unit has to be in + * the layout's unit + * @param value the placement grid column width in the layout's unit + */ + void SetGridColWidthConverted(qreal value); + + /** + * @brief GetGridRowHeight returns the placement grid row height in Unit::Px + * @return the placement grid row height in Unit::Px + */ + auto GetGridRowHeight() const -> qreal; + + /** + * @brief GetGridRowHeightConverted returns the placement grid row height in the layout's unit + * @return the placement grid row height in the layout's unit + */ + auto GetGridRowHeightConverted() const -> qreal; + + /** + * @brief SetGridRowHeight sets the placement grid row height to the given value, the unit has to be Unit::Px + * @param value the placement grid row height in Unit::Px + */ + void SetGridRowHeight(qreal value); + + /** + * @brief SetGridRowHeightConverted sets the placement grid row height to the given value, the unit has to be in + * the layout's unit + * @param value the placement grid row height in the layout's unit + */ + void SetGridRowHeightConverted(qreal value); + + void SetStickyEdges(bool state); + auto GetStickyEdges() const -> bool; + +private: + Unit m_unit{Unit::Cm}; + + bool m_warningSuperpositionOfPieces{false}; + bool m_warningPiecesOutOfBound{false}; + + QString m_title{}; + QString m_description{}; + + /** + * @brief m_size the Size of the tiles in Unit::Px + */ + QSizeF m_tilesSize{}; + + /** + * @brief holds the orientation of the tiles + */ + PageOrientation m_tilesOrientation {PageOrientation::Portrait}; + + // margins + /** + * @brief m_margins the margins of the tiles in Unit::Px + */ + QMarginsF m_tilesMargins{}; + + bool m_showTiles{false}; + + /** + * @brief m_size the Size in Unit::Px + */ + QSizeF m_size{}; + + /** + * @brief holds the orientation of the sheet + */ + PageOrientation m_orientation {PageOrientation::Portrait}; + + // 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}; + + // placement grid + /** + * @brief GetShowGrid Returns true if the placement grid has to be shown on the current sheet + */ + bool m_showGrid{false}; + /** + * @brief m_gridColWidth the column width of the placement grid in Unit::Px + */ + qreal m_gridColWidth{0}; + + /** + * @brief m_gridRowHeight the row height of the placement grid in Unit::Px + */ + qreal m_gridRowHeight{0}; + + bool m_stickyEdges{false}; +}; + +#endif // VPLAYOUTSETTINGS_H diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 76d1dfa68..dd56f6d0d 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -33,7 +33,6 @@ #include #include "vpmimedatapiece.h" -#include "vppiecelist.h" #include "vplayout.h" #include "vpsheet.h" #include "../vwidgets/vmaingraphicsscene.h" @@ -61,11 +60,6 @@ VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, VPTileFactory *tileFact m_graphicsTileGrid = new VPGraphicsTileGrid(layout, tileFactory); m_scene->addItem(m_graphicsTileGrid); - - // add the connections - connect(m_layout, &VPLayout::PieceMovedToPieceList, this, &VPMainGraphicsView::on_PieceMovedToPieceList); - connect(m_scene, &VMainGraphicsScene::selectionChanged, this, - &VPMainGraphicsView::on_SceneSelectionChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -90,16 +84,14 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene() //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::PrepareForExport() { - m_layout->ClearSelection(); - m_graphicsSheet->SetShowBorder(false); m_graphicsSheet->SetShowMargin(false); - m_showGridTmp = m_layout->GetFocusedSheet()->GetShowGrid(); - m_layout->GetFocusedSheet()->SetShowGrid(false); + m_showGridTmp = m_layout->GetFocusedSheet()->GetLayout()->LayoutSettings().GetShowGrid(); + m_layout->GetFocusedSheet()->GetLayout()->LayoutSettings().SetShowGrid(false); - m_showTilesTmp = m_layout->GetShowTiles(); - m_layout->SetShowTiles(false); + m_showTilesTmp = m_layout->LayoutSettings().GetShowTiles(); + m_layout->LayoutSettings().SetShowTiles(false); RefreshLayout(); } @@ -110,14 +102,13 @@ void VPMainGraphicsView::CleanAfterExport() m_graphicsSheet->SetShowBorder(true); m_graphicsSheet->SetShowMargin(true); - m_layout->GetFocusedSheet()->SetShowGrid(m_showGridTmp); + m_layout->GetFocusedSheet()->GetLayout()->LayoutSettings().SetShowGrid(m_showGridTmp); - m_layout->SetShowTiles(m_showTilesTmp); + m_layout->LayoutSettings().SetShowTiles(m_showTilesTmp); RefreshLayout(); } - //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) { @@ -147,8 +138,6 @@ void VPMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) event->accept(); } - - //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::dropEvent(QDropEvent *event) { @@ -170,11 +159,7 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event) piece->SetPosition(mapToScene(point)); // change the piecelist of the piece - VPPieceList *focusedPieceList = m_layout->GetFocusedSheet()->GetPieceList(); - if(focusedPieceList != nullptr) - { - m_layout->MovePieceToPieceList(piece, focusedPieceList); - } + piece->SetSheet(m_layout->GetFocusedSheet()); } } } @@ -193,65 +178,7 @@ void VPMainGraphicsView::keyPressEvent(QKeyEvent *event) if(piece->GetIsSelected()) { piece->SetIsSelected(false); - m_layout->MovePieceToPieceList(piece, m_layout->GetUnplacedPieceList()); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter) -{ - Q_UNUSED(pieceListBefore) - - VPGraphicsPiece *_graphicsPiece = nullptr; - for(auto *graphicPiece : m_graphicsPieces) - { - if(graphicPiece->GetPiece() == piece) - { - _graphicsPiece = graphicPiece; - } - } - - if(pieceListAfter == m_layout->GetUnplacedPieceList() && _graphicsPiece != nullptr) - { - scene()->removeItem(_graphicsPiece); - m_graphicsPieces.removeAll(_graphicsPiece); - } - else if(pieceListAfter != m_layout->GetUnplacedPieceList() && pieceListAfter != m_layout->GetTrashPieceList()) - { - if(_graphicsPiece == nullptr) - { - _graphicsPiece = new VPGraphicsPiece(piece); - m_graphicsPieces.append(_graphicsPiece); - } - - scene()->addItem(_graphicsPiece); - // not very clean to directly call slots - _graphicsPiece->on_PieceSelectionChanged(); - _graphicsPiece->on_PiecePositionChanged(); - _graphicsPiece->on_PieceRotationChanged(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPMainGraphicsView::on_SceneSelectionChanged() -{ - // most of the selection behaviour takes place automatically - // but we need to make sure that the unplaced pieces are unselected when the scene selection has changed - // because as they are not part of the scene, they are not updated - m_layout->GetUnplacedPieceList()->ClearSelection(); - - - // make sure, that the selected items are on top - // FIXME: maybe there is a more proper way to do it - for(auto *graphicPiece : m_graphicsPieces) - { - if((graphicPiece != nullptr) && not graphicPiece->GetPiece()->GetIsSelected()) - { - if(!m_scene->selectedItems().isEmpty()) - { - graphicPiece->stackBefore(m_scene->selectedItems().first()); + piece->SetSheet(nullptr); } } } diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index 42e774df4..13196c932 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -68,7 +68,6 @@ public: */ void CleanAfterExport(); - protected: void dragEnterEvent(QDragEnterEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; @@ -79,21 +78,6 @@ protected: void drawTilesLine(); -private slots: - /** - * @brief on_PieceMovedToPieceList The slot is called when the given piece was moved from the given piece list to the other - * given piece list - * @param piece the piece that was moved - * @param pieceListBefore the piece list before the move - * @param pieceListAfter the piece list after the move - */ - void on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); - - /** - * @brief on_SceneSelectionChanged Slot is called when the scene selection has changed - */ - void on_SceneSelectionChanged(); - private: Q_DISABLE_COPY(VPMainGraphicsView) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 0f82c5b40..c86ba19e8 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -70,15 +70,15 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : m_statusLabel(new QLabel(this)) { // // ----- for test purposes, to be removed------------------ - m_layout->SetUnit(Unit::Cm); - m_layout->SetWarningSuperpositionOfPieces(true); - m_layout->SetTitle(QString("My Test Layout")); - m_layout->SetDescription(QString("Description of my Layout")); + m_layout->LayoutSettings().SetUnit(Unit::Cm); + m_layout->LayoutSettings().SetWarningSuperpositionOfPieces(true); + m_layout->LayoutSettings().SetTitle(QString("My Test Layout")); + m_layout->LayoutSettings().SetDescription(QString("Description of my Layout")); - m_layout->SetTilesSizeConverted(21,29.7); - m_layout->SetTilesOrientation(PageOrientation::Portrait); - m_layout->SetTilesMarginsConverted(1,1,1,1); - m_layout->SetShowTiles(true); + m_layout->LayoutSettings().SetTilesSizeConverted(21,29.7); + m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Portrait); + m_layout->LayoutSettings().SetTilesMarginsConverted(1,1,1,1); + m_layout->LayoutSettings().SetShowTiles(true); // -------------------------------------------------------- @@ -281,7 +281,8 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() VPPiece *piece = CreatePiece(rawPiece); - m_layout->GetUnplacedPieceList()->AddPiece(piece); + piece->SetSheet(nullptr); // just in case + m_layout->AddPiece(piece); } m_carrousel->Refresh(); @@ -475,7 +476,7 @@ void VPMainWindow::InitPropertyTabCurrentSheet() sheetTemplates.append(PaperSizeTemplate::Custom); ui->comboBoxSheetTemplate->blockSignals(true); - VPSheet::PopulateComboBox(&sheetTemplates, ui->comboBoxSheetTemplate); + VPLayoutSettings::PopulateComboBox(&sheetTemplates, ui->comboBoxSheetTemplate); ui->comboBoxSheetTemplate->blockSignals(false); ui->comboBoxSheetTemplate->setCurrentIndex(0); @@ -514,7 +515,7 @@ void VPMainWindow::InitPropertyTabTiles() tilesTemplates.append(PaperSizeTemplate::Custom); ui->comboBoxTilesTemplate->blockSignals(true); - VPSheet::PopulateComboBox(&tilesTemplates, ui->comboBoxTilesTemplate); + VPLayoutSettings::PopulateComboBox(&tilesTemplates, ui->comboBoxTilesTemplate); ui->comboBoxTilesTemplate->blockSignals(false); ui->comboBoxTilesTemplate->setCurrentIndex(4); //A4 @@ -607,9 +608,9 @@ void VPMainWindow::SetPropertyTabCurrentPieceData() QPointF pos = selectedPiece->GetPosition(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, - UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); + UnitConvertor(pos.x(), Unit::Px, m_layout->LayoutSettings().GetUnit())); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, - UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); + UnitConvertor(pos.y(), Unit::Px, m_layout->LayoutSettings().GetUnit())); qreal angle = selectedPiece->GetRotation(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); @@ -633,12 +634,12 @@ void VPMainWindow::SetPropertyTabSheetData() ui->lineEditSheetName->setText(m_layout->GetFocusedSheet()->GetName()); // set Width / Length - QSizeF size = m_layout->GetFocusedSheet()->GetSheetSizeConverted(); + QSizeF size = m_layout->LayoutSettings().GetSheetSizeConverted(); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, size.width()); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height()); // Set Orientation - if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + if(m_layout->LayoutSettings().GetOrientation() == PageOrientation::Portrait) { ui->radioButtonSheetPortrait->setChecked(true); } @@ -648,22 +649,22 @@ void VPMainWindow::SetPropertyTabSheetData() } // set margins - QMarginsF margins = m_layout->GetFocusedSheet()->GetSheetMarginsConverted(); + QMarginsF margins = m_layout->LayoutSettings().GetSheetMarginsConverted(); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, margins.left()); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, margins.top()); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, margins.right()); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, margins.bottom()); // set placement grid - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridColWidth, m_layout->GetFocusedSheet()->GetGridColWidthConverted()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridRowHeight, m_layout->GetFocusedSheet()->GetGridRowHeightConverted()); - SetCheckBoxValue(ui->checkBoxSheetShowGrid, m_layout->GetFocusedSheet()->GetShowGrid()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridColWidth, m_layout->LayoutSettings().GetGridColWidthConverted()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridRowHeight, m_layout->LayoutSettings().GetGridRowHeightConverted()); + SetCheckBoxValue(ui->checkBoxSheetShowGrid, m_layout->LayoutSettings().GetShowGrid()); // set pieces gap - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPiecesGap, m_layout->GetFocusedSheet()->GetPiecesGapConverted()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPiecesGap, m_layout->LayoutSettings().GetPiecesGapConverted()); // set the checkboxes - SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); + SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->LayoutSettings().GetStickyEdges()); } @@ -671,12 +672,12 @@ void VPMainWindow::SetPropertyTabSheetData() void VPMainWindow::SetPropertyTabTilesData() { // set Width / Length - QSizeF size = m_layout->GetTilesSizeConverted(); + QSizeF size = m_layout->LayoutSettings().GetTilesSizeConverted(); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesWidth, size.width()); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesLength, size.height()); // Set Orientation - if(m_layout->GetTilesOrientation() == PageOrientation::Portrait) + if(m_layout->LayoutSettings().GetTilesOrientation() == PageOrientation::Portrait) { ui->radioButtonSheetPortrait->setChecked(true); } @@ -686,25 +687,25 @@ void VPMainWindow::SetPropertyTabTilesData() } // set margins - QMarginsF margins = m_layout->GetTilesMarginsConverted(); + QMarginsF margins = m_layout->LayoutSettings().GetTilesMarginsConverted(); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginLeft, margins.left()); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginTop, margins.top()); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginRight, margins.right()); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginBottom, margins.bottom()); // set "show tiles" checkbox - SetCheckBoxValue(ui->checkBoxTilesShowTiles, m_layout->GetShowTiles()); + SetCheckBoxValue(ui->checkBoxTilesShowTiles, m_layout->LayoutSettings().GetShowTiles()); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabLayoutData() { // set the title and description - ui->lineEditLayoutName->setText(m_layout->GetTitle()); - ui->plainTextEditLayoutDescription->setPlainText(m_layout->GetDescription()); + ui->lineEditLayoutName->setText(m_layout->LayoutSettings().GetTitle()); + ui->plainTextEditLayoutDescription->setPlainText(m_layout->LayoutSettings().GetDescription()); // set Unit - int index = ui->comboBoxLayoutUnit->findData(QVariant(UnitsToStr(m_layout->GetUnit()))); + int index = ui->comboBoxLayoutUnit->findData(QVariant(UnitsToStr(m_layout->LayoutSettings().GetUnit()))); if(index != -1) { ui->comboBoxLayoutUnit->blockSignals(true); // FIXME: is there a better way to block the signals? @@ -713,8 +714,10 @@ void VPMainWindow::SetPropertyTabLayoutData() } // set controls - SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, m_layout->GetWarningPiecesOutOfBound()); - SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); + SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, + m_layout->LayoutSettings().GetWarningPiecesOutOfBound()); + SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, + m_layout->LayoutSettings().GetWarningSuperpositionOfPieces()); } @@ -786,7 +789,8 @@ void VPMainWindow::InitScaleToolBar() // define the mouse position ui->toolBarScale->addSeparator(); - m_mouseCoordinate = new QLabel(QStringLiteral("0, 0 (%1)").arg(UnitsToStr(m_layout->GetUnit(), true))); + m_mouseCoordinate = new QLabel(QStringLiteral("0, 0 (%1)") + .arg(UnitsToStr(m_layout->LayoutSettings().GetUnit(), true))); ui->toolBarScale->addWidget(m_mouseCoordinate); ui->toolBarScale->addSeparator(); } @@ -975,7 +979,7 @@ void VPMainWindow::generateTiledPdf(QString fileName) m_graphicsView->PrepareForExport(); m_tileFactory->refreshTileInfos(); - PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); + PageOrientation tilesOrientation = m_layout->LayoutSettings().GetTilesOrientation(); // ------------- Set up the printer QScopedPointer printer(new QPrinter()); @@ -985,7 +989,7 @@ void VPMainWindow::generateTiledPdf(QString fileName) printer->setPageOrientation(QPageLayout::Portrait); // in the pdf file the pages should always be in portrait // here we might need to so some rounding for the size. - printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm), + printer->setPageSize(QPageSize(m_layout->LayoutSettings().GetTilesSize(Unit::Mm), QPageSize::Millimeter)); printer->setFullPage(true); @@ -1087,12 +1091,12 @@ void VPMainWindow::AddSheet() auto *sheet = new VPSheet(m_layout); sheet->SetName(QObject::tr("Sheet %1").arg(m_layout->GetSheets().size()+1)); m_layout->AddSheet(sheet); - m_layout->SetFocusedSheet(); + m_layout->SetFocusedSheet(sheet); // // ----- for test purposes, to be removed------------------ - sheet->SetSheetMarginsConverted(1, 1, 1, 1); - sheet->SetSheetSizeConverted(84.1, 118.9); - sheet->SetPiecesGapConverted(1); + m_layout->LayoutSettings().SetSheetMarginsConverted(1, 1, 1, 1); + m_layout->LayoutSettings().SetSheetSizeConverted(84.1, 118.9); + m_layout->LayoutSettings().SetPiecesGapConverted(1); } //--------------------------------------------------------------------------------------------------------------------- @@ -1359,15 +1363,15 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) if(comboBoxValue == QVariant(UnitsToStr(Unit::Cm))) { - m_layout->SetUnit(Unit::Cm); + m_layout->LayoutSettings().SetUnit(Unit::Cm); } else if(comboBoxValue == QVariant(UnitsToStr(Unit::Mm))) { - m_layout->SetUnit(Unit::Mm); + m_layout->LayoutSettings().SetUnit(Unit::Mm); } else if(comboBoxValue == QVariant(UnitsToStr(Unit::Inch))) { - m_layout->SetUnit(Unit::Inch); + m_layout->LayoutSettings().SetUnit(Unit::Inch); } SetPropertyTabCurrentPieceData(); @@ -1393,14 +1397,16 @@ void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) ui->comboBoxSheetTemplate->itemData(index).toInt() ); - QSizeF tmplSize = VPSheet::GetTemplateSize(tmpl); + QSizeF tmplSize = VPLayoutSettings::GetTemplateSize(tmpl); if(!tmplSize.isEmpty()) { ui->doubleSpinBoxSheetWidth->blockSignals(true); ui->doubleSpinBoxSheetLength->blockSignals(true); - ui->doubleSpinBoxSheetWidth->setValue(UnitConvertor(tmplSize.width(), Unit::Px, m_layout->GetUnit())); - ui->doubleSpinBoxSheetLength->setValue(UnitConvertor(tmplSize.height(), Unit::Px, m_layout->GetUnit())); + ui->doubleSpinBoxSheetWidth->setValue(UnitConvertor(tmplSize.width(), Unit::Px, + m_layout->LayoutSettings().GetUnit())); + ui->doubleSpinBoxSheetLength->setValue(UnitConvertor(tmplSize.height(), Unit::Px, + m_layout->LayoutSettings().GetUnit())); on_SheetSizeChanged(false); @@ -1412,7 +1418,7 @@ void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetSizeChanged(bool changedViaSizeCombobox) { - m_layout->GetFocusedSheet()->SetSheetSizeConverted( + m_layout->LayoutSettings().SetSheetSizeConverted( ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value() ); @@ -1442,11 +1448,11 @@ void VPMainWindow::on_SheetOrientationChanged() // Updates the orientation if(ui->radioButtonSheetPortrait->isChecked()) { - m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Portrait); + m_layout->LayoutSettings().SetOrientation(PageOrientation::Portrait); } else { - m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Landscape); + m_layout->LayoutSettings().SetOrientation(PageOrientation::Landscape); } m_tileFactory->refreshTileInfos(); @@ -1472,7 +1478,7 @@ void VPMainWindow::on_pushButtonSheetRemoveUnusedLength_clicked() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetMarginChanged() { - m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + m_layout->LayoutSettings().SetSheetMarginsConverted( ui->doubleSpinBoxSheetMarginLeft->value(), ui->doubleSpinBoxSheetMarginTop->value(), ui->doubleSpinBoxSheetMarginRight->value(), @@ -1487,21 +1493,21 @@ void VPMainWindow::on_SheetMarginChanged() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxSheetShowGrid_toggled(bool checked) { - m_layout->GetFocusedSheet()->SetShowGrid(checked); + m_layout->LayoutSettings().SetShowGrid(checked); m_graphicsView->RefreshLayout(); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_doubleSpinBoxSheetGridColWidth_valueChanged(double value) { - m_layout->GetFocusedSheet()->SetGridColWidthConverted(value); + m_layout->LayoutSettings().SetGridColWidthConverted(value); m_graphicsView->RefreshLayout(); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_doubleSpinBoxSheetGridRowHeight_valueChanged(double value) { - m_layout->GetFocusedSheet()->SetGridRowHeightConverted(value); + m_layout->LayoutSettings().SetGridRowHeightConverted(value); m_graphicsView->RefreshLayout(); } @@ -1512,14 +1518,16 @@ void VPMainWindow::on_comboBoxTilesTemplate_currentIndexChanged(int index) ui->comboBoxTilesTemplate->itemData(index).toInt() ); - QSizeF tmplSize = VPSheet::GetTemplateSize(tmpl); + QSizeF tmplSize = VPLayoutSettings::GetTemplateSize(tmpl); if(!tmplSize.isEmpty()) { ui->doubleSpinBoxTilesWidth->blockSignals(true); ui->doubleSpinBoxTilesLength->blockSignals(true); - ui->doubleSpinBoxTilesWidth->setValue(UnitConvertor(tmplSize.width(), Unit::Px, m_layout->GetUnit())); - ui->doubleSpinBoxTilesLength->setValue(UnitConvertor(tmplSize.height(), Unit::Px, m_layout->GetUnit())); + ui->doubleSpinBoxTilesWidth->setValue(UnitConvertor(tmplSize.width(), Unit::Px, + m_layout->LayoutSettings().GetUnit())); + ui->doubleSpinBoxTilesLength->setValue(UnitConvertor(tmplSize.height(), Unit::Px, + m_layout->LayoutSettings().GetUnit())); on_TilesSizeChanged(false); @@ -1531,7 +1539,8 @@ void VPMainWindow::on_comboBoxTilesTemplate_currentIndexChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_TilesSizeChanged(bool changedViaSizeCombobox) { - m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value()); + m_layout->LayoutSettings().SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), + ui->doubleSpinBoxTilesLength->value()); m_tileFactory->refreshTileInfos(); if(changedViaSizeCombobox) @@ -1560,11 +1569,11 @@ void VPMainWindow::on_TilesOrientationChanged() // Updates the orientation if(ui->radioButtonTilesPortrait->isChecked()) { - m_layout->SetTilesOrientation(PageOrientation::Portrait); + m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Portrait); } else { - m_layout->SetTilesOrientation(PageOrientation::Landscape); + m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Landscape); } m_tileFactory->refreshTileInfos(); @@ -1576,7 +1585,7 @@ void VPMainWindow::on_TilesOrientationChanged() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_TilesMarginChanged() { - m_layout->SetTilesMarginsConverted( + m_layout->LayoutSettings().SetTilesMarginsConverted( ui->doubleSpinBoxTilesMarginLeft->value(), ui->doubleSpinBoxTilesMarginTop->value(), ui->doubleSpinBoxTilesMarginRight->value(), @@ -1593,7 +1602,7 @@ void VPMainWindow::on_TilesMarginChanged() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) { - m_layout->SetShowTiles(checked); + m_layout->LayoutSettings().SetShowTiles(checked); // TODO Undo / Redo @@ -1635,7 +1644,7 @@ void VPMainWindow::on_SheetFollowGrainlineChanged() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_doubleSpinBoxSheetPiecesGap_valueChanged(double value) { - m_layout->GetFocusedSheet()->SetPiecesGapConverted(value); + m_layout->LayoutSettings().SetPiecesGapConverted(value); // TODO Undo / Redo // TODO update the QGraphicView @@ -1644,7 +1653,7 @@ void VPMainWindow::on_doubleSpinBoxSheetPiecesGap_valueChanged(double value) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool checked) { - m_layout->SetWarningSuperpositionOfPieces(checked); + m_layout->LayoutSettings().SetWarningSuperpositionOfPieces(checked); // TODO Undo / Redo // TODO update the QGraphicView @@ -1653,7 +1662,7 @@ void VPMainWindow::on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool chec //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked) { - m_layout->SetWarningPiecesOutOfBound(checked); + m_layout->LayoutSettings().SetWarningPiecesOutOfBound(checked); // TODO Undo / Redo // TODO update the QGraphicView @@ -1662,7 +1671,7 @@ void VPMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) { - m_layout->GetFocusedSheet()->SetStickyEdges(checked); + m_layout->LayoutSettings().SetStickyEdges(checked); // TODO Undo / Redo // TODO update the QGraphicView @@ -1748,8 +1757,10 @@ void VPMainWindow::on_CurrentPiecePositionEdited() if(m_selectedPieces.count() == 1) { VPPiece *piece = m_selectedPieces.first(); - QPointF pos(UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionX->value(), m_layout->GetUnit(), Unit::Px), - UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionY->value(), m_layout->GetUnit(), Unit::Px)); + QPointF pos(UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionX->value(), + m_layout->LayoutSettings().GetUnit(), Unit::Px), + UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionY->value(), + m_layout->LayoutSettings().GetUnit(), Unit::Px)); piece->SetPosition(pos); } } @@ -1770,7 +1781,7 @@ void VPMainWindow::on_CarrouselLocationChanged(Qt::DockWidgetArea area) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_PieceSelectionChanged() { - m_selectedPieces = m_layout->GetSelectedPieces(); +// m_selectedPieces = m_layout->GetSelectedPieces(); // update the property of the piece currently selected SetPropertyTabCurrentPieceData(); @@ -1786,9 +1797,9 @@ void VPMainWindow::on_PiecePositionChanged() QPointF pos = piece->GetPosition(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, - UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); + UnitConvertor(pos.x(), Unit::Px, m_layout->LayoutSettings().GetUnit())); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, - UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); + UnitConvertor(pos.y(), Unit::Px, m_layout->LayoutSettings().GetUnit())); } } @@ -1825,9 +1836,11 @@ void VPMainWindow::on_MouseMoved(const QPointF &scenePos) if (m_mouseCoordinate != nullptr) { m_mouseCoordinate->setText(QStringLiteral("%1, %2 (%3)") - .arg(static_cast(FromPixel(scenePos.x(), m_layout->GetUnit()))) - .arg(static_cast(FromPixel(scenePos.y(), m_layout->GetUnit()))) - .arg(UnitsToStr(m_layout->GetUnit(), true))); + .arg(static_cast(FromPixel(scenePos.x(), + m_layout->LayoutSettings().GetUnit()))) + .arg(static_cast(FromPixel(scenePos.y(), + m_layout->LayoutSettings().GetUnit()))) + .arg(UnitsToStr(m_layout->LayoutSettings().GetUnit(), true))); } } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 2783bbbfa..005aa48ef 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -415,7 +415,7 @@ private: VPCommandLinePtr m_cmd; - VPLayout *m_layout{new VPLayout()}; + VPLayout *m_layout{new VPLayout(this)}; QListm_selectedPieces{QList()}; VPTileFactory *m_tileFactory{nullptr}; diff --git a/src/app/puzzle/vppiece.cpp b/src/app/puzzle/vppiece.cpp index 17d04e5b9..d5561c927 100644 --- a/src/app/puzzle/vppiece.cpp +++ b/src/app/puzzle/vppiece.cpp @@ -29,7 +29,6 @@ #include -#include "vppiecelist.h" #include "../vmisc/def.h" #include @@ -38,12 +37,6 @@ Q_LOGGING_CATEGORY(pPiece, "p.piece") -//--------------------------------------------------------------------------------------------------------------------- -VPPiece::VPPiece() -{ - -} - //--------------------------------------------------------------------------------------------------------------------- VPPiece::VPPiece(VLayoutPiece layoutPiece): VLayoutPiece(layoutPiece) { @@ -198,16 +191,26 @@ bool VPPiece::GetIsSelected() } //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPPiece::GetPieceList() +auto VPPiece::Sheet() const -> VPSheet * { - return m_pieceList; + return m_sheet; } //--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetPieceList(VPPieceList* pieceList) +void VPPiece::SetSheet(VPSheet *newSheet) { - if(pieceList != m_pieceList) - { - m_pieceList = pieceList; - } + m_sheet = newSheet; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPPiece::Layout() const -> VPLayout * +{ + return m_layout; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetLayout(VPLayout *layout) +{ + SCASSERT(layout != nullptr) + m_layout = layout; } diff --git a/src/app/puzzle/vppiece.h b/src/app/puzzle/vppiece.h index d68955108..6e1e22ffe 100644 --- a/src/app/puzzle/vppiece.h +++ b/src/app/puzzle/vppiece.h @@ -35,17 +35,17 @@ #include "../vlayout/vlayoutpiece.h" -class VPPieceList; +class VPLayout; +class VPSheet; class VPPiece : public QObject, public VLayoutPiece { Q_OBJECT public: - VPPiece(); + VPPiece() = default; explicit VPPiece(VLayoutPiece layoutPiece); - ~VPPiece(); - + virtual ~VPPiece(); /** * @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not @@ -111,7 +111,6 @@ public: */ void RotateToGrainline(qreal angleOfGrainline, bool add180IfAlreadyInPosition = false); - /** * @brief SetIsSelected Sets wether the piece is selected * @param value true if the piece is selected @@ -124,20 +123,14 @@ public: */ bool GetIsSelected(); - /** - * @brief GetPieceList Returns the piecelist in which the piece is. - * @return pieceList of the piece - */ - VPPieceList* GetPieceList(); - - /** - * @brief SetPieceList Sets the pieceList of the piece to the given pieceList - * @param pieceList pointer to the piece list - */ - void SetPieceList(VPPieceList* pieceList); - QIcon PieceIcon(const QSize &size) const; + auto Sheet() const -> VPSheet *; + void SetSheet(VPSheet *newSheet); + + auto Layout() const -> VPLayout *; + void SetLayout(VPLayout *layout); + signals: /** * @brief SelectionChanged emited when the selection of the piece was @@ -163,11 +156,13 @@ signals: */ void PropertiesChanged(); - - private: Q_DISABLE_COPY(VPPiece) + VPLayout *m_layout{nullptr}; + + VPSheet *m_sheet{nullptr}; + QVector m_grainline{}; bool m_isGrainlineEnabled{false}; @@ -181,7 +176,6 @@ private: bool m_mirrorPiece{false}; bool m_isSelected{false}; - VPPieceList *m_pieceList{nullptr}; }; #endif // VPPIECE_H diff --git a/src/app/puzzle/vppiecelist.cpp b/src/app/puzzle/vppiecelist.cpp deleted file mode 100644 index c016c5f19..000000000 --- a/src/app/puzzle/vppiecelist.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/************************************************************************ - ** - ** @file vppiecelist.cpp - ** @author Ronan Le Tiec - ** @date 13 4, 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 "vppiecelist.h" - -#include "vplayout.h" - -#include - -Q_LOGGING_CATEGORY(pPieceList, "p.pieceList") - -//--------------------------------------------------------------------------------------------------------------------- -VPPieceList::VPPieceList(VPLayout *layout, VPSheet *sheet): - m_sheet(sheet), - m_layout(layout) -{ - -} - -//--------------------------------------------------------------------------------------------------------------------- -VPPieceList::~VPPieceList() -{ - qDeleteAll(m_pieces); -} - -//--------------------------------------------------------------------------------------------------------------------- -VPLayout* VPPieceList::GetLayout() -{ - return m_layout; -} - -//--------------------------------------------------------------------------------------------------------------------- -VPSheet* VPPieceList::GetSheet() -{ - return m_sheet; -} - -//--------------------------------------------------------------------------------------------------------------------- -QList VPPieceList::GetPieces() -{ - return m_pieces; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPPieceList::ClearSelection() -{ - for (auto *piece: m_pieces) - { - piece->SetIsSelected(false); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPieceList::AddPiece(VPPiece *piece) -{ - qCDebug(pPieceList(), "piece -- %s -- added to %s", qUtf8Printable(piece->GetName()), qUtf8Printable(this->GetName())); - - m_pieces.append(piece); - piece->SetPieceList(this); - - emit PieceAdded(piece); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPieceList::RemovePiece(VPPiece *piece) -{ - m_pieces.removeAll(piece); - piece->SetPieceList(nullptr); - - emit PieceRemoved(piece); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VPPieceList::GetName() const -{ - return m_name; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPieceList::SetName(const QString &name) -{ - m_name = name; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPieceList::SetIsVisible(bool value) -{ - m_isVisible = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPPieceList::GetIsVisible() const -{ - return m_isVisible; -} diff --git a/src/app/puzzle/vppiecelist.h b/src/app/puzzle/vppiecelist.h deleted file mode 100644 index c0e86b6fd..000000000 --- a/src/app/puzzle/vppiecelist.h +++ /dev/null @@ -1,102 +0,0 @@ -/************************************************************************ - ** - ** @file vppiecelist.h - ** @author Ronan Le Tiec - ** @date 13 4, 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 VPPIECELIST_H -#define VPPIECELIST_H - -#include -#include "vppiece.h" -#include "vpsheet.h" - -class VPLayout; - -class VPPieceList : public QObject -{ - Q_OBJECT -public: - VPPieceList(VPLayout *layout, VPSheet *sheet = nullptr); - ~VPPieceList(); - - QList GetPieces(); - void AddPiece(VPPiece *piece); - void RemovePiece(VPPiece *piece); - - // here add some more function if we want to add/move a piece at a - // certain position in the list - - QString GetName() const; - void SetName(const QString &name); - - void SetIsVisible(bool value); - bool GetIsVisible() const; - - /** - * @brief GetLayout Returns the layout in which this piece list is - * @return the layout of this piece list - */ - VPLayout* GetLayout(); - - - /** - * @brief GetSheet returns the sheet corresponding to this piece list, or nullptr - * if no sheet associated - * @return the sheet - */ - VPSheet* GetSheet(); - - /** - * @brief ClearSelection Clears the selection of the pieces in this piece list - */ - void ClearSelection(); - -signals: - /** - * @brief PieceAdded The signal is emited when a piece was added - */ - void PieceAdded(VPPiece *piece); - - /** - * @brief PieceRemoved The signal is emited when a piece was removed - */ - void PieceRemoved(VPPiece *piece); - -private: - Q_DISABLE_COPY(VPPieceList) - - QString m_name{}; - QList m_pieces{}; - - VPSheet *m_sheet{nullptr}; - - VPLayout *m_layout{nullptr}; - - // control - bool m_isVisible{true}; - -}; - -#endif // VPPIECELIST_H diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index 15ca24b27..e7ed966a8 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -27,279 +27,37 @@ *************************************************************************/ #include "vpsheet.h" -#include "vppiecelist.h" #include "vplayout.h" //--------------------------------------------------------------------------------------------------------------------- VPSheet::VPSheet(VPLayout* layout) : + QObject(layout), m_layout(layout) { - m_pieceList = new VPPieceList(layout, this); + SCASSERT(layout != nullptr) } //--------------------------------------------------------------------------------------------------------------------- -VPSheet::~VPSheet() -{ - delete m_pieceList; -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPSheet::GetTemplateSize(PaperSizeTemplate tmpl) -{ - qreal height = 0; - qreal width = 0; - - switch (tmpl) - { - case PaperSizeTemplate::A0: - width = UnitConvertor(841, Unit::Mm, Unit::Px); - height = UnitConvertor(1189, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A1: - width = UnitConvertor(594, Unit::Mm, Unit::Px); - height = UnitConvertor(841, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A2: - width = UnitConvertor(420, Unit::Mm, Unit::Px); - height = UnitConvertor(594, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A3: - width = UnitConvertor(297, Unit::Mm, Unit::Px); - height = UnitConvertor(420, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A4: - width = UnitConvertor(210, Unit::Mm, Unit::Px); - height = UnitConvertor(297, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::Letter: - width = UnitConvertor(8.5, Unit::Inch, Unit::Px); - height = UnitConvertor(11, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Legal: - width = UnitConvertor(8.5, Unit::Inch, Unit::Px); - height = UnitConvertor(14, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Tabloid: - width = UnitConvertor(11, Unit::Inch, Unit::Px); - height = UnitConvertor(17, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll24in: - width = UnitConvertor(24, Unit::Inch, Unit::Px); - height = UnitConvertor(48, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll30in: - width = UnitConvertor(30, Unit::Inch, Unit::Px); - height = UnitConvertor(60, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll36in: - width = UnitConvertor(36, Unit::Inch, Unit::Px); - height = UnitConvertor(72, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll42in: - width = UnitConvertor(42, Unit::Inch, Unit::Px); - height = UnitConvertor(84, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll44in: - width = UnitConvertor(44, Unit::Inch, Unit::Px); - height = UnitConvertor(88, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll48in: - width = UnitConvertor(48, Unit::Inch, Unit::Px); - height = UnitConvertor(96, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll62in: - width = UnitConvertor(62, Unit::Inch, Unit::Px); - height = UnitConvertor(124, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll72in: - width = UnitConvertor(72, Unit::Inch, Unit::Px); - height = UnitConvertor(144, Unit::Inch, Unit::Px); - break; - - default: - break; - } - - return QSizeF(width, height); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VPSheet::GetTemplateName(PaperSizeTemplate tmpl) -{ - QString tmplName; - switch (tmpl) - { - case PaperSizeTemplate::A0: - tmplName = QString("A0"); - break; - - case PaperSizeTemplate::A1: - tmplName = QString("A1"); - break; - - case PaperSizeTemplate::A2: - tmplName = QString("A2"); - break; - - case PaperSizeTemplate::A3: - tmplName = QString("A3"); - break; - - case PaperSizeTemplate::A4: - tmplName = QString("A4"); - break; - - case PaperSizeTemplate::Letter: - tmplName = tr("Letter"); - break; - - case PaperSizeTemplate::Legal: - tmplName = tr("Legal"); - break; - - case PaperSizeTemplate::Tabloid: - tmplName = tr("Tabloid"); - break; - - case PaperSizeTemplate::Roll24in: - tmplName = tr("Roll 24in"); - break; - - case PaperSizeTemplate::Roll30in: - tmplName = tr("Roll 30in"); - break; - - case PaperSizeTemplate::Roll36in: - tmplName = tr("Roll 36in"); - break; - - case PaperSizeTemplate::Roll42in: - tmplName = tr("Roll 42in"); - break; - - case PaperSizeTemplate::Roll44in: - tmplName = tr("Roll 44in"); - break; - - case PaperSizeTemplate::Roll48in: - tmplName = tr("Roll 48in"); - break; - - case PaperSizeTemplate::Roll62in: - tmplName = tr("Roll 62in"); - break; - - case PaperSizeTemplate::Roll72in: - tmplName = tr("Roll 72in"); - break; - - case PaperSizeTemplate::Custom: - tmplName = tr("Custom"); - break; - - default: - break; - } - - if(not tmplName.isEmpty()) - { - tmplName += " " + QStringLiteral("(%1ppi)").arg(PrintDPI); - } - - return tmplName; -} - -//--------------------------------------------------------------------------------------------------------------------- -PaperSizeTemplate VPSheet::GetTemplate(QSizeF size) -{ - Q_UNUSED(size); - // TODO, float comparision not safe and problems with - // inch / cm - -// const int max = static_cast(PaperSizeTemplate::Custom); - -// for (int i=0; i < max; i++) -// { -// PaperSizeTemplate tmpl = static_cast(i); -// const QSizeF tmplSize = GetTemplateSize(tmpl); - -// if(size.width() == tmplSize.width()) -// { -// if(isRollTemplate(tmpl)) -// { -// return tmpl; -// } -// else if(size.height() == tmplSize.height()) -// { -// return tmpl; -// } -// } -// } - - return PaperSizeTemplate::Custom; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPSheet::isRollTemplate(PaperSizeTemplate tmpl) -{ - switch (tmpl) { - case PaperSizeTemplate::Roll24in: - case PaperSizeTemplate::Roll30in: - case PaperSizeTemplate::Roll36in: - case PaperSizeTemplate::Roll42in: - case PaperSizeTemplate::Roll44in: - case PaperSizeTemplate::Roll48in: - case PaperSizeTemplate::Roll62in: - case PaperSizeTemplate::Roll72in: - return true; - default: - return false; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::PopulateComboBox(QVector *tmpls, QComboBox* comboBox) -{ - const QIcon icoPaper("://puzzleicon/16x16/template.png"); - const QIcon icoRoll("://puzzleicon/16x16/roll.png"); - - QIcon icon; - for (auto tmpl : *tmpls) - { - icon = (isRollTemplate(tmpl))? icoRoll : icoPaper; - comboBox->addItem(icon, GetTemplateName(tmpl), QVariant(static_cast(tmpl))); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -VPLayout* VPSheet::GetLayout() +auto VPSheet::GetLayout() -> VPLayout* { return m_layout; } //--------------------------------------------------------------------------------------------------------------------- -VPPieceList* VPSheet::GetPieceList() +auto VPSheet::GetPieces() const -> QList { - return m_pieceList; + QList list; + + if (m_layout != nullptr) + { + return m_layout->PiecesForSheet(this); + } + + return {}; } //--------------------------------------------------------------------------------------------------------------------- -QString VPSheet::GetName() const +auto VPSheet::GetName() const -> QString { return m_name; } @@ -309,222 +67,3 @@ 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; -} - -//--------------------------------------------------------------------------------------------------------------------- -PageOrientation VPSheet::GetOrientation() -{ - return m_orientation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::SetOrientation(PageOrientation orientation) -{ - if(orientation != m_orientation) - { - m_orientation = orientation; - } -} - - -//--------------------------------------------------------------------------------------------------------------------- -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(); -} - - -//--------------------------------------------------------------------------------------------------------------------- -bool VPSheet::GetShowGrid() -{ - return m_showGrid; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::SetShowGrid(bool value) -{ - m_showGrid = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPSheet::GetGridColWidth() const -{ - return m_gridColWidth; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPSheet::GetGridColWidthConverted() const -{ - return UnitConvertor(m_gridColWidth, Unit::Px, m_layout->GetUnit()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::SetGridColWidth(qreal value) -{ - m_gridColWidth = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::SetGridColWidthConverted(qreal value) -{ - m_gridColWidth = UnitConvertor(value, m_layout->GetUnit(), Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPSheet::GetGridRowHeight() const -{ - return m_gridRowHeight; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPSheet::GetGridRowHeightConverted() const -{ - return UnitConvertor(m_gridRowHeight, Unit::Px, m_layout->GetUnit()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::SetGridRowHeight(qreal value) -{ - m_gridRowHeight = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPSheet::SetGridRowHeightConverted(qreal value) -{ - m_gridRowHeight = UnitConvertor(value, m_layout->GetUnit(), Unit::Px); -} diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h index ecbefc919..effe3d0c2 100644 --- a/src/app/puzzle/vpsheet.h +++ b/src/app/puzzle/vpsheet.h @@ -36,35 +36,8 @@ #include "def.h" -// is this the right place for the definition? -enum class FollowGrainline : qint8 { - No = 0, - Follow90 = 1, - Follow180 = 2 -}; - -enum class PaperSizeTemplate : qint8 { - A0 = 0, - A1, - A2, - A3, - A4, - Letter, - Legal, - Tabloid, - Roll24in, - Roll30in, - Roll36in, - Roll42in, - Roll44in, - Roll48in, - Roll62in, - Roll72in, - Custom -}; - class VPLayout; -class VPPieceList; +class VPPiece; class VPSheet : public QObject { @@ -72,60 +45,21 @@ class VPSheet : public QObject public: explicit VPSheet(VPLayout* layout); - ~VPSheet(); - - /** - * @brief GetTemplateSize Returns the size in Px of the given template - * @param tmpl paper size template - * @return the size in Px - */ - static QSizeF GetTemplateSize(PaperSizeTemplate tmpl); - - /** - * @brief GetTemplateName Returns the name of the given template - * @param tmpl paper size template - * @return name of the given template - */ - static QString GetTemplateName(PaperSizeTemplate tmpl); - - /** - * @brief GetTemplate GetTemplate Returns the template that corresponds to the given size - * @param size the Size in Px - * @return template that corresponds to the given size - */ - static PaperSizeTemplate GetTemplate(QSizeF size); - - /** - * @brief PopulateComboBox Populates the given combo with the given templates - * @param tmpls list of paper size templates - * @param comboBox pointer to the combobox - */ - static void PopulateComboBox(QVector *tmpls, QComboBox* comboBox); - - /** - * @brief isRollTemplate Returns wether the given template is a roll or not. - * @param tmpl paper size template - * @return true if the given template is a roll - */ - static bool isRollTemplate(PaperSizeTemplate tmpl); + virtual ~VPSheet() = default; /** * @brief GetLayout Returns the Layout of the sheet * @return Layout of the sheet */ - VPLayout* GetLayout(); + auto GetLayout() -> VPLayout*; - /** - * @brief GetPieceList returns the piece list of the sheet - * @return piece list - */ - VPPieceList* GetPieceList(); + auto GetPieces() const -> QList; /** * @brief GetName Returns the name of the sheet * @return the name */ - QString GetName() const; + auto GetName() const -> QString; /** * @brief SetName Sets the name of the sheet to the given name @@ -133,256 +67,12 @@ public: */ 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 GetOrientation Returns the orientation of the sheet - * @return orientation of the sheet - */ - PageOrientation GetOrientation(); - - /** - * @brief SetOrientation Sets the orientation of the sheet to the given value - * @param orientation the new page orientation - */ - void SetOrientation(PageOrientation orientation); - - /** - * @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(); - - /** - * @brief GetShowGrid Returns true if the placement grid has to be shown on the current sheet - * @return true if the placement grid has to be shown on the current sheet - */ - bool GetShowGrid(); - - /** - * @brief SetShowGrid Returns true if the placement grid has to be shown on the current sheet - * @param value whether to show the grid or not - */ - void SetShowGrid(bool value); - - /** - * @brief GetGridColWidth returns the placement grid column width in Unit::Px - * @return the placement grid column width in Unit::Px - */ - qreal GetGridColWidth() const; - - /** - * @brief GetGridColWidth returns the placement grid column width in the layout's unit - * @return the placement grid column width in the layout's unit - */ - qreal GetGridColWidthConverted() const; - - /** - * @brief SetGridColWidth sets the placement grid column width to the given value, the unit has to be Unit::Px - * @param value the placement grid column width in Unit::Px - */ - void SetGridColWidth(qreal value); - - /** - * @brief SetGridColWidthConverted sets the placement grid column width to the given value, the unit has to be in the layout's unit - * @param value the placement grid column width in the layout's unit - */ - void SetGridColWidthConverted(qreal value); - - /** - * @brief GetGridRowHeight returns the placement grid row height in Unit::Px - * @return the placement grid row height in Unit::Px - */ - qreal GetGridRowHeight() const; - - /** - * @brief GetGridRowHeightConverted returns the placement grid row height in the layout's unit - * @return the placement grid row height in the layout's unit - */ - qreal GetGridRowHeightConverted() const; - - /** - * @brief SetGridRowHeight sets the placement grid row height to the given value, the unit has to be Unit::Px - * @param value the placement grid row height in Unit::Px - */ - void SetGridRowHeight(qreal value); - - /** - * @brief SetGridRowHeightConverted sets the placement grid row height to the given value, the unit has to be in the layout's unit - * @param value the placement grid row height in the layout's unit - */ - void SetGridRowHeightConverted(qreal value); - - - - - - 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{}; - - /** - * @brief holds the orientation of the sheet - */ - PageOrientation m_orientation {PageOrientation::Portrait}; - - // 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}; - - // placement grid - /** - * @brief GetShowGrid Returns true if the placement grid has to be shown on the current sheet - */ - bool m_showGrid{false}; - /** - * @brief m_gridColWidth the column width of the placement grid in Unit::Px - */ - qreal m_gridColWidth{0}; - - /** - * @brief m_gridRowHeight the row height of the placement grid in Unit::Px - */ - qreal m_gridRowHeight{0}; - - bool m_stickyEdges{false}; }; #endif // VPSHEET_H diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index a929de02f..076102845 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -27,9 +27,9 @@ void VPTileFactory::refreshTileInfos() { if(m_layout != nullptr) { - PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); - QSizeF tilesSize = m_layout->GetTilesSize(); - QMarginsF tilesMargins = m_layout->GetTilesMargins(); + PageOrientation tilesOrientation = m_layout->LayoutSettings().GetTilesOrientation(); + QSizeF tilesSize = m_layout->LayoutSettings().GetTilesSize(); + QMarginsF tilesMargins = m_layout->LayoutSettings().GetTilesMargins(); // sets the drawing height m_drawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? @@ -44,11 +44,11 @@ void VPTileFactory::refreshTileInfos() tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth; - QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); + QSizeF sheetSize = m_layout->LayoutSettings().GetSheetSize(); qreal totalDrawingWidth = 0; qreal totaldrawingHeight = 0; - if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + if(m_layout->LayoutSettings().GetOrientation() == PageOrientation::Portrait) { totalDrawingWidth = sheetSize.width(); totaldrawingHeight = sheetSize.height(); @@ -68,7 +68,7 @@ void VPTileFactory::refreshTileInfos() //--------------------------------------------------------------------------------------------------------------------- void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView, int row, int col) { - QMarginsF tilesMargins = m_layout->GetTilesMargins(); + QMarginsF tilesMargins = m_layout->LayoutSettings().GetTilesMargins(); QPen penTileInfos = QPen(QColor(180,180,180), m_commonSettings->WidthHairLine(), Qt::DashLine, Qt::RoundCap, Qt::RoundJoin); QPen penTileDrawing = QPen(Qt::black, m_commonSettings->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); diff --git a/src/app/puzzle/vptilefactory.h b/src/app/puzzle/vptilefactory.h index 839ee0c06..0032f7d9d 100644 --- a/src/app/puzzle/vptilefactory.h +++ b/src/app/puzzle/vptilefactory.h @@ -45,7 +45,7 @@ class VPTileFactory : QObject public: VPTileFactory(VPLayout *layout, VCommonSettings *commonSettings); - ~VPTileFactory(); + virtual ~VPTileFactory(); /** * @brief drawTile draws the tile of given coordinate (row, col) from the diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 6ac0db5ca..8476ed0b0 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -30,6 +30,7 @@ #include "vplayoutfilereader.h" #include "vplayoutfilewriter.h" #include "vplayoutliterals.h" +#include "vpsheet.h" #include "../ifc/exception/vexception.h" #include "../ifc/exception/vexceptionconversionerror.h" @@ -66,7 +67,14 @@ void VPLayoutFileReader::ReadLayout(VPLayout *layout) { AssertRootTag(ML::TagLayout); - const QStringList tags({ML::TagProperties, ML::TagUnplacedPieces, ML::TagSheets}); + const QStringList tags + { + ML::TagProperties, // 0 + ML::TagUnplacedPieces, // 1 + ML::TagSheets, // 2 + ML::TagSize, // 3 + ML::TagMargin // 4 + }; while (readNextStartElement()) { @@ -81,6 +89,12 @@ void VPLayoutFileReader::ReadLayout(VPLayout *layout) case 2: // ML::TagSheets ReadSheets(layout); break; + case 3: // size + layout->LayoutSettings().SetSheetSize(ReadSize()); + break; + case 4: // margin + layout->LayoutSettings().SetSheetMargins(ReadMargins()); + break; default: qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); skipCurrentElement(); @@ -111,15 +125,15 @@ void VPLayoutFileReader::ReadProperties(VPLayout *layout) { case 0:// unit qDebug("read unit"); - layout->SetUnit(StrToUnits(readElementText())); + layout->LayoutSettings().SetUnit(StrToUnits(readElementText())); break; case 1:// title qDebug("read title"); - layout->SetTitle(readElementText()); + layout->LayoutSettings().SetTitle(readElementText()); break; case 2:// description qDebug("read description"); - layout->SetDescription(readElementText()); + layout->LayoutSettings().SetDescription(readElementText()); break; case 3:// control qDebug("read control"); @@ -143,8 +157,9 @@ void VPLayoutFileReader::ReadControl(VPLayout *layout) AssertRootTag(ML::TagControl); QXmlStreamAttributes attribs = attributes(); - layout->SetWarningSuperpositionOfPieces(ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr)); - layout->SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr)); + layout->LayoutSettings().SetWarningSuperpositionOfPieces( + ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr)); + layout->LayoutSettings().SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr)); readElementText(); } @@ -154,7 +169,7 @@ void VPLayoutFileReader::ReadUnplacedPieces(VPLayout *layout) { AssertRootTag(ML::TagUnplacedPieces); - ReadPieceList(layout->GetUnplacedPieceList()); + ReadPieces(layout); } //--------------------------------------------------------------------------------------------------------------------- @@ -163,7 +178,7 @@ void VPLayoutFileReader::ReadTiles(VPLayout *layout) AssertRootTag(ML::TagTiles); QXmlStreamAttributes attribs = attributes(); - layout->SetShowTiles(ReadAttributeBool(attribs, ML::AttrVisible, falseStr)); + layout->LayoutSettings().SetShowTiles(ReadAttributeBool(attribs, ML::AttrVisible, falseStr)); // attribs.value(ML::AttrMatchingMarks); // TODO const QStringList tags @@ -177,10 +192,10 @@ void VPLayoutFileReader::ReadTiles(VPLayout *layout) switch (tags.indexOf(name().toString())) { case 0: // size - layout->SetTilesSize(ReadSize()); + layout->LayoutSettings().SetTilesSize(ReadSize()); break; case 1: // margin - layout->SetTilesMargins(ReadMargins()); + layout->LayoutSettings().SetTilesMargins(ReadMargins()); break; default: qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); @@ -211,14 +226,6 @@ void VPLayoutFileReader::ReadSheets(VPLayout *layout) } } -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutFileReader::ReadSheetPieces(VPSheet *sheet) -{ - AssertRootTag(ML::TagPieces); - - ReadPieceList(sheet->GetPieceList()); -} - //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileReader::ReadSheet(VPLayout *layout) { @@ -227,9 +234,7 @@ void VPLayoutFileReader::ReadSheet(VPLayout *layout) const QStringList tags { ML::TagName, // 0 - ML::TagSize, // 1 - ML::TagMargin, // 2 - ML::TagPieces // 3 + ML::TagPieces // 1 }; QScopedPointer sheet (new VPSheet(layout)); @@ -241,17 +246,11 @@ void VPLayoutFileReader::ReadSheet(VPLayout *layout) case 0: // name sheet->SetName(readElementText()); break; - case 1: // size - sheet->SetSheetSize(ReadSize()); - break; - case 2: // margin - sheet->SetSheetMargins(ReadMargins()); - break; - case 3: // pieces + case 1: // pieces #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) - ReadSheetPieces(sheet.get()); + ReadPieces(layout, sheet.get()); #else - ReadSheetPieces(sheet.data()); + ReadPieces(layout, sheet.data()); #endif break; default: @@ -268,19 +267,16 @@ void VPLayoutFileReader::ReadSheet(VPLayout *layout) //--------------------------------------------------------------------------------------------------------------------- -void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList) +void VPLayoutFileReader::ReadPieces(VPLayout *layout, VPSheet *sheet) { - QXmlStreamAttributes attribs = attributes(); - pieceList->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece List"))); - pieceList->SetIsVisible(ReadAttributeBool(attribs, ML::AttrVisible, trueStr)); - while (readNextStartElement()) { if (name() == ML::TagPiece) { QScopedPointerpiece(new VPPiece()); ReadPiece(piece.data()); - pieceList->AddPiece(piece.take()); + piece->SetSheet(sheet); + layout->AddPiece(piece.take()); } else { diff --git a/src/app/puzzle/xml/vplayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h index a7477ff4d..fdb8e9f74 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -32,7 +32,6 @@ #include #include "../ifc/xml/vabstractconverter.h" #include "vplayout.h" -#include "vppiecelist.h" #include "vppiece.h" #include @@ -57,9 +56,8 @@ private: void ReadTiles(VPLayout *layout); void ReadUnplacedPieces(VPLayout *layout); void ReadSheets(VPLayout *layout); - void ReadSheetPieces(VPSheet *sheet); void ReadSheet(VPLayout *layout); - void ReadPieceList(VPPieceList *pieceList); + void ReadPieces(VPLayout *layout, VPSheet *sheet=nullptr); void ReadPiece(VPPiece *piece); QMarginsF ReadMargins(); diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 2216f5df8..cb008a09d 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -29,7 +29,6 @@ #include "vplayoutfilewriter.h" #include "vplayout.h" #include "vpsheet.h" -#include "vppiecelist.h" #include "vppiece.h" #include "vplayoutliterals.h" #include "../ifc/xml/vlayoutconverter.h" @@ -57,7 +56,7 @@ void VPLayoutFileWriter::WriteLayout(VPLayout *layout) .arg(APP_VERSION_STR)); WriteProperties(layout); - WritePieceList(layout->GetUnplacedPieceList(), ML::TagUnplacedPieces); + WritePieceList(layout->GetUnplacedPieces(), ML::TagUnplacedPieces); WriteSheets(layout); writeEndElement(); //layout @@ -68,13 +67,15 @@ void VPLayoutFileWriter::WriteProperties(VPLayout *layout) { writeStartElement(ML::TagProperties); - writeTextElement(ML::TagUnit, UnitsToStr(layout->GetUnit())); - writeTextElement(ML::TagTitle, layout->GetTitle()); - writeTextElement(ML::TagDescription, layout->GetDescription()); + writeTextElement(ML::TagUnit, UnitsToStr(layout->LayoutSettings().GetUnit())); + writeTextElement(ML::TagTitle, layout->LayoutSettings().GetTitle()); + writeTextElement(ML::TagDescription, layout->LayoutSettings().GetDescription()); + WriteSize(layout->LayoutSettings().GetSheetSize()); + WriteMargins(layout->LayoutSettings().GetSheetMargins()); writeStartElement(ML::TagControl); - SetAttribute(ML::AttrWarningSuperposition, layout->GetWarningSuperpositionOfPieces()); - SetAttribute(ML::AttrWarningOutOfBound, layout->GetWarningPiecesOutOfBound()); + SetAttribute(ML::AttrWarningSuperposition, layout->LayoutSettings().GetWarningSuperpositionOfPieces()); + SetAttribute(ML::AttrWarningOutOfBound, layout->LayoutSettings().GetWarningPiecesOutOfBound()); writeEndElement(); // control WriteTiles(layout); @@ -102,9 +103,7 @@ void VPLayoutFileWriter::WriteSheet(VPSheet* sheet) writeStartElement(ML::TagSheet); writeTextElement(ML::TagName, sheet->GetName()); - WriteSize(sheet->GetSheetSize()); - WriteMargins(sheet->GetSheetMargins()); - WritePieceList(sheet->GetPieceList(), ML::TagPieces); + WritePieceList(sheet->GetPieces(), ML::TagPieces); writeEndElement(); // sheet @@ -116,26 +115,20 @@ void VPLayoutFileWriter::WriteTiles(VPLayout *layout) Q_UNUSED(layout); // to be removed writeStartElement(ML::TagTiles); - SetAttribute(ML::AttrVisible, layout->GetShowTiles()); + SetAttribute(ML::AttrVisible, layout->LayoutSettings().GetShowTiles()); SetAttribute(ML::AttrMatchingMarks, "standard"); // TODO / Fixme get the right value - WriteSize(layout->GetTilesSize()); - WriteMargins(layout->GetTilesMargins()); + WriteSize(layout->LayoutSettings().GetTilesSize()); + WriteMargins(layout->LayoutSettings().GetTilesMargins()); writeEndElement(); // tiles } //--------------------------------------------------------------------------------------------------------------------- -void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList, const QString &tagName) +void VPLayoutFileWriter::WritePieceList(const QList &list, const QString &tagName) { writeStartElement(tagName); // piece list - SetAttribute(ML::AttrName, pieceList->GetName()); - SetAttribute(ML::AttrVisible, pieceList->GetIsVisible()); - // TODO selected info. Not sure how it's saved yet - //SetAttribute("selected", pieceList->GetIsSelected()); - - QList pieces = pieceList->GetPieces(); - for (auto *piece : pieces) + for (auto *piece : list) { WritePiece(piece); } diff --git a/src/app/puzzle/xml/vplayoutfilewriter.h b/src/app/puzzle/xml/vplayoutfilewriter.h index 3e362a788..769b277dd 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.h +++ b/src/app/puzzle/xml/vplayoutfilewriter.h @@ -58,7 +58,7 @@ private: void WriteSheets(VPLayout *layout); void WriteSheet(VPSheet* sheet); void WriteTiles(VPLayout *layout); - void WritePieceList(VPPieceList *pieceList, const QString &tagName); + void WritePieceList(const QList &list, const QString &tagName); void WritePiece(VPPiece *piece); void WriteMargins(const QMarginsF &margins);