diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | core/settings/qPref.cpp | 1 | ||||
-rw-r--r-- | core/settings/qPref.h | 5 | ||||
-rw-r--r-- | core/settings/qPrefAnimations.cpp | 20 | ||||
-rw-r--r-- | core/settings/qPrefAnimations.h | 38 | ||||
-rw-r--r-- | core/settings/qPrefDisplay.cpp | 36 | ||||
-rw-r--r-- | core/settings/qPrefDisplay.h | 5 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 120 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.h | 48 |
9 files changed, 112 insertions, 162 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 67f0623a7..5b476c779 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -100,6 +100,7 @@ set(SUBSURFACE_CORE_LIB_SRCS # classes to manage struct preferences for QWidget and QML settings/qPref.cpp + settings/qPrefAnimations.cpp settings/qPrefDisplay.cpp #Subsurface Qt have the Subsurface structs QObjectified for easy access via QML. diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index 189fad499..027d4af5a 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -15,6 +15,7 @@ static qPref *self = new qPref; void qPref::loadSync(bool doSync) { + qPrefDisplay::instance()->loadSync(doSync); } const QString qPref::canonical_version() const diff --git a/core/settings/qPref.h b/core/settings/qPref.h index e0e21ad6e..758b159d7 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -6,6 +6,7 @@ #include <QSettings> #include "core/pref.h" +#include "qPrefAnimations.h" #include "qPrefDisplay.h" class qPref : public QObject { @@ -20,6 +21,8 @@ public: // Load/Sync local settings (disk) and struct preference void loadSync(bool doSync); + void load() { loadSync(false); } + void sync() { loadSync(true); } public: enum cloud_status { @@ -32,8 +35,6 @@ public: const QString canonical_version() const; const QString mobile_version() const; - -private: }; #endif diff --git a/core/settings/qPrefAnimations.cpp b/core/settings/qPrefAnimations.cpp new file mode 100644 index 000000000..a6ecc1d5b --- /dev/null +++ b/core/settings/qPrefAnimations.cpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qPref.h" +#include "qPref_private.h" +#include "qPrefAnimations.h" + +qPrefAnimations::qPrefAnimations(QObject *parent) : QObject(parent) +{ +} +qPrefAnimations *qPrefAnimations::instance() +{ + static qPrefAnimations *self = new qPrefAnimations; + return self; +} + +void qPrefAnimations::loadSync(bool doSync) +{ + disk_animation_speed(doSync); +} + +HANDLE_PREFERENCE_INT(Animations, "/animation_speed", animation_speed); diff --git a/core/settings/qPrefAnimations.h b/core/settings/qPrefAnimations.h new file mode 100644 index 000000000..fb58b207e --- /dev/null +++ b/core/settings/qPrefAnimations.h @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef QPREFANIMATIONS_H +#define QPREFANIMATIONS_H + +#include <QObject> +#include <QSettings> + +class qPrefAnimations : public QObject { + Q_OBJECT + Q_PROPERTY(int animation_speed READ animation_speed WRITE set_animation_speed NOTIFY animation_speed_changed); + +public: + qPrefAnimations(QObject *parent = NULL); + static qPrefAnimations *instance(); + + // Load/Sync local settings (disk) and struct preference + void loadSync(bool doSync); + void load() { loadSync(false); } + void sync() { loadSync(true); } + +public: + int animation_speed() const; + +public slots: + void set_animation_speed(int value); + +signals: + void animation_speed_changed(int value); + +private: + const QString group = QStringLiteral("Animations"); + QSettings setting; + + // functions to load/sync variable with disk + void disk_animation_speed(bool doSync); +}; + +#endif diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp index cf0a4e54d..fee960f97 100644 --- a/core/settings/qPrefDisplay.cpp +++ b/core/settings/qPrefDisplay.cpp @@ -39,7 +39,12 @@ void qPrefDisplay::set_divelist_font(const QString& value) emit divelist_font_changed(value); } } -DISK_LOADSYNC_TXT(Display, "/divelist_font", divelist_font); +void qPrefDisplay::disk_divelist_font(bool doSync) +{ + LOADSYNC_TXT("/divelist_font", divelist_font); + if (!doSync) + setCorrectFont(); +} GET_PREFERENCE_DOUBLE(Display, font_size); void qPrefDisplay::set_font_size(double value) @@ -53,10 +58,37 @@ void qPrefDisplay::set_font_size(double value) emit font_size_changed(value); } } -DISK_LOADSYNC_DOUBLE(Display, "/font_size", font_size); +void qPrefDisplay::disk_font_size(bool doSync) +{ + LOADSYNC_DOUBLE("/font_size", font_size); + if (!doSync) + setCorrectFont(); +} HANDLE_PREFERENCE_BOOL(Display, "/displayinvalid", display_invalid_dives); HANDLE_PREFERENCE_BOOL(Display, "/show_developer", show_developer); HANDLE_PREFERENCE_TXT(Display, "/theme", theme); + + +void qPrefDisplay::setCorrectFont() +{ + // get the font from the settings or our defaults + // respect the system default font size if none is explicitly set + QFont defaultFont(prefs.divelist_font); + if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) { + prefs.font_size = qApp->font().pointSizeF(); + system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit + } + // painful effort to ignore previous default fonts on Windows - ridiculous + QString fontName = defaultFont.toString(); + if (fontName.contains(",")) + fontName = fontName.left(fontName.indexOf(",")); + if (subsurface_ignore_font(qPrintable(fontName))) + defaultFont = QFont(prefs.divelist_font); + else + COPY_TXT(divelist_font, fontName); + defaultFont.setPointSizeF(prefs.font_size); + qApp->setFont(defaultFont); +} diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index 6448e0115..4a1c0ada5 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -19,6 +19,8 @@ public: // Load/Sync local settings (disk) and struct preference void loadSync(bool doSync); + void load() { loadSync(false); } + void sync() { loadSync(true); } public: const QString divelist_font() const; @@ -51,5 +53,8 @@ private: void disk_display_invalid_dives(bool doSync); void disk_show_developer(bool doSync); void disk_theme(bool doSync); + + // font helper function + void setCorrectFont(); }; #endif diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 80b9df8ee..e2fadd90c 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1913,75 +1913,6 @@ void GeneralSettingsObjectWrapper::setAutoRecalculateThumbnails(bool value) emit autoRecalculateThumbnailsChanged(value); } -DisplaySettingsObjectWrapper::DisplaySettingsObjectWrapper(QObject *parent) : - QObject(parent) -{ -} - -QString DisplaySettingsObjectWrapper::divelistFont() const -{ - return prefs.divelist_font; -} - -double DisplaySettingsObjectWrapper::fontSize() const -{ - return prefs.font_size; -} - -bool DisplaySettingsObjectWrapper::displayInvalidDives() const -{ - return prefs.display_invalid_dives; -} - -void DisplaySettingsObjectWrapper::setDivelistFont(const QString& value) -{ - - QString newValue = value; - if (value.contains(",")) - newValue = value.left(value.indexOf(",")); - - if (newValue == prefs.divelist_font) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("divelist_font", value); - - if (!subsurface_ignore_font(qPrintable(newValue))) { - free((void *)prefs.divelist_font); - prefs.divelist_font = copy_qstring(newValue); - qApp->setFont(QFont(newValue)); - } - emit divelistFontChanged(newValue); -} - -void DisplaySettingsObjectWrapper::setFontSize(double value) -{ - if (value == prefs.font_size) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("font_size", value); - prefs.font_size = value; - QFont defaultFont = qApp->font(); - defaultFont.setPointSizeF(prefs.font_size); - qApp->setFont(defaultFont); - emit fontSizeChanged(value); -} - -void DisplaySettingsObjectWrapper::setDisplayInvalidDives(bool value) -{ - if (value == prefs.display_invalid_dives) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("displayinvalid", value); - prefs.display_invalid_dives = value; - emit displayInvalidDivesChanged(value); -} - LanguageSettingsObjectWrapper::LanguageSettingsObjectWrapper(QObject *parent) : QObject(parent) { @@ -2123,27 +2054,6 @@ void LanguageSettingsObjectWrapper::setDateFormatOverride(bool value) emit dateFormatOverrideChanged(value); } -AnimationsSettingsObjectWrapper::AnimationsSettingsObjectWrapper(QObject* parent): - QObject(parent) -{ -} - -int AnimationsSettingsObjectWrapper::animationSpeed() const -{ - return prefs.animation_speed; -} - -void AnimationsSettingsObjectWrapper::setAnimationSpeed(int value) -{ - if (value == prefs.animation_speed) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("animation_speed", value); - prefs.animation_speed = value; - emit animationSpeedChanged(value); -} LocationServiceSettingsObjectWrapper::LocationServiceSettingsObjectWrapper(QObject* parent): QObject(parent) @@ -2194,9 +2104,9 @@ QObject(parent), planner_settings(new DivePlannerSettings(this)), unit_settings(new UnitsSettings(this)), general_settings(new GeneralSettingsObjectWrapper(this)), - display_settings(new DisplaySettingsObjectWrapper(this)), + display_settings(new qPrefDisplay(this)), language_settings(new LanguageSettingsObjectWrapper(this)), - animation_settings(new AnimationsSettingsObjectWrapper(this)), + animation_settings(new qPrefAnimations(this)), location_settings(new LocationServiceSettingsObjectWrapper(this)), update_manager_settings(new UpdateManagerSettings(this)), dive_computer_settings(new DiveComputerSettings(this)) @@ -2287,29 +2197,7 @@ void SettingsObjectWrapper::load() GET_BOOL("auto_recalculate_thumbnails", auto_recalculate_thumbnails); s.endGroup(); - s.beginGroup("Display"); - // get the font from the settings or our defaults - // respect the system default font size if none is explicitly set - QFont defaultFont = s.value("divelist_font", prefs.divelist_font).value<QFont>(); - if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) { - prefs.font_size = qApp->font().pointSizeF(); - system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit - } - prefs.font_size = s.value("font_size", prefs.font_size).toFloat(); - // painful effort to ignore previous default fonts on Windows - ridiculous - QString fontName = defaultFont.toString(); - if (fontName.contains(",")) - fontName = fontName.left(fontName.indexOf(",")); - if (subsurface_ignore_font(qPrintable(fontName))) { - defaultFont = QFont(prefs.divelist_font); - } else { - free((void *)prefs.divelist_font); - prefs.divelist_font = copy_qstring(fontName); - } - defaultFont.setPointSizeF(prefs.font_size); - qApp->setFont(defaultFont); - GET_BOOL("displayinvalid", display_invalid_dives); - s.endGroup(); + qPrefDisplay::instance()->load(); s.beginGroup("Animations"); GET_INT("animation_speed", animation_speed); @@ -2420,6 +2308,8 @@ void SettingsObjectWrapper::load() void SettingsObjectWrapper::sync() { + qPrefDisplay::instance()->sync(); + QSettings s; s.beginGroup("Planner"); s.setValue("last_stop", prefs.last_stop); diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h index 64f0621b2..075227384 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.h +++ b/core/subsurface-qt/SettingsObjectWrapper.h @@ -6,6 +6,7 @@ #include <QDate> #include "core/pref.h" +#include "core/settings/qPref.h" /* Wrapper class for the Settings. This will allow * seamlessy integration of the settings with the QML @@ -594,28 +595,6 @@ private: const QString group = QStringLiteral("GeneralSettings"); }; -class DisplaySettingsObjectWrapper : public QObject { - Q_OBJECT - Q_PROPERTY(QString divelist_font READ divelistFont WRITE setDivelistFont NOTIFY divelistFontChanged) - Q_PROPERTY(double font_size READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - Q_PROPERTY(bool display_invalid_dives READ displayInvalidDives WRITE setDisplayInvalidDives NOTIFY displayInvalidDivesChanged) -public: - DisplaySettingsObjectWrapper(QObject *parent); - QString divelistFont() const; - double fontSize() const; - bool displayInvalidDives() const; -public slots: - void setDivelistFont(const QString& value); - void setFontSize(double value); - void setDisplayInvalidDives(bool value); -signals: - void divelistFontChanged(const QString& value); - void fontSizeChanged(double value); - void displayInvalidDivesChanged(bool value); -private: - const QString group = QStringLiteral("Display"); -}; - class LanguageSettingsObjectWrapper : public QObject { Q_OBJECT Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged) @@ -661,23 +640,6 @@ private: const QString group = QStringLiteral("Language"); }; -class AnimationsSettingsObjectWrapper : public QObject { - Q_OBJECT - Q_PROPERTY(int animation_speed READ animationSpeed WRITE setAnimationSpeed NOTIFY animationSpeedChanged) -public: - AnimationsSettingsObjectWrapper(QObject *parent); - int animationSpeed() const; - -public slots: - void setAnimationSpeed(int value); - -signals: - void animationSpeedChanged(int value); - -private: - const QString group = QStringLiteral("Animations"); -}; - class LocationServiceSettingsObjectWrapper : public QObject { Q_OBJECT Q_PROPERTY(int time_threshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged) @@ -709,9 +671,9 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(UnitsSettings* units MEMBER unit_settings CONSTANT) Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT) - Q_PROPERTY(DisplaySettingsObjectWrapper* display MEMBER display_settings CONSTANT) + Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT) Q_PROPERTY(LanguageSettingsObjectWrapper* language MEMBER language_settings CONSTANT) - Q_PROPERTY(AnimationsSettingsObjectWrapper* animation MEMBER animation_settings CONSTANT) + Q_PROPERTY(qPrefAnimations* animation MEMBER animation_settings CONSTANT) Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT) Q_PROPERTY(UpdateManagerSettings* update MEMBER update_manager_settings CONSTANT) @@ -728,9 +690,9 @@ public: DivePlannerSettings *planner_settings; UnitsSettings *unit_settings; GeneralSettingsObjectWrapper *general_settings; - DisplaySettingsObjectWrapper *display_settings; + qPrefDisplay *display_settings; LanguageSettingsObjectWrapper *language_settings; - AnimationsSettingsObjectWrapper *animation_settings; + qPrefAnimations *animation_settings; LocationServiceSettingsObjectWrapper *location_settings; UpdateManagerSettings *update_manager_settings; DiveComputerSettings *dive_computer_settings; |