diff options
Diffstat (limited to 'core/settings')
-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 |
6 files changed, 101 insertions, 4 deletions
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 |