aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-14 08:15:23 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-14 08:16:14 -0700
commitdc22747cb02caff55da809da234fd7ad1cf23f27 (patch)
treee9ac9a875c841974b10baa27fe58c41dfbbf1133 /core
parente834874a7a6f8e37fade28bf20640b8d0815373b (diff)
parentf63217495d27c77b2f7f866caec568a19ee9543d (diff)
downloadsubsurface-dc22747cb02caff55da809da234fd7ad1cf23f27.tar.gz
Merge branch 'qPrefAnimations' of https://github.com/janiversen/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/CMakeLists.txt1
-rw-r--r--core/settings/qPref.h3
-rw-r--r--core/settings/qPrefAnimations.cpp20
-rw-r--r--core/settings/qPrefAnimations.h38
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp23
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h21
6 files changed, 63 insertions, 43 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.h b/core/settings/qPref.h
index 70eef3cb3..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 {
@@ -34,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/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index c5a335a8e..e2fadd90c 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -2054,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)
@@ -2127,7 +2106,7 @@ QObject(parent),
general_settings(new GeneralSettingsObjectWrapper(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))
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index a6a47a0a1..075227384 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -640,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)
@@ -690,7 +673,7 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_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)
@@ -709,7 +692,7 @@ public:
GeneralSettingsObjectWrapper *general_settings;
qPrefDisplay *display_settings;
LanguageSettingsObjectWrapper *language_settings;
- AnimationsSettingsObjectWrapper *animation_settings;
+ qPrefAnimations *animation_settings;
LocationServiceSettingsObjectWrapper *location_settings;
UpdateManagerSettings *update_manager_settings;
DiveComputerSettings *dive_computer_settings;