summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-22 16:09:31 -0700
committerGravatar Jan Mulder <jlmulder@xs4all.nl>2018-09-25 15:58:17 +0200
commit617019bc6b9e5bebba1cb96b1ed039befa8470ff (patch)
tree335bf32c030ba7f6394aa298ff8c5410f1e6e426 /core
parent38307a5b3c7bfd798815d18d7b2b982075ec8e12 (diff)
downloadsubsurface-617019bc6b9e5bebba1cb96b1ed039befa8470ff.tar.gz
qPref: add mobile_scale preference
We use that in the mobile app to scale the whole app, as all sizes there are relative to the default font. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/pref.h1
-rw-r--r--core/settings/qPrefDisplay.cpp43
-rw-r--r--core/settings/qPrefDisplay.h5
-rw-r--r--core/subsurfacestartup.c1
4 files changed, 44 insertions, 6 deletions
diff --git a/core/pref.h b/core/pref.h
index b36c46091..2e11efbe4 100644
--- a/core/pref.h
+++ b/core/pref.h
@@ -108,6 +108,7 @@ struct preferences {
bool display_invalid_dives;
const char *divelist_font;
double font_size;
+ double mobile_scale;
bool show_developer;
// ********** Facebook **********
diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp
index fcca8cd20..ca340d504 100644
--- a/core/settings/qPrefDisplay.cpp
+++ b/core/settings/qPrefDisplay.cpp
@@ -30,7 +30,7 @@ QByteArray qPrefDisplay::st_bottomSplitter;
static const QByteArray st_bottomSplitter_default = "";
bool qPrefDisplay::st_maximized;
-static bool st_maximized_default = false;
+static bool st_maximized_default = false;
QByteArray qPrefDisplay::st_geometry;
static const QByteArray st_geometry_default = 0;
@@ -39,7 +39,7 @@ QByteArray qPrefDisplay::st_windowState;
static const QByteArray st_windowState_default = 0;
int qPrefDisplay::st_lastState;
-static int st_lastState_default = false;
+static int st_lastState_default = false;
qPrefDisplay::qPrefDisplay(QObject *parent) : QObject(parent)
{
@@ -56,6 +56,7 @@ void qPrefDisplay::loadSync(bool doSync)
disk_animation_speed(doSync);
disk_divelist_font(doSync);
disk_font_size(doSync);
+ disk_mobile_scale(doSync);
disk_display_invalid_dives(doSync);
disk_show_developer(doSync);
if (!doSync) {
@@ -103,17 +104,46 @@ void qPrefDisplay::set_font_size(double value)
disk_font_size(true);
QFont defaultFont = qApp->font();
- defaultFont.setPointSizeF(prefs.font_size);
+ defaultFont.setPointSizeF(prefs.font_size * prefs.mobile_scale);
qApp->setFont(defaultFont);
emit instance()->font_sizeChanged(value);
}
}
+
void qPrefDisplay::disk_font_size(bool doSync)
{
- if (doSync)
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, "font_size"), prefs.font_size, default_prefs.font_size);
+ // inverted logic compared to the other disk_xxx functions
+ if (!doSync)
+ setCorrectFont();
+#if !defined(SUBSURFACE_MOBILE)
+ // we never want to save the font_size to disk - we always want to grab that from the system default
else
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, "font_size"), prefs.font_size, default_prefs.font_size);
+#endif
+}
+
+void qPrefDisplay::set_mobile_scale(double value)
+{
+ if (!IS_FP_SAME(value, prefs.mobile_scale)) {
+ prefs.mobile_scale = value;
+ disk_mobile_scale(true);
+
+ QFont defaultFont = qApp->font();
+ defaultFont.setPointSizeF(prefs.font_size * prefs.mobile_scale);
+ qApp->setFont(defaultFont);
+ emit instance()->mobile_scaleChanged(value);
+ emit instance()->font_sizeChanged(value);
+ }
+}
+
+void qPrefDisplay::disk_mobile_scale(bool doSync)
+{
+ if (doSync) {
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, "mobile_scale"), prefs.mobile_scale, default_prefs.mobile_scale);
+ } else {
+ prefs.mobile_scale = qPrefPrivate::propValue(keyFromGroupAndName(group, "mobile_scale"), default_prefs.mobile_scale).toDouble();
setCorrectFont();
+ }
}
//JAN static const QString group = QStringLiteral("Animations");
@@ -134,6 +164,7 @@ void qPrefDisplay::setCorrectFont()
}
prefs.font_size = qPrefPrivate::propValue(keyFromGroupAndName(group, "font_size"), prefs.font_size).toFloat();
+
// painful effort to ignore previous default fonts on Windows - ridiculous
QString fontName = defaultFont.toString();
if (fontName.contains(","))
@@ -144,7 +175,7 @@ void qPrefDisplay::setCorrectFont()
free((void *)prefs.divelist_font);
prefs.divelist_font = copy_qstring(fontName);
}
- defaultFont.setPointSizeF(prefs.font_size);
+ defaultFont.setPointSizeF(prefs.font_size * prefs.mobile_scale);
qApp->setFont(defaultFont);
prefs.display_invalid_dives = qPrefPrivate::propValue(keyFromGroupAndName(group, "displayinvalid"), default_prefs.display_invalid_dives).toBool();
diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h
index f7293e67b..b1090b7a1 100644
--- a/core/settings/qPrefDisplay.h
+++ b/core/settings/qPrefDisplay.h
@@ -11,6 +11,7 @@ class qPrefDisplay : public QObject {
Q_PROPERTY(int animation_speed READ animation_speed WRITE set_animation_speed NOTIFY animation_speedChanged);
Q_PROPERTY(QString divelist_font READ divelist_font WRITE set_divelist_font NOTIFY divelist_fontChanged);
Q_PROPERTY(double font_size READ font_size WRITE set_font_size NOTIFY font_sizeChanged);
+ Q_PROPERTY(double mobile_scale READ mobile_scale WRITE set_mobile_scale NOTIFY mobile_scaleChanged);
Q_PROPERTY(bool display_invalid_dives READ display_invalid_dives WRITE set_display_invalid_dives NOTIFY display_invalid_divesChanged);
Q_PROPERTY(QString lastDir READ lastDir WRITE set_lastDir NOTIFY lastDirChanged);
Q_PROPERTY(bool show_developer READ show_developer WRITE set_show_developer NOTIFY show_developerChanged);
@@ -38,6 +39,7 @@ public:
static int animation_speed() { return prefs.animation_speed; }
static QString divelist_font() { return prefs.divelist_font; }
static double font_size() { return prefs.font_size; }
+ static double mobile_scale() { return prefs.mobile_scale; }
static bool display_invalid_dives() { return prefs.display_invalid_dives; }
static QString lastDir() { return st_lastDir; ; }
static bool show_developer() { return prefs.show_developer; }
@@ -56,6 +58,7 @@ public slots:
static void set_animation_speed(int value);
static void set_divelist_font(const QString &value);
static void set_font_size(double value);
+ static void set_mobile_scale(double value);
static void set_display_invalid_dives(bool value);
static void set_lastDir(const QString &value);
static void set_show_developer(bool value);
@@ -74,6 +77,7 @@ signals:
void animation_speedChanged(int value);
void divelist_fontChanged(const QString &value);
void font_sizeChanged(double value);
+ void mobile_scaleChanged(double value);
void display_invalid_divesChanged(bool value);
void lastDirChanged(const QString &value);
void show_developerChanged(bool value);
@@ -93,6 +97,7 @@ private:
static void disk_animation_speed(bool doSync);
static void disk_divelist_font(bool doSync);
static void disk_font_size(bool doSync);
+ static void disk_mobile_scale(bool doSync);
static void disk_display_invalid_dives(bool doSync);
static void disk_show_developer(bool doSync);
diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c
index 42e9aef7b..263845671 100644
--- a/core/subsurfacestartup.c
+++ b/core/subsurfacestartup.c
@@ -42,6 +42,7 @@ struct preferences default_prefs = {
.show_ccr_sensors = false,
.show_scr_ocpo2 = false,
.font_size = -1,
+ .mobile_scale = 1.0,
.display_invalid_dives = false,
.show_sac = false,
.display_unused_tanks = false,