diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index a1983ed7d..4f02469f2 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -88,14 +88,14 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : ui->setupUi(this); - InitMenuBar(); - InitProperties(); - InitCarrousel(); - // init the tile factory m_tileFactory = new VPTileFactory(m_layout, qApp->Settings()); m_tileFactory->refreshTileInfos(); + InitMenuBar(); + InitProperties(); + InitCarrousel(); + InitMainGraphics(); InitZoomToolBar(); @@ -314,11 +314,33 @@ void VPMainWindow::InitPropertyTabCurrentSheet() connect(ui->radioButtonSheetFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_SheetFollowGrainlineChanged); - // -------------------- export --------------------------- + // -------------------- sheet template --------------------------- - // TODO init the file format export combobox + // FIXME: find a nicer way to initiliase it + QVector sheetTemplates = QVector(); + sheetTemplates.append(PaperSizeTemplate::A0); + sheetTemplates.append(PaperSizeTemplate::A1); + sheetTemplates.append(PaperSizeTemplate::A2); + sheetTemplates.append(PaperSizeTemplate::A3); + sheetTemplates.append(PaperSizeTemplate::A4); + sheetTemplates.append(PaperSizeTemplate::Letter); + sheetTemplates.append(PaperSizeTemplate::Legal); + sheetTemplates.append(PaperSizeTemplate::Tabloid); + sheetTemplates.append(PaperSizeTemplate::Roll24in); + sheetTemplates.append(PaperSizeTemplate::Roll30in); + sheetTemplates.append(PaperSizeTemplate::Roll36in); + sheetTemplates.append(PaperSizeTemplate::Roll42in); + sheetTemplates.append(PaperSizeTemplate::Roll44in); + sheetTemplates.append(PaperSizeTemplate::Roll48in); + sheetTemplates.append(PaperSizeTemplate::Roll62in); + sheetTemplates.append(PaperSizeTemplate::Roll72in); + sheetTemplates.append(PaperSizeTemplate::Custom); + ui->comboBoxSheetTemplate->blockSignals(true); + VPSheet::PopulateComboBox(&sheetTemplates, ui->comboBoxSheetTemplate); + ui->comboBoxSheetTemplate->blockSignals(false); + ui->comboBoxSheetTemplate->setCurrentIndex(0); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,6 +356,24 @@ void VPMainWindow::InitPropertyTabTiles() connect(ui->radioButtonTilesLandscape, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_TilesOrientationChanged); + // -------------------- tiles template + QVector tilesTemplates = QVector(); + tilesTemplates.append(PaperSizeTemplate::A0); + tilesTemplates.append(PaperSizeTemplate::A1); + tilesTemplates.append(PaperSizeTemplate::A2); + tilesTemplates.append(PaperSizeTemplate::A3); + tilesTemplates.append(PaperSizeTemplate::A4); + tilesTemplates.append(PaperSizeTemplate::Letter); + tilesTemplates.append(PaperSizeTemplate::Legal); + tilesTemplates.append(PaperSizeTemplate::Custom); + + ui->comboBoxTilesTemplate->blockSignals(true); + VPSheet::PopulateComboBox(&tilesTemplates, ui->comboBoxTilesTemplate); + ui->comboBoxTilesTemplate->blockSignals(false); + + ui->comboBoxTilesTemplate->setCurrentIndex(4); //A4 + + // -------------------- margins ------------------------ connect(ui->doubleSpinBoxTilesMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); @@ -1004,26 +1044,46 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO VPMainWindow::SheetTemplateChanged"); - int ret = msgBox.exec(); + PaperSizeTemplate tmpl = static_cast( + ui->comboBoxSheetTemplate->itemData(index).toInt() + ); - Q_UNUSED(index); - Q_UNUSED(ret); + QSizeF tmplSize = VPSheet::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())); - // TODO + on_SheetSizeChanged(false); + + ui->doubleSpinBoxSheetWidth->blockSignals(false); + ui->doubleSpinBoxSheetLength->blockSignals(false); + } } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_SheetSizeChanged() +void VPMainWindow::on_SheetSizeChanged(bool changedViaSizeCombobox) { m_layout->GetFocusedSheet()->SetSheetSizeConverted( ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value() ); + if(changedViaSizeCombobox) + { + ui->comboBoxSheetTemplate->blockSignals(true); + + // we don't try to get the right size, because it doesn't work well because of mm / inch conversion + int index = ui->comboBoxSheetTemplate->findData( + QVariant(static_cast(PaperSizeTemplate::Custom))); + + ui->comboBoxSheetTemplate->setCurrentIndex(index); + ui->comboBoxSheetTemplate->blockSignals(false); + } + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1079,16 +1139,53 @@ void VPMainWindow::on_SheetMarginChanged() m_graphicsView->RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_comboBoxTilesTemplate_currentIndexChanged(int index) +{ + PaperSizeTemplate tmpl = static_cast( + ui->comboBoxTilesTemplate->itemData(index).toInt() + ); + + QSizeF tmplSize = VPSheet::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())); + + on_TilesSizeChanged(false); + + ui->doubleSpinBoxTilesWidth->blockSignals(false); + ui->doubleSpinBoxTilesLength->blockSignals(false); + } +} //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_TilesSizeChanged() +void VPMainWindow::on_TilesSizeChanged(bool changedViaSizeCombobox) { m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value()); m_tileFactory->refreshTileInfos(); + if(changedViaSizeCombobox) + { + ui->comboBoxTilesTemplate->blockSignals(true); + + // we don't try to get the right size, because it doesn't work well because of mm / inch conversion + int index = ui->comboBoxTilesTemplate->findData( + QVariant(static_cast(PaperSizeTemplate::Custom))); + + ui->comboBoxTilesTemplate->setCurrentIndex(index); + ui->comboBoxTilesTemplate->blockSignals(false); + } + // TODO Undo / Redo - m_graphicsView->RefreshLayout(); + if(m_graphicsView != nullptr) + { + m_graphicsView->RefreshLayout(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 462e8a8bf..72287ecfa 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -287,7 +287,7 @@ private slots: /** * @brief on_comboBoxLayoutTemplate_currentIndexChanged When the template is - * changed in the layout property tab. + * changed in the sheet property tab. * The slot is automatically connected through name convention. * @param index the index of the selected templated */ @@ -296,8 +296,9 @@ private slots: /** * @brief on_SheetSizeChanged When the width or the length has been changed in * the sheet property tab + * @param changedViaSizeCombobox true if the change happened through the combobox */ - void on_SheetSizeChanged(); + void on_SheetSizeChanged(bool changedViaSizeCombobox = true); /** * @brief on_SheetOrientationChanged When one of the radio boxes for the sheet @@ -332,12 +333,20 @@ private slots: */ void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); + /** + * @brief on_comboBoxTilesTemplate_currentIndexChanged When the template is + * changed in the tiles property tab. + * The slot is automatically connected through name convention. + * @param index the index of the selected templated + */ + void on_comboBoxTilesTemplate_currentIndexChanged(int index); /** * @brief on_TilesSizeChanged When the width or the length has been changed in * the tiles property tab + * @param changedViaSizeCombobox true if the change happened through the combobox */ - void on_TilesSizeChanged(); + void on_TilesSizeChanged(bool changedViaSizeCombobox = true); /** * @brief on_TilesOrientationChanged When one of the radio boxes for the tiles diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 7e875e3d6..0951bd143 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 3 + 2 @@ -632,6 +632,9 @@ + + 2 + 100000.000000000000000 @@ -646,6 +649,9 @@ + + 2 + 100000.000000000000000 @@ -1006,42 +1012,42 @@ - + Width - + 100000.000000000000000 - + Length - + 100000.000000000000000 - + Orientation - + @@ -1082,6 +1088,16 @@ + + + + Template + + + + + + diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index e1f6cb501..475584860 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -43,6 +43,217 @@ 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) +{ + switch (tmpl) + { + case PaperSizeTemplate::A0: + return QString("A0"); + + case PaperSizeTemplate::A1: + return QString("A1"); + + case PaperSizeTemplate::A2: + return QString("A2"); + + case PaperSizeTemplate::A3: + return QString("A3"); + + case PaperSizeTemplate::A4: + return QString("A4"); + + case PaperSizeTemplate::Letter: + return tr("Letter"); + + case PaperSizeTemplate::Legal: + return tr("Legal"); + + case PaperSizeTemplate::Tabloid: + return tr("Tabloid"); + + case PaperSizeTemplate::Roll24in: + return tr("Roll 24in"); + + case PaperSizeTemplate::Roll30in: + return tr("Roll 30in"); + + case PaperSizeTemplate::Roll36in: + return tr("Roll 36in"); + + case PaperSizeTemplate::Roll42in: + return tr("Roll 42in"); + + case PaperSizeTemplate::Roll44in: + return tr("Roll 44in"); + + case PaperSizeTemplate::Roll48in: + return tr("Roll 48in"); + + case PaperSizeTemplate::Roll62in: + return tr("Roll 62in"); + + case PaperSizeTemplate::Roll72in: + return tr("Roll 72in"); + + case PaperSizeTemplate::Custom: + return tr("Custom"); + + default: + break; + } + + return QString(""); +} + +//--------------------------------------------------------------------------------------------------------------------- +PaperSizeTemplate VPSheet::GetTemplate(QSizeF size) +{ + 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) +{ + for (auto tmpl : *tmpls) + { + comboBox->addItem(GetTemplateName(tmpl), QVariant(static_cast(tmpl))); + } +} + //--------------------------------------------------------------------------------------------------------------------- VPLayout* VPSheet::GetLayout() { diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h index 2e49acaf3..39fa05268 100644 --- a/src/app/puzzle/vpsheet.h +++ b/src/app/puzzle/vpsheet.h @@ -32,11 +32,36 @@ #include #include #include +#include #include "def.h" // is this the right place for the definition? -enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; +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; @@ -45,10 +70,47 @@ class VPSheet : public QObject { Q_OBJECT public: + + explicit VPSheet(VPLayout* layout); ~VPSheet(); + /** + * @brief GetTemplateSize Returns the size in Px of the given template + * @param tmpl + * @return the size in Px + */ + static QSizeF GetTemplateSize(PaperSizeTemplate tmpl); + + /** + * @brief GetTemplateName Returns the name of the given template + * @param tmpl + * @return + */ + static QString GetTemplateName(PaperSizeTemplate tmpl); + + /** + * @brief GetTemplate GetTemplate Returns the template that corresponds to the given size + * @param size the Size in Px + * @return + */ + static PaperSizeTemplate GetTemplate(QSizeF size); + + /** + * @brief PopulateComboBox Populates the given combo with the given templates + * @param tmpls + * @param comboBox + */ + static void PopulateComboBox(QVector *tmpls, QComboBox* comboBox); + + /** + * @brief isRollTemplate Returns wether the given template is a roll or not. + * @param tmpl + * @return + */ + static bool isRollTemplate(PaperSizeTemplate tmpl); + /** * @brief GetLayout Returns the Layout of the sheet * @return diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 1f3cd73c6..a243fa857 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -25,40 +25,43 @@ VPTileFactory::~VPTileFactory() //--------------------------------------------------------------------------------------------------------------------- void VPTileFactory::refreshTileInfos() { - PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); - QSizeF tilesSize = m_layout->GetTilesSize(); - QMarginsF tilesMargins = m_layout->GetTilesMargins(); - - // sets the drawing height - m_drawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.height() : tilesSize.width(); - m_drawingAreaHeight -= - tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth; - - // sets the drawing width - m_drawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.width() : tilesSize.height(); - m_drawingAreaWidth -= - tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth; - - - QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); - qreal totalDrawingWidth = 0; - qreal totaldrawingHeight = 0; - - if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + if(m_layout != nullptr) { - totalDrawingWidth = sheetSize.width(); - totaldrawingHeight = sheetSize.height(); - } - else - { - totalDrawingWidth = sheetSize.height(); - totaldrawingHeight = sheetSize.width(); - } + PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); + QSizeF tilesSize = m_layout->GetTilesSize(); + QMarginsF tilesMargins = m_layout->GetTilesMargins(); - m_nbCol = qCeil(totalDrawingWidth/m_drawingAreaWidth); - m_nbRow = qCeil(totaldrawingHeight/m_drawingAreaHeight); + // sets the drawing height + m_drawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.height() : tilesSize.width(); + m_drawingAreaHeight -= + tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth; + + // sets the drawing width + m_drawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.width() : tilesSize.height(); + m_drawingAreaWidth -= + tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth; + + + QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); + qreal totalDrawingWidth = 0; + qreal totaldrawingHeight = 0; + + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + { + totalDrawingWidth = sheetSize.width(); + totaldrawingHeight = sheetSize.height(); + } + else + { + totalDrawingWidth = sheetSize.height(); + totaldrawingHeight = sheetSize.width(); + } + + m_nbCol = qCeil(totalDrawingWidth/m_drawingAreaWidth); + m_nbRow = qCeil(totaldrawingHeight/m_drawingAreaHeight); + } }