diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index 6f14c4cae..6744850d1 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -230,3 +230,120 @@ VPSheet* VPLayout::GetFocusedSheet() { return m_focusedSheet; } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSize(qreal width, qreal height) +{ + m_tilesSize.setWidth(width); + m_tilesSize.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSizeConverted(qreal width, qreal height) +{ + m_tilesSize.setWidth(UnitConvertor(width, GetUnit(), Unit::Px)); + m_tilesSize.setHeight(UnitConvertor(height, GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSize(const QSizeF &size) +{ + m_tilesSize = 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::GetTilesSizeConverted() const +{ + QSizeF convertedSize = QSizeF( + UnitConvertor(m_tilesSize.width(), Unit::Px, GetUnit()), + UnitConvertor(m_tilesSize.height(), Unit::Px, GetUnit()) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +PageOrientation VPLayout::GetTilesOrientation() +{ + return m_tilesOrientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesOrientation(PageOrientation orientation) +{ + if(orientation != m_tilesOrientation) + { + m_tilesOrientation = orientation; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +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::GetTilesMarginsConverted() const +{ + return UnitConvertor(m_tilesMargins, Unit::Px, GetUnit()); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPLayout::GetShowTiles() +{ + return m_showTiles; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetShowTiles(bool value) +{ + m_showTiles = value; +} diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index 17a529a9b..144578b46 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -138,6 +138,111 @@ public: VPSheet* GetFocusedSheet(); + /** + * @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 sheet 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 sheet size + */ + void SetTilesSizeConverted(const QSizeF &size); + + /** + * @brief GetTilesSize Returns the size of the tiles in Unit::Px + * @return sheet size in Unit::Px + */ + QSizeF GetTilesSize() 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 size in Unit::Px + */ + QMarginsF GetTilesMargins() 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 + */ + 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); @@ -169,6 +274,23 @@ private: 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}; }; #endif // VPLAYOUT_H diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 8ed52ad0e..b6de14936 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -78,6 +78,12 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : m_layout->SetWarningSuperpositionOfPieces(true); m_layout->SetTitle(QString("My Test Layout")); m_layout->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); + // -------------------------------------------------------- ui->setupUi(this); @@ -269,27 +275,6 @@ void VPMainWindow::InitPropertyTabCurrentSheet() // FIXME ---- For MVP we hide a few things. To be displayed when functions there ui->pushButtonSheetRemoveUnusedLength->hide(); ui->groupBoxSheetControl->hide(); -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::InitPropertyTabLayout() -{ - - // FIXME ---- For MVP we hide a few things. To be displayed when functions there - ui->groupBoxLayoutControl->hide(); - - // -------------------- init the unit combobox --------------------- - ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); - ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); - ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch))); - - // set default unit - TODO when we have the setting for the unit -// const qint32 indexUnit = -1;//ui->comboBoxLayoutUnit->findData(qApp->ValentinaSettings()->GetUnit()); -// if (indexUnit != -1) -// { -// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); -// } // some of the UI Elements are connected to the slots via auto-connect // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect @@ -326,14 +311,52 @@ void VPMainWindow::InitPropertyTabLayout() // TODO init the file format export combobox + } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitPropertyTabTiles() { - // for the MVP we don't want the tiles tab. - // we remove it. As soon as we need it, update this code - ui->tabWidgetProperties->removeTab(2); // remove tiles + // -------------------- layout width, length, orientation ------------------------ + connect(ui->doubleSpinBoxSheetWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesSizeChanged); + connect(ui->doubleSpinBoxSheetLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesSizeChanged); + connect(ui->radioButtonSheetPortrait, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_TilesOrientationChanged); + connect(ui->radioButtonSheetLandscape, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_TilesOrientationChanged); + + // -------------------- margins ------------------------ + connect(ui->doubleSpinBoxSheetMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); + connect(ui->doubleSpinBoxSheetMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); + connect(ui->doubleSpinBoxSheetMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); + connect(ui->doubleSpinBoxSheetMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitPropertyTabLayout() +{ + + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->groupBoxLayoutControl->hide(); + + // -------------------- init the unit combobox --------------------- + ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); + ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); + ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch))); + + // set default unit - TODO when we have the setting for the unit +// const qint32 indexUnit = -1;//ui->comboBoxLayoutUnit->findData(qApp->ValentinaSettings()->GetUnit()); +// if (indexUnit != -1) +// { +// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); +// } } //--------------------------------------------------------------------------------------------------------------------- @@ -423,7 +446,7 @@ void VPMainWindow::SetPropertyTabSheetData() SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height()); // Set Orientation - if(size.width() <= size.height()) + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) { ui->radioButtonSheetPortrait->setChecked(true); } @@ -446,6 +469,36 @@ void VPMainWindow::SetPropertyTabSheetData() SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); } + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::SetPropertyTabTilesData() +{ + // set Width / Length + QSizeF size = m_layout->GetTilesSizeConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesWidth, size.width()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesLength, size.height()); + + // Set Orientation + if(m_layout->GetTilesOrientation() == PageOrientation::Portrait) + { + ui->radioButtonSheetPortrait->setChecked(true); + } + else + { + ui->radioButtonSheetLandscape->setChecked(true); + } + + // set margins + QMarginsF margins = m_layout->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 + ui->checkBoxTilesShowTiles->setChecked(m_layout->GetShowTiles()); +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabLayoutData() { @@ -467,11 +520,7 @@ void VPMainWindow::SetPropertyTabLayoutData() SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); } -//--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::SetPropertyTabTilesData() -{ -// TODO -} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitMainGraphics() @@ -941,6 +990,62 @@ void VPMainWindow::on_SheetMarginChanged() } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_TilesSizeChanged() +{ + m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value()); + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_TilesOrientationChanged() +{ + // Updates the orientation + if(ui->radioButtonTilesPortrait->isChecked()) + { + m_layout->SetTilesOrientation(PageOrientation::Portrait); + } + else + { + m_layout->SetTilesOrientation(PageOrientation::Landscape); + } + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_TilesMarginChanged() +{ + m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + ui->doubleSpinBoxTilesMarginLeft->value(), + ui->doubleSpinBoxTilesMarginTop->value(), + ui->doubleSpinBoxTilesMarginRight->value(), + ui->doubleSpinBoxTilesMarginBottom->value() + ); + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + + + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) +{ + m_layout->SetShowTiles(checked); + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetFollowGrainlineChanged() { diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 43a40f07a..d01c7b447 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -285,33 +285,33 @@ private slots: void on_comboBoxSheetTemplate_currentIndexChanged(int index); /** - * @brief LayoutSizeChanged When the width or the length has been changed in - * the layout property tab + * @brief on_SheetSizeChanged When the width or the length has been changed in + * the sheet property tab */ void on_SheetSizeChanged(); /** - * @brief LayoutOrientationChanged When one of the radio boxes for the layout + * @brief on_SheetOrientationChanged When one of the radio boxes for the sheet * orientation has been clicked */ void on_SheetOrientationChanged(); /** * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button - * "Remove unused length" in the layout property tab is clicked. + * "Remove unused length" in the sheet property tab is clicked. * The slot is automatically connected through name convention. */ void on_pushButtonSheetRemoveUnusedLength_clicked(); /** - * @brief on_LayoutMarginChanged When one of the margin values has been changed - * in the layout property tab. + * @brief on_SheetMarginChanged When one of the margin values has been changed + * in the sheet property tab. */ void on_SheetMarginChanged(); /** * @brief LayoutFollowGrainlineChanged When one of the radio boxes for the - * "Follow grainline" has been clicked in the layout property tab. + * "Follow grainline" has been clicked in the sheet property tab. */ void on_SheetFollowGrainlineChanged(); @@ -323,6 +323,33 @@ private slots: */ void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); + + /** + * @brief on_TilesSizeChanged When the width or the length has been changed in + * the tiles property tab + */ + void on_TilesSizeChanged(); + + /** + * @brief on_TilesOrientationChanged When one of the radio boxes for the tiles + * orientation has been clicked + */ + void on_TilesOrientationChanged(); + + /** + * @brief on_TilesMarginChanged When one of the margin values has been changed + * in the tiles property tab. + */ + void on_TilesMarginChanged(); + + /** + * @brief on_checkBoxTilesShowTiles_toggled When the checkbox "show tiles" is + * clicked + * @param checkedĀ“ + */ + void on_checkBoxTilesShowTiles_toggled(bool checked); + + /** * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the * "Warning when pieces superposition" checkbox value in the layout diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 68adf8583..3941db274 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 1 + 2 @@ -530,7 +530,7 @@ - Layout properties + Sheet properties @@ -1199,6 +1199,9 @@ + + Layout properties + 0