diff --git a/src/app/puzzle/carousel/vpmimedatapiece.h b/src/app/puzzle/carousel/vpmimedatapiece.h index 9ad6e6338..68e794b1a 100644 --- a/src/app/puzzle/carousel/vpmimedatapiece.h +++ b/src/app/puzzle/carousel/vpmimedatapiece.h @@ -30,6 +30,7 @@ #define VPMIMEDATAPIECE_H #include +#include #include "../layout/layoutdef.h" @@ -62,7 +63,7 @@ public: private: Q_DISABLE_COPY(VPMimeDataPiece) - VPPiecePtr m_piece{}; + VPPieceWeakPtr m_piece{}; }; #endif // VPMIMEDATAPIECE_H diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp index f5c06d700..094f64011 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp @@ -43,14 +43,44 @@ PuzzlePreferencesConfigurationPage::PuzzlePreferencesConfigurationPage(QWidget * m_langChanged = true; }); + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + // Theme - ui->darkModeCheck->setChecked(VPApplication::VApp()->PuzzleSettings()->GetDarkMode()); + ui->darkModeCheck->setChecked(settings->GetDarkMode()); // Native dialogs - ui->checkBoxDontUseNativeDialog->setChecked(VPApplication::VApp()->PuzzleSettings()->IsDontUseNativeDialog()); + ui->checkBoxDontUseNativeDialog->setChecked(settings->IsDontUseNativeDialog()); //----------------------- Toolbar - ui->toolBarStyleCheck->setChecked(VPApplication::VApp()->PuzzleSettings()->GetToolBarStyle()); + ui->toolBarStyleCheck->setChecked(settings->GetToolBarStyle()); + + // Undo + ui->undoCount->setValue(settings->GetUndoCount()); + + //Graphical output + ui->graphOutputCheck->setChecked(settings->GetGraphicalOutput()); + ui->checkBoxOpenGLRender->setChecked(settings->IsOpenGLRender()); + + // Tab Scrolling + ui->spinBoxDuration->setMinimum(VCommonSettings::scrollingDurationMin); + ui->spinBoxDuration->setMaximum(VCommonSettings::scrollingDurationMax); + ui->spinBoxDuration->setValue(settings->GetScrollingDuration()); + + ui->spinBoxUpdateInterval->setMinimum(VCommonSettings::scrollingUpdateIntervalMin); + ui->spinBoxUpdateInterval->setMaximum(VCommonSettings::scrollingUpdateIntervalMax); + ui->spinBoxUpdateInterval->setValue(settings->GetScrollingUpdateInterval()); + + ui->doubleSpinBoxSensor->setMinimum(VCommonSettings::sensorMouseScaleMin); + ui->doubleSpinBoxSensor->setMaximum(VCommonSettings::sensorMouseScaleMax); + ui->doubleSpinBoxSensor->setValue(settings->GetSensorMouseScale()); + + ui->doubleSpinBoxWheel->setMinimum(VCommonSettings::wheelMouseScaleMin); + ui->doubleSpinBoxWheel->setMaximum(VCommonSettings::wheelMouseScaleMax); + ui->doubleSpinBoxWheel->setValue(settings->GetWheelMouseScale()); + + ui->doubleSpinBoxAcceleration->setMinimum(VCommonSettings::scrollingAccelerationMin); + ui->doubleSpinBoxAcceleration->setMaximum(VCommonSettings::scrollingAccelerationMax); + ui->doubleSpinBoxAcceleration->setValue(settings->GetScrollingAcceleration()); } //--------------------------------------------------------------------------------------------------------------------- @@ -60,7 +90,7 @@ PuzzlePreferencesConfigurationPage::~PuzzlePreferencesConfigurationPage() } //--------------------------------------------------------------------------------------------------------------------- -QStringList PuzzlePreferencesConfigurationPage::Apply() +auto PuzzlePreferencesConfigurationPage::Apply() -> QStringList { QStringList preferences; VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); @@ -88,6 +118,35 @@ QStringList PuzzlePreferencesConfigurationPage::Apply() qApp->processEvents();// force to call changeEvent } + /* Maximum number of commands in undo stack may only be set when the undo stack is empty, since setting it on a + * non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack + * prints a warning and does nothing.*/ + if (settings->GetUndoCount() != ui->undoCount->value()) + { + preferences.append(tr("undo limit")); + settings->SetUndoCount(ui->undoCount->value()); + } + + // Scene antialiasing + if (settings->GetGraphicalOutput() != ui->graphOutputCheck->isChecked()) + { + preferences.append(tr("antialiasing")); + settings->SetGraphicalOutput(ui->graphOutputCheck->isChecked()); + } + + if (settings->IsOpenGLRender() != ui->checkBoxOpenGLRender->isChecked()) + { + preferences.append(tr("scene render")); + settings->SetOpenGLRender(ui->checkBoxOpenGLRender->isChecked()); + } + + // Tab Scrolling + settings->SetScrollingDuration(ui->spinBoxDuration->value()); + settings->SetScrollingUpdateInterval(ui->spinBoxUpdateInterval->value()); + settings->SetSensorMouseScale(ui->doubleSpinBoxSensor->value()); + settings->SetWheelMouseScale(ui->doubleSpinBoxWheel->value()); + settings->SetScrollingAcceleration(ui->doubleSpinBoxAcceleration->value()); + return preferences; } diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui index 7f10c762d..35b7e19a7 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.ui @@ -6,8 +6,8 @@ 0 0 - 505 - 548 + 702 + 741 @@ -15,97 +15,365 @@ - - - true + + + 0 - - - - 0 - 0 - 494 - 514 - - + + + General + - - - Language + + + true - - - QFormLayout::ExpandingFieldsGrow + + + + 0 + 0 + 660 + 672 + - - - - GUI language: - - - - - - - + + + + + Language + + + + QFormLayout::ExpandingFieldsGrow + + + + + GUI language: + + + + + + + + + + + + + Toolbar + + + + + + The text appears under the icon (recommended for beginners). + + + true + + + + + + + + + + User Interface + + + + + + Activate dark mode + + + + + + + Don't use the native file dialog + + + + + + + + + + Graphical output + + + + + + Use antialiasing + + + + + + + Use OpenGL to render a scene. +This option will take an affect after restart. + + + Use OpenGL render + + + false + + + + + + + + + + Undo + + + + QFormLayout::ExpandingFieldsGrow + + + + + Count steps (0 - no limit): + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Scrolling + + - - - Toolbar + + + true - - - - - The text appears under the icon (recommended for beginners). - - - true - - - - + + + + 0 + 0 + 660 + 672 + + + + + + + Animation + + + + QFormLayout::ExpandingFieldsGrow + + + + + Duration: + + + + + + + Scrolling animation duration + + + ms + + + 100 + + + 1000 + + + 300 + + + + + + + Update interval: + + + + + + + Time in milliseconds between each animation update + + + ms + + + 10 + + + 100 + + + 30 + + + + + + + + + + Mouse scale + + + + QFormLayout::ExpandingFieldsGrow + + + + + Sensor: + + + + + + + Scale scrolling sensitivity for mouse with sensor + + + 1.000000000000000 + + + 10.000000000000000 + + + 0.100000000000000 + + + 2.000000000000000 + + + + + + + Wheel: + + + + + + + Scale scrolling sensitivity for mouse with wheel + + + 1.000000000000000 + + + 100.000000000000000 + + + 0.100000000000000 + + + 45.000000000000000 + + + + + + + + + + Scrolling + + + + QFormLayout::ExpandingFieldsGrow + + + + + Acceleration: + + + + + + + 1.000000000000000 + + + 10.000000000000000 + + + 0.100000000000000 + + + 1.300000000000000 + + + + + + + + + + Qt::Vertical + + + + 20 + 359 + + + + + + - - - - User Interface - - - - - - Activate dark mode - - - - - - - Don't use the native file dialog - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp new file mode 100644 index 000000000..4695a6848 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp @@ -0,0 +1,657 @@ +/************************************************************************ + ** + ** @file puzzlepreferenceslayoutpage.cpp + ** @author Roman Telezhynskyi + ** @date 20 8, 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 "puzzlepreferenceslayoutpage.h" +#include "ui_puzzlepreferenceslayoutpage.h" +#include "vpapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +PuzzlePreferencesLayoutPage::PuzzlePreferencesLayoutPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::PuzzlePreferencesLayoutPage) +{ + ui->setupUi(this); + + VPApplication::VApp()->PuzzleSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + + InitLayoutUnits(); + VAbstractLayoutDialog::InitTemplates(ui->comboBoxSheetTemplates); + VAbstractLayoutDialog::InitTemplates(ui->comboBoxTileTemplates); + MinimumSheetPaperSize(); + MinimumTilePaperSize(); + + ReadSettings(); + + connect(ui->comboBoxLayoutUnit, QOverload::of(&QComboBox::currentIndexChanged), + this, &PuzzlePreferencesLayoutPage::ConvertPaperSize); + + connect(ui->comboBoxSheetTemplates, QOverload::of(&QComboBox::currentIndexChanged), + this, [this]{SheetSize(SheetTemplate());}); + connect(ui->comboBoxTileTemplates, QOverload::of(&QComboBox::currentIndexChanged), + this, [this]{TileSize(TileTemplate());}); + + connect(ui->doubleSpinBoxSheetPaperWidth, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::SheetPaperSizeChanged); + connect(ui->doubleSpinBoxSheetPaperHeight, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::SheetPaperSizeChanged); + connect(ui->doubleSpinBoxTilePaperWidth, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::TilePaperSizeChanged); + connect(ui->doubleSpinBoxTilePaperHeight, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::TilePaperSizeChanged); + + connect(ui->doubleSpinBoxSheetPaperWidth, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::FindSheetTemplate); + connect(ui->doubleSpinBoxSheetPaperHeight, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::FindSheetTemplate); + connect(ui->doubleSpinBoxTilePaperWidth, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::FindTileTemplate); + connect(ui->doubleSpinBoxTilePaperHeight, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::FindTileTemplate); + + connect(ui->doubleSpinBoxSheetPaperWidth, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::CorrectMaxMargins); + connect(ui->doubleSpinBoxSheetPaperHeight, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::CorrectMaxMargins); + connect(ui->doubleSpinBoxTilePaperWidth, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::CorrectMaxMargins); + connect(ui->doubleSpinBoxTilePaperHeight, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PuzzlePreferencesLayoutPage::CorrectMaxMargins); + + connect(ui->checkBoxLayoutIgnoreFileds, &QCheckBox::stateChanged, this, + &PuzzlePreferencesLayoutPage::LayoutSheetIgnoreMargins); + connect(ui->checkBoxTileIgnoreFileds, &QCheckBox::stateChanged, this, + &PuzzlePreferencesLayoutPage::LayoutTileIgnoreMargins); + + connect(ui->toolButtonSheetPortraitOritation, &QToolButton::toggled, this, + &PuzzlePreferencesLayoutPage::SwapSheetOrientation); + connect(ui->toolButtonSheetLandscapeOrientation, &QToolButton::toggled, this, + &PuzzlePreferencesLayoutPage::SwapSheetOrientation); + connect(ui->toolButtonTilePortraitOrientation, &QToolButton::toggled, this, + &PuzzlePreferencesLayoutPage::SwapTileOrientation); + connect(ui->toolButtonTileLandscapeOrientation, &QToolButton::toggled, this, + &PuzzlePreferencesLayoutPage::SwapTileOrientation); +} + +//--------------------------------------------------------------------------------------------------------------------- +PuzzlePreferencesLayoutPage::~PuzzlePreferencesLayoutPage() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PuzzlePreferencesLayoutPage::Apply() -> QStringList +{ + QStringList preferences; + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + + settings->SetLayoutUnit(LayoutUnit()); + + settings->SetLayoutSheetPaperHeight( + UnitConvertor(ui->doubleSpinBoxSheetPaperHeight->value(), m_oldLayoutUnit, Unit::Px)); + settings->SetLayoutSheetPaperWidth( + UnitConvertor(ui->doubleSpinBoxSheetPaperWidth->value(), m_oldLayoutUnit, Unit::Px)); + + settings->SetLayoutSheetIgnoreMargins(ui->checkBoxLayoutIgnoreFileds->isChecked()); + settings->SetLayoutSheetMargins(GetSheetMargins()); + + settings->SetLayoutTileShowTiles(ui->checkBoxTileShowTiles->isChecked()); + + settings->SetLayoutTilePaperHeight( + UnitConvertor(ui->doubleSpinBoxTilePaperHeight->value(), m_oldLayoutUnit, Unit::Px)); + settings->SetLayoutTilePaperWidth( + UnitConvertor(ui->doubleSpinBoxTilePaperWidth->value(), m_oldLayoutUnit, Unit::Px)); + + settings->SetLayoutTileIgnoreMargins(ui->checkBoxTileIgnoreFileds->isChecked()); + settings->SetLayoutTileMargins(GetTileMargins()); + + settings->SetLayoutPieceGap(UnitConvertor(ui->doubleSpinBoxPiecesGap->value(), m_oldLayoutUnit, Unit::Px)); + + settings->SetLayoutWarningPiecesSuperposition(ui->checkBoxWarningPiecesSuperposition->isChecked()); + settings->SetLayoutStickyEdges(ui->checkBoxStickyEdges->isChecked()); + settings->SetLayoutWarningPiecesOutOfBound(ui->checkBoxWarningPiecesOutOfBound->isChecked()); + settings->SetLayoutFollowGrainline(ui->checkBoxFollowGrainline->isChecked()); + + preferences.append(tr("default layout settings")); + return preferences; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + } + // remember to call base class implementation + QWidget::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::ConvertPaperSize() +{ + const Unit layoutUnit = LayoutUnit(); + + const qreal sheetWidth = ui->doubleSpinBoxSheetPaperWidth->value(); + const qreal sheetHeight = ui->doubleSpinBoxSheetPaperHeight->value(); + + const qreal sheetLeftMargin = ui->doubleSpinBoxSheetMarginLeft->value(); + const qreal sheetRightMargin = ui->doubleSpinBoxSheetMarginRight->value(); + const qreal sheetTopMargin = ui->doubleSpinBoxSheetMarginTop->value(); + const qreal sheetBottomMargin = ui->doubleSpinBoxSheetMarginBottom->value(); + + ui->doubleSpinBoxSheetPaperWidth->blockSignals(true); + ui->doubleSpinBoxSheetPaperHeight->blockSignals(true); + ui->doubleSpinBoxSheetPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, layoutUnit)); + ui->doubleSpinBoxSheetPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, layoutUnit)); + ui->doubleSpinBoxSheetPaperWidth->blockSignals(false); + ui->doubleSpinBoxSheetPaperHeight->blockSignals(false); + + const qreal newSheetWidth = UnitConvertor(sheetWidth, m_oldLayoutUnit, layoutUnit); + const qreal newSheetHeight = UnitConvertor(sheetHeight, m_oldLayoutUnit, layoutUnit); + + const qreal newSheetLeftMargin = UnitConvertor(sheetLeftMargin, m_oldLayoutUnit, layoutUnit); + const qreal newSheetRightMargin = UnitConvertor(sheetRightMargin, m_oldLayoutUnit, layoutUnit); + const qreal newSheetTopMargin = UnitConvertor(sheetTopMargin, m_oldLayoutUnit, layoutUnit); + const qreal newSheetBottomMargin = UnitConvertor(sheetBottomMargin, m_oldLayoutUnit, layoutUnit); + + const qreal tileWidth = ui->doubleSpinBoxTilePaperWidth->value(); + const qreal tileHeight = ui->doubleSpinBoxTilePaperHeight->value(); + + const qreal tileLeftMargin = ui->doubleSpinBoxTileMarginLeft->value(); + const qreal tileRightMargin = ui->doubleSpinBoxTileMarginRight->value(); + const qreal tileTopMargin = ui->doubleSpinBoxTileMarginTop->value(); + const qreal tileBottomMargin = ui->doubleSpinBoxTileMarginBottom->value(); + + ui->doubleSpinBoxTilePaperWidth->blockSignals(true); + ui->doubleSpinBoxTilePaperHeight->blockSignals(true); + ui->doubleSpinBoxTilePaperWidth->setMaximum(FromPixel(QIMAGE_MAX, layoutUnit)); + ui->doubleSpinBoxTilePaperHeight->setMaximum(FromPixel(QIMAGE_MAX, layoutUnit)); + ui->doubleSpinBoxTilePaperWidth->blockSignals(false); + ui->doubleSpinBoxTilePaperHeight->blockSignals(false); + + const qreal newTileWidth = UnitConvertor(tileWidth, m_oldLayoutUnit, layoutUnit); + const qreal newTileHeight = UnitConvertor(tileHeight, m_oldLayoutUnit, layoutUnit); + + const qreal newTileLeftMargin = UnitConvertor(tileLeftMargin, m_oldLayoutUnit, layoutUnit); + const qreal newTileRightMargin = UnitConvertor(tileRightMargin, m_oldLayoutUnit, layoutUnit); + const qreal newTileTopMargin = UnitConvertor(tileTopMargin, m_oldLayoutUnit, layoutUnit); + const qreal newTileBottomMargin = UnitConvertor(tileBottomMargin, m_oldLayoutUnit, layoutUnit); + + qreal newGap = UnitConvertor(ui->doubleSpinBoxPiecesGap->value(), m_oldLayoutUnit, layoutUnit); + + m_oldLayoutUnit = layoutUnit; + CorrectPaperDecimals(); + MinimumSheetPaperSize(); + MinimumTilePaperSize(); + + ui->doubleSpinBoxSheetPaperWidth->setValue(newSheetWidth); + ui->doubleSpinBoxSheetPaperHeight->setValue(newSheetHeight); + + ui->doubleSpinBoxSheetMarginLeft->setValue(newSheetLeftMargin); + ui->doubleSpinBoxSheetMarginRight->setValue(newSheetRightMargin); + ui->doubleSpinBoxSheetMarginTop->setValue(newSheetTopMargin); + ui->doubleSpinBoxSheetMarginBottom->setValue(newSheetBottomMargin); + + ui->doubleSpinBoxTilePaperWidth->setValue(newTileWidth); + ui->doubleSpinBoxTilePaperHeight->setValue(newTileHeight); + + ui->doubleSpinBoxTileMarginLeft->setValue(newTileLeftMargin); + ui->doubleSpinBoxTileMarginRight->setValue(newTileRightMargin); + ui->doubleSpinBoxTileMarginTop->setValue(newTileTopMargin); + ui->doubleSpinBoxTileMarginBottom->setValue(newTileBottomMargin); + + ui->doubleSpinBoxPiecesGap->setMaximum(UnitConvertor(50, Unit::Cm, layoutUnit)); + ui->doubleSpinBoxPiecesGap->setValue(newGap); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::LayoutSheetIgnoreMargins(int state) +{ + ui->doubleSpinBoxSheetMarginLeft->setDisabled(state != 0); + ui->doubleSpinBoxSheetMarginRight->setDisabled(state != 0); + ui->doubleSpinBoxSheetMarginTop->setDisabled(state != 0); + ui->doubleSpinBoxSheetMarginBottom->setDisabled(state != 0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::LayoutTileIgnoreMargins(int state) +{ + ui->doubleSpinBoxTileMarginLeft->setDisabled(state != 0); + ui->doubleSpinBoxTileMarginRight->setDisabled(state != 0); + ui->doubleSpinBoxTileMarginTop->setDisabled(state != 0); + ui->doubleSpinBoxTileMarginBottom->setDisabled(state != 0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::FindSheetTemplate() +{ + const qreal width = ui->doubleSpinBoxSheetPaperWidth->value(); + const qreal height = ui->doubleSpinBoxSheetPaperHeight->value(); + FindTemplate(ui->comboBoxSheetTemplates, width, height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::FindTileTemplate() +{ + const qreal width = ui->doubleSpinBoxTilePaperWidth->value(); + const qreal height = ui->doubleSpinBoxTilePaperHeight->value(); + FindTemplate(ui->comboBoxTileTemplates, width, height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::CorrectMaxMargins() +{ + const qreal sheetWidth = ui->doubleSpinBoxSheetPaperWidth->value(); + const qreal sheetHeight = ui->doubleSpinBoxSheetPaperHeight->value(); + + // 80%/2 of paper size for each field + const qreal sheetWidthMargin = (sheetWidth*80.0/100.0)/2.0; + const qreal sheetHeightMargin = (sheetHeight*80.0/100.0)/2.0; + + ui->doubleSpinBoxSheetMarginLeft->setMaximum(sheetWidthMargin); + ui->doubleSpinBoxSheetMarginRight->setMaximum(sheetWidthMargin); + ui->doubleSpinBoxSheetMarginTop->setMaximum(sheetHeightMargin); + ui->doubleSpinBoxSheetMarginBottom->setMaximum(sheetHeightMargin); + + const qreal tileWidth = ui->doubleSpinBoxTilePaperWidth->value(); + const qreal tileHeight = ui->doubleSpinBoxTilePaperHeight->value(); + + // 80%/2 of paper size for each field + const qreal tileWidthMargin = (tileWidth*80.0/100.0)/2.0; + const qreal tileHeightMargin = (tileHeight*80.0/100.0)/2.0; + + ui->doubleSpinBoxTileMarginLeft->setMaximum(tileWidthMargin); + ui->doubleSpinBoxTileMarginRight->setMaximum(tileWidthMargin); + ui->doubleSpinBoxTileMarginTop->setMaximum(tileHeightMargin); + ui->doubleSpinBoxTileMarginBottom->setMaximum(tileHeightMargin); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SwapSheetOrientation(bool checked) +{ + if (checked) + { + const qreal width = ui->doubleSpinBoxSheetPaperWidth->value(); + const qreal height = ui->doubleSpinBoxSheetPaperHeight->value(); + + ui->doubleSpinBoxSheetPaperWidth->blockSignals(true); + ui->doubleSpinBoxSheetPaperWidth->setValue(height); + ui->doubleSpinBoxSheetPaperWidth->blockSignals(false); + + ui->doubleSpinBoxSheetPaperHeight->blockSignals(true); + ui->doubleSpinBoxSheetPaperHeight->setValue(width); + ui->doubleSpinBoxSheetPaperHeight->blockSignals(false); + + SheetPaperSizeChanged(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SwapTileOrientation(bool checked) +{ + if (checked) + { + const qreal width = ui->doubleSpinBoxTilePaperWidth->value(); + const qreal height = ui->doubleSpinBoxTilePaperHeight->value(); + + ui->doubleSpinBoxTilePaperWidth->blockSignals(true); + ui->doubleSpinBoxTilePaperWidth->setValue(height); + ui->doubleSpinBoxTilePaperWidth->blockSignals(false); + + ui->doubleSpinBoxTilePaperHeight->blockSignals(true); + ui->doubleSpinBoxTilePaperHeight->setValue(width); + ui->doubleSpinBoxTilePaperHeight->blockSignals(false); + + TilePaperSizeChanged(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::InitLayoutUnits() +{ + ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); + ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); + ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch))); + ui->comboBoxLayoutUnit->addItem(tr("Pixels"), QVariant(UnitsToStr(Unit::Px))); + + // set default unit + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + m_oldLayoutUnit = StrToUnits(settings->GetUnit()); + const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(settings->GetUnit()); + if (indexUnit != -1) + { + ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF PuzzlePreferencesLayoutPage::Template(VAbstractLayoutDialog::PaperSizeTemplate t) const +{ + const Unit layoutUnit = LayoutUnit(); + + switch (t) + { + case VAbstractLayoutDialog::PaperSizeTemplate::A0: + case VAbstractLayoutDialog::PaperSizeTemplate::A1: + case VAbstractLayoutDialog::PaperSizeTemplate::A2: + case VAbstractLayoutDialog::PaperSizeTemplate::A3: + case VAbstractLayoutDialog::PaperSizeTemplate::A4: + case VAbstractLayoutDialog::PaperSizeTemplate::Letter: + case VAbstractLayoutDialog::PaperSizeTemplate::Legal: + case VAbstractLayoutDialog::PaperSizeTemplate::Tabloid: + return VAbstractLayoutDialog::GetTemplateSize(t, layoutUnit); + case VAbstractLayoutDialog::PaperSizeTemplate::Roll24in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll30in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll36in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll42in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll44in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll48in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll62in: + case VAbstractLayoutDialog::PaperSizeTemplate::Roll72in: + return VAbstractLayoutDialog::GetTemplateSize(t, layoutUnit); + case VAbstractLayoutDialog::PaperSizeTemplate::Custom: + return VAbstractLayoutDialog::GetTemplateSize(t, layoutUnit); + default: + break; + } + return QSizeF(); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PuzzlePreferencesLayoutPage::SheetTemplate() const -> QSizeF +{ + auto t = static_cast(ui->comboBoxSheetTemplates->currentData().toInt()); + return Template(t); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PuzzlePreferencesLayoutPage::TileTemplate() const -> QSizeF +{ + auto t = static_cast(ui->comboBoxTileTemplates->currentData().toInt()); + return Template(t); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::MinimumSheetPaperSize() +{ + const qreal value = UnitConvertor(1, Unit::Px, m_oldLayoutUnit); + ui->doubleSpinBoxSheetPaperWidth->setMinimum(value); + ui->doubleSpinBoxSheetPaperHeight->setMinimum(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::MinimumTilePaperSize() +{ + const qreal value = UnitConvertor(1, Unit::Px, m_oldLayoutUnit); + ui->doubleSpinBoxTilePaperWidth->setMinimum(value); + ui->doubleSpinBoxTilePaperHeight->setMinimum(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PuzzlePreferencesLayoutPage::LayoutUnit() const -> Unit +{ + return StrToUnits(ui->comboBoxLayoutUnit->currentData().toString()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SetLayoutUnit(Unit unit) +{ + const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(UnitsToStr(unit)); + if (indexUnit != -1) + { + ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SheetSize(const QSizeF &size) +{ + m_oldLayoutUnit = LayoutUnit(); + ui->doubleSpinBoxSheetPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, m_oldLayoutUnit)); + ui->doubleSpinBoxSheetPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, m_oldLayoutUnit)); + + ui->doubleSpinBoxSheetPaperWidth->setValue(size.width()); + ui->doubleSpinBoxSheetPaperHeight->setValue(size.height()); + + CorrectPaperDecimals(); + SheetPaperSizeChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::TileSize(const QSizeF &size) +{ + m_oldLayoutUnit = LayoutUnit(); + ui->doubleSpinBoxTilePaperWidth->setMaximum(FromPixel(QIMAGE_MAX, m_oldLayoutUnit)); + ui->doubleSpinBoxTilePaperHeight->setMaximum(FromPixel(QIMAGE_MAX, m_oldLayoutUnit)); + + ui->doubleSpinBoxTilePaperWidth->setValue(size.width()); + ui->doubleSpinBoxTilePaperHeight->setValue(size.height()); + + CorrectPaperDecimals(); + TilePaperSizeChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::CorrectPaperDecimals() +{ + switch (m_oldLayoutUnit) + { + case Unit::Cm: + case Unit::Mm: + case Unit::Px: + ui->doubleSpinBoxSheetPaperWidth->setDecimals(2); + ui->doubleSpinBoxSheetPaperHeight->setDecimals(2); + + ui->doubleSpinBoxTilePaperWidth->setDecimals(2); + ui->doubleSpinBoxTilePaperHeight->setDecimals(2); + + ui->doubleSpinBoxSheetMarginLeft->setDecimals(4); + ui->doubleSpinBoxSheetMarginRight->setDecimals(4); + ui->doubleSpinBoxSheetMarginTop->setDecimals(4); + ui->doubleSpinBoxSheetMarginBottom->setDecimals(4); + + ui->doubleSpinBoxTileMarginLeft->setDecimals(4); + ui->doubleSpinBoxTileMarginRight->setDecimals(4); + ui->doubleSpinBoxTileMarginTop->setDecimals(4); + ui->doubleSpinBoxTileMarginBottom->setDecimals(4); + + ui->doubleSpinBoxPiecesGap->setDecimals(2); + break; + case Unit::Inch: + ui->doubleSpinBoxSheetPaperWidth->setDecimals(5); + ui->doubleSpinBoxSheetPaperHeight->setDecimals(5); + + ui->doubleSpinBoxTilePaperWidth->setDecimals(5); + ui->doubleSpinBoxTilePaperHeight->setDecimals(5); + + ui->doubleSpinBoxSheetMarginLeft->setDecimals(5); + ui->doubleSpinBoxSheetMarginRight->setDecimals(5); + ui->doubleSpinBoxSheetMarginTop->setDecimals(5); + ui->doubleSpinBoxSheetMarginBottom->setDecimals(5); + + ui->doubleSpinBoxTileMarginLeft->setDecimals(5); + ui->doubleSpinBoxTileMarginRight->setDecimals(5); + ui->doubleSpinBoxTileMarginTop->setDecimals(5); + ui->doubleSpinBoxTileMarginBottom->setDecimals(5); + + ui->doubleSpinBoxPiecesGap->setDecimals(5); + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SheetPaperSizeChanged() +{ + bool portrait = ui->doubleSpinBoxSheetPaperHeight->value() > ui->doubleSpinBoxSheetPaperWidth->value(); + + ui->toolButtonSheetPortraitOritation->blockSignals(true); + ui->toolButtonSheetPortraitOritation->setChecked(portrait); + ui->toolButtonSheetPortraitOritation->blockSignals(false); + + ui->toolButtonSheetLandscapeOrientation->blockSignals(true); + ui->toolButtonSheetLandscapeOrientation->setChecked(not portrait); + ui->toolButtonSheetLandscapeOrientation->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::TilePaperSizeChanged() +{ + bool portrait = ui->doubleSpinBoxTilePaperHeight->value() > ui->doubleSpinBoxTilePaperWidth->value(); + + ui->toolButtonTilePortraitOrientation->blockSignals(true); + ui->toolButtonTilePortraitOrientation->setChecked(portrait); + ui->toolButtonTilePortraitOrientation->blockSignals(false); + + ui->toolButtonTileLandscapeOrientation->blockSignals(true); + ui->toolButtonTileLandscapeOrientation->setChecked(not portrait); + ui->toolButtonTileLandscapeOrientation->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PuzzlePreferencesLayoutPage::GetSheetMargins() const -> QMarginsF +{ + QMarginsF fields; + fields.setLeft(UnitConvertor(ui->doubleSpinBoxSheetMarginLeft->value(), m_oldLayoutUnit, Unit::Px)); + fields.setRight(UnitConvertor(ui->doubleSpinBoxSheetMarginRight->value(), m_oldLayoutUnit, Unit::Px)); + fields.setTop(UnitConvertor(ui->doubleSpinBoxSheetMarginTop->value(), m_oldLayoutUnit, Unit::Px)); + fields.setBottom(UnitConvertor(ui->doubleSpinBoxSheetMarginBottom->value(), m_oldLayoutUnit, Unit::Px)); + return fields; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SetSheetMargins(const QMarginsF &value) +{ + ui->doubleSpinBoxSheetMarginLeft->setValue(UnitConvertor(value.left(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxSheetMarginRight->setValue(UnitConvertor(value.right(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxSheetMarginTop->setValue(UnitConvertor(value.top(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxSheetMarginBottom->setValue(UnitConvertor(value.bottom(), Unit::Px, LayoutUnit())); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PuzzlePreferencesLayoutPage::GetTileMargins() const -> QMarginsF +{ + QMarginsF fields; + fields.setLeft(UnitConvertor(ui->doubleSpinBoxTileMarginLeft->value(), m_oldLayoutUnit, Unit::Px)); + fields.setRight(UnitConvertor(ui->doubleSpinBoxTileMarginRight->value(), m_oldLayoutUnit, Unit::Px)); + fields.setTop(UnitConvertor(ui->doubleSpinBoxTileMarginTop->value(), m_oldLayoutUnit, Unit::Px)); + fields.setBottom(UnitConvertor(ui->doubleSpinBoxTileMarginBottom->value(), m_oldLayoutUnit, Unit::Px)); + return fields; +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SetTileMargins(const QMarginsF &value) +{ + ui->doubleSpinBoxTileMarginLeft->setValue(UnitConvertor(value.left(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxTileMarginRight->setValue(UnitConvertor(value.right(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxTileMarginTop->setValue(UnitConvertor(value.top(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxTileMarginBottom->setValue(UnitConvertor(value.bottom(), Unit::Px, LayoutUnit())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::SetPieceGap(qreal gap) +{ + qreal value = UnitConvertor(gap, Unit::Px, LayoutUnit()); + ui->doubleSpinBoxPiecesGap->setValue(value); + CorrectPaperDecimals(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::ReadSettings() +{ + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + + SetLayoutUnit(settings->LayoutUnit()); + m_oldLayoutUnit = LayoutUnit(); + + const qreal sheetWidth = UnitConvertor(settings->GetLayoutSheetPaperWidth(), Unit::Px, LayoutUnit()); + const qreal sheetHeight = UnitConvertor(settings->GetLayoutSheetPaperHeight(), Unit::Px, LayoutUnit()); + SheetSize(QSizeF(sheetWidth, sheetHeight)); + + ui->checkBoxLayoutIgnoreFileds->setChecked(settings->GetLayoutSheetIgnoreMargins()); + SetSheetMargins(settings->GetLayoutSheetMargins()); + + const qreal tileWidth = UnitConvertor(settings->GetLayoutTilePaperWidth(), Unit::Px, LayoutUnit()); + const qreal tileHeight = UnitConvertor(settings->GetLayoutTilePaperHeight(), Unit::Px, LayoutUnit()); + TileSize(QSizeF(tileWidth, tileHeight)); + + ui->checkBoxTileShowTiles->setChecked(settings->GetLayoutTileShowTiles()); + ui->checkBoxTileIgnoreFileds->setChecked(settings->GetLayoutTileIgnoreMargins()); + SetTileMargins(settings->GetLayoutSheetMargins()); + + ui->checkBoxWarningPiecesSuperposition->setChecked(settings->GetLayoutWarningPiecesSuperposition()); + ui->checkBoxStickyEdges->setChecked(settings->GetLayoutStickyEdges()); + ui->checkBoxWarningPiecesOutOfBound->setChecked(settings->GetLayoutWarningPiecesOutOfBound()); + ui->checkBoxFollowGrainline->setChecked(settings->GetLayoutFollowGrainline()); + + ui->doubleSpinBoxPiecesGap->setMaximum(UnitConvertor(50, Unit::Cm, LayoutUnit())); + SetPieceGap(settings->GetLayoutPieceGap()); + + FindSheetTemplate(); + FindTileTemplate(); + + SheetPaperSizeChanged(); + TilePaperSizeChanged(); + + LayoutSheetIgnoreMargins(static_cast(ui->checkBoxLayoutIgnoreFileds->isChecked())); + LayoutTileIgnoreMargins(static_cast(ui->checkBoxTileIgnoreFileds->isChecked())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzlePreferencesLayoutPage::FindTemplate(QComboBox *box, qreal width, qreal height) +{ + SCASSERT(box != nullptr) + const Unit paperUnit = LayoutUnit(); + + const int max = static_cast(VAbstractLayoutDialog::PaperSizeTemplate::Custom); + for (int i=0; i < max; ++i) + { + const QSizeF tmplSize = VAbstractLayoutDialog::GetTemplateSize( + static_cast(i), paperUnit); + if (QSizeF(width, height) == tmplSize || QSizeF(height, width) == tmplSize) + { + box->blockSignals(true); + const int index = ui->comboBoxTileTemplates->findData(i); + if (index != -1) + { + box->setCurrentIndex(index); + } + box->blockSignals(false); + return; + } + } + + box->blockSignals(true); + const int index = box->findData(max); + if (index != -1) + { + box->setCurrentIndex(index); + } + box->blockSignals(false); +} diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h new file mode 100644 index 000000000..eefc4246b --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file puzzlepreferenceslayoutpage.h + ** @author Roman Telezhynskyi + ** @date 20 8, 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 PUZZLEPREFERENCESLAYOUTPAGE_H +#define PUZZLEPREFERENCESLAYOUTPAGE_H + +#include + +#include "../vmisc/def.h" +#include "../vlayout/dialogs/vabstractlayoutdialog.h" + +namespace Ui +{ + class PuzzlePreferencesLayoutPage; +} + +class PuzzlePreferencesLayoutPage : public QWidget +{ + Q_OBJECT + +public: + explicit PuzzlePreferencesLayoutPage(QWidget *parent = nullptr); + ~PuzzlePreferencesLayoutPage(); + + QStringList Apply(); + +protected: + virtual void changeEvent(QEvent* event) override; + +private slots: + void ConvertPaperSize(); + void LayoutSheetIgnoreMargins(int state); + void LayoutTileIgnoreMargins(int state); + void FindSheetTemplate(); + void FindTileTemplate(); + void CorrectMaxMargins(); + void SwapSheetOrientation(bool checked); + void SwapTileOrientation(bool checked); + +private: + Q_DISABLE_COPY(PuzzlePreferencesLayoutPage) + Ui::PuzzlePreferencesLayoutPage *ui; + Unit m_oldLayoutUnit{Unit::Mm}; + + void InitLayoutUnits(); + + QSizeF Template(VAbstractLayoutDialog::PaperSizeTemplate t) const; + QSizeF SheetTemplate() const; + QSizeF TileTemplate() const; + + void MinimumSheetPaperSize(); + void MinimumTilePaperSize(); + + Unit LayoutUnit() const; + void SetLayoutUnit(Unit unit); + + void SheetSize(const QSizeF &size); + void TileSize(const QSizeF &size); + + void CorrectPaperDecimals(); + + void SheetPaperSizeChanged(); + void TilePaperSizeChanged(); + + QMarginsF GetSheetMargins() const; + void SetSheetMargins(const QMarginsF &value); + + QMarginsF GetTileMargins() const; + void SetTileMargins(const QMarginsF &value); + + void SetPieceGap(qreal gap); + + void ReadSettings(); + + void FindTemplate(QComboBox *box, qreal width, qreal height); +}; + +#endif // PUZZLEPREFERENCESLAYOUTPAGE_H diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui new file mode 100644 index 000000000..02593bac5 --- /dev/null +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui @@ -0,0 +1,653 @@ + + + PuzzlePreferencesLayoutPage + + + + 0 + 0 + 616 + 668 + + + + Form + + + + + + + + Sheet + + + + + + false + + + Format + + + false + + + false + + + false + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Unit: + + + + + + + + + + + 0 + 0 + + + + Templates: + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + ... + + + + :/icon/16x16/portrait.png:/icon/16x16/portrait.png + + + true + + + true + + + true + + + + + + + ... + + + + :/icon/16x16/landscape.png:/icon/16x16/landscape.png + + + true + + + false + + + true + + + + + + + + + + 0 + 0 + + + + Width: + + + + + + + + 0 + 0 + + + + Height: + + + + + + + + 94 + 0 + + + + 2 + + + 99999.000000000000000 + + + + + + + + 94 + 0 + + + + 2 + + + 99999.990000000005239 + + + + + + + + + + + + Margins + + + + + + + + Right: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 0.100000000000000 + + + + + + + Top: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.100000000000000 + + + + + + + 0.100000000000000 + + + + + + + Left: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Bottom: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.100000000000000 + + + + + + + + + + 0 + 0 + + + + Ignore margins + + + + + + + + + + + + + Control + + + + + + Warning superposition of pieces + + + + + + + Warning pieces out of bound + + + + + + + Sticky edges + + + + + + + Follow grainline + + + + + + + + + Pieces gap + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Tiles + + + false + + + false + + + + + + Show Tiles on sheet + + + + + + + false + + + Format + + + false + + + false + + + false + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + + 0 + 0 + + + + Templates: + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + ... + + + + :/icon/16x16/portrait.png:/icon/16x16/portrait.png + + + true + + + true + + + true + + + + + + + ... + + + + :/icon/16x16/landscape.png:/icon/16x16/landscape.png + + + true + + + false + + + true + + + + + + + + + + 0 + 0 + + + + Width: + + + + + + + + 0 + 0 + + + + Height: + + + + + + + + 94 + 0 + + + + 2 + + + 99999.000000000000000 + + + + + + + + 94 + 0 + + + + 2 + + + 99999.990000000005239 + + + + + + + + + + + + Margins + + + + + + + + Right: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 0.100000000000000 + + + + + + + Top: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.100000000000000 + + + + + + + 0.100000000000000 + + + + + + + Left: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Bottom: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.100000000000000 + + + + + + + + + + 0 + 0 + + + + Ignore margins + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + diff --git a/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp b/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp index 1691fbab3..deb8c4a5f 100644 --- a/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp @@ -31,6 +31,7 @@ #include "../vpapplication.h" #include "configpages/puzzlepreferencesconfigurationpage.h" #include "configpages/puzzlepreferencespathpage.h" +#include "configpages/puzzlepreferenceslayoutpage.h" #include #include @@ -41,6 +42,7 @@ DialogPuzzlePreferences::DialogPuzzlePreferences(QWidget *parent) : QDialog(parent), ui(new Ui::DialogPuzzlePreferences), m_configurationPage(new PuzzlePreferencesConfigurationPage), + m_layoutPage(new PuzzlePreferencesLayoutPage), m_pathPage(new PuzzlePreferencesPathPage) { ui->setupUi(this); @@ -60,7 +62,8 @@ DialogPuzzlePreferences::DialogPuzzlePreferences(QWidget *parent) : connect(bApply, &QPushButton::clicked, this, &DialogPuzzlePreferences::Apply); ui->pagesWidget->insertWidget(0, m_configurationPage); - ui->pagesWidget->insertWidget(1, m_pathPage); + ui->pagesWidget->insertWidget(1, m_layoutPage); + ui->pagesWidget->insertWidget(2, m_pathPage); connect(ui->contentsWidget, &QListWidget::currentItemChanged, this, &DialogPuzzlePreferences::PageChanged); ui->pagesWidget->setCurrentIndex(0); @@ -127,6 +130,7 @@ void DialogPuzzlePreferences::Apply() QStringList preferences; preferences += m_configurationPage->Apply(); + preferences += m_layoutPage->Apply(); m_pathPage->Apply(); if (not preferences.isEmpty()) diff --git a/src/app/puzzle/dialogs/dialogpuzzlepreferences.h b/src/app/puzzle/dialogs/dialogpuzzlepreferences.h index 487a558cc..c84390bf1 100644 --- a/src/app/puzzle/dialogs/dialogpuzzlepreferences.h +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.h @@ -38,6 +38,7 @@ namespace Ui class PuzzlePreferencesConfigurationPage; class PuzzlePreferencesPathPage; class QListWidgetItem; +class PuzzlePreferencesLayoutPage; class DialogPuzzlePreferences : public QDialog { @@ -65,6 +66,7 @@ private: Ui::DialogPuzzlePreferences *ui; bool m_isInitialized{false}; PuzzlePreferencesConfigurationPage *m_configurationPage; + PuzzlePreferencesLayoutPage *m_layoutPage; PuzzlePreferencesPathPage *m_pathPage; }; diff --git a/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui b/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui index 632f93440..7d3869348 100644 --- a/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.ui @@ -53,7 +53,7 @@ QListView::IconMode - 0 + -1 @@ -70,6 +70,18 @@ ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled + + + Layout + + + AlignCenter + + + + :/icon/layout.png:/icon/layout.png + + Paths diff --git a/src/app/puzzle/layout/layoutdef.h b/src/app/puzzle/layout/layoutdef.h index fa3db8f46..d23aac007 100644 --- a/src/app/puzzle/layout/layoutdef.h +++ b/src/app/puzzle/layout/layoutdef.h @@ -29,7 +29,9 @@ #define LAYOUTDEF_H #include -#include + +template class QSharedPointer; +template class QWeakPointer; class VPLayout; using VPLayoutPtr = QSharedPointer; diff --git a/src/app/puzzle/layout/vplayout.cpp b/src/app/puzzle/layout/vplayout.cpp index 165f07fe7..2e574dee1 100644 --- a/src/app/puzzle/layout/vplayout.cpp +++ b/src/app/puzzle/layout/vplayout.cpp @@ -29,6 +29,7 @@ #include "vplayout.h" #include "vppiece.h" #include "vpsheet.h" +#include "../vpapplication.h" #include #include @@ -56,6 +57,32 @@ auto VPLayout::CreateLayout(QUndoStack *undoStack) -> VPLayoutPtr layout->AddSheet(sheet); layout->SetFocusedSheet(sheet); + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + + layout->LayoutSettings().SetUnit(settings->LayoutUnit()); + + layout->LayoutSettings().SetShowTiles(settings->GetLayoutTileShowTiles()); + layout->LayoutSettings().SetTilesSize(QSizeF(settings->GetLayoutTilePaperWidth(), + settings->GetLayoutTilePaperHeight())); + layout->LayoutSettings().SetIgnoreTilesMargins(settings->GetLayoutTileIgnoreMargins()); + layout->LayoutSettings().SetTilesMargins(settings->GetLayoutTileMargins()); + + layout->LayoutSettings().SetIgnoreMargins(settings->GetLayoutSheetIgnoreMargins()); + layout->LayoutSettings().SetSheetMargins(settings->GetLayoutSheetMargins()); + layout->LayoutSettings().SetSheetSize(QSizeF(settings->GetLayoutSheetPaperWidth(), + settings->GetLayoutSheetPaperHeight())); + + layout->LayoutSettings().SetWarningSuperpositionOfPieces(settings->GetLayoutWarningPiecesSuperposition()); + layout->LayoutSettings().SetWarningPiecesOutOfBound(settings->GetLayoutWarningPiecesOutOfBound()); + layout->LayoutSettings().SetFollowGrainline(settings->GetLayoutFollowGrainline()); + layout->LayoutSettings().SetStickyEdges(settings->GetLayoutStickyEdges()); + layout->LayoutSettings().SetPiecesGap(settings->GetLayoutPieceGap()); + + // ----- for test purposes, to be removed------------------ + layout->LayoutSettings().SetTitle(QString("My Test Layout")); + layout->LayoutSettings().SetDescription(QString("Description of my Layout")); + // -------------------------------------------------------- + return layout; } diff --git a/src/app/puzzle/layout/vplayoutsettings.cpp b/src/app/puzzle/layout/vplayoutsettings.cpp index 16b891ddb..619a62c33 100644 --- a/src/app/puzzle/layout/vplayoutsettings.cpp +++ b/src/app/puzzle/layout/vplayoutsettings.cpp @@ -145,16 +145,7 @@ auto VPLayoutSettings::GetTilesSizeConverted() const -> QSizeF //--------------------------------------------------------------------------------------------------------------------- auto VPLayoutSettings::GetTilesOrientation() -> PageOrientation { - return m_tilesOrientation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetTilesOrientation(PageOrientation orientation) -{ - if(orientation != m_tilesOrientation) - { - m_tilesOrientation = orientation; - } + return m_tilesSize.height() >= m_tilesSize.width() ? PageOrientation::Portrait : PageOrientation::Landscape; } //--------------------------------------------------------------------------------------------------------------------- @@ -563,13 +554,13 @@ auto VPLayoutSettings::GetSheetMarginsConverted() const -> QMarginsF } //--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetFollowGrainline(FollowGrainline state) +void VPLayoutSettings::SetFollowGrainline(bool state) { m_followGrainLine = state; } //--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetFollowGrainline() const -> FollowGrainline +auto VPLayoutSettings::GetFollowGrainline() const -> bool { return m_followGrainLine; } @@ -670,3 +661,27 @@ void VPLayoutSettings::SetGridRowHeightConverted(qreal value) { m_gridRowHeight = UnitConvertor(value, m_unit, Unit::Px); } + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::IgnoreTilesMargins() const -> bool +{ + return m_ignoreTilesMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetIgnoreTilesMargins(bool newIgnoreTilesMargins) +{ + m_ignoreTilesMargins = newIgnoreTilesMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutSettings::IgnoreMargins() const -> bool +{ + return m_ignoreMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetIgnoreMargins(bool newIgnoreMargins) +{ + m_ignoreMargins = newIgnoreMargins; +} diff --git a/src/app/puzzle/layout/vplayoutsettings.h b/src/app/puzzle/layout/vplayoutsettings.h index bfe0c6f84..4fc95bb22 100644 --- a/src/app/puzzle/layout/vplayoutsettings.h +++ b/src/app/puzzle/layout/vplayoutsettings.h @@ -35,12 +35,6 @@ #include "def.h" -enum class FollowGrainline : qint8 { - No = 0, - Follow90 = 1, - Follow180 = 2 -}; - enum class PaperSizeTemplate : qint8 { A0 = 0, A1, @@ -67,6 +61,8 @@ class VPLayoutSettings public: VPLayoutSettings() = default; + // Layout + /** * @brief SetUnit Sets the unit of the layout to the given unit * @param unit the new unit @@ -79,12 +75,6 @@ public: */ 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 @@ -109,6 +99,55 @@ public: */ auto GetDescription() const -> QString; + void SetStickyEdges(bool state); + auto GetStickyEdges() const -> bool; + + // Piece + + void SetWarningSuperpositionOfPieces(bool state); + auto GetWarningSuperpositionOfPieces() const -> bool; + + void SetWarningPiecesOutOfBound(bool state); + auto GetWarningPiecesOutOfBound() const -> bool; + + /** + * @brief SetFollowGrainline Sets the type of grainline for the pieces to follow + * @param state the type of grainline + */ + void SetFollowGrainline(bool 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 -> bool; + + /** + * @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; + + // Tiles + /** * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px * @param width tiles width @@ -158,12 +197,6 @@ public: */ 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 @@ -260,6 +293,8 @@ public: */ static auto isRollTemplate(PaperSizeTemplate tmpl) -> bool; + // Sheet + /** * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px * @param width sheet width @@ -351,42 +386,6 @@ public: */ 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 @@ -449,8 +448,11 @@ public: */ void SetGridRowHeightConverted(qreal value); - void SetStickyEdges(bool state); - auto GetStickyEdges() const -> bool; + auto IgnoreTilesMargins() const -> bool; + void SetIgnoreTilesMargins(bool newIgnoreTilesMargins); + + auto IgnoreMargins() const -> bool; + void SetIgnoreMargins(bool newIgnoreMargins); private: Unit m_unit{Unit::Cm}; @@ -477,6 +479,8 @@ private: */ QMarginsF m_tilesMargins{}; + bool m_ignoreTilesMargins{false}; + bool m_showTiles{false}; /** @@ -495,8 +499,10 @@ private: */ QMarginsF m_margins{}; + bool m_ignoreMargins{false}; + // control - FollowGrainline m_followGrainLine{FollowGrainline::No}; + bool m_followGrainLine{false}; /** * @brief m_piecesGap the pieces gap in Unit::Px diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index 2f605734f..d2a4b800d 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -4,6 +4,7 @@ SOURCES += \ $$PWD/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp \ $$PWD/dialogs/configpages/puzzlepreferencespathpage.cpp \ + $$PWD/dialogs/configpages/puzzlepreferenceslayoutpage.cpp \ $$PWD/dialogs/dialogpuzzlepreferences.cpp \ $$PWD/dialogs/vpdialogabout.cpp \ $$PWD/main.cpp \ @@ -43,6 +44,7 @@ SOURCES += \ HEADERS += \ $$PWD/dialogs/configpages/puzzlepreferencesconfigurationpage.h \ $$PWD/dialogs/configpages/puzzlepreferencespathpage.h \ + $$PWD/dialogs/configpages/puzzlepreferenceslayoutpage.h \ $$PWD/dialogs/dialogpuzzlepreferences.h \ $$PWD/dialogs/vpdialogabout.h \ $$PWD/layout/layoutdef.h \ @@ -82,6 +84,7 @@ HEADERS += \ FORMS += \ $$PWD/dialogs/configpages/puzzlepreferencesconfigurationpage.ui \ $$PWD/dialogs/configpages/puzzlepreferencespathpage.ui \ + $$PWD/dialogs/configpages/puzzlepreferenceslayoutpage.ui \ $$PWD/dialogs/dialogpuzzlepreferences.ui \ $$PWD/dialogs/vpdialogabout.ui \ $$PWD/carousel/vpcarrousel.ui \ diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index ddb7dfdd1..0b349b0c4 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -638,6 +638,18 @@ void VPApplication::NewLocalSocketConnection() MainWindow()->activateWindow(); } +//--------------------------------------------------------------------------------------------------------------------- +auto VPApplication::PreferencesDialog() const -> QSharedPointer +{ + return m_preferencesDialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPApplication::SetPreferencesDialog(const QSharedPointer &newPreferencesDialog) +{ + m_preferencesDialog = newPreferencesDialog; +} + //--------------------------------------------------------------------------------------------------------------------- void VPApplication::Clean() { diff --git a/src/app/puzzle/vpapplication.h b/src/app/puzzle/vpapplication.h index e66e98003..7cc36ecba 100644 --- a/src/app/puzzle/vpapplication.h +++ b/src/app/puzzle/vpapplication.h @@ -33,10 +33,10 @@ #include "../vmisc/vabstractapplication.h" #include "vpcommandline.h" -#include - +template class QWeakPointer; class VPMainWindow; class QLocalServer; +class DialogPuzzlePreferences; enum class SocketConnection : bool {Client = false, Server = true}; @@ -68,6 +68,10 @@ public: static VPCommandLinePtr CommandLine(); static VPApplication *VApp(); + + auto PreferencesDialog() const -> QSharedPointer; + void SetPreferencesDialog(const QSharedPointer &newPreferencesDialog); + public slots: void ProcessCMD(); @@ -85,6 +89,7 @@ private: Q_DISABLE_COPY(VPApplication) QList > mainWindows{}; QLocalServer *localServer{nullptr}; + QWeakPointer m_preferencesDialog{}; void Clean(); }; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 8b437f0dc..b65acc6df 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -78,23 +78,6 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : { ui->setupUi(this); - // ----- for test purposes, to be removed------------------ - 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->LayoutSettings().SetTilesSizeConverted(21, 29.7); - m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Portrait); - m_layout->LayoutSettings().SetTilesMarginsConverted(1, 1, 1, 1); - m_layout->LayoutSettings().SetShowTiles(true); - - m_layout->LayoutSettings().SetSheetMarginsConverted(1, 1, 1, 1); - m_layout->LayoutSettings().SetSheetSizeConverted(84.1, 118.9); - m_layout->LayoutSettings().SetPiecesGapConverted(1); - - // -------------------------------------------------------- - // init the tile factory m_tileFactory = new VPTileFactory(m_layout, VPApplication::VApp()->Settings()); m_tileFactory->refreshTileInfos(); @@ -228,6 +211,7 @@ auto VPMainWindow::LoadFile(QString path) -> bool m_carrousel->Refresh(); m_graphicsView->RefreshLayout(); m_graphicsView->RefreshPieces(); + m_tileFactory->refreshTileInfos(); return true; } @@ -940,7 +924,7 @@ void VPMainWindow::ReadSettings() m_graphicsView->SetAntialiasing(settings->GetGraphicalOutput()); // Stack limit -// qApp->getUndoStack()->setUndoLimit(settings->GetUndoCount()); + m_undoStack->setUndoLimit(settings->GetUndoCount()); } else { @@ -1148,6 +1132,14 @@ auto VPMainWindow::IsLayoutReadOnly() const -> bool return not fileWritable; } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::ConnectToPreferences(const QSharedPointer &preferences) +{ + // Must be first + connect(preferences.get(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::WindowsLocale); + connect(preferences.get(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::ToolBarStyles); +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_actionNew_triggered() { @@ -1612,14 +1604,6 @@ void VPMainWindow::on_TilesSizeChanged(bool changedViaSizeCombobox) void VPMainWindow::on_TilesOrientationChanged() { // Updates the orientation - if(ui->radioButtonTilesPortrait->isChecked()) - { - m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Portrait); - } - else - { - m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Landscape); - } m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1909,19 +1893,33 @@ void VPMainWindow::ShowWindow() const void VPMainWindow::on_actionPreferences_triggered() { // Calling constructor of the dialog take some time. Because of this user have time to call the dialog twice. - static QPointer guard;// Prevent any second run - if (guard.isNull()) + QSharedPointer preferences = VPApplication::VApp()->PreferencesDialog(); + if (preferences.isNull()) { + auto CleanAfterDialog = qScopeGuard([&preferences]() + { + preferences.clear(); + }); + QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - auto *preferences = new DialogPuzzlePreferences(this); - // QScopedPointer needs to be sure any exception will never block guard - QScopedPointer dlg(preferences); - guard = preferences; - // Must be first - connect(dlg.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::WindowsLocale); - connect(dlg.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::ToolBarStyles); + + preferences.reset(new DialogPuzzlePreferences()); + preferences->setWindowModality(Qt::ApplicationModal); + VPApplication::VApp()->SetPreferencesDialog(preferences); + + const QList windows = VPApplication::VApp()->MainWindows(); + for (auto *window : windows) + { + window->ConnectToPreferences(preferences); + } + QGuiApplication::restoreOverrideCursor(); - dlg->exec(); + + preferences->exec(); + } + else + { + preferences->show(); } } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 81d45aa17..227f939e5 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -52,6 +52,8 @@ namespace Ui } class QFileSystemWatcher; +template class QSharedPointer; +class DialogPuzzlePreferences; class VPMainWindow : public VAbstractMainWindow { @@ -563,6 +565,8 @@ private: void CreateWindowMenu(QMenu *menu); auto IsLayoutReadOnly() const -> bool; + + void ConnectToPreferences(const QSharedPointer &preferences); }; #endif // VPMAINWINDOW_H diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index e0b469fc4..46f18ca67 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -195,7 +195,7 @@ QTabWidget::Rounded - 1 + 2 @@ -669,7 +669,7 @@ 0 - 0 + -170 342 870 diff --git a/src/app/puzzle/vpsettings.cpp b/src/app/puzzle/vpsettings.cpp index 4d7360762..e93947ccf 100644 --- a/src/app/puzzle/vpsettings.cpp +++ b/src/app/puzzle/vpsettings.cpp @@ -27,31 +27,56 @@ *************************************************************************/ #include "vpsettings.h" +#include + namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetPropertiesActive, (QLatin1String("dockWidget/properties"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockPropertiesContentsActive, (QLatin1String("dockWidget/contents"))) -} +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnit, (QLatin1String("layout/unit"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSheetPaperWidth, (QLatin1String("layout/sheetPaperWidth"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSheetPaperHeight, (QLatin1String("layout/sheetPaperHeight"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTilePaperWidth, (QLatin1String("layout/tilePaperWidth"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTilePaperHeight, (QLatin1String("layout/tilePaperHeight"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSheetMargins, (QLatin1String("layout/sheetMargins"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileMargins, (QLatin1String("layout/tileMargins"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSheetIgnoreMargins, (QLatin1String("layout/sheetIgnoreMargins"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileIgnoreMargins, (QLatin1String("layout/tileIgnoreMargins"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileShowTiles, (QLatin1String("layout/tileShowTiles"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutWarningPiecesSuperposition, + (QLatin1String("layout/warningPiecesSuperposition"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutStickyEdges, (QLatin1String("layout/stickyEdges"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutWarningPiecesOutOfBound, + (QLatin1String("layout/warningPiecesOutOfBound"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutFollowGrainline, (QLatin1String("layout/followGrainline"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPieceGap, (QLatin1String("layout/pieceGap"))) +} // namespace + +Q_DECLARE_METATYPE(QMarginsF) //--------------------------------------------------------------------------------------------------------------------- VPSettings::VPSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) : VCommonSettings(format, scope, organization, application, parent) -{} +{ + qRegisterMetaTypeStreamOperators("QMarginsF"); +} //--------------------------------------------------------------------------------------------------------------------- VPSettings::VPSettings(const QString &fileName, QSettings::Format format, QObject *parent) : VCommonSettings(fileName, format, parent) -{} +{ + qRegisterMetaTypeStreamOperators("QMarginsF"); +} //--------------------------------------------------------------------------------------------------------------------- -bool VPSettings::IsDockWidgetPropertiesActive() const +auto VPSettings::IsDockWidgetPropertiesActive() const -> bool { return value(*settingDockWidgetPropertiesActive, GetDefDockWidgetPropertiesActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VPSettings::GetDefDockWidgetPropertiesActive() +auto VPSettings::GetDefDockWidgetPropertiesActive() -> bool { return true; } @@ -63,13 +88,13 @@ void VPSettings::SetDockWidgetPropertiesActive(bool value) } //--------------------------------------------------------------------------------------------------------------------- -bool VPSettings::IsDockWidgetPropertiesContentsActive() const +auto VPSettings::IsDockWidgetPropertiesContentsActive() const -> bool { return value(*settingDockWidgetPropertiesActive, GetDefDockWidgetPropertiesActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VPSettings::GetDefDockWidgetPropertiesContentsActive() +auto VPSettings::GetDefDockWidgetPropertiesContentsActive() -> bool { return true; } @@ -79,3 +104,182 @@ void VPSettings::SetDockWidgetPropertiesContentsActive(bool value) { setValue(*settingDockPropertiesContentsActive, value); } + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutUnit(Unit unit) +{ + setValue(*settingLayoutUnit, UnitsToStr(unit)); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::LayoutUnit() const -> Unit +{ + return StrToUnits(value(*settingLayoutUnit, QString()).toString()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutSheetPaperWidth(qreal width) +{ + setValue(*settingLayoutSheetPaperWidth, width); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutSheetPaperWidth() const -> qreal +{ + return ValueOrDef(*this, *settingLayoutSheetPaperWidth, UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutSheetPaperHeight(qreal height) +{ + setValue(*settingLayoutSheetPaperHeight, height); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutSheetPaperHeight() const -> qreal +{ + return ValueOrDef(*this, *settingLayoutSheetPaperHeight, UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutTilePaperWidth(qreal width) +{ + setValue(*settingLayoutTilePaperWidth, width); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutTilePaperWidth() const -> qreal +{ + return ValueOrDef(*this, *settingLayoutTilePaperWidth, UnitConvertor(210/*A4*/, Unit::Mm, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutTilePaperHeight(qreal height) +{ + setValue(*settingLayoutTilePaperHeight, height); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutTilePaperHeight() const -> qreal +{ + return ValueOrDef(*this, *settingLayoutTilePaperHeight, UnitConvertor(297/*A4*/, Unit::Mm, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutSheetMargins(const QMarginsF &margins) +{ + setValue(*settingLayoutSheetMargins, QVariant::fromValue(margins)); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutSheetMargins() const -> QMarginsF +{ + return ValueOrDef(*this, *settingLayoutSheetMargins, QMarginsF()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutTileMargins(const QMarginsF &margins) +{ + setValue(*settingLayoutTileMargins, QVariant::fromValue(margins)); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutTileMargins() const -> QMarginsF +{ + return ValueOrDef(*this, *settingLayoutTileMargins, QMarginsF()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutSheetIgnoreMargins(bool value) +{ + setValue(*settingLayoutSheetIgnoreMargins, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutSheetIgnoreMargins() const -> bool +{ + return value(*settingLayoutSheetIgnoreMargins, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutTileIgnoreMargins(bool value) +{ + setValue(*settingLayoutTileIgnoreMargins, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutTileIgnoreMargins() const -> bool +{ + return value(*settingLayoutTileIgnoreMargins, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutTileShowTiles(bool value) +{ + setValue(*settingLayoutTileShowTiles, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutTileShowTiles() const -> bool +{ + return value(*settingLayoutTileShowTiles, true).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutWarningPiecesSuperposition(bool value) +{ + setValue(*settingLayoutWarningPiecesSuperposition, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutWarningPiecesSuperposition() const -> bool +{ + return value(*settingLayoutWarningPiecesSuperposition, true).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutStickyEdges(bool value) +{ + setValue(*settingLayoutStickyEdges, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutStickyEdges() const -> bool +{ + return value(*settingLayoutStickyEdges, true).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutWarningPiecesOutOfBound(bool value) +{ + setValue(*settingLayoutWarningPiecesOutOfBound, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutWarningPiecesOutOfBound() const -> bool +{ + return value(*settingLayoutWarningPiecesOutOfBound, true).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutFollowGrainline(bool value) +{ + setValue(*settingLayoutFollowGrainline, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutFollowGrainline() const -> bool +{ + return value(*settingLayoutFollowGrainline, false).toBool(); +} + +void VPSettings::SetLayoutPieceGap(qreal value) +{ + setValue(*settingLayoutPieceGap, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutPieceGap() const -> qreal +{ + return ValueOrDef(*this, *settingLayoutPieceGap, UnitConvertor(5, Unit::Mm, Unit::Px)); +} diff --git a/src/app/puzzle/vpsettings.h b/src/app/puzzle/vpsettings.h index 6d822042d..74d26178c 100644 --- a/src/app/puzzle/vpsettings.h +++ b/src/app/puzzle/vpsettings.h @@ -40,14 +40,59 @@ public: QObject *parent = nullptr); VPSettings(const QString &fileName, Format format, QObject *parent = nullptr); - bool IsDockWidgetPropertiesActive() const; - static bool GetDefDockWidgetPropertiesActive(); + auto IsDockWidgetPropertiesActive() const -> bool; + static auto GetDefDockWidgetPropertiesActive() -> bool; void SetDockWidgetPropertiesActive(bool value); - bool IsDockWidgetPropertiesContentsActive() const; - static bool GetDefDockWidgetPropertiesContentsActive(); + auto IsDockWidgetPropertiesContentsActive() const -> bool; + static auto GetDefDockWidgetPropertiesContentsActive() -> bool; void SetDockWidgetPropertiesContentsActive(bool value); + void SetLayoutUnit(Unit unit); + auto LayoutUnit() const -> Unit; + + void SetLayoutSheetPaperWidth(qreal width); + auto GetLayoutSheetPaperWidth() const -> qreal; + + void SetLayoutSheetPaperHeight(qreal height); + auto GetLayoutSheetPaperHeight() const -> qreal; + + void SetLayoutTilePaperWidth(qreal width); + auto GetLayoutTilePaperWidth() const -> qreal; + + void SetLayoutTilePaperHeight(qreal height); + auto GetLayoutTilePaperHeight() const -> qreal; + + void SetLayoutSheetMargins(const QMarginsF &margins); + auto GetLayoutSheetMargins() const -> QMarginsF; + + void SetLayoutTileMargins(const QMarginsF &margins); + auto GetLayoutTileMargins() const -> QMarginsF; + + void SetLayoutSheetIgnoreMargins(bool value); + auto GetLayoutSheetIgnoreMargins() const -> bool; + + void SetLayoutTileIgnoreMargins(bool value); + auto GetLayoutTileIgnoreMargins() const -> bool; + + void SetLayoutTileShowTiles(bool value); + auto GetLayoutTileShowTiles() const -> bool; + + void SetLayoutWarningPiecesSuperposition(bool value); + auto GetLayoutWarningPiecesSuperposition() const -> bool; + + void SetLayoutStickyEdges(bool value); + auto GetLayoutStickyEdges() const -> bool; + + void SetLayoutWarningPiecesOutOfBound(bool value); + auto GetLayoutWarningPiecesOutOfBound() const -> bool; + + void SetLayoutFollowGrainline(bool value); + auto GetLayoutFollowGrainline() const -> bool; + + void SetLayoutPieceGap(qreal value); + auto GetLayoutPieceGap() const -> qreal; + private: Q_DISABLE_COPY(VPSettings) }; diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index 364ff0f0a..22737dad9 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -136,24 +136,24 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) ui->checkBoxDontUseNativeDialog->setChecked(settings->IsDontUseNativeDialog()); // Tab Scrolling - ui->spinBoxDuration->setMinimum(VValentinaSettings::scrollingDurationMin); - ui->spinBoxDuration->setMaximum(VValentinaSettings::scrollingDurationMax); + ui->spinBoxDuration->setMinimum(VCommonSettings::scrollingDurationMin); + ui->spinBoxDuration->setMaximum(VCommonSettings::scrollingDurationMax); ui->spinBoxDuration->setValue(settings->GetScrollingDuration()); - ui->spinBoxUpdateInterval->setMinimum(VValentinaSettings::scrollingUpdateIntervalMin); - ui->spinBoxUpdateInterval->setMaximum(VValentinaSettings::scrollingUpdateIntervalMax); + ui->spinBoxUpdateInterval->setMinimum(VCommonSettings::scrollingUpdateIntervalMin); + ui->spinBoxUpdateInterval->setMaximum(VCommonSettings::scrollingUpdateIntervalMax); ui->spinBoxUpdateInterval->setValue(settings->GetScrollingUpdateInterval()); - ui->doubleSpinBoxSensor->setMinimum(VValentinaSettings::sensorMouseScaleMin); - ui->doubleSpinBoxSensor->setMaximum(VValentinaSettings::sensorMouseScaleMax); + ui->doubleSpinBoxSensor->setMinimum(VCommonSettings::sensorMouseScaleMin); + ui->doubleSpinBoxSensor->setMaximum(VCommonSettings::sensorMouseScaleMax); ui->doubleSpinBoxSensor->setValue(settings->GetSensorMouseScale()); - ui->doubleSpinBoxWheel->setMinimum(VValentinaSettings::wheelMouseScaleMin); - ui->doubleSpinBoxWheel->setMaximum(VValentinaSettings::wheelMouseScaleMax); + ui->doubleSpinBoxWheel->setMinimum(VCommonSettings::wheelMouseScaleMin); + ui->doubleSpinBoxWheel->setMaximum(VCommonSettings::wheelMouseScaleMax); ui->doubleSpinBoxWheel->setValue(settings->GetWheelMouseScale()); - ui->doubleSpinBoxAcceleration->setMinimum(VValentinaSettings::scrollingAccelerationMin); - ui->doubleSpinBoxAcceleration->setMaximum(VValentinaSettings::scrollingAccelerationMax); + ui->doubleSpinBoxAcceleration->setMinimum(VCommonSettings::scrollingAccelerationMin); + ui->doubleSpinBoxAcceleration->setMaximum(VCommonSettings::scrollingAccelerationMax); ui->doubleSpinBoxAcceleration->setValue(settings->GetScrollingAcceleration()); } diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui index 5004dcd15..17f6b00c3 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui @@ -33,9 +33,9 @@ 0 - -189 + 0 624 - 745 + 765 diff --git a/src/libs/vlayout/dialogs/vabstractlayoutdialog.h b/src/libs/vlayout/dialogs/vabstractlayoutdialog.h index 811f9a10a..07323945f 100644 --- a/src/libs/vlayout/dialogs/vabstractlayoutdialog.h +++ b/src/libs/vlayout/dialogs/vabstractlayoutdialog.h @@ -61,6 +61,8 @@ public: static auto GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) -> QSizeF; + static void InitTemplates(QComboBox *comboBoxTemplates); + protected: typedef QStringList FormatsVector; const static FormatsVector pageFormatNames; @@ -68,7 +70,7 @@ protected: static auto RoundTemplateSize(qreal width, qreal height, Unit unit) -> QSizeF; - static void InitTemplates(QComboBox *comboBoxTemplates); + private: Q_DISABLE_COPY(VAbstractLayoutDialog) }; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 816379595..8e7bf8cf4 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -525,7 +525,7 @@ Q_DECL_RELAXED_CONSTEXPR inline qreal UnitConvertor(qreal value, const Unit &fro case Unit::Cm: return value / 10.0; case Unit::Inch: - return value / 25.4; + return value / 10.0 / 2.54; case Unit::Px: return (value / 25.4) * PrintDPI; default: @@ -551,7 +551,7 @@ Q_DECL_RELAXED_CONSTEXPR inline qreal UnitConvertor(qreal value, const Unit &fro switch (to) { case Unit::Mm: - return value * 25.4; + return value * 2.54 * 10.0; case Unit::Cm: return value * 2.54; case Unit::Inch: diff --git a/src/libs/vmisc/share/resources/icon.qrc b/src/libs/vmisc/share/resources/icon.qrc index 72ed1fe0f..7e62554aa 100644 --- a/src/libs/vmisc/share/resources/icon.qrc +++ b/src/libs/vmisc/share/resources/icon.qrc @@ -93,5 +93,6 @@ icon/24x24/star@2x.png icon/24x24/close.png icon/24x24/close@2x.png + icon/layout.png diff --git a/src/libs/vmisc/share/resources/icon/layout.png b/src/libs/vmisc/share/resources/icon/layout.png new file mode 100644 index 000000000..3f4159168 Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/layout.png differ diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 1aa73dc8d..3d2e54a0f 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h"