diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index cfee78a09..e07037c56 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -27,6 +27,8 @@ *************************************************************************/ #include "vpgraphicssheet.h" +#include "vplayout.h" +#include //--------------------------------------------------------------------------------------------------------------------- VPGraphicsSheet::VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent): @@ -68,6 +70,66 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->drawRect(GetSheetRect()); } + // show the tiles grid. Maybe it shouldn't be in the graphics sheet, maybe better in maingraphicsview + VPLayout* layout = m_sheet->GetLayout(); + if(layout->GetShowTiles()) + { + pen.setColor(QColor(255,0,0,127)); + pen.setStyle(Qt::DashLine); + painter->setPen(pen); + + QSizeF tilesSize = layout->GetTilesSize(); + QSizeF sheetSize = m_sheet->GetSheetSize(); + + QMarginsF tilesMargins = layout->GetTilesMargins(); + + PageOrientation tilesOrientation = layout->GetTilesOrientation(); + PageOrientation sheetOrientation = m_sheet->GetOrientation(); + + qreal colWidth = 0; + qreal rowHeight = 0; + if(tilesOrientation == PageOrientation::Portrait) + { + colWidth = tilesSize.width() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px)); + rowHeight = tilesSize.height() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px)); + } + else + { + colWidth = tilesSize.height() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px)); + rowHeight = tilesSize.width() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px)); + } + // the "+ UnitConvertor(1, Unit::Cm, Unit::Px)" is because of the part for gluing and where we + // have infos of the single tile. Maybe it's not the right value, to be corrected. + + + qreal drawingWidth = 0; + qreal drawingHeight = 0; + + if(sheetOrientation == PageOrientation::Portrait) + { + drawingWidth = sheetSize.width(); + drawingHeight = sheetSize.height(); + } + else + { + drawingWidth = sheetSize.height(); + drawingHeight = sheetSize.width(); + } + + int nbCol = qCeil(drawingWidth/colWidth); + int nbRow = qCeil(drawingHeight/rowHeight); + + for(int i=0;i<=nbCol;i++) + { + painter->drawLine(QPointF(i*colWidth, 0), QPointF(i*colWidth,nbRow*rowHeight)); + } + + for(int j=0;j<=nbRow;j++) + { + painter->drawLine(QPointF(0, j*rowHeight), QPointF(nbCol*colWidth, j*rowHeight)); + } + } + m_boundingRect = GetSheetRect(); } diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 4c838f9fd..6e63b4643 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -84,8 +84,14 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene() //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::PrepareForExport() { + m_layout->ClearSelection(); + m_graphicsSheet->SetShowBorder(false); m_graphicsSheet->SetShowMargin(false); + + m_showTilesTmp = m_layout->GetShowTiles(); + m_layout->SetShowTiles(false); + RefreshLayout(); } @@ -94,6 +100,9 @@ void VPMainGraphicsView::CleanAfterExport() { m_graphicsSheet->SetShowBorder(true); m_graphicsSheet->SetShowMargin(true); + + m_layout->SetShowTiles(m_showTilesTmp); + RefreshLayout(); } diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index 94d52e1b5..5641bf2d2 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -99,6 +99,11 @@ private: QList m_graphicsPieces{}; + /** + * variable to hold temporarly hte value of the show tiles + */ + bool m_showTilesTmp{false}; + }; #endif // VPMAINGRAPHICSVIEW_H diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index b6de14936..9b4a182d2 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -318,23 +318,23 @@ void VPMainWindow::InitPropertyTabCurrentSheet() void VPMainWindow::InitPropertyTabTiles() { // -------------------- layout width, length, orientation ------------------------ - connect(ui->doubleSpinBoxSheetWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesSizeChanged); - connect(ui->doubleSpinBoxSheetLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesSizeChanged); - connect(ui->radioButtonSheetPortrait, QOverload::of(&QRadioButton::clicked), this, + connect(ui->radioButtonTilesPortrait, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_TilesOrientationChanged); - connect(ui->radioButtonSheetLandscape, QOverload::of(&QRadioButton::clicked), this, + connect(ui->radioButtonTilesLandscape, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_TilesOrientationChanged); // -------------------- margins ------------------------ - connect(ui->doubleSpinBoxSheetMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); - connect(ui->doubleSpinBoxSheetMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); - connect(ui->doubleSpinBoxSheetMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); - connect(ui->doubleSpinBoxSheetMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); } @@ -1021,7 +1021,7 @@ void VPMainWindow::on_TilesOrientationChanged() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_TilesMarginChanged() { - m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + m_layout->SetTilesMarginsConverted( ui->doubleSpinBoxTilesMarginLeft->value(), ui->doubleSpinBoxTilesMarginTop->value(), ui->doubleSpinBoxTilesMarginRight->value(), @@ -1034,7 +1034,6 @@ void VPMainWindow::on_TilesMarginChanged() } - //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) { @@ -1045,6 +1044,36 @@ void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) m_graphicsView->RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_pushButtonTilesExport_clicked() +{ + // svg export to do some test for the first test + + QString dir = QDir::homePath(); + QString filters(tr("PDF Files") + QLatin1String("(*.pdf)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), + dir + QLatin1String("/") + tr("Layout") + QLatin1String(".pdf"), + filters, nullptr +#ifdef Q_OS_LINUX + , QFileDialog::DontUseNativeDialog +#endif + ); + + if(not fileName.isEmpty()) + { + m_graphicsView->PrepareForExport(); + + + + // TODO : Tiles export + + + + m_graphicsView->CleanAfterExport(); + } +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetFollowGrainlineChanged() diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index d01c7b447..dc1145e26 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -349,6 +349,10 @@ private slots: */ void on_checkBoxTilesShowTiles_toggled(bool checked); + /** + * @brief on_pushButtonTilesExport_clicked When the export tiles button is clicked + */ + void on_pushButtonTilesExport_clicked(); /** * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 3941db274..6e7a241c5 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1106,10 +1106,18 @@ - + + + 0.100000000000000 + + - + + + 0.100000000000000 + + @@ -1122,7 +1130,11 @@ - + + + 0.100000000000000 + + @@ -1135,7 +1147,11 @@ - + + + 0.100000000000000 + + diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index 591194813..e1f6cb501 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -43,6 +43,12 @@ VPSheet::~VPSheet() delete m_pieceList; } +//--------------------------------------------------------------------------------------------------------------------- +VPLayout* VPSheet::GetLayout() +{ + return m_layout; +} + //--------------------------------------------------------------------------------------------------------------------- VPPieceList* VPSheet::GetPieceList() { diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h index 47c62d819..2e49acaf3 100644 --- a/src/app/puzzle/vpsheet.h +++ b/src/app/puzzle/vpsheet.h @@ -49,6 +49,12 @@ public: ~VPSheet(); + /** + * @brief GetLayout Returns the Layout of the sheet + * @return + */ + VPLayout* GetLayout(); + /** * @brief GetPieceList returns the piece list of the sheet * @return piece list @@ -203,6 +209,7 @@ public: void SetStickyEdges(bool state); bool GetStickyEdges() const; + private: Q_DISABLE_COPY(VPSheet)