From d16aa1af6460df7f61d8bf872e2949eb04740210 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 9 Feb 2022 17:49:14 +0200 Subject: [PATCH] New option piece line width. --- .../puzzlepreferenceslayoutpage.cpp | 8 ++++++ .../puzzlepreferenceslayoutpage.ui | 25 +++++++++++++++++-- src/app/puzzle/layout/vplayout.cpp | 3 ++- src/app/puzzle/scene/vpgraphicspiece.cpp | 10 +++++--- src/app/puzzle/vpmainwindow.cpp | 7 ++++++ src/app/puzzle/vpmainwindow.ui | 19 +++++++------- src/app/puzzle/vpsettings.cpp | 22 ++++++++++++++++ src/app/puzzle/vpsettings.h | 3 +++ 8 files changed, 81 insertions(+), 16 deletions(-) diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp index 9920c2572..23b0bd39f 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp @@ -117,6 +117,9 @@ PuzzlePreferencesLayoutPage::PuzzlePreferencesLayoutPage(QWidget *parent) : connect(ui->doubleSpinBoxPiecesGap, QOverload::of(&QDoubleSpinBox::valueChanged), this, [this](){m_settingsChanged=true;}); + ui->doubleSpinBoxPiecesGap->setSuffix(UnitsToStr(m_oldLayoutUnit)); + + ui->spinBoxLineWidth->setSuffix(UnitsToStr(Unit::Px)); connect(ui->checkBoxWarningPiecesSuperposition, &QCheckBox::stateChanged, this, [this](){m_settingsChanged=true;}); connect(ui->checkBoxStickyEdges, &QCheckBox::stateChanged, this, [this](){m_settingsChanged=true;}); @@ -164,6 +167,8 @@ auto PuzzlePreferencesLayoutPage::Apply() -> QStringList settings->SetLayoutWarningPiecesOutOfBound(ui->checkBoxWarningPiecesOutOfBound->isChecked()); settings->SetLayoutFollowGrainline(ui->checkBoxFollowGrainline->isChecked()); + settings->SetLayoutLineWidth(ui->spinBoxLineWidth->value()); + if (m_settingsChanged) { preferences.append(tr("default layout settings")); @@ -260,6 +265,7 @@ void PuzzlePreferencesLayoutPage::ConvertPaperSize() ui->doubleSpinBoxPiecesGap->setMaximum(UnitConvertor(VPSettings::GetMaxLayoutPieceGap(), Unit::Cm, layoutUnit)); ui->doubleSpinBoxPiecesGap->setValue(newGap); + ui->doubleSpinBoxPiecesGap->setSuffix(UnitsToStr(layoutUnit)); m_settingsChanged = true; } @@ -670,6 +676,8 @@ void PuzzlePreferencesLayoutPage::ReadSettings() LayoutSheetIgnoreMargins(static_cast(ui->checkBoxLayoutIgnoreFileds->isChecked())); LayoutTileIgnoreMargins(static_cast(ui->checkBoxTileIgnoreFileds->isChecked())); + ui->spinBoxLineWidth->setValue(settings->GetLayoutLineWidth()); + m_settingsChanged = false; } diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui index b181ebe16..686a1f150 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.ui @@ -7,7 +7,7 @@ 0 0 616 - 668 + 686 @@ -294,7 +294,7 @@ Control - + @@ -337,6 +337,27 @@ + + + + + + Line width: + + + + + + + 1 + + + 10 + + + + + diff --git a/src/app/puzzle/layout/vplayout.cpp b/src/app/puzzle/layout/vplayout.cpp index c2e203a90..62558086e 100644 --- a/src/app/puzzle/layout/vplayout.cpp +++ b/src/app/puzzle/layout/vplayout.cpp @@ -140,7 +140,8 @@ void VPLayout::SetTileFactory(VPTileFactory *newTileFactory) //--------------------------------------------------------------------------------------------------------------------- void VPLayout::RefreshScenePieces() const { - for (const auto& sheet : GetSheets()) + const QList sheets = GetSheets(); + for (const auto& sheet : sheets) { if (not sheet.isNull()) { diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index b33f434f9..817bf532b 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -45,6 +45,8 @@ #include "../vlayout/vtextmanager.h" +#include "../vpapplication.h" + #include "vlayoutpiecepath.h" #include "vplacelabelitem.h" @@ -56,8 +58,6 @@ Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") namespace { -constexpr qreal penWidth = 1; - QColor mainColor = Qt::black; QColor errorColor = Qt::red; } @@ -94,7 +94,8 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF shape.addPath(m_placeLabels); shape.addPath(m_stickyPath); - constexpr qreal halfPenWidth = penWidth/2.; + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + const qreal halfPenWidth = settings->GetLayoutLineWidth()/2.; return shape.boundingRect().adjusted(-halfPenWidth, -halfPenWidth, halfPenWidth, halfPenWidth); } @@ -116,7 +117,8 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o Q_UNUSED(widget); Q_UNUSED(option); - QPen pen(PieceColor(), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + QPen pen(PieceColor(), settings->GetLayoutLineWidth(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); painter->setPen(pen); PaintPiece(painter); diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 32fb3f481..743325306 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -1873,6 +1873,13 @@ void VPMainWindow::ConnectToPreferences(const QSharedPointerRefreshScenePieces(); + } + }); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 799afc25d..cf3cad2a4 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -14,7 +14,7 @@ Puzzle - + :/puzzleicon/64x64/logo.png:/puzzleicon/64x64/logo.png @@ -232,7 +232,7 @@ - + :/puzzleicon/64x64/iconCurrentPiece.png:/puzzleicon/64x64/iconCurrentPiece.png @@ -665,7 +665,7 @@ 20 - 40 + 400000 @@ -678,7 +678,7 @@ - + :/puzzleicon/64x64/iconLayout.png:/puzzleicon/64x64/iconLayout.png @@ -953,7 +953,7 @@ ... - + :/puzzleicon/32X32/horizontal_grainline.png:/puzzleicon/32X32/horizontal_grainline.png @@ -976,7 +976,7 @@ ... - + :/puzzleicon/32X32/vertical_grainline.png:/puzzleicon/32X32/vertical_grainline.png @@ -1202,7 +1202,7 @@ - + :/puzzleicon/64x64/iconTiles.png:/puzzleicon/64x64/iconTiles.png @@ -1575,7 +1575,7 @@ - + :/puzzleicon/64x64/iconProperties.png:/puzzleicon/64x64/iconProperties.png @@ -2352,12 +2352,13 @@ checkBoxLayoutWarningPiecesOutOfBound + + - diff --git a/src/app/puzzle/vpsettings.cpp b/src/app/puzzle/vpsettings.cpp index f7da12b33..b936587bb 100644 --- a/src/app/puzzle/vpsettings.cpp +++ b/src/app/puzzle/vpsettings.cpp @@ -26,6 +26,7 @@ ** *************************************************************************/ #include "vpsettings.h" +#include "qglobal.h" #include @@ -52,6 +53,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutWarningPiecesOutOfBound, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutFollowGrainline, (QLatin1String("layout/followGrainline"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPieceGap, (QLatin1String("layout/pieceGap"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutExportFormat, (QLatin1String("layout/exportFormat"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutLineWidth, (QLatin1String("layout/lineWidth"))) + +int cachedLineWidth = -1; } // namespace Q_DECLARE_METATYPE(QMarginsF) @@ -316,3 +320,21 @@ void VPSettings::SetLayoutExportFormat(qint8 format) { setValue(*settingLayoutExportFormat, format); } + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSettings::GetLayoutLineWidth() const -> int +{ + if (cachedLineWidth == -1) + { + cachedLineWidth = qvariant_cast(value(*settingLayoutLineWidth, 1)); + } + + return cachedLineWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetLayoutLineWidth(int width) +{ + cachedLineWidth = qBound(1, width, 10); + setValue(*settingLayoutLineWidth, cachedLineWidth); +} diff --git a/src/app/puzzle/vpsettings.h b/src/app/puzzle/vpsettings.h index 032f86a7f..742ac0d6d 100644 --- a/src/app/puzzle/vpsettings.h +++ b/src/app/puzzle/vpsettings.h @@ -100,6 +100,9 @@ public: auto GetLayoutExportFormat() const -> qint8; void SetLayoutExportFormat(qint8 format); + auto GetLayoutLineWidth() const -> int; + void SetLayoutLineWidth(int width); + private: Q_DISABLE_COPY(VPSettings) };