mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
38307a5b3c
commit
617019bc6b
4 changed files with 45 additions and 7 deletions
|
@ -108,6 +108,7 @@ struct preferences {
|
|||
bool display_invalid_dives;
|
||||
const char *divelist_font;
|
||||
double font_size;
|
||||
double mobile_scale;
|
||||
bool show_developer;
|
||||
|
||||
// ********** Facebook **********
|
||||
|
|
|
@ -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);
|
||||
else
|
||||
// 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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue