New option piece line width.

This commit is contained in:
Roman Telezhynskyi 2022-02-09 17:49:14 +02:00
parent b14cb7128b
commit d16aa1af64
8 changed files with 81 additions and 16 deletions

View File

@ -117,6 +117,9 @@ PuzzlePreferencesLayoutPage::PuzzlePreferencesLayoutPage(QWidget *parent) :
connect(ui->doubleSpinBoxPiecesGap, QOverload<double>::of(&QDoubleSpinBox::valueChanged), connect(ui->doubleSpinBoxPiecesGap, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, [this](){m_settingsChanged=true;}); 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->checkBoxWarningPiecesSuperposition, &QCheckBox::stateChanged, this, [this](){m_settingsChanged=true;});
connect(ui->checkBoxStickyEdges, &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->SetLayoutWarningPiecesOutOfBound(ui->checkBoxWarningPiecesOutOfBound->isChecked());
settings->SetLayoutFollowGrainline(ui->checkBoxFollowGrainline->isChecked()); settings->SetLayoutFollowGrainline(ui->checkBoxFollowGrainline->isChecked());
settings->SetLayoutLineWidth(ui->spinBoxLineWidth->value());
if (m_settingsChanged) if (m_settingsChanged)
{ {
preferences.append(tr("default layout settings")); preferences.append(tr("default layout settings"));
@ -260,6 +265,7 @@ void PuzzlePreferencesLayoutPage::ConvertPaperSize()
ui->doubleSpinBoxPiecesGap->setMaximum(UnitConvertor(VPSettings::GetMaxLayoutPieceGap(), Unit::Cm, layoutUnit)); ui->doubleSpinBoxPiecesGap->setMaximum(UnitConvertor(VPSettings::GetMaxLayoutPieceGap(), Unit::Cm, layoutUnit));
ui->doubleSpinBoxPiecesGap->setValue(newGap); ui->doubleSpinBoxPiecesGap->setValue(newGap);
ui->doubleSpinBoxPiecesGap->setSuffix(UnitsToStr(layoutUnit));
m_settingsChanged = true; m_settingsChanged = true;
} }
@ -670,6 +676,8 @@ void PuzzlePreferencesLayoutPage::ReadSettings()
LayoutSheetIgnoreMargins(static_cast<int>(ui->checkBoxLayoutIgnoreFileds->isChecked())); LayoutSheetIgnoreMargins(static_cast<int>(ui->checkBoxLayoutIgnoreFileds->isChecked()));
LayoutTileIgnoreMargins(static_cast<int>(ui->checkBoxTileIgnoreFileds->isChecked())); LayoutTileIgnoreMargins(static_cast<int>(ui->checkBoxTileIgnoreFileds->isChecked()));
ui->spinBoxLineWidth->setValue(settings->GetLayoutLineWidth());
m_settingsChanged = false; m_settingsChanged = false;
} }

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>616</width> <width>616</width>
<height>668</height> <height>686</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -294,7 +294,7 @@
<property name="title"> <property name="title">
<string>Control</string> <string>Control</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_14"> <layout class="QVBoxLayout" name="verticalLayout_8">
<item> <item>
<widget class="QCheckBox" name="checkBoxWarningPiecesSuperposition"> <widget class="QCheckBox" name="checkBoxWarningPiecesSuperposition">
<property name="text"> <property name="text">
@ -337,6 +337,27 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Line width:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxLineWidth">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -140,7 +140,8 @@ void VPLayout::SetTileFactory(VPTileFactory *newTileFactory)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayout::RefreshScenePieces() const void VPLayout::RefreshScenePieces() const
{ {
for (const auto& sheet : GetSheets()) const QList<VPSheetPtr> sheets = GetSheets();
for (const auto& sheet : sheets)
{ {
if (not sheet.isNull()) if (not sheet.isNull())
{ {

View File

@ -45,6 +45,8 @@
#include "../vlayout/vtextmanager.h" #include "../vlayout/vtextmanager.h"
#include "../vpapplication.h"
#include "vlayoutpiecepath.h" #include "vlayoutpiecepath.h"
#include "vplacelabelitem.h" #include "vplacelabelitem.h"
@ -56,8 +58,6 @@ Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece")
namespace namespace
{ {
constexpr qreal penWidth = 1;
QColor mainColor = Qt::black; QColor mainColor = Qt::black;
QColor errorColor = Qt::red; QColor errorColor = Qt::red;
} }
@ -94,7 +94,8 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF
shape.addPath(m_placeLabels); shape.addPath(m_placeLabels);
shape.addPath(m_stickyPath); 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); 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(widget);
Q_UNUSED(option); 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); painter->setPen(pen);
PaintPiece(painter); PaintPiece(painter);

View File

@ -1873,6 +1873,13 @@ void VPMainWindow::ConnectToPreferences(const QSharedPointer<DialogPuzzlePrefere
// Must be first // Must be first
connect(preferences.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::WindowsLocale); connect(preferences.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::WindowsLocale);
connect(preferences.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::ToolBarStyles); connect(preferences.data(), &DialogPuzzlePreferences::UpdateProperties, this, &VPMainWindow::ToolBarStyles);
connect(preferences.data(), &DialogPuzzlePreferences::UpdateProperties, this, [this]()
{
if (not m_layout.isNull())
{
m_layout->RefreshScenePieces();
}
});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -14,7 +14,7 @@
<string>Puzzle</string> <string>Puzzle</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/logo.png</normaloff>:/puzzleicon/64x64/logo.png</iconset> <normaloff>:/puzzleicon/64x64/logo.png</normaloff>:/puzzleicon/64x64/logo.png</iconset>
</property> </property>
<property name="layoutDirection"> <property name="layoutDirection">
@ -232,7 +232,7 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<attribute name="icon"> <attribute name="icon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconCurrentPiece.png</normaloff>:/puzzleicon/64x64/iconCurrentPiece.png</iconset> <normaloff>:/puzzleicon/64x64/iconCurrentPiece.png</normaloff>:/puzzleicon/64x64/iconCurrentPiece.png</iconset>
</attribute> </attribute>
<attribute name="title"> <attribute name="title">
@ -665,7 +665,7 @@
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>40</height> <height>400000</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -678,7 +678,7 @@
</widget> </widget>
<widget class="QWidget" name="tabSheetProperty"> <widget class="QWidget" name="tabSheetProperty">
<attribute name="icon"> <attribute name="icon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconLayout.png</normaloff>:/puzzleicon/64x64/iconLayout.png</iconset> <normaloff>:/puzzleicon/64x64/iconLayout.png</normaloff>:/puzzleicon/64x64/iconLayout.png</iconset>
</attribute> </attribute>
<attribute name="title"> <attribute name="title">
@ -953,7 +953,7 @@
<string notr="true">...</string> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/32X32/horizontal_grainline.png</normaloff>:/puzzleicon/32X32/horizontal_grainline.png</iconset> <normaloff>:/puzzleicon/32X32/horizontal_grainline.png</normaloff>:/puzzleicon/32X32/horizontal_grainline.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -976,7 +976,7 @@
<string notr="true">...</string> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/32X32/vertical_grainline.png</normaloff>:/puzzleicon/32X32/vertical_grainline.png</iconset> <normaloff>:/puzzleicon/32X32/vertical_grainline.png</normaloff>:/puzzleicon/32X32/vertical_grainline.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -1202,7 +1202,7 @@
</widget> </widget>
<widget class="QWidget" name="tabTilesProperty"> <widget class="QWidget" name="tabTilesProperty">
<attribute name="icon"> <attribute name="icon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconTiles.png</normaloff>:/puzzleicon/64x64/iconTiles.png</iconset> <normaloff>:/puzzleicon/64x64/iconTiles.png</normaloff>:/puzzleicon/64x64/iconTiles.png</iconset>
</attribute> </attribute>
<attribute name="title"> <attribute name="title">
@ -1575,7 +1575,7 @@
</widget> </widget>
<widget class="QWidget" name="tabLayoutProperty"> <widget class="QWidget" name="tabLayoutProperty">
<attribute name="icon"> <attribute name="icon">
<iconset> <iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconProperties.png</normaloff>:/puzzleicon/64x64/iconProperties.png</iconset> <normaloff>:/puzzleicon/64x64/iconProperties.png</normaloff>:/puzzleicon/64x64/iconProperties.png</iconset>
</attribute> </attribute>
<attribute name="title"> <attribute name="title">
@ -2352,12 +2352,13 @@
<tabstop>checkBoxLayoutWarningPiecesOutOfBound</tabstop> <tabstop>checkBoxLayoutWarningPiecesOutOfBound</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="share/resources/puzzleicon.qrc"/>
<include location="../../libs/vmisc/share/resources/icon.qrc"/> <include location="../../libs/vmisc/share/resources/icon.qrc"/>
</resources> </resources>
<connections/> <connections/>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroupRotationDirection"/>
<buttongroup name="buttonGroupTileOrientation"/> <buttongroup name="buttonGroupTileOrientation"/>
<buttongroup name="buttonGroupSheetOrientation"/> <buttongroup name="buttonGroupSheetOrientation"/>
<buttongroup name="buttonGroupRotationDirection"/>
</buttongroups> </buttongroups>
</ui> </ui>

View File

@ -26,6 +26,7 @@
** **
*************************************************************************/ *************************************************************************/
#include "vpsettings.h" #include "vpsettings.h"
#include "qglobal.h"
#include <QMarginsF> #include <QMarginsF>
@ -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, settingLayoutFollowGrainline, (QLatin1String("layout/followGrainline")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPieceGap, (QLatin1String("layout/pieceGap"))) 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, settingLayoutExportFormat, (QLatin1String("layout/exportFormat")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutLineWidth, (QLatin1String("layout/lineWidth")))
int cachedLineWidth = -1;
} // namespace } // namespace
Q_DECLARE_METATYPE(QMarginsF) Q_DECLARE_METATYPE(QMarginsF)
@ -316,3 +320,21 @@ void VPSettings::SetLayoutExportFormat(qint8 format)
{ {
setValue(*settingLayoutExportFormat, format); setValue(*settingLayoutExportFormat, format);
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPSettings::GetLayoutLineWidth() const -> int
{
if (cachedLineWidth == -1)
{
cachedLineWidth = qvariant_cast<int>(value(*settingLayoutLineWidth, 1));
}
return cachedLineWidth;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSettings::SetLayoutLineWidth(int width)
{
cachedLineWidth = qBound(1, width, 10);
setValue(*settingLayoutLineWidth, cachedLineWidth);
}

View File

@ -100,6 +100,9 @@ public:
auto GetLayoutExportFormat() const -> qint8; auto GetLayoutExportFormat() const -> qint8;
void SetLayoutExportFormat(qint8 format); void SetLayoutExportFormat(qint8 format);
auto GetLayoutLineWidth() const -> int;
void SetLayoutLineWidth(int width);
private: private:
Q_DISABLE_COPY(VPSettings) Q_DISABLE_COPY(VPSettings)
}; };