From 7b1449f11ec17d80eb105822d93f75e955a48d24 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 10 May 2020 18:32:14 +0300 Subject: [PATCH 01/10] Redesign settings. All apps settings classes moved to binaries. Use common part to get access from static libraries. Fixed issues with VMainGraphicsView class. --- src/app/puzzle/puzzle.pri | 2 + src/app/puzzle/puzzle.pro | 24 +- src/app/puzzle/puzzleapplication.h | 2 +- src/app/puzzle/vpuzzlesettings.cpp | 81 ++++ .../vmisc => app/puzzle}/vpuzzlesettings.h | 9 + .../tapepreferencesconfigurationpage.cpp | 2 +- .../configpages/tapepreferencespathpage.cpp | 2 +- .../tape/dialogs/dialognewmeasurements.cpp | 2 +- src/app/tape/mapplication.h | 2 +- src/app/tape/tape.pri | 6 +- .../vmisc => app/tape}/vtapesettings.cpp | 0 src/{libs/vmisc => app/tape}/vtapesettings.h | 0 src/app/valentina/core/core.pri | 6 +- src/app/valentina/core/vapplication.cpp | 10 +- src/app/valentina/core/vapplication.h | 4 +- src/app/valentina/core/vcmdexport.cpp | 6 +- .../valentina/core/vvalentinasettings.cpp} | 365 +++++------------- .../valentina/core/vvalentinasettings.h} | 56 +-- .../preferencesconfigurationpage.cpp | 26 +- .../configpages/preferencespathpage.cpp | 10 +- .../configpages/preferencespatternpage.cpp | 8 +- .../dialogs/dialogfinalmeasurements.cpp | 2 +- .../valentina/dialogs/dialogincrements.cpp | 2 +- .../valentina/dialogs/dialoglayoutscale.cpp | 6 +- .../dialogs/dialoglayoutsettings.cpp | 26 +- .../valentina/dialogs/dialognewpattern.cpp | 2 +- .../dialogs/dialogpatternproperties.cpp | 4 +- .../valentina/dialogs/dialogsavelayout.cpp | 6 +- src/app/valentina/mainwindow.cpp | 18 +- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/app/valentina/xml/vpattern.cpp | 2 +- src/libs/vmisc/testvapplication.h | 30 +- src/libs/vmisc/vabstractapplication.h | 1 - src/libs/vmisc/vcommonsettings.cpp | 149 +++++++ src/libs/vmisc/vcommonsettings.h | 86 +++++ src/libs/vmisc/vmisc.pri | 10 +- src/libs/vmisc/vpuzzlesettings.cpp | 37 -- src/libs/vwidgets/vmaingraphicsview.cpp | 10 +- 38 files changed, 548 insertions(+), 468 deletions(-) create mode 100644 src/app/puzzle/vpuzzlesettings.cpp rename src/{libs/vmisc => app/puzzle}/vpuzzlesettings.h (79%) rename src/{libs/vmisc => app/tape}/vtapesettings.cpp (100%) rename src/{libs/vmisc => app/tape}/vtapesettings.h (100%) rename src/{libs/vmisc/vsettings.cpp => app/valentina/core/vvalentinasettings.cpp} (63%) rename src/{libs/vmisc/vsettings.h => app/valentina/core/vvalentinasettings.h} (75%) delete mode 100644 src/libs/vmisc/vpuzzlesettings.cpp diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index 418af8d9d..47095dbab 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -18,6 +18,7 @@ SOURCES += \ $$PWD/vpuzzlemaingraphicsview.cpp \ $$PWD/vpuzzlemimedatapiece.cpp \ $$PWD/vpuzzlepiece.cpp \ + $$PWD/vpuzzlesettings.cpp \ $$PWD/xml/layoutliterals.cpp \ $$PWD/xml/vpuzzlelayoutfilewriter.cpp \ $$PWD/xml/vpuzzlelayoutfilereader.cpp \ @@ -43,6 +44,7 @@ HEADERS += \ $$PWD/vpuzzlemaingraphicsview.h \ $$PWD/vpuzzlemimedatapiece.h \ $$PWD/vpuzzlepiece.h \ + $$PWD/vpuzzlesettings.h \ $$PWD/xml/layoutliterals.h \ $$PWD/xml/vpuzzlelayoutfilewriter.h \ $$PWD/xml/vpuzzlelayoutfilereader.h \ diff --git a/src/app/puzzle/puzzle.pro b/src/app/puzzle/puzzle.pro index be7037a9e..462579124 100644 --- a/src/app/puzzle/puzzle.pro +++ b/src/app/puzzle/puzzle.pro @@ -197,14 +197,14 @@ noRunPath{ # For enable run qmake with CONFIG+=noRunPath #win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib #else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a -##VWidgets static library -#unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets +#VWidgets static library +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets -#INCLUDEPATH += $$PWD/../../libs/vwidgets -#DEPENDPATH += $$PWD/../../libs/vwidgets +INCLUDEPATH += $$PWD/../../libs/vwidgets +DEPENDPATH += $$PWD/../../libs/vwidgets -#win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib -#else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a ## VFormat static library (depend on VPatternDB, IFC) #unix|win32: LIBS += -L$$OUT_PWD/../../libs/vformat/$${DESTDIR}/ -lvformat @@ -277,13 +277,13 @@ else:unix: LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser INCLUDEPATH += $${PWD}/../../libs/qmuparser DEPENDPATH += $${PWD}/../../libs/qmuparser -## VPropertyExplorer library -#win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer -#else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer -#else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +# VPropertyExplorer library +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer -#INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer -#DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer +INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer +DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer contains(DEFINES, APPIMAGE) { unix:!macx: LIBS += -licudata -licui18n -licuuc diff --git a/src/app/puzzle/puzzleapplication.h b/src/app/puzzle/puzzleapplication.h index d93748835..0b7b2ac84 100644 --- a/src/app/puzzle/puzzleapplication.h +++ b/src/app/puzzle/puzzleapplication.h @@ -29,7 +29,7 @@ #define PUZZLEAPPLICATION_H #include "../vmisc/def.h" -#include "../vmisc/vpuzzlesettings.h" +#include "vpuzzlesettings.h" #include "../vmisc/vabstractapplication.h" #include "vpuzzlecommandline.h" diff --git a/src/app/puzzle/vpuzzlesettings.cpp b/src/app/puzzle/vpuzzlesettings.cpp new file mode 100644 index 000000000..6d4ad24d0 --- /dev/null +++ b/src/app/puzzle/vpuzzlesettings.cpp @@ -0,0 +1,81 @@ +/************************************************************************ + ** + ** @file vpuzzlesettings.cpp + ** @author Roman Telezhynskyi + ** @date 16 2, 2020 + ** + ** @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) 2020 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 "vpuzzlesettings.h" + +namespace +{ +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetPropertiesActive, (QLatin1String("dockWidget/properties"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockPropertiesContentsActive, (QLatin1String("dockWidget/contents"))) +} + +//--------------------------------------------------------------------------------------------------------------------- +VPuzzleSettings::VPuzzleSettings(Format format, Scope scope, const QString &organization, const QString &application, + QObject *parent) + : VCommonSettings(format, scope, organization, application, parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPuzzleSettings::VPuzzleSettings(const QString &fileName, QSettings::Format format, QObject *parent) + : VCommonSettings(fileName, format, parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPuzzleSettings::IsDockWidgetPropertiesActive() const +{ + return value(*settingDockWidgetPropertiesActive, GetDefDockWidgetPropertiesActive()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPuzzleSettings::GetDefDockWidgetPropertiesActive() +{ + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleSettings::SetDockWidgetPropertiesActive(bool value) +{ + setValue(*settingDockWidgetPropertiesActive, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPuzzleSettings::IsDockWidgetPropertiesContentsActive() const +{ + return value(*settingDockWidgetPropertiesActive, GetDefDockWidgetPropertiesActive()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPuzzleSettings::GetDefDockWidgetPropertiesContentsActive() +{ + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleSettings::SetDockWidgetPropertiesContentsActive(bool value) +{ + setValue(*settingDockPropertiesContentsActive, value); +} diff --git a/src/libs/vmisc/vpuzzlesettings.h b/src/app/puzzle/vpuzzlesettings.h similarity index 79% rename from src/libs/vmisc/vpuzzlesettings.h rename to src/app/puzzle/vpuzzlesettings.h index f4ab19b01..97906df41 100644 --- a/src/libs/vmisc/vpuzzlesettings.h +++ b/src/app/puzzle/vpuzzlesettings.h @@ -38,6 +38,15 @@ class VPuzzleSettings : public VCommonSettings public: VPuzzleSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), QObject *parent = nullptr); + VPuzzleSettings(const QString &fileName, Format format, QObject *parent = nullptr); + + bool IsDockWidgetPropertiesActive() const; + static bool GetDefDockWidgetPropertiesActive(); + void SetDockWidgetPropertiesActive(bool value); + + bool IsDockWidgetPropertiesContentsActive() const; + static bool GetDefDockWidgetPropertiesContentsActive(); + void SetDockWidgetPropertiesContentsActive(bool value); private: Q_DISABLE_COPY(VPuzzleSettings) diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp index b8d42f37f..07d1ad1c4 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp @@ -29,7 +29,7 @@ #include "tapepreferencesconfigurationpage.h" #include "ui_tapepreferencesconfigurationpage.h" #include "../../mapplication.h" -#include "../vmisc/vtapesettings.h" +#include "../../vtapesettings.h" #include "../vpatterndb/variables/vmeasurement.h" #include "../vpatterndb/pmsystems.h" diff --git a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp index be64952b3..1908dc500 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp @@ -29,7 +29,7 @@ #include "tapepreferencespathpage.h" #include "ui_tapepreferencespathpage.h" #include "../../mapplication.h" -#include "../vmisc/vtapesettings.h" +#include "../../vtapesettings.h" #include #include diff --git a/src/app/tape/dialogs/dialognewmeasurements.cpp b/src/app/tape/dialogs/dialognewmeasurements.cpp index 9643fa021..2b206225c 100644 --- a/src/app/tape/dialogs/dialognewmeasurements.cpp +++ b/src/app/tape/dialogs/dialognewmeasurements.cpp @@ -30,7 +30,7 @@ #include "ui_dialognewmeasurements.h" #include "../vpatterndb/variables/vmeasurement.h" -#include "../vmisc/vtapesettings.h" +#include "../vtapesettings.h" #include "../mapplication.h" #include diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index a121ced88..839780026 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -31,7 +31,7 @@ #include "../vpatterndb/vtranslatevars.h" #include "../vmisc/def.h" -#include "../vmisc/vtapesettings.h" +#include "vtapesettings.h" #include "../vmisc/vabstractapplication.h" #include "dialogs/dialogmdatabase.h" diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index 6f46e9e94..c6d13b731 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -11,7 +11,8 @@ SOURCES += \ $$PWD/vlitepattern.cpp \ $$PWD/dialogs/dialogtapepreferences.cpp \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.cpp \ - $$PWD/dialogs/configpages/tapepreferencespathpage.cpp + $$PWD/dialogs/configpages/tapepreferencespathpage.cpp \ + $$PWD/vtapesettings.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -26,7 +27,8 @@ HEADERS += \ $$PWD/vlitepattern.h \ $$PWD/dialogs/dialogtapepreferences.h \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.h \ - $$PWD/dialogs/configpages/tapepreferencespathpage.h + $$PWD/dialogs/configpages/tapepreferencespathpage.h \ + $$PWD/vtapesettings.h FORMS += \ $$PWD/tmainwindow.ui \ diff --git a/src/libs/vmisc/vtapesettings.cpp b/src/app/tape/vtapesettings.cpp similarity index 100% rename from src/libs/vmisc/vtapesettings.cpp rename to src/app/tape/vtapesettings.cpp diff --git a/src/libs/vmisc/vtapesettings.h b/src/app/tape/vtapesettings.h similarity index 100% rename from src/libs/vmisc/vtapesettings.h rename to src/app/tape/vtapesettings.h diff --git a/src/app/valentina/core/core.pri b/src/app/valentina/core/core.pri index 8cd2a23c9..4c41cef6e 100644 --- a/src/app/valentina/core/core.pri +++ b/src/app/valentina/core/core.pri @@ -6,11 +6,13 @@ HEADERS += \ $$PWD/vformulaproperty.h \ $$PWD/vformulapropertyeditor.h \ $$PWD/vtooloptionspropertybrowser.h \ - $$PWD/vcmdexport.h + $$PWD/vcmdexport.h \ + $$PWD/vvalentinasettings.h SOURCES += \ $$PWD/vapplication.cpp \ $$PWD/vformulaproperty.cpp \ $$PWD/vformulapropertyeditor.cpp \ $$PWD/vtooloptionspropertybrowser.cpp \ - $$PWD/vcmdexport.cpp + $$PWD/vcmdexport.cpp \ + $$PWD/vvalentinasettings.cpp diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 91514f439..6d0cf88bc 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -447,7 +447,7 @@ bool VApplication::notify(QObject *receiver, QEvent *event) void VApplication::ActivateDarkMode() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); if (settings->GetDarkMode()) { QFile f(QStringLiteral(":qdarkstyle/style.qss")); @@ -726,15 +726,15 @@ void VApplication::AboutToQuit() */ void VApplication::OpenSettings() { - settings = new VSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), - QCoreApplication::applicationName(), this); + settings = new VValentinaSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), + QCoreApplication::applicationName(), this); } //--------------------------------------------------------------------------------------------------------------------- -VSettings *VApplication::ValentinaSettings() +VValentinaSettings *VApplication::ValentinaSettings() { SCASSERT(settings != nullptr) - return qobject_cast(settings); + return qobject_cast(settings); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h index 94dc56eff..a1af112bc 100644 --- a/src/app/valentina/core/vapplication.h +++ b/src/app/valentina/core/vapplication.h @@ -32,7 +32,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vwidgets/vmaingraphicsview.h" #include "../vpatterndb/vtranslatevars.h" -#include "vsettings.h" +#include "vvalentinasettings.h" #include "vcmdexport.h" class VApplication;// use in define @@ -76,7 +76,7 @@ public: virtual bool IsPedantic() const override; virtual void OpenSettings() override; - VSettings *ValentinaSettings(); + VValentinaSettings *ValentinaSettings(); protected: virtual void InitTrVars() override; diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index e8354c418..40cfe7a6e 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -32,7 +32,7 @@ #include "../ifc/xml/vdomdocument.h" #include "../vformat/vmeasurements.h" #include "../vmisc/commandoptions.h" -#include "../vmisc/vsettings.h" +#include "vvalentinasettings.h" #include "../vmisc/dialogs/dialogexporttocsv.h" #include "../vlayout/vlayoutgenerator.h" #include "../vpatterndb/variables/vmeasurement.h" @@ -801,7 +801,7 @@ QStringList VCommandLine::OptionValues(const QString &option) const //--------------------------------------------------------------------------------------------------------------------- int VCommandLine::OptNestingTime() const { - int time = VSettings::GetDefNestingTime(); + int time = VValentinaSettings::GetDefNestingTime(); if (IsOptionSet(LONG_OPTION_NESTING_TIME)) { bool ok = false; @@ -821,7 +821,7 @@ int VCommandLine::OptNestingTime() const //--------------------------------------------------------------------------------------------------------------------- qreal VCommandLine::OptEfficiencyCoefficient() const { - qreal coefficient = VSettings::GetDefEfficiencyCoefficient(); + qreal coefficient = VValentinaSettings::GetDefEfficiencyCoefficient(); if (IsOptionSet(LONG_OPTION_EFFICIENCY_COEFFICIENT)) { bool ok = false; diff --git a/src/libs/vmisc/vsettings.cpp b/src/app/valentina/core/vvalentinasettings.cpp similarity index 63% rename from src/libs/vmisc/vsettings.cpp rename to src/app/valentina/core/vvalentinasettings.cpp index dbe6ff220..a12d2b050 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/app/valentina/core/vvalentinasettings.cpp @@ -26,7 +26,7 @@ ** *************************************************************************/ -#include "vsettings.h" +#include "vvalentinasettings.h" #include #include @@ -47,26 +47,6 @@ Q_DECLARE_METATYPE(QMarginsF) -const int VSettings::defaultScrollingDuration = 300; -const int VSettings::scrollingDurationMin = 100; -const int VSettings::scrollingDurationMax = 1000; - -const int VSettings::defaultScrollingUpdateInterval = 30; -const int VSettings::scrollingUpdateIntervalMin = 10; -const int VSettings::scrollingUpdateIntervalMax = 100; - -const qreal VSettings::defaultSensorMouseScale = 2.0; -const qreal VSettings::sensorMouseScaleMin = 1.0; -const qreal VSettings::sensorMouseScaleMax = 10.0; - -const qreal VSettings::defaultWheelMouseScale = 45.0; -const qreal VSettings::wheelMouseScaleMin = 1.0; -const qreal VSettings::wheelMouseScaleMax = 100.0; - -const qreal VSettings::defaultScrollingAcceleration = 1.3; -const qreal VSettings::scrollingAccelerationMin = 1.0; -const qreal VSettings::scrollingAccelerationMax = 10.0; - namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationLabelLanguage, @@ -76,8 +56,6 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingAutoRefreshPatternMessage, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsLayout, (QLatin1String("paths/layout"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput, (QLatin1String("pattern/graphicalOutput"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender, (QLatin1String("pattern/useOpenGLRender"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternKnownMaterials, (QLatin1String("pattern/knownMaterials"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternRememberMaterials, (QLatin1String("pattern/rememberMaterials"))) @@ -107,13 +85,6 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperHeight, (QLatin1Str Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperWidth, (QLatin1String("tiledPDF/paperWidth"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingSensorMouseScale, - (QLatin1String("scrolling/sensorMouseScale"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingWheelMouseScale, (QLatin1String("scrolling/wheelMouseScale"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingAcceleration, (QLatin1String("scrolling/acceleration"))) - Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingdockWidgetGroupsActive, (QLatin1String("dockWidget/groupsActive"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetToolOptionsActive, (QLatin1String("dockWidget/toolOptionsActive"))) @@ -122,17 +93,10 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetPatternMessagesActive, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternMessagesFontSize, (QLatin1String("font/patternMessagesSize"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkEditorSize, (QLatin1String("watermarkEditorSize"))) - -// Reading settings file is very expensive, cache values to speed up getting a value -int scrollingDurationCached = -1; -int scrollingUpdateIntervalCached = -1; -qreal scrollingSensorMouseScaleCached = -1; -qreal scrollingWheelMouseScaleCached = -1; -qreal scrollingAccelerationCached = -1; } //--------------------------------------------------------------------------------------------------------------------- -VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, +VValentinaSettings::VValentinaSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) :VCommonSettings(format, scope, organization, application, parent) { @@ -140,63 +104,39 @@ VSettings::VSettings(Format format, Scope scope, const QString &organization, co } //--------------------------------------------------------------------------------------------------------------------- -VSettings::VSettings(const QString &fileName, QSettings::Format format, QObject *parent) +VValentinaSettings::VValentinaSettings(const QString &fileName, QSettings::Format format, QObject *parent) :VCommonSettings(fileName, format, parent) { qRegisterMetaTypeStreamOperators("QMarginsF"); } //--------------------------------------------------------------------------------------------------------------------- -template -inline T VSettings::ValueOrDef(const QString &setting, const T &defValue) const -{ - const QVariant val = value(setting, QVariant::fromValue(defValue)); - return val.canConvert() ? val.value() : defValue; -} - -//--------------------------------------------------------------------------------------------------------------------- -template <> -inline Cases VSettings::ValueOrDef(const QString &setting, const Cases &defValue) const -{ - const QVariant val = value(setting, QVariant::fromValue(static_cast(defValue))); - const int g = val.canConvert() ? val.value() : static_cast(defValue); - if (g < static_cast(Cases::CaseThreeGroup) || g >= static_cast(Cases::UnknownCase)) - { - return defValue; - } - else - { - return static_cast(g); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VSettings::GetLabelLanguage() const +QString VValentinaSettings::GetLabelLanguage() const { return value(*settingConfigurationLabelLanguage, QLocale().bcp47Name()).toString(); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLabelLanguage(const QString &value) +void VValentinaSettings::SetLabelLanguage(const QString &value) { setValue(*settingConfigurationLabelLanguage, value); } //--------------------------------------------------------------------------------------------------------------------- -QString VSettings::GetDefPathLayout() +QString VValentinaSettings::GetDefPathLayout() { return QDir::homePath() + QStringLiteral("/valentina/") + tr("layouts"); } //--------------------------------------------------------------------------------------------------------------------- -QString VSettings::GetPathLayout() const +QString VValentinaSettings::GetPathLayout() const { QSettings settings(this->format(), this->scope(), this->organizationName(), this->applicationName()); return settings.value(*settingPathsLayout, GetDefPathLayout()).toString(); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetPathLayout(const QString &value) +void VValentinaSettings::SetPathLayout(const QString &value) { QSettings settings(this->format(), this->scope(), this->organizationName(), this->applicationName()); settings.setValue(*settingPathsLayout, value); @@ -204,358 +144,334 @@ void VSettings::SetPathLayout(const QString &value) } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetGraphicalOutput() const +qreal VValentinaSettings::GetLayoutPaperHeight() const { - return value(*settingPatternGraphicalOutput, 1).toBool(); + return ValueOrDef(*this, *settingLayoutPaperHeight, UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px)); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetGraphicalOutput(const bool &value) -{ - setValue(*settingPatternGraphicalOutput, value); -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VSettings::IsOpenGLRender() const -{ - return value(*settingPatternUseOpenGLRender, 0).toBool(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetOpenGLRender(bool value) -{ - setValue(*settingPatternUseOpenGLRender, value); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetLayoutPaperHeight() const -{ - return ValueOrDef(*settingLayoutPaperHeight, UnitConvertor(1189/*A0*/, Unit::Mm, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutPaperHeight(qreal value) +void VValentinaSettings::SetLayoutPaperHeight(qreal value) { setValue(*settingLayoutPaperHeight, value); } //--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetLayoutPaperWidth() const +qreal VValentinaSettings::GetLayoutPaperWidth() const { - return ValueOrDef(*settingLayoutPaperWidth, UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px)); + return ValueOrDef(*this, *settingLayoutPaperWidth, UnitConvertor(841/*A0*/, Unit::Mm, Unit::Px)); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutPaperWidth(qreal value) +void VValentinaSettings::SetLayoutPaperWidth(qreal value) { setValue(*settingLayoutPaperWidth, value); } //--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetLayoutWidth() const +qreal VValentinaSettings::GetLayoutWidth() const { - return ValueOrDef(*settingLayoutWidth, GetDefLayoutWidth()); + return ValueOrDef(*this, *settingLayoutWidth, GetDefLayoutWidth()); } //--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetDefLayoutWidth() +qreal VValentinaSettings::GetDefLayoutWidth() { return UnitConvertor(2.5, Unit::Mm, Unit::Px); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutWidth(qreal value) +void VValentinaSettings::SetLayoutWidth(qreal value) { setValue(*settingLayoutWidth, value); } //--------------------------------------------------------------------------------------------------------------------- -int VSettings::GetNestingTime() const +int VValentinaSettings::GetNestingTime() const { - return ValueOrDef(*settingNestingTime, GetDefNestingTime()); + return ValueOrDef(*this, *settingNestingTime, GetDefNestingTime()); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetNestingTime(int value) +void VValentinaSettings::SetNestingTime(int value) { setValue(*settingNestingTime, value); } //--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetEfficiencyCoefficient() const +qreal VValentinaSettings::GetEfficiencyCoefficient() const { - return ValueOrDef(*settingEfficiencyCoefficient, GetDefEfficiencyCoefficient()); + return ValueOrDef(*this, *settingEfficiencyCoefficient, GetDefEfficiencyCoefficient()); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetEfficiencyCoefficient(qreal value) +void VValentinaSettings::SetEfficiencyCoefficient(qreal value) { setValue(*settingEfficiencyCoefficient, value); } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF VSettings::GetFields(const QMarginsF &def) const +QMarginsF VValentinaSettings::GetFields(const QMarginsF &def) const { - return ValueOrDef(*settingFields, def); + return ValueOrDef(*this, *settingFields, def); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetFields(const QMarginsF &value) +void VValentinaSettings::SetFields(const QMarginsF &value) { setValue(*settingFields, QVariant::fromValue(value)); } //--------------------------------------------------------------------------------------------------------------------- -Cases VSettings::GetLayoutGroup() const +Cases VValentinaSettings::GetLayoutGroup() const { - return ValueOrDef(*settingLayoutSorting, GetDefLayoutGroup()); + return ValueOrDef(*this, *settingLayoutSorting, GetDefLayoutGroup()); } //--------------------------------------------------------------------------------------------------------------------- -Cases VSettings::GetDefLayoutGroup() +Cases VValentinaSettings::GetDefLayoutGroup() { return Cases::CaseDesc; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutGroup(const Cases &value) +void VValentinaSettings::SetLayoutGroup(const Cases &value) { setValue(*settingLayoutSorting, static_cast(value)); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutFollowGrainline() const +bool VValentinaSettings::GetLayoutFollowGrainline() const { return value(*settingLayoutFollowGrainline, GetDefLayoutFollowGrainline()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutFollowGrainline() +bool VValentinaSettings::GetDefLayoutFollowGrainline() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutFollowGrainline(bool value) +void VValentinaSettings::SetLayoutFollowGrainline(bool value) { setValue(*settingLayoutFollowGrainline, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutManualPriority() const +bool VValentinaSettings::GetLayoutManualPriority() const { return value(*settingLayoutManualPriority, GetDefLayoutManualPriority()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutManualPriority() +bool VValentinaSettings::GetDefLayoutManualPriority() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutManualPriority(bool value) +void VValentinaSettings::SetLayoutManualPriority(bool value) { setValue(*settingLayoutManualPriority, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutNestQuantity() const +bool VValentinaSettings::GetLayoutNestQuantity() const { return value(*settingLayoutNestQuantity, GetDefLayoutNestQuantity()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutNestQuantity() +bool VValentinaSettings::GetDefLayoutNestQuantity() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutNestQuantity(bool value) +void VValentinaSettings::SetLayoutNestQuantity(bool value) { setValue(*settingLayoutNestQuantity, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutAutoCropLength() const +bool VValentinaSettings::GetLayoutAutoCropLength() const { return value(*settingLayoutAutoCropLength, GetDefLayoutAutoCropLength()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutAutoCropLength() +bool VValentinaSettings::GetDefLayoutAutoCropLength() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutAutoCropLength(bool value) +void VValentinaSettings::SetLayoutAutoCropLength(bool value) { setValue(*settingLayoutAutoCropLength, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutAutoCropWidth() const +bool VValentinaSettings::GetLayoutAutoCropWidth() const { return value(*settingLayoutAutoCropWidth, GetDefLayoutAutoCropWidth()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutAutoCropWidth() +bool VValentinaSettings::GetDefLayoutAutoCropWidth() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutAutoCropWidth(bool value) +void VValentinaSettings::SetLayoutAutoCropWidth(bool value) { setValue(*settingLayoutAutoCropWidth, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutSaveLength() const +bool VValentinaSettings::GetLayoutSaveLength() const { return value(*settingLayoutSaveLength, GetDefLayoutSaveLength()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutSaveLength() +bool VValentinaSettings::GetDefLayoutSaveLength() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutSaveLength(bool value) +void VValentinaSettings::SetLayoutSaveLength(bool value) { setValue(*settingLayoutSaveLength, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutPreferOneSheetSolution() const +bool VValentinaSettings::GetLayoutPreferOneSheetSolution() const { return value(*settingLayoutPreferOneSheetSolution, GetDefLayoutPreferOneSheetSolution()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutPreferOneSheetSolution() +bool VValentinaSettings::GetDefLayoutPreferOneSheetSolution() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutPreferOneSheetSolution(bool value) +void VValentinaSettings::SetLayoutPreferOneSheetSolution(bool value) { setValue(*settingLayoutPreferOneSheetSolution, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetLayoutUnitePages() const +bool VValentinaSettings::GetLayoutUnitePages() const { return value(*settingLayoutUnitePages, GetDefLayoutUnitePages()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefLayoutUnitePages() +bool VValentinaSettings::GetDefLayoutUnitePages() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutUnitePages(bool value) +void VValentinaSettings::SetLayoutUnitePages(bool value) { setValue(*settingLayoutUnitePages, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetIgnoreAllFields() const +bool VValentinaSettings::GetIgnoreAllFields() const { return value(*settingIgnoreFields, GetDefIgnoreAllFields()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefIgnoreAllFields() +bool VValentinaSettings::GetDefIgnoreAllFields() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetIgnoreAllFields(bool value) +void VValentinaSettings::SetIgnoreAllFields(bool value) { setValue(*settingIgnoreFields, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetStripOptimization() const +bool VValentinaSettings::GetStripOptimization() const { return value(*settingStripOptimization, GetDefStripOptimization()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefStripOptimization() +bool VValentinaSettings::GetDefStripOptimization() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetStripOptimization(bool value) +void VValentinaSettings::SetStripOptimization(bool value) { setValue(*settingStripOptimization, value); } //--------------------------------------------------------------------------------------------------------------------- -quint8 VSettings::GetMultiplier() const +quint8 VValentinaSettings::GetMultiplier() const { return static_cast(value(*settingMultiplier, GetDefMultiplier()).toUInt()); } //--------------------------------------------------------------------------------------------------------------------- -quint8 VSettings::GetDefMultiplier() +quint8 VValentinaSettings::GetDefMultiplier() { return 1; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetMultiplier(quint8 value) +void VValentinaSettings::SetMultiplier(quint8 value) { setValue(*settingMultiplier, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetTextAsPaths() const +bool VValentinaSettings::GetTextAsPaths() const { return value(*settingTextAsPaths, GetDefTextAsPaths()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefTextAsPaths() +bool VValentinaSettings::GetDefTextAsPaths() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetTextAsPaths(bool value) +void VValentinaSettings::SetTextAsPaths(bool value) { setValue(*settingTextAsPaths, value); } //--------------------------------------------------------------------------------------------------------------------- -QStringList VSettings::GetKnownMaterials() const +QStringList VValentinaSettings::GetKnownMaterials() const { return value(*settingPatternKnownMaterials, QStringList()).toStringList(); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetKnownMaterials(const QStringList &list) +void VValentinaSettings::SetKnownMaterials(const QStringList &list) { setValue(*settingPatternKnownMaterials, list); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::IsRememberPatternMaterials() const +bool VValentinaSettings::IsRememberPatternMaterials() const { return value(*settingPatternRememberMaterials, true).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetRememberPatternMaterials(bool value) +void VValentinaSettings::SetRememberPatternMaterials(bool value) { setValue(*settingPatternRememberMaterials, value); } @@ -569,10 +485,11 @@ void VSettings::SetRememberPatternMaterials(bool value) * internaly as mm so there is conversion beeing made. * @return tiled pdf margins */ -QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const +QMarginsF VValentinaSettings::GetTiledPDFMargins(const Unit &unit) const { // default value is 10mm. We save the margins in mm in the setting. - return UnitConvertor(ValueOrDef(*settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit); + return UnitConvertor(ValueOrDef(*this, *settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, + unit); } //--------------------------------------------------------------------------------------------------------------------- @@ -582,7 +499,7 @@ QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const * @param unit the unit in which are the value. Necessary because we save the values * internaly as mm so there is conversion beeing made. */ -void VSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit) +void VValentinaSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit) { setValue(*settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm))); } @@ -594,9 +511,9 @@ void VSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit) * internaly as mm so there is conversion beeing made. * @return tiled pdf paper height */ -qreal VSettings::GetTiledPDFPaperHeight(const Unit &unit) const +qreal VValentinaSettings::GetTiledPDFPaperHeight(const Unit &unit) const { - return UnitConvertor(ValueOrDef(*settingTiledPDFPaperHeight, 297 /*A4*/), Unit::Mm, unit); + return UnitConvertor(ValueOrDef(*this, *settingTiledPDFPaperHeight, 297 /*A4*/), Unit::Mm, unit); } //--------------------------------------------------------------------------------------------------------------------- @@ -605,7 +522,7 @@ qreal VSettings::GetTiledPDFPaperHeight(const Unit &unit) const * @param value in mm * @param unit unit of the given value */ -void VSettings::SetTiledPDFPaperHeight(qreal value, const Unit &unit) +void VValentinaSettings::SetTiledPDFPaperHeight(qreal value, const Unit &unit) { setValue(*settingTiledPDFPaperHeight, UnitConvertor(value, unit, Unit::Mm)); } @@ -617,9 +534,9 @@ void VSettings::SetTiledPDFPaperHeight(qreal value, const Unit &unit) * internaly as mm so there is conversion beeing made. * @return tiled pdf paper width */ -qreal VSettings::GetTiledPDFPaperWidth(const Unit &unit) const +qreal VValentinaSettings::GetTiledPDFPaperWidth(const Unit &unit) const { - return UnitConvertor(ValueOrDef(*settingTiledPDFPaperWidth, 210 /*A4*/), Unit::Mm, unit); + return UnitConvertor(ValueOrDef(*this, *settingTiledPDFPaperWidth, 210 /*A4*/), Unit::Mm, unit); } //--------------------------------------------------------------------------------------------------------------------- @@ -628,13 +545,13 @@ qreal VSettings::GetTiledPDFPaperWidth(const Unit &unit) const * @param unit unit of the given value * @param value in mm */ -void VSettings::SetTiledPDFPaperWidth(qreal value, const Unit &unit) +void VValentinaSettings::SetTiledPDFPaperWidth(qreal value, const Unit &unit) { setValue(*settingTiledPDFPaperWidth, UnitConvertor(value,unit, Unit::Mm)); } //--------------------------------------------------------------------------------------------------------------------- -PageOrientation VSettings::GetTiledPDFOrientation() const +PageOrientation VValentinaSettings::GetTiledPDFOrientation() const { bool defaultValue = static_cast(PageOrientation::Portrait); bool result = value(*settingTiledPDFOrientation, defaultValue).toBool(); @@ -642,137 +559,69 @@ PageOrientation VSettings::GetTiledPDFOrientation() const } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetTiledPDFOrientation(PageOrientation value) +void VValentinaSettings::SetTiledPDFOrientation(PageOrientation value) { setValue(*settingTiledPDFOrientation, static_cast (value)); } -//--------------------------------------------------------------------------------------------------------------------- -int VSettings::GetScrollingDuration() const -{ - return GetCachedValue(scrollingDurationCached, *settingScrollingDuration, defaultScrollingDuration, - scrollingDurationMin, scrollingDurationMax); -} + //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetScrollingDuration(int duration) -{ - scrollingDurationCached = qBound(scrollingDurationMin, duration, scrollingDurationMax); - setValue(*settingScrollingDuration, scrollingDurationCached); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VSettings::GetScrollingUpdateInterval() const -{ - return GetCachedValue(scrollingUpdateIntervalCached, *settingScrollingUpdateInterval, - defaultScrollingUpdateInterval, scrollingUpdateIntervalMin, scrollingUpdateIntervalMax); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetScrollingUpdateInterval(int updateInterval) -{ - scrollingUpdateIntervalCached = qBound(scrollingUpdateIntervalMin, updateInterval, scrollingUpdateIntervalMax); - setValue(*settingScrollingUpdateInterval, scrollingUpdateIntervalCached); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetSensorMouseScale() const -{ - return GetCachedValue(scrollingSensorMouseScaleCached, *settingScrollingSensorMouseScale, defaultSensorMouseScale, - sensorMouseScaleMin, sensorMouseScaleMax); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetSensorMouseScale(qreal scale) -{ - scrollingSensorMouseScaleCached = qBound(sensorMouseScaleMin, scale, sensorMouseScaleMax); - setValue(*settingScrollingSensorMouseScale, scrollingSensorMouseScaleCached); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetWheelMouseScale() const -{ - return GetCachedValue(scrollingWheelMouseScaleCached, *settingScrollingWheelMouseScale, defaultWheelMouseScale, - wheelMouseScaleMin, wheelMouseScaleMax); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetWheelMouseScale(qreal scale) -{ - scrollingWheelMouseScaleCached = qBound(wheelMouseScaleMin, scale, wheelMouseScaleMax); - setValue(*settingScrollingWheelMouseScale, scrollingWheelMouseScaleCached); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetScrollingAcceleration() const -{ - return GetCachedValue(scrollingAccelerationCached, *settingScrollingAcceleration, defaultScrollingAcceleration, - scrollingAccelerationMin, scrollingAccelerationMax); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetScrollingAcceleration(qreal acceleration) -{ - scrollingAccelerationCached = qBound(scrollingAccelerationMin, acceleration, scrollingAccelerationMax); - setValue(*settingScrollingAcceleration, scrollingAccelerationCached); -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VSettings::IsDockWidgetGroupsActive() const +bool VValentinaSettings::IsDockWidgetGroupsActive() const { return value(*settingdockWidgetGroupsActive, GetDefDockWidgetGroupsActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefDockWidgetGroupsActive() +bool VValentinaSettings::GetDefDockWidgetGroupsActive() { return true; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetDockWidgetGroupsActive(bool value) +void VValentinaSettings::SetDockWidgetGroupsActive(bool value) { setValue(*settingdockWidgetGroupsActive, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::IsDockWidgetToolOptionsActive() const +bool VValentinaSettings::IsDockWidgetToolOptionsActive() const { return value(*settingDockWidgetToolOptionsActive, GetDefDockWidgetToolOptionsActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefDockWidgetToolOptionsActive() +bool VValentinaSettings::GetDefDockWidgetToolOptionsActive() { return true; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetDockWidgetToolOptionsActive(bool value) +void VValentinaSettings::SetDockWidgetToolOptionsActive(bool value) { setValue(*settingDockWidgetToolOptionsActive, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::IsDockWidgetPatternMessagesActive() const +bool VValentinaSettings::IsDockWidgetPatternMessagesActive() const { return value(*settingDockWidgetPatternMessagesActive, GetDefDockWidgetPatternMessagesActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefDockWidgetPatternMessagesActive() +bool VValentinaSettings::GetDefDockWidgetPatternMessagesActive() { return true; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetDockWidgetPatternMessagesActive(bool value) +void VValentinaSettings::SetDockWidgetPatternMessagesActive(bool value) { setValue(*settingDockWidgetPatternMessagesActive, value); } //--------------------------------------------------------------------------------------------------------------------- -int VSettings::GetPatternMessageFontSize(int fontSizeDef) const +int VValentinaSettings::GetPatternMessageFontSize(int fontSizeDef) const { fontSizeDef = qBound(GetDefMinPatternMessageFontSize(), fontSizeDef, GetDefMaxPatternMessageFontSize()); const int fontSize = value(*settingPatternMessagesFontSize, fontSizeDef).toInt(); @@ -780,56 +629,44 @@ int VSettings::GetPatternMessageFontSize(int fontSizeDef) const } //--------------------------------------------------------------------------------------------------------------------- -int VSettings::GetDefMinPatternMessageFontSize() +int VValentinaSettings::GetDefMinPatternMessageFontSize() { return 5; } //--------------------------------------------------------------------------------------------------------------------- -int VSettings::GetDefMaxPatternMessageFontSize() +int VValentinaSettings::GetDefMaxPatternMessageFontSize() { return 40; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetPatternMessageFontSize(int size) +void VValentinaSettings::SetPatternMessageFontSize(int size) { setValue(*settingPatternMessagesFontSize, qBound(GetDefMinPatternMessageFontSize(), size, GetDefMaxPatternMessageFontSize())); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetAutoRefreshPatternMessage() const +bool VValentinaSettings::GetAutoRefreshPatternMessage() const { return value(*settingAutoRefreshPatternMessage, true).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetAutoRefreshPatternMessage(bool value) +void VValentinaSettings::SetAutoRefreshPatternMessage(bool value) { setValue(*settingAutoRefreshPatternMessage, value); } //--------------------------------------------------------------------------------------------------------------------- -QSize VSettings::GetWatermarkEditorSize() const +QSize VValentinaSettings::GetWatermarkEditorSize() const { return value(*settingWatermarkEditorSize, QSize(0, 0)).toSize(); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetWatermarkEditorSize(const QSize &sz) +void VValentinaSettings::SetWatermarkEditorSize(const QSize &sz) { setValue(*settingWatermarkEditorSize, sz); } - -//--------------------------------------------------------------------------------------------------------------------- -template -T VSettings::GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const -{ - if (cache < 0) - { - cache = qBound(valueMin, ValueOrDef(setting, defValue), valueMax); - } - - return cache; -} diff --git a/src/libs/vmisc/vsettings.h b/src/app/valentina/core/vvalentinasettings.h similarity index 75% rename from src/libs/vmisc/vsettings.h rename to src/app/valentina/core/vvalentinasettings.h index 8b6d0aacd..90b362b49 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/app/valentina/core/vvalentinasettings.h @@ -26,8 +26,8 @@ ** *************************************************************************/ -#ifndef VSETTINGS_H -#define VSETTINGS_H +#ifndef VVALENTINASETTINGS_H +#define VVALENTINASETTINGS_H #include #include @@ -39,13 +39,13 @@ #include "vcommonsettings.h" #include "../vlayout/vbank.h" -class VSettings : public VCommonSettings +class VValentinaSettings : public VCommonSettings { Q_OBJECT public: - VSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), + VValentinaSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), QObject *parent = nullptr); - VSettings(const QString &fileName, Format format, QObject *parent = nullptr); + VValentinaSettings(const QString &fileName, Format format, QObject *parent = nullptr); QString GetLabelLanguage() const; void SetLabelLanguage(const QString &value); @@ -54,12 +54,6 @@ public: QString GetPathLayout() const; void SetPathLayout(const QString &value); - bool GetGraphicalOutput() const; - void SetGraphicalOutput(const bool &value); - - bool IsOpenGLRender() const; - void SetOpenGLRender(bool value); - // Layout settings qreal GetLayoutPaperHeight() const; void SetLayoutPaperHeight(qreal value); @@ -153,36 +147,6 @@ public: PageOrientation GetTiledPDFOrientation() const; void SetTiledPDFOrientation(PageOrientation value); - static const int defaultScrollingDuration; - static const int scrollingDurationMin; - static const int scrollingDurationMax; - int GetScrollingDuration() const; - void SetScrollingDuration(int duration); - - static const int defaultScrollingUpdateInterval; - static const int scrollingUpdateIntervalMin; - static const int scrollingUpdateIntervalMax; - int GetScrollingUpdateInterval() const; - void SetScrollingUpdateInterval(int updateInterval); - - static const qreal defaultSensorMouseScale; - static const qreal sensorMouseScaleMin; - static const qreal sensorMouseScaleMax; - qreal GetSensorMouseScale() const; - void SetSensorMouseScale(qreal scale); - - static const qreal defaultWheelMouseScale; - static const qreal wheelMouseScaleMin; - static const qreal wheelMouseScaleMax; - qreal GetWheelMouseScale() const; - void SetWheelMouseScale(qreal scale); - - static const qreal defaultScrollingAcceleration; - static const qreal scrollingAccelerationMin; - static const qreal scrollingAccelerationMax; - qreal GetScrollingAcceleration() const; - void SetScrollingAcceleration(qreal acceleration); - bool IsDockWidgetGroupsActive() const; static bool GetDefDockWidgetGroupsActive(); void SetDockWidgetGroupsActive(bool value); @@ -207,13 +171,7 @@ public: void SetWatermarkEditorSize(const QSize& sz); private: - Q_DISABLE_COPY(VSettings) - - template - T GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const; - - template - T ValueOrDef(const QString &setting, const T &defValue) const; + Q_DISABLE_COPY(VValentinaSettings) }; -#endif // VSETTINGS_H +#endif // VVALENTINASETTINGS_H diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index 42b28b929..00dd4c869 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -110,13 +110,13 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) //----------------------------- Pattern Editing connect(ui->resetWarningsButton, &QPushButton::released, this, []() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetConfirmItemDelete(true); settings->SetConfirmFormatRewriting(true); }); - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); ui->checkBoxFreeCurve->setChecked(settings->IsFreeCurveMode()); ui->checkBoxZoomFitBestCurrentPP->setChecked(settings->IsDoubleClickZoomFitBestCurrentPP()); @@ -128,24 +128,24 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) ui->darkModeCheck->setChecked(settings->GetDarkMode()); // Tab Scrolling - ui->spinBoxDuration->setMinimum(VSettings::scrollingDurationMin); - ui->spinBoxDuration->setMaximum(VSettings::scrollingDurationMax); + ui->spinBoxDuration->setMinimum(VValentinaSettings::scrollingDurationMin); + ui->spinBoxDuration->setMaximum(VValentinaSettings::scrollingDurationMax); ui->spinBoxDuration->setValue(settings->GetScrollingDuration()); - ui->spinBoxUpdateInterval->setMinimum(VSettings::scrollingUpdateIntervalMin); - ui->spinBoxUpdateInterval->setMaximum(VSettings::scrollingUpdateIntervalMax); + ui->spinBoxUpdateInterval->setMinimum(VValentinaSettings::scrollingUpdateIntervalMin); + ui->spinBoxUpdateInterval->setMaximum(VValentinaSettings::scrollingUpdateIntervalMax); ui->spinBoxUpdateInterval->setValue(settings->GetScrollingUpdateInterval()); - ui->doubleSpinBoxSensor->setMinimum(VSettings::sensorMouseScaleMin); - ui->doubleSpinBoxSensor->setMaximum(VSettings::sensorMouseScaleMax); + ui->doubleSpinBoxSensor->setMinimum(VValentinaSettings::sensorMouseScaleMin); + ui->doubleSpinBoxSensor->setMaximum(VValentinaSettings::sensorMouseScaleMax); ui->doubleSpinBoxSensor->setValue(settings->GetSensorMouseScale()); - ui->doubleSpinBoxWheel->setMinimum(VSettings::wheelMouseScaleMin); - ui->doubleSpinBoxWheel->setMaximum(VSettings::wheelMouseScaleMax); + ui->doubleSpinBoxWheel->setMinimum(VValentinaSettings::wheelMouseScaleMin); + ui->doubleSpinBoxWheel->setMaximum(VValentinaSettings::wheelMouseScaleMax); ui->doubleSpinBoxWheel->setValue(settings->GetWheelMouseScale()); - ui->doubleSpinBoxAcceleration->setMinimum(VSettings::scrollingAccelerationMin); - ui->doubleSpinBoxAcceleration->setMaximum(VSettings::scrollingAccelerationMax); + ui->doubleSpinBoxAcceleration->setMinimum(VValentinaSettings::scrollingAccelerationMin); + ui->doubleSpinBoxAcceleration->setMaximum(VValentinaSettings::scrollingAccelerationMax); ui->doubleSpinBoxAcceleration->setValue(settings->GetScrollingAcceleration()); } @@ -160,7 +160,7 @@ QStringList PreferencesConfigurationPage::Apply() { // Tab General QStringList preferences; - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetAutosaveState(ui->autoSaveCheck->isChecked()); settings->SetAutosaveTime(ui->autoTime->value()); diff --git a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp index 182ab1c35..63a23fc87 100644 --- a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp @@ -28,7 +28,7 @@ #include "preferencespathpage.h" #include "ui_preferencespathpage.h" -#include "../vmisc/vsettings.h" +#include "../../core/vvalentinasettings.h" #include "../../core/vapplication.h" #include @@ -65,7 +65,7 @@ PreferencesPathPage::~PreferencesPathPage() //--------------------------------------------------------------------------------------------------------------------- QStringList PreferencesPathPage::Apply() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetPathIndividualMeasurements(ui->pathTable->item(0, 1)->text()); settings->SetPathMultisizeMeasurements(ui->pathTable->item(1, 1)->text()); settings->SetPathPattern(ui->pathTable->item(2, 1)->text()); @@ -105,13 +105,13 @@ void PreferencesPathPage::DefaultPath() path = VCommonSettings::GetDefPathMultisizeMeasurements(); break; case 2: // pattern path - path = VSettings::GetDefPathPattern(); + path = VValentinaSettings::GetDefPathPattern(); break; case 0: // individual measurements path = VCommonSettings::GetDefPathIndividualMeasurements(); break; case 3: // layout path - path = VSettings::GetDefPathLayout(); + path = VValentinaSettings::GetDefPathLayout(); break; case 4: // templates path = VCommonSettings::GetDefPathTemplate(); @@ -206,7 +206,7 @@ void PreferencesPathPage::InitTable() ui->pathTable->setRowCount(7); ui->pathTable->setColumnCount(2); - const VSettings *settings = qApp->ValentinaSettings(); + const VValentinaSettings *settings = qApp->ValentinaSettings(); { ui->pathTable->setItem(0, 0, new QTableWidgetItem(tr("My Individual Measurements"))); diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp index 58a436366..ee71cc4d2 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -63,7 +63,7 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) ui->setupUi(this); RetranslateUi(); - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); ui->graphOutputCheck->setChecked(settings->GetGraphicalOutput()); ui->checkBoxOpenGLRender->setChecked(settings->IsOpenGLRender()); @@ -125,7 +125,7 @@ QStringList PreferencesPatternPage::Apply() { QStringList preferences; - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); // Scene antialiasing if (settings->GetGraphicalOutput() != ui->graphOutputCheck->isChecked()) @@ -200,7 +200,7 @@ void PreferencesPatternPage::changeEvent(QEvent *event) //--------------------------------------------------------------------------------------------------------------------- void PreferencesPatternPage::EditDateTimeFormats() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); QPushButton *button = qobject_cast(sender()); if (button == ui->pushButtonEditDateFormats) @@ -230,7 +230,7 @@ void PreferencesPatternPage::ManageKnownMaterials() //--------------------------------------------------------------------------------------------------------------------- void PreferencesPatternPage::InitLabelDateTimeFormats() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); InitComboBoxFormats(ui->comboBoxDateFormats, VCommonSettings::PredefinedDateFormats() + settings->GetUserDefinedDateFormats(), diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp index eed634d6a..0a4348df4 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp @@ -28,7 +28,7 @@ #include "dialogfinalmeasurements.h" #include "ui_dialogfinalmeasurements.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include "../vmisc/compatibility.h" #include "../qmuparser/qmudef.h" #include "../qmuparser/qmutokenparser.h" diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index b626b416c..958164d59 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -29,7 +29,7 @@ #include "dialogincrements.h" #include "ui_dialogincrements.h" #include "../vwidgets/vwidgetpopup.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include "../qmuparser/qmudef.h" #include "../qmuparser/qmutokenparser.h" #include "../vpatterndb/vtranslatevars.h" diff --git a/src/app/valentina/dialogs/dialoglayoutscale.cpp b/src/app/valentina/dialogs/dialoglayoutscale.cpp index 256c66f14..8178c3151 100644 --- a/src/app/valentina/dialogs/dialoglayoutscale.cpp +++ b/src/app/valentina/dialogs/dialoglayoutscale.cpp @@ -29,7 +29,7 @@ #include "dialoglayoutscale.h" #include "ui_dialoglayoutscale.h" #include "../core/vapplication.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include @@ -180,7 +180,7 @@ void DialogLayoutScale::VerticalScaleChanged(double d) //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutScale::ReadSettings() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); const Unit unit = qApp->patternUnit(); // read Margins top, right, bottom, left @@ -200,7 +200,7 @@ void DialogLayoutScale::ReadSettings() //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutScale::WriteSettings() const { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); const Unit unit = qApp->patternUnit(); // write Margins top, right, bottom, left diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 04549ef52..39665e287 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -30,7 +30,7 @@ #include "ui_dialoglayoutsettings.h" #include "../core/vapplication.h" #include "../ifc/xml/vdomdocument.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include "../vmisc/vmath.h" #include "../vlayout/vlayoutgenerator.h" @@ -698,17 +698,17 @@ void DialogLayoutSettings::RestoreDefaults() InitPrinter(); ui->comboBoxPrinter->blockSignals(false); - SetLayoutWidth(VSettings::GetDefLayoutWidth()); - SetGroup(VSettings::GetDefLayoutGroup()); - SetFollowGrainline(VSettings::GetDefLayoutFollowGrainline()); - SetManualPriority(VSettings::GetDefLayoutManualPriority()); + SetLayoutWidth(VValentinaSettings::GetDefLayoutWidth()); + SetGroup(VValentinaSettings::GetDefLayoutGroup()); + SetFollowGrainline(VValentinaSettings::GetDefLayoutFollowGrainline()); + SetManualPriority(VValentinaSettings::GetDefLayoutManualPriority()); SetFields(GetDefPrinterFields()); - SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields()); - SetMultiplier(VSettings::GetDefMultiplier()); - SetNestingTime(VSettings::GetDefNestingTime()); - SetEfficiencyCoefficient(VSettings::GetDefEfficiencyCoefficient()); - SetNestQuantity(VSettings::GetDefLayoutNestQuantity()); - SetPreferOneSheetSolution(VSettings::GetDefLayoutPreferOneSheetSolution()); + SetIgnoreAllFields(VValentinaSettings::GetDefIgnoreAllFields()); + SetMultiplier(VValentinaSettings::GetDefMultiplier()); + SetNestingTime(VValentinaSettings::GetDefNestingTime()); + SetEfficiencyCoefficient(VValentinaSettings::GetDefEfficiencyCoefficient()); + SetNestQuantity(VValentinaSettings::GetDefLayoutNestQuantity()); + SetPreferOneSheetSolution(VValentinaSettings::GetDefLayoutPreferOneSheetSolution()); CorrectMaxFileds(); IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); @@ -1019,7 +1019,7 @@ void DialogLayoutSettings::MinimumLayoutSize() //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::ReadSettings() { - const VSettings *settings = qApp->ValentinaSettings(); + const VValentinaSettings *settings = qApp->ValentinaSettings(); SetLayoutWidth(settings->GetLayoutWidth()); SetNestingTime(settings->GetNestingTime()); SetEfficiencyCoefficient(settings->GetEfficiencyCoefficient()); @@ -1051,7 +1051,7 @@ void DialogLayoutSettings::ReadSettings() //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::WriteSettings() const { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetLayoutWidth(GetLayoutWidth()); settings->SetLayoutGroup(GetGroup()); settings->SetLayoutPaperHeight(GetPaperHeight()); diff --git a/src/app/valentina/dialogs/dialognewpattern.cpp b/src/app/valentina/dialogs/dialognewpattern.cpp index d3277640f..b31592ffa 100644 --- a/src/app/valentina/dialogs/dialognewpattern.cpp +++ b/src/app/valentina/dialogs/dialognewpattern.cpp @@ -29,7 +29,7 @@ #include "dialognewpattern.h" #include "ui_dialognewpattern.h" #include "../core/vapplication.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include "../vpatterndb/vcontainer.h" #include diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index a4a70120a..a73e74251 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -81,7 +81,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat SCASSERT(doc != nullptr) - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); patternMaterials = doc->GetPatternMaterials(); @@ -951,7 +951,7 @@ void DialogPatternProperties::EditLabel() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::ManagePatternMaterials() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); DialogPatternMaterials editor(patternMaterials, settings->IsRememberPatternMaterials()); diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 58ec2458a..305ce6907 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -29,7 +29,7 @@ #include "dialogsavelayout.h" #include "ui_dialogsavelayout.h" #include "../core/vapplication.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include "../ifc/exception/vexception.h" #include @@ -903,7 +903,7 @@ void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format) */ void DialogSaveLayout::ReadSettings() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); const Unit unit = qApp->patternUnit(); // read Margins top, right, bottom, left @@ -957,7 +957,7 @@ void DialogSaveLayout::WriteSettings() const return; } - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); const Unit unit = qApp->patternUnit(); // write Margins top, right, bottom, left diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 9b12bdc46..afb76e1d1 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -37,7 +37,7 @@ #include "version.h" #include "core/vapplication.h" #include "../vmisc/customevents.h" -#include "../vmisc/vsettings.h" +#include "core/vvalentinasettings.h" #include "../vmisc/def.h" #include "../vmisc/qxtcsvmodel.h" #include "../vmisc/vmodifierkey.h" @@ -301,7 +301,7 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->toolButtonMessagesZoomInFont, &QToolButton::clicked, this, [this]() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); QFont f = ui->plainTextEditPatternMessages->font(); if (f.pointSize() < settings->GetDefMaxPatternMessageFontSize()) { @@ -313,7 +313,7 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->toolButtonMessagesZoomOutFont, &QToolButton::clicked, this, [this]() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); QFont f = ui->plainTextEditPatternMessages->font(); if (f.pointSize() > settings->GetDefMinPatternMessageFontSize()) { @@ -2195,7 +2195,7 @@ void MainWindow::ToolBarTools() ui->actionIncreaseLabelFont->setShortcut(QKeySequence(Qt::ShiftModifier + Qt::Key_Plus)); connect(ui->actionIncreaseLabelFont, &QAction::triggered, this, [this]() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetLabelFontSize(settings->GetLabelFontSize() + 1); if (sceneDraw) { @@ -2211,7 +2211,7 @@ void MainWindow::ToolBarTools() ui->actionDecreaseLabelFont->setShortcut(QKeySequence(Qt::ShiftModifier + Qt::Key_Minus)); connect(ui->actionDecreaseLabelFont, &QAction::triggered, this, [this]() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetLabelFontSize(settings->GetLabelFontSize() - 1); if (sceneDraw) { @@ -2227,7 +2227,7 @@ void MainWindow::ToolBarTools() ui->actionOriginalLabelFont->setShortcut(QKeySequence(Qt::ShiftModifier + Qt::Key_0)); connect(ui->actionOriginalLabelFont, &QAction::triggered, this, [this]() { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetLabelFontSize(settings->GetDefLabelFontSize()); if (sceneDraw) { @@ -4172,7 +4172,7 @@ void MainWindow::setCurrentFile(const QString &fileName) if (not qApp->GetPatternPath().isEmpty() && VApplication::IsGUIMode()) { qCDebug(vMainWindow, "Updating recent file list."); - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); QStringList files = settings->GetRecentFileList(); files.removeAll(fileName); files.prepend(fileName); @@ -4201,7 +4201,7 @@ void MainWindow::setCurrentFile(const QString &fileName) void MainWindow::ReadSettings() { qCDebug(vMainWindow, "Reading settings."); - const VSettings *settings = qApp->ValentinaSettings(); + const VValentinaSettings *settings = qApp->ValentinaSettings(); if (settings->status() == QSettings::NoError) { @@ -4243,7 +4243,7 @@ void MainWindow::WriteSettings() { ActionDraw(true); - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); settings->SetGeometry(saveGeometry()); settings->SetWindowState(saveState()); settings->SetToolbarsState(saveState(APP_VERSION)); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index adfb73090..eb15fd5f6 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1820,7 +1820,7 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr } else { - VSettings *settings = qApp->ValentinaSettings(); + VValentinaSettings *settings = qApp->ValentinaSettings(); pageMargin = QMarginsF(settings->GetTiledPDFMargins(Unit::Mm)); orientation = settings->GetTiledPDFOrientation(); } diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index f3a6824cb..7c5ae24c7 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -40,7 +40,7 @@ #include "../ifc/exception/vexceptionundo.h" #include "../ifc/xml/vpatternconverter.h" #include "../vmisc/customevents.h" -#include "../vmisc/vsettings.h" +#include "../core/vvalentinasettings.h" #include "../vmisc/vmath.h" #include "../vmisc/projectversion.h" #include "../vmisc/compatibility.h" diff --git a/src/libs/vmisc/testvapplication.h b/src/libs/vmisc/testvapplication.h index b19c21541..ab21aa014 100644 --- a/src/libs/vmisc/testvapplication.h +++ b/src/libs/vmisc/testvapplication.h @@ -37,7 +37,17 @@ #endif #define qApp (static_cast(QCoreApplication::instance())) -class VTestSettings; +class VTestSettings : public VCommonSettings +{ + Q_OBJECT +public: + VTestSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), + QObject *parent = nullptr) + : VCommonSettings(format, scope, organization, application, parent) + { + qRegisterMetaTypeStreamOperators("QMarginsF"); + } +}; class TestVApplication : public VAbstractApplication { @@ -50,7 +60,7 @@ public: setApplicationName("ValentinaTest"); setOrganizationName(VER_COMPANYNAME_STR); - OpenSettings(); + TestVApplication::OpenSettings(); } virtual ~TestVApplication() Q_DECL_EQ_DEFAULT; @@ -62,8 +72,8 @@ public: virtual void OpenSettings() override { - settings = new VSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), - QCoreApplication::applicationName(), this); + settings = new VTestSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), + QCoreApplication::applicationName(), this); } virtual bool IsAppInGUIMode() const override @@ -88,16 +98,4 @@ private: VTranslateVars *m_trVars; }; -class VTestSettings : public VCommonSettings -{ - Q_OBJECT -public: - VTestSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), - QObject *parent = nullptr) - : VCommonSettings(format, scope, organization, application, parent) - { - qRegisterMetaTypeStreamOperators("QMarginsF"); - } -}; - #endif // TESTVAPPLICATION_H diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index d3e16cd5a..47bc7b6e9 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -45,7 +45,6 @@ #include "def.h" #include "vcommonsettings.h" #include "vlockguard.h" -#include "vsettings.h" class QUndoStack; class VAbstractApplication;// use in define diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index c394aafcf..170eb7561 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -47,6 +47,26 @@ #include "../vmisc/compatibility.h" #include "../vpatterndb/pmsystems.h" +const int VCommonSettings::defaultScrollingDuration = 300; +const int VCommonSettings::scrollingDurationMin = 100; +const int VCommonSettings::scrollingDurationMax = 1000; + +const int VCommonSettings::defaultScrollingUpdateInterval = 30; +const int VCommonSettings::scrollingUpdateIntervalMin = 10; +const int VCommonSettings::scrollingUpdateIntervalMax = 100; + +const qreal VCommonSettings::defaultSensorMouseScale = 2.0; +const qreal VCommonSettings::sensorMouseScaleMin = 1.0; +const qreal VCommonSettings::sensorMouseScaleMax = 10.0; + +const qreal VCommonSettings::defaultWheelMouseScale = 45.0; +const qreal VCommonSettings::wheelMouseScaleMin = 1.0; +const qreal VCommonSettings::wheelMouseScaleMax = 100.0; + +const qreal VCommonSettings::defaultScrollingAcceleration = 1.3; +const qreal VCommonSettings::scrollingAccelerationMin = 1.0; +const qreal VCommonSettings::scrollingAccelerationMax = 10.0; + namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements"))) @@ -81,6 +101,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowCurveDetails, (QLatin Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternPieceShowMainPath, (QLatin1String("pattern/pieceShowMainPath"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFontSize, (QLatin1String("pattern/labelFontSize"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternHideLabels, (QLatin1String("pattern/hideLabels"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender, (QLatin1String("pattern/useOpenGLRender"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput, (QLatin1String("pattern/graphicalOutput"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRecentFileList, (QLatin1String("recentFileList"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRestoreFileList, (QLatin1String("restoreFileList"))) @@ -105,12 +127,24 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserDateFormats, (QLatin1St Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats, (QLatin1String("label/userTimeFormats"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingSensorMouseScale, + (QLatin1String("scrolling/sensorMouseScale"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingWheelMouseScale, (QLatin1String("scrolling/wheelMouseScale"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingAcceleration, (QLatin1String("scrolling/acceleration"))) + // Reading settings file is very expensive, cache curve approximation to speed up getting value qreal curveApproximationCached = -1; Q_GLOBAL_STATIC(QString, localeCached) qreal lineWidthCached = 0; int labelFontSizeCached = 0; int pieceShowMainPath = -1; +int scrollingDurationCached = -1; +int scrollingUpdateIntervalCached = -1; +qreal scrollingSensorMouseScaleCached = -1; +qreal scrollingWheelMouseScaleCached = -1; +qreal scrollingAccelerationCached = -1; //--------------------------------------------------------------------------------------------------------------------- QStringList ClearFormats(const QStringList &predefinedFormats, QStringList formats) @@ -1219,3 +1253,118 @@ qreal VCommonSettings::WidthHairLine() const { return WidthMainLine()/3.0; } + +//--------------------------------------------------------------------------------------------------------------------- +int VCommonSettings::GetScrollingDuration() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return GetCachedValue(settings, scrollingDurationCached, *settingScrollingDuration, defaultScrollingDuration, + scrollingDurationMin, scrollingDurationMax); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetScrollingDuration(int duration) +{ + scrollingDurationCached = qBound(scrollingDurationMin, duration, scrollingDurationMax); + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingScrollingDuration, scrollingDurationCached); + settings.sync(); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VCommonSettings::GetScrollingUpdateInterval() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return GetCachedValue(settings, scrollingUpdateIntervalCached, *settingScrollingUpdateInterval, + defaultScrollingUpdateInterval, scrollingUpdateIntervalMin, scrollingUpdateIntervalMax); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetScrollingUpdateInterval(int updateInterval) +{ + scrollingUpdateIntervalCached = qBound(scrollingUpdateIntervalMin, updateInterval, scrollingUpdateIntervalMax); + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingScrollingUpdateInterval, scrollingUpdateIntervalCached); + settings.sync(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VCommonSettings::GetSensorMouseScale() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return GetCachedValue(settings, scrollingSensorMouseScaleCached, *settingScrollingSensorMouseScale, + defaultSensorMouseScale, sensorMouseScaleMin, sensorMouseScaleMax); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetSensorMouseScale(qreal scale) +{ + scrollingSensorMouseScaleCached = qBound(sensorMouseScaleMin, scale, sensorMouseScaleMax); + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingScrollingSensorMouseScale, scrollingSensorMouseScaleCached); + settings.sync(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VCommonSettings::GetWheelMouseScale() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return GetCachedValue(settings, scrollingWheelMouseScaleCached, *settingScrollingWheelMouseScale, + defaultWheelMouseScale, wheelMouseScaleMin, wheelMouseScaleMax); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetWheelMouseScale(qreal scale) +{ + scrollingWheelMouseScaleCached = qBound(wheelMouseScaleMin, scale, wheelMouseScaleMax); + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingScrollingWheelMouseScale, scrollingWheelMouseScaleCached); + settings.sync(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VCommonSettings::GetScrollingAcceleration() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return GetCachedValue(settings, scrollingAccelerationCached, *settingScrollingAcceleration, + defaultScrollingAcceleration, scrollingAccelerationMin, scrollingAccelerationMax); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetScrollingAcceleration(qreal acceleration) +{ + scrollingAccelerationCached = qBound(scrollingAccelerationMin, acceleration, scrollingAccelerationMax); + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingScrollingAcceleration, scrollingAccelerationCached); + settings.sync(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VCommonSettings::IsOpenGLRender() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return settings.value(*settingPatternUseOpenGLRender, 0).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetOpenGLRender(bool value) +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingPatternUseOpenGLRender, value); + settings.sync(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VCommonSettings::GetGraphicalOutput() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return settings.value(*settingPatternGraphicalOutput, 1).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetGraphicalOutput(const bool &value) +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingPatternGraphicalOutput, value); + settings.sync(); +} diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index c8ff8bba9..710752a59 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -38,6 +38,8 @@ #include #include +#include "../vlayout/vbank.h" + class VCommonSettings : public QSettings { Q_OBJECT @@ -225,6 +227,52 @@ public: void SetLineWidth(qreal width); qreal WidthMainLine() const; qreal WidthHairLine() const; + + static const int defaultScrollingDuration; + static const int scrollingDurationMin; + static const int scrollingDurationMax; + int GetScrollingDuration() const; + void SetScrollingDuration(int duration); + + static const int defaultScrollingUpdateInterval; + static const int scrollingUpdateIntervalMin; + static const int scrollingUpdateIntervalMax; + int GetScrollingUpdateInterval() const; + void SetScrollingUpdateInterval(int updateInterval); + + static const qreal defaultSensorMouseScale; + static const qreal sensorMouseScaleMin; + static const qreal sensorMouseScaleMax; + qreal GetSensorMouseScale() const; + void SetSensorMouseScale(qreal scale); + + static const qreal defaultWheelMouseScale; + static const qreal wheelMouseScaleMin; + static const qreal wheelMouseScaleMax; + qreal GetWheelMouseScale() const; + void SetWheelMouseScale(qreal scale); + + static const qreal defaultScrollingAcceleration; + static const qreal scrollingAccelerationMin; + static const qreal scrollingAccelerationMax; + qreal GetScrollingAcceleration() const; + void SetScrollingAcceleration(qreal acceleration); + + bool IsOpenGLRender() const; + void SetOpenGLRender(bool value); + + bool GetGraphicalOutput() const; + void SetGraphicalOutput(const bool &value); + +protected: + + template + static T GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue, T valueMin, + T valueMax); + + template + static T ValueOrDef(const QSettings &settings, const QString &setting, const T &defValue); + private: Q_DISABLE_COPY(VCommonSettings) }; @@ -247,4 +295,42 @@ inline qreal VCommonSettings::MaximalLineWidth() return 5.0; // mm } +//--------------------------------------------------------------------------------------------------------------------- +template +T VCommonSettings::GetCachedValue(const QSettings &settings, T &cache, const QString &setting, T defValue, T valueMin, + T valueMax) +{ + if (cache < 0) + { + cache = qBound(valueMin, ValueOrDef(settings, setting, defValue), valueMax); + } + + return cache; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +inline T VCommonSettings::ValueOrDef(const QSettings &settings, const QString &setting, const T &defValue) +{ + const QVariant val = settings.value(setting, QVariant::fromValue(defValue)); + return val.canConvert() ? val.value() : defValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +template <> +inline Cases VCommonSettings::ValueOrDef(const QSettings &settings, const QString &setting, + const Cases &defValue) +{ + const QVariant val = settings.value(setting, QVariant::fromValue(static_cast(defValue))); + const int g = val.canConvert() ? val.value() : static_cast(defValue); + if (g < static_cast(Cases::CaseThreeGroup) || g >= static_cast(Cases::UnknownCase)) + { + return defValue; + } + else + { + return static_cast(g); + } +} + #endif // VCOMMONSETTINGS_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index c91baa68f..db111a201 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -3,18 +3,15 @@ SOURCES += \ $$PWD/def.cpp \ - $$PWD/vsettings.cpp \ $$PWD/vabstractapplication.cpp \ $$PWD/projectversion.cpp \ $$PWD/vcommonsettings.cpp \ - $$PWD/vtapesettings.cpp \ $$PWD/commandoptions.cpp \ $$PWD/qxtcsvmodel.cpp \ $$PWD/vtablesearch.cpp \ $$PWD/dialogs/dialogexporttocsv.cpp \ $$PWD/literals.cpp \ - $$PWD/vmodifierkey.cpp \ - $$PWD/vpuzzlesettings.cpp + $$PWD/vmodifierkey.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -29,11 +26,9 @@ HEADERS += \ $$PWD/stable.h \ $$PWD/def.h \ $$PWD/vmath.h \ - $$PWD/vsettings.h \ $$PWD/vabstractapplication.h \ $$PWD/projectversion.h \ $$PWD/vcommonsettings.h \ - $$PWD/vtapesettings.h \ $$PWD/debugbreak.h \ $$PWD/vlockguard.h \ $$PWD/vsysexits.h \ @@ -51,8 +46,7 @@ HEADERS += \ $$PWD/vdatastreamenum.h \ $$PWD/vmodifierkey.h \ $$PWD/typedef.h \ - $$PWD/backport/qscopeguard.h \ - $$PWD/vpuzzlesettings.h + $$PWD/backport/qscopeguard.h contains(DEFINES, APPIMAGE) { SOURCES += \ diff --git a/src/libs/vmisc/vpuzzlesettings.cpp b/src/libs/vmisc/vpuzzlesettings.cpp deleted file mode 100644 index 337fcb69a..000000000 --- a/src/libs/vmisc/vpuzzlesettings.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/************************************************************************ - ** - ** @file vpuzzlesettings.cpp - ** @author Roman Telezhynskyi - ** @date 16 2, 2020 - ** - ** @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) 2020 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 "vpuzzlesettings.h" - - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleSettings::VPuzzleSettings(Format format, Scope scope, const QString &organization, const QString &application, - QObject *parent) - :VCommonSettings(format, scope, organization, application, parent) -{ - -} diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index 439f75140..6e903f4d2 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -56,7 +56,7 @@ #include "vsimplecurve.h" #include "vcontrolpointspline.h" #include "../vmisc/vabstractapplication.h" -#include "../vmisc/vsettings.h" +#include "../vmisc/vcommonsettings.h" #include "vabstractmainwindow.h" const qreal maxSceneSize = ((20.0 * 1000.0) / 25.4) * PrintDPI; // 20 meters in pixels @@ -70,7 +70,7 @@ qreal ScrollingSteps(QWheelEvent* wheel_event) const QPoint numPixels = wheel_event->pixelDelta(); const QPoint numDegrees = wheel_event->angleDelta() / 8; qreal numSteps = 0; - VSettings *settings = qobject_cast(qApp->Settings()); + VCommonSettings *settings = qApp->Settings(); if (not numPixels.isNull()) { @@ -105,7 +105,7 @@ qreal PrepareScrolling(qreal scheduledScrollings, QWheelEvent *wheel_event) scheduledScrollings += numSteps; } - scheduledScrollings *= qobject_cast(qApp->Settings())->GetScrollingAcceleration(); + scheduledScrollings *= qApp->Settings()->GetScrollingAcceleration(); return scheduledScrollings; } @@ -197,7 +197,7 @@ void GraphicsViewZoom::set_zoom_factor_base(double value) //--------------------------------------------------------------------------------------------------------------------- void GraphicsViewZoom::InitScrollingAnimation() { - VSettings *settings = qobject_cast(qApp->Settings()); + VCommonSettings *settings = qApp->Settings(); if (not verticalScrollAnim.isNull()) { @@ -427,7 +427,7 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent) m_oldCursor(), m_currentCursor(Qt::ArrowCursor) { - VSettings *settings = qobject_cast(qApp->Settings()); + VCommonSettings *settings = qApp->Settings(); if (settings && settings->IsOpenGLRender()) { QOpenGLWidget *viewport = new QOpenGLWidget(); From c1051783f6a666d6675f82b1cad19eb67af1675d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 10 May 2020 18:35:15 +0300 Subject: [PATCH 02/10] Fix code style. --- src/app/puzzle/puzzlemainwindow.cpp | 9 ++++----- src/app/tape/mapplication.h | 2 +- src/app/valentina/core/vapplication.cpp | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index b76bcb9b0..df72ac4f4 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -796,8 +796,6 @@ void PuzzleMainWindow::on_checkBoxLayoutStickyEdges_toggled(bool checked) // TODO update the QGraphicView } - - //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::on_pushButtonLayoutExport_clicked() { @@ -883,14 +881,15 @@ void PuzzleMainWindow::on_PieceSelectionChanged() //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::on_PiecePositionChanged() { - if(m_selectedPieces.count() == 1) { VPuzzlePiece *piece = m_selectedPieces.first(); QPointF pos = piece->GetPosition(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); - SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); + SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, + UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); + SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, + UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); } } diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index 839780026..d1d4a6d27 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -101,8 +101,8 @@ private: void Clean(); }; -//--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- inline const VTranslateVars *MApplication::TrVars() { return trVars; diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 6d0cf88bc..bea11612d 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -445,6 +445,7 @@ bool VApplication::notify(QObject *receiver, QEvent *event) return false; } +//--------------------------------------------------------------------------------------------------------------------- void VApplication::ActivateDarkMode() { VValentinaSettings *settings = qApp->ValentinaSettings(); @@ -465,7 +466,6 @@ void VApplication::ActivateDarkMode() } } - //--------------------------------------------------------------------------------------------------------------------- QString VApplication::TapeFilePath() const { From 19fd03b66e73da53fe61a6809659b2abe22d2a23 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 10 May 2020 18:38:06 +0300 Subject: [PATCH 03/10] Read/write window state. Will help with setting the carousel size. --- src/app/puzzle/puzzlemainwindow.cpp | 118 ++++++++++++++++++++++++++++ src/app/puzzle/puzzlemainwindow.h | 7 ++ 2 files changed, 125 insertions(+) diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index df72ac4f4..34fba421e 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -36,6 +36,7 @@ #include "puzzleapplication.h" #include "../vlayout/vrawlayout.h" #include "../vmisc/vsysexits.h" +#include "../vmisc/projectversion.h" #include "../ifc/xml/vlayoutconverter.h" #include "../ifc/exception/vexception.h" @@ -75,6 +76,8 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa SetPropertiesData(); + + ReadSettings(); } //--------------------------------------------------------------------------------------------------------------------- @@ -469,7 +472,98 @@ void PuzzleMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value) checkbox->blockSignals(false); } +//--------------------------------------------------------------------------------------------------------------------- +void PuzzleMainWindow::ReadSettings() +{ + qCDebug(pWindow, "Reading settings."); + const VPuzzleSettings *settings = qApp->PuzzleSettings(); + if (settings->status() == QSettings::NoError) + { + restoreGeometry(settings->GetGeometry()); + restoreState(settings->GetWindowState()); + restoreState(settings->GetToolbarsState(), APP_VERSION); + + ui->dockWidgetProperties->setVisible(settings->IsDockWidgetPropertiesActive()); + ui->dockWidgetPropertiesContents->setVisible(settings->IsDockWidgetPropertiesContentsActive()); + + // Scene antialiasing + m_graphicsView->SetAntialiasing(settings->GetGraphicalOutput()); + + // Stack limit +// qApp->getUndoStack()->setUndoLimit(settings->GetUndoCount()); + } + else + { + qWarning() << tr("Cannot read settings from a malformed .INI file."); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void PuzzleMainWindow::WriteSettings() +{ + VPuzzleSettings *settings = qApp->PuzzleSettings(); + settings->SetGeometry(saveGeometry()); + settings->SetWindowState(saveState()); + settings->SetToolbarsState(saveState(APP_VERSION)); + + settings->SetDockWidgetPropertiesActive(ui->dockWidgetProperties->isEnabled()); + settings->SetDockWidgetPropertiesContentsActive(ui->dockWidgetPropertiesContents->isEnabled()); + + settings->sync(); + if (settings->status() == QSettings::AccessError) + { + qWarning() << tr("Cannot save settings. Access denied."); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool PuzzleMainWindow::MaybeSave() +{ + // TODO: Implement maybe save check +// if (this->isWindowModified()) +// { +// if (curFile.isEmpty() && ui->tableWidget->rowCount() == 0) +// { +// return true;// Don't ask if file was created without modifications. +// } + +// QScopedPointer messageBox(new QMessageBox(tr("Unsaved changes"), +// tr("Measurements have been modified.\n" +// "Do you want to save your changes?"), +// QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, +// QMessageBox::Cancel, this, Qt::Sheet)); + +// messageBox->setDefaultButton(QMessageBox::Yes); +// messageBox->setEscapeButton(QMessageBox::Cancel); + +// messageBox->setButtonText(QMessageBox::Yes, curFile.isEmpty() || mIsReadOnly ? tr("Saveā€¦") : tr("Save")); +// messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); + +// messageBox->setWindowModality(Qt::ApplicationModal); +// const auto ret = static_cast(messageBox->exec()); + +// switch (ret) +// { +// case QMessageBox::Yes: +// if (mIsReadOnly) +// { +// return FileSaveAs(); +// } +// else +// { +// return FileSave(); +// } +// case QMessageBox::No: +// return true; +// case QMessageBox::Cancel: +// return false; +// default: +// break; +// } +// } + return true; +} //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::on_actionNew_triggered() @@ -486,6 +580,30 @@ void PuzzleMainWindow::on_actionNew_triggered() } +//--------------------------------------------------------------------------------------------------------------------- +void PuzzleMainWindow::closeEvent(QCloseEvent *event) +{ +#if defined(Q_OS_MAC) && QT_VERSION < QT_VERSION_CHECK(5, 11, 1) + // Workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-43344 + static int numCalled = 0; + if (numCalled++ >= 1) + { + return; + } +#endif + + if (MaybeSave()) + { + WriteSettings(); + event->accept(); + deleteLater(); + } + else + { + event->ignore(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::on_actionOpen_triggered() { diff --git a/src/app/puzzle/puzzlemainwindow.h b/src/app/puzzle/puzzlemainwindow.h index 4ffa3f29c..00abf3c7f 100644 --- a/src/app/puzzle/puzzlemainwindow.h +++ b/src/app/puzzle/puzzlemainwindow.h @@ -84,6 +84,8 @@ public slots: protected: enum { MaxRecentFiles = 5 }; + virtual void closeEvent(QCloseEvent *event) override; + private: Q_DISABLE_COPY(PuzzleMainWindow) Ui::PuzzleMainWindow *ui; @@ -188,6 +190,11 @@ private: */ void SetCheckBoxValue(QCheckBox *checkbox, bool value); + void ReadSettings(); + void WriteSettings(); + + bool MaybeSave(); + private slots: /** * @brief on_actionOpen_triggered When the menu action File > Open is From a89259d47d4cf4f57d056734ff46aeef46492ca2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 11 May 2020 17:39:54 +0300 Subject: [PATCH 04/10] Fix issue with VMainGraphicsView. --- src/app/puzzle/puzzle.pri | 2 - src/app/puzzle/vpuzzlemaingraphicsscene.cpp | 35 ---------------- src/app/puzzle/vpuzzlemaingraphicsscene.h | 44 --------------------- src/app/puzzle/vpuzzlemaingraphicsview.cpp | 21 ++++------ src/app/puzzle/vpuzzlemaingraphicsview.h | 19 +++++---- 5 files changed, 16 insertions(+), 105 deletions(-) delete mode 100644 src/app/puzzle/vpuzzlemaingraphicsscene.cpp delete mode 100644 src/app/puzzle/vpuzzlemaingraphicsscene.h diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index 47095dbab..e55760817 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -14,7 +14,6 @@ SOURCES += \ $$PWD/vpuzzlegraphicspiece.cpp \ $$PWD/vpuzzlelayout.cpp \ $$PWD/vpuzzlelayer.cpp \ - $$PWD/vpuzzlemaingraphicsscene.cpp \ $$PWD/vpuzzlemaingraphicsview.cpp \ $$PWD/vpuzzlemimedatapiece.cpp \ $$PWD/vpuzzlepiece.cpp \ @@ -40,7 +39,6 @@ HEADERS += \ $$PWD/vpuzzlegraphicspiece.h \ $$PWD/vpuzzlelayout.h \ $$PWD/vpuzzlelayer.h \ - $$PWD/vpuzzlemaingraphicsscene.h \ $$PWD/vpuzzlemaingraphicsview.h \ $$PWD/vpuzzlemimedatapiece.h \ $$PWD/vpuzzlepiece.h \ diff --git a/src/app/puzzle/vpuzzlemaingraphicsscene.cpp b/src/app/puzzle/vpuzzlemaingraphicsscene.cpp deleted file mode 100644 index 5a4d1d17f..000000000 --- a/src/app/puzzle/vpuzzlemaingraphicsscene.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************************************ - ** - ** @file vpuzzlemaingraphicsscene.cpp - ** @author Ronan Le Tiec - ** @date 3 5, 2020 - ** - ** @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) 2020 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 "vpuzzlemaingraphicsscene.h" - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleMainGraphicsScene::VPuzzleMainGraphicsScene(QObject *parent): QGraphicsScene(parent) -{ - -} diff --git a/src/app/puzzle/vpuzzlemaingraphicsscene.h b/src/app/puzzle/vpuzzlemaingraphicsscene.h deleted file mode 100644 index 199ed0e8f..000000000 --- a/src/app/puzzle/vpuzzlemaingraphicsscene.h +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************ - ** - ** @file vpuzzlemaingraphicsscene.cpp - ** @author Ronan Le Tiec - ** @date 3 5, 2020 - ** - ** @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) 2020 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 VPUZZLEMAINGRAPHICSSCENE_H -#define VPUZZLEMAINGRAPHICSSCENE_H - -#include - -// TODO: When ready, extend from QGraphicsScene instead - -class VPuzzleMainGraphicsScene : public QGraphicsScene -{ - Q_OBJECT -public: - VPuzzleMainGraphicsScene(QObject *parent = nullptr); - -}; - -#endif // VPUZZLEMAINGRAPHICSSCENE_H diff --git a/src/app/puzzle/vpuzzlemaingraphicsview.cpp b/src/app/puzzle/vpuzzlemaingraphicsview.cpp index d4740eeb1..4be5cf375 100644 --- a/src/app/puzzle/vpuzzlemaingraphicsview.cpp +++ b/src/app/puzzle/vpuzzlemaingraphicsview.cpp @@ -34,6 +34,7 @@ #include "vpuzzlemimedatapiece.h" #include "vpuzzlelayer.h" +#include "../vwidgets/vmaingraphicsscene.h" #include @@ -42,30 +43,22 @@ Q_LOGGING_CATEGORY(pMainGraphicsView, "p.mainGraphicsView") //--------------------------------------------------------------------------------------------------------------------- VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent) : - QGraphicsView(parent), - m_layout(layout), - m_graphicsPieces(QList()) + VMainGraphicsView(parent), + m_layout(layout) { - m_scene = new VPuzzleMainGraphicsScene(this); + m_scene = new VMainGraphicsScene(this); setScene(m_scene); m_graphicsLayout = new VPuzzleGraphicsLayout(layout); - m_graphicsLayout->setPos(0,0); + m_graphicsLayout->setPos(0, 0); m_scene->addItem(m_graphicsLayout); - setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - setAcceptDrops(true); // add the connections connect(m_layout, &VPuzzleLayout::PieceMovedToLayer, this, &VPuzzleMainGraphicsView::on_PieceMovedToLayer); - connect(m_scene, &VPuzzleMainGraphicsScene::selectionChanged, this, &VPuzzleMainGraphicsView::on_SceneSelectionChanged); -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleMainGraphicsView::~VPuzzleMainGraphicsView() -{ - + connect(m_scene, &VMainGraphicsScene::selectionChanged, this, + &VPuzzleMainGraphicsView::on_SceneSelectionChanged); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpuzzlemaingraphicsview.h b/src/app/puzzle/vpuzzlemaingraphicsview.h index fea0d7947..bccff359c 100644 --- a/src/app/puzzle/vpuzzlemaingraphicsview.h +++ b/src/app/puzzle/vpuzzlemaingraphicsview.h @@ -29,21 +29,19 @@ #ifndef VPUZZLEMAINGRAPHICSVIEW_H #define VPUZZLEMAINGRAPHICSVIEW_H -#include - #include "vpuzzlegraphicslayout.h" -#include "vpuzzlemaingraphicsscene.h" #include "vpuzzlegraphicspiece.h" +#include "../vwidgets/vmaingraphicsview.h" + +class VMainGraphicsScene; -// TODO: when ready, extend the VMainGrapchisView instead - -class VPuzzleMainGraphicsView : public QGraphicsView +class VPuzzleMainGraphicsView : public VMainGraphicsView { Q_OBJECT public: VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent); - ~VPuzzleMainGraphicsView(); + ~VPuzzleMainGraphicsView() = default; /** * @brief RefreshLayout Refreshes the rectangles for the layout border and the margin @@ -60,7 +58,8 @@ protected: private slots: /** - * @brief on_PieceMovedToLayer The slot is called when the given piece was moved from the given layer to the other given layer + * @brief on_PieceMovedToLayer The slot is called when the given piece was moved from the given layer to the other + * given layer * @param piece the piece that was moved * @param layerBefore the layer before the move * @param layerAfter the layer after the move @@ -75,12 +74,12 @@ private slots: private: Q_DISABLE_COPY(VPuzzleMainGraphicsView) - VPuzzleMainGraphicsScene *m_scene{nullptr}; + VMainGraphicsScene *m_scene{nullptr}; VPuzzleGraphicsLayout *m_graphicsLayout{nullptr}; VPuzzleLayout *m_layout{nullptr}; - QList m_graphicsPieces; + QList m_graphicsPieces{}; }; From 067dd637a7a50a9e802dda4a493440d179269833 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 11 May 2020 17:40:53 +0300 Subject: [PATCH 05/10] Cppcheck warning. --- src/app/puzzle/vpuzzlegraphicslayout.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/puzzle/vpuzzlegraphicslayout.h b/src/app/puzzle/vpuzzlegraphicslayout.h index 477fcfc75..a8c2c509e 100644 --- a/src/app/puzzle/vpuzzlegraphicslayout.h +++ b/src/app/puzzle/vpuzzlegraphicslayout.h @@ -37,7 +37,7 @@ class VPuzzleGraphicsLayout : public QGraphicsItem { public: - VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent = nullptr); + explicit VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent = nullptr); ~VPuzzleGraphicsLayout(); QRectF boundingRect() const override; From 21dd764d53ab0d15c35d700b05149fdd9a564216 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 11 May 2020 17:44:30 +0300 Subject: [PATCH 06/10] Code style. --- src/app/puzzle/puzzlemainwindow.cpp | 6 ++++-- src/app/puzzle/vpuzzlepiece.cpp | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index 34fba421e..a1dccb8af 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -373,8 +373,10 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData() ui->checkBoxCurrentPieceMirrorPiece->setChecked(selectedPiece->GetPieceMirrored()); QPointF pos = selectedPiece->GetPosition(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); - SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); + SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, + UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit())); + SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, + UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit())); qreal angle = selectedPiece->GetRotation(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); diff --git a/src/app/puzzle/vpuzzlepiece.cpp b/src/app/puzzle/vpuzzlepiece.cpp index 466d47888..074bf168e 100644 --- a/src/app/puzzle/vpuzzlepiece.cpp +++ b/src/app/puzzle/vpuzzlepiece.cpp @@ -245,7 +245,6 @@ VPuzzleLayer* VPuzzlePiece::GetLayer() return m_layer; } - //--------------------------------------------------------------------------------------------------------------------- void VPuzzlePiece::SetLayer(VPuzzleLayer* layer) { From 56ec768777199efc7c3af0527cd12149d254f435 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 11 May 2020 17:44:53 +0300 Subject: [PATCH 07/10] GCC warning. --- src/app/puzzle/vpiececarrouselpiece.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/puzzle/vpiececarrouselpiece.cpp b/src/app/puzzle/vpiececarrouselpiece.cpp index 3602ce054..85958ab63 100644 --- a/src/app/puzzle/vpiececarrouselpiece.cpp +++ b/src/app/puzzle/vpiececarrouselpiece.cpp @@ -277,7 +277,7 @@ void VPieceCarrouselPiece::on_ActionPieceMovedToLayer() { QAction *act = qobject_cast(sender()); QVariant v = act->data(); - VPuzzleLayer *layer = (VPuzzleLayer *) v.value(); + VPuzzleLayer *layer = v.value(); if(layer != nullptr) { layer->GetLayout()->MovePieceToLayer(m_piece, layer); From 5fc927b32a762ea6ecaa579cc0d0c13ca0d65c49 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 11 May 2020 17:46:25 +0300 Subject: [PATCH 08/10] Since we store a dockwidget size no need to handle size manually. --- src/app/puzzle/puzzlemainwindow.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index a1dccb8af..874477d53 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -977,14 +977,10 @@ void PuzzleMainWindow::on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area) if(area == Qt::BottomDockWidgetArea || area == Qt::TopDockWidgetArea) { m_pieceCarrousel->SetOrientation(Qt::Horizontal); - ui->dockWidgetPieceCarrousel->setMaximumHeight(208); - ui->dockWidgetPieceCarrousel->setMaximumWidth(10000); } else if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea) { m_pieceCarrousel->SetOrientation(Qt::Vertical); - ui->dockWidgetPieceCarrousel->setMaximumHeight(10000); - ui->dockWidgetPieceCarrousel->setMaximumWidth(160); } } From f1057de239bdafb198f966d082b919bed764335a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 11 May 2020 17:48:08 +0300 Subject: [PATCH 09/10] Redesign. Move initialization in ui file. Use QListWidget instead of a custom solution. Basic functions do not work yet. --- src/app/puzzle/puzzle.pri | 3 +- src/app/puzzle/vpiececarrousel.cpp | 161 ++++++++--------------------- src/app/puzzle/vpiececarrousel.h | 21 ++-- src/app/puzzle/vpiececarrousel.ui | 77 ++++++++++++++ src/app/puzzle/vpuzzlepiece.cpp | 45 ++++++++ src/app/puzzle/vpuzzlepiece.h | 2 + 6 files changed, 178 insertions(+), 131 deletions(-) create mode 100644 src/app/puzzle/vpiececarrousel.ui diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index e55760817..5ed131c58 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -51,4 +51,5 @@ HEADERS += \ FORMS += \ $$PWD/puzzlemainwindow.ui \ - $$PWD/dialogs/dialogaboutpuzzle.ui + $$PWD/dialogs/dialogaboutpuzzle.ui \ + $$PWD/vpiececarrousel.ui diff --git a/src/app/puzzle/vpiececarrousel.cpp b/src/app/puzzle/vpiececarrousel.cpp index 65e46a410..5b0abe3b8 100644 --- a/src/app/puzzle/vpiececarrousel.cpp +++ b/src/app/puzzle/vpiececarrousel.cpp @@ -26,98 +26,57 @@ ** *************************************************************************/ #include "vpiececarrousel.h" +#include "ui_vpiececarrousel.h" #include #include #include #include "../vmisc/backport/qoverload.h" +#include "vpuzzlelayer.h" #include +#include +#include Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel") //--------------------------------------------------------------------------------------------------------------------- VPieceCarrousel::VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent) : QWidget(parent), - m_layout(layout), - m_comboBoxLayer(new QComboBox(this)), - m_scrollArea(new QScrollArea(this)), - m_layersContainer(new QWidget(this)), - m_carrouselLayers(QList()) + ui(new Ui::VPieceCarrousel), + m_layout(layout) { - Init(); -} - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrousel::~VPieceCarrousel() -{ - delete m_comboBoxLayer; - delete m_layersContainer; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::Init() -{ - // ------ first we initialize the structure of the carrousel + ui->setupUi(this); // init the combo box - connect(m_comboBoxLayer, QOverload::of(&QComboBox::currentIndexChanged), this, - &VPieceCarrousel::on_ActiveLayerChanged); + connect(ui->comboBoxLayer, QOverload::of(&QComboBox::currentIndexChanged), this, + &VPieceCarrousel::on_ActiveLayerChanged); - // init the layers container and corresponding scroll area - QWidget *layersContainerWrapper = new QWidget(); - - QVBoxLayout *layersContainerWrapperLayout = new QVBoxLayout(); - layersContainerWrapperLayout->setMargin(0); - layersContainerWrapper->setLayout(layersContainerWrapperLayout); - - QVBoxLayout *layersContainerLayout = new QVBoxLayout(); - layersContainerLayout->setMargin(0); - m_layersContainer->setLayout(layersContainerLayout); - m_layersContainer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding); - - - layersContainerWrapperLayout->addWidget(m_layersContainer); - layersContainerWrapperLayout->addSpacerItem(spacer); - - m_scrollArea->setWidgetResizable( true ); - m_scrollArea->setWidget(layersContainerWrapper); - - // init the layout of the piece carrousel - QVBoxLayout *mainLayout = new QVBoxLayout(); - setLayout(mainLayout); - - mainLayout->addWidget(m_comboBoxLayer); - mainLayout->addWidget(m_scrollArea); + ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu); // ------ then we fill the carrousel with the layout content - Refresh(); - } + Refresh(); +} //--------------------------------------------------------------------------------------------------------------------- void VPieceCarrousel::Refresh() { - // NOTE: alternative to clearing the carrousel and adding things again, we could make comparision // --- clears the content of the carrousel Clear(); // --- add the content saved in the layout to the carrousel. - QList layers = m_layout->GetLayers(); - layers.prepend(m_layout->GetUnplacedPiecesLayer()); + // Do not rely on m_layout because we do not control it. + m_layers = m_layout->GetLayers(); + m_layers.prepend(m_layout->GetUnplacedPiecesLayer()); - for (auto layer : layers) + for (auto layer : m_layers) { // add layer name to combo - m_comboBoxLayer->addItem(layer->GetName()); - - // add new carrousel layer - VPieceCarrouselLayer *carrouselLayer = new VPieceCarrouselLayer(layer, this); - m_carrouselLayers.append(carrouselLayer); - m_layersContainer->layout()->addWidget(carrouselLayer); + ui->comboBoxLayer->blockSignals(true); + ui->comboBoxLayer->addItem(layer->GetName()); + ui->comboBoxLayer->blockSignals(false); } on_ActiveLayerChanged(0); @@ -129,31 +88,9 @@ void VPieceCarrousel::Refresh() void VPieceCarrousel::Clear() { // remove the combobox entries - int layerCount = m_comboBoxLayer->count(); - for(int i=0;iremoveItem(0); - } + ui->comboBoxLayer->clear(); - // remove the carrousel layers from the qlayout - while(!m_layersContainer->layout()->isEmpty()) - { - QLayoutItem* item = m_layersContainer->layout()->takeAt(0); - if(item != nullptr) - { - delete item; - } - } - - // Removes and deletes the carrousel layers from the list - while (!m_carrouselLayers.isEmpty()) - { - VPieceCarrouselLayer *carrouselLayer = m_carrouselLayers.takeLast(); - if(carrouselLayer != nullptr) - { - delete carrouselLayer; - } - } + ui->listWidget->clear(); } //--------------------------------------------------------------------------------------------------------------------- @@ -161,10 +98,21 @@ void VPieceCarrousel::on_ActiveLayerChanged(int index) { qCDebug(pCarrousel, "index changed %i", index); - int j=0; - for (VPieceCarrouselLayer *carrouselLayer: m_carrouselLayers) { - carrouselLayer->setVisible(j == index); - j++; + ui->listWidget->clear(); + + if (index >= 0 && index < m_layers.size()) + { + VPuzzleLayer *layer = m_layers.at(index); + + if (layer) + { + QList pieces = layer->GetPieces(); + + for (auto piece : pieces) + { + new QListWidgetItem(piece->PieceIcon(QSize(120, 120)) , piece->GetName(), ui->listWidget); + } + } } } @@ -178,47 +126,26 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) //--------------------------------------------------------------------------------------------------------------------- void VPieceCarrousel::RefreshOrientation() { - QBoxLayout::Direction direction = (m_orientation == Qt::Horizontal)? - QBoxLayout::LeftToRight - : - QBoxLayout::TopToBottom; - - // Update the various qlayouts - QBoxLayout* mainScrollAreaLayout = qobject_cast(m_layersContainer->layout()); - mainScrollAreaLayout->setDirection(direction); - - QBoxLayout* layerContainerWrapper = qobject_cast(m_scrollArea->widget()->layout()); - layerContainerWrapper->setDirection(direction); - - for (VPieceCarrouselLayer *widget: m_carrouselLayers) { - QBoxLayout* layerLayout = qobject_cast(widget->layout()); - layerLayout->setDirection(direction); - } - // then update the scrollarea min height / width and scrollbar behaviour if(m_orientation == Qt::Horizontal) { - m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + ui->comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // scroll bar policy of scroll area - m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - // FIXME: find a nicer way than putting directly the 120 height of the piece - m_scrollArea->setMinimumHeight(128 + m_scrollArea->horizontalScrollBar()->sizeHint().height()+2); - m_scrollArea->setMinimumWidth(0); + ui->listWidget->setFlow(QListView::TopToBottom); } else // Qt::Vertical { - m_comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + ui->comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); // scroll bar policy of scroll area - m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - m_scrollArea->setMinimumHeight(0); - m_scrollArea->setMinimumWidth(124 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2); - // FIXME: find a nicer way than putting directly the 120 width of the piece + ui->listWidget->setFlow(QListView::LeftToRight); } } diff --git a/src/app/puzzle/vpiececarrousel.h b/src/app/puzzle/vpiececarrousel.h index a781b8ac2..569ffc3ac 100644 --- a/src/app/puzzle/vpiececarrousel.h +++ b/src/app/puzzle/vpiececarrousel.h @@ -34,14 +34,18 @@ #include #include "vpuzzlelayout.h" #include "vpuzzlepiece.h" -#include "vpiececarrousellayer.h" + +namespace Ui +{ +class VPieceCarrousel; +} class VPieceCarrousel : public QWidget { Q_OBJECT public: explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr); - virtual ~VPieceCarrousel(); + virtual ~VPieceCarrousel() = default; /** * @brief SetOrientation Sets the orientation to the given value and refreshes @@ -56,11 +60,6 @@ public: */ void RefreshOrientation(); - /** - * @brief Inits the carroussel - */ - void Init(); - /** * @brief Refresh Refreshes the content of the carrousel */ @@ -78,14 +77,10 @@ public: private: Q_DISABLE_COPY(VPieceCarrousel) + Ui::VPieceCarrousel *ui; VPuzzleLayout *m_layout; - - QComboBox *m_comboBoxLayer; - QScrollArea *m_scrollArea; - QWidget *m_layersContainer; - - QList m_carrouselLayers; + QList m_layers{}; Qt::Orientation m_orientation{Qt::Vertical}; diff --git a/src/app/puzzle/vpiececarrousel.ui b/src/app/puzzle/vpiececarrousel.ui new file mode 100644 index 000000000..511853607 --- /dev/null +++ b/src/app/puzzle/vpiececarrousel.ui @@ -0,0 +1,77 @@ + + + VPieceCarrousel + + + + 0 + 0 + 583 + 557 + + + + Carrousel + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + + + + + Qt::ScrollBarAlwaysOn + + + QAbstractItemView::DragOnly + + + + 120 + 120 + + + + QListView::Static + + + QListView::TopToBottom + + + QListView::Adjust + + + 6 + + + QListView::IconMode + + + true + + + + + + + + diff --git a/src/app/puzzle/vpuzzlepiece.cpp b/src/app/puzzle/vpuzzlepiece.cpp index 074bf168e..dc11f77ca 100644 --- a/src/app/puzzle/vpuzzlepiece.cpp +++ b/src/app/puzzle/vpuzzlepiece.cpp @@ -32,7 +32,9 @@ #include "vpuzzlelayer.h" #include "../vmisc/def.h" +#include #include +#include Q_LOGGING_CATEGORY(pPiece, "p.piece") @@ -253,3 +255,46 @@ void VPuzzlePiece::SetLayer(VPuzzleLayer* layer) m_layer = layer; } } + +//--------------------------------------------------------------------------------------------------------------------- +QIcon VPuzzlePiece::PieceIcon(const QSize &size) const +{ + QVector points = GetSeamLine(); + if(points.isEmpty()) + { + points = GetCuttingLine(); + } + + QPolygonF shape(points); + shape << shape.first(); + + QRectF boundingRect = shape.boundingRect(); + qreal canvasSize = qMax(boundingRect.height(), boundingRect.width()); + QRectF canvas = QRectF(0, 0, canvasSize, canvasSize); + + qreal dx = canvas.center().x() - boundingRect.center().x(); + qreal dy = canvas.center().y() - boundingRect.center().y(); + + QPixmap pixmap(size); + pixmap.fill(QColor("white")); + + QPainter painter; + painter.begin(&pixmap); + painter.setRenderHint(QPainter::Antialiasing); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + int spacing = 2; + painter.translate(spacing, spacing); + + qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100; + qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100; + painter.scale(1./scaleFactorX, 1./scaleFactorY); + painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY))); + + painter.translate(dx, dy); + + painter.drawPolygon(shape); + painter.end(); + + return QIcon(pixmap); +} diff --git a/src/app/puzzle/vpuzzlepiece.h b/src/app/puzzle/vpuzzlepiece.h index b55ffeae0..c859de99e 100644 --- a/src/app/puzzle/vpuzzlepiece.h +++ b/src/app/puzzle/vpuzzlepiece.h @@ -198,6 +198,8 @@ public: */ void SetLayer(VPuzzleLayer* layer); + QIcon PieceIcon(const QSize &size) const; + signals: /** * @brief SelectionChanged emited when the selection of the piece was From beaedae7b5c9b57756e2d0766df7d215172ee00f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 13 May 2020 17:52:43 +0300 Subject: [PATCH 10/10] Improve the property browser. Show full arc name. (cherry picked from commit 590e0089da204f3796e0bebf70b4d0f78512fd30) --- ChangeLog.txt | 1 + src/app/valentina/core/vtooloptionspropertybrowser.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index cc924b47f..1df379dbf 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -47,6 +47,7 @@ - Setting scale factor for export and print. - New layout generator option: Prefer one sheet solution. - [smart-pattern/valentina#15] Organization of groups - groups categories +- Improve the property browser. Show full arc name. # Version 0.6.2 (unreleased) - [#903] Bug in tool Cut Spline path. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 27bd25e7a..2c8f9bd16 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -983,6 +983,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolArc(VPE::VProperty *property) SCASSERT(i != nullptr) switch (PropertiesList().indexOf(id)) { + case 0: // AttrName + Q_UNREACHABLE();//The attribute is read only + break; case 8: // AttrRadius i->SetFormulaRadius(value.value()); break; @@ -1021,6 +1024,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolArcWithLength(VPE::VProperty *pr SCASSERT(i != nullptr) switch (PropertiesList().indexOf(id)) { + case 0: // AttrName + Q_UNREACHABLE();//The attribute is read only + break; case 8: // AttrRadius i->SetFormulaRadius(value.value()); break; @@ -2019,6 +2025,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolArc(QGraphicsItem *item) i->ShowVisualization(true); formView->setTitle(tr("Arc")); + AddPropertyObjectName(i, tr("Name:"), true); AddPropertyParentPointName(i->CenterPointName(), tr("Center point:"), AttrCenter); AddPropertyFormula(tr("Radius:"), i->GetFormulaRadius(), AttrRadius); AddPropertyFormula(tr("First angle:"), i->GetFormulaF1(), AttrAngle1); @@ -2035,6 +2042,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolArcWithLength(QGraphicsItem *it i->ShowVisualization(true); formView->setTitle(tr("Arc with given length")); + AddPropertyObjectName(i, tr("Name:"), true); AddPropertyParentPointName(i->CenterPointName(), tr("Center point:"), AttrCenter); AddPropertyFormula(tr("Radius:"), i->GetFormulaRadius(), AttrRadius); AddPropertyFormula(tr("First angle:"), i->GetFormulaF1(), AttrAngle1);