mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
mobile/UI: remember the system default font size
We need to do this before the preferences are loaded, or the system default size is lost. Given that our other sizes are all relative to this value, that would be a problem. With this we can now ensure that we always have the right font size for smaller, regular, and larger theme settings. Also removes some obsolete commented out code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
1472117541
commit
323e97c603
6 changed files with 37 additions and 26 deletions
|
@ -24,7 +24,6 @@ IconMetrics::IconMetrics() :
|
||||||
QFont defaultModelFont()
|
QFont defaultModelFont()
|
||||||
{
|
{
|
||||||
QFont font;
|
QFont font;
|
||||||
// font.setPointSizeF(font.pointSizeF() * 0.8);
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ void set_non_bt_addresses();
|
||||||
|
|
||||||
#if defined(SUBSURFACE_MOBILE)
|
#if defined(SUBSURFACE_MOBILE)
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
void run_mobile_ui();
|
void run_mobile_ui(double initial_font_size);
|
||||||
#else
|
#else
|
||||||
void run_ui();
|
void run_ui();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,13 +56,7 @@ ThemeInterface::ThemeInterface()
|
||||||
// get current theme
|
// get current theme
|
||||||
m_currentTheme = qPrefDisplay::theme();
|
m_currentTheme = qPrefDisplay::theme();
|
||||||
update_theme();
|
update_theme();
|
||||||
|
m_basePointSize = -1.0; // simply a placeholder to declare 'this isn't set, yet'
|
||||||
// check system font and create QFontInfo in order to reliably get the point size
|
|
||||||
QFontInfo qfi(defaultModelFont());
|
|
||||||
m_basePointSize = qfi.pointSize();
|
|
||||||
|
|
||||||
// set initial font size
|
|
||||||
set_currentScale(qPrefDisplay::mobile_scale());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeInterface::set_currentTheme(const QString &theme)
|
void ThemeInterface::set_currentTheme(const QString &theme)
|
||||||
|
@ -73,6 +67,12 @@ void ThemeInterface::set_currentTheme(const QString &theme)
|
||||||
emit currentThemeChanged();
|
emit currentThemeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThemeInterface::setInitialFontSize(double fontSize)
|
||||||
|
{
|
||||||
|
m_basePointSize = fontSize;
|
||||||
|
set_currentScale(qPrefDisplay::mobile_scale());
|
||||||
|
}
|
||||||
|
|
||||||
double ThemeInterface::currentScale()
|
double ThemeInterface::currentScale()
|
||||||
{
|
{
|
||||||
return qPrefDisplay::mobile_scale();
|
return qPrefDisplay::mobile_scale();
|
||||||
|
@ -80,17 +80,17 @@ double ThemeInterface::currentScale()
|
||||||
|
|
||||||
void ThemeInterface::set_currentScale(double newScale)
|
void ThemeInterface::set_currentScale(double newScale)
|
||||||
{
|
{
|
||||||
|
static bool needSignals = true; // make sure the signals fire the first time
|
||||||
|
|
||||||
if (!IS_FP_SAME(newScale, qPrefDisplay::mobile_scale())) {
|
if (!IS_FP_SAME(newScale, qPrefDisplay::mobile_scale())) {
|
||||||
double factor = newScale / qPrefDisplay::mobile_scale();
|
|
||||||
qPrefDisplay::set_mobile_scale(newScale);
|
qPrefDisplay::set_mobile_scale(newScale);
|
||||||
emit currentScaleChanged();
|
emit currentScaleChanged();
|
||||||
|
needSignals = true;
|
||||||
// Set current font size
|
|
||||||
m_basePointSize *= factor;
|
|
||||||
defaultModelFont().setPointSizeF(m_basePointSize);
|
|
||||||
}
|
}
|
||||||
|
if (needSignals) {
|
||||||
// adjust all used font sizes
|
// adjust all used font sizes
|
||||||
m_regularPointSize = m_basePointSize;
|
m_regularPointSize = m_basePointSize * newScale;
|
||||||
|
defaultModelFont().setPointSizeF(m_regularPointSize);
|
||||||
emit regularPointSizeChanged();
|
emit regularPointSizeChanged();
|
||||||
|
|
||||||
m_headingPointSize = m_regularPointSize * 1.2;
|
m_headingPointSize = m_regularPointSize * 1.2;
|
||||||
|
@ -101,6 +101,9 @@ void ThemeInterface::set_currentScale(double newScale)
|
||||||
|
|
||||||
m_titlePointSize = m_regularPointSize * 1.5;
|
m_titlePointSize = m_regularPointSize * 1.5;
|
||||||
emit titlePointSizeChanged();
|
emit titlePointSizeChanged();
|
||||||
|
|
||||||
|
needSignals = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeInterface::update_theme()
|
void ThemeInterface::update_theme()
|
||||||
|
|
|
@ -37,6 +37,7 @@ class ThemeInterface : public QObject {
|
||||||
public:
|
public:
|
||||||
static ThemeInterface *instance();
|
static ThemeInterface *instance();
|
||||||
double currentScale();
|
double currentScale();
|
||||||
|
void setInitialFontSize(double fontSize);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void set_currentTheme(const QString &theme);
|
void set_currentTheme(const QString &theme);
|
||||||
|
|
|
@ -69,7 +69,7 @@ void exit_ui()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SUBSURFACE_MOBILE
|
#ifdef SUBSURFACE_MOBILE
|
||||||
void run_mobile_ui()
|
void run_mobile_ui(double initial_font_size)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
// work around an odd interaction between the OnePlus flavor of Android and Qt font handling
|
// work around an odd interaction between the OnePlus flavor of Android and Qt font handling
|
||||||
|
@ -127,9 +127,13 @@ void run_mobile_ui()
|
||||||
ctxt->setContextProperty("diveModel", MobileModels::instance()->listModel());
|
ctxt->setContextProperty("diveModel", MobileModels::instance()->listModel());
|
||||||
set_non_bt_addresses();
|
set_non_bt_addresses();
|
||||||
|
|
||||||
|
// we need to setup the initial font size before the QML UI is instantiated
|
||||||
|
ThemeInterface *themeInterface = ThemeInterface::instance();
|
||||||
|
themeInterface->setInitialFontSize(initial_font_size);
|
||||||
|
|
||||||
ctxt->setContextProperty("connectionListModel", &connectionListModel);
|
ctxt->setContextProperty("connectionListModel", &connectionListModel);
|
||||||
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
|
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
|
||||||
ctxt->setContextProperty("subsurfaceTheme", ThemeInterface::instance());
|
ctxt->setContextProperty("subsurfaceTheme", themeInterface);
|
||||||
|
|
||||||
qmlRegisterUncreatableType<QMLManager>("org.subsurfacedivelog.mobile",1,0,"ExportType","Enum is not a type");
|
qmlRegisterUncreatableType<QMLManager>("org.subsurfacedivelog.mobile",1,0,"ExportType","Enum is not a type");
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "core/settings/qPrefCloudStorage.h"
|
#include "core/settings/qPrefCloudStorage.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QFont>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@ -60,6 +61,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
parse_xml_init();
|
parse_xml_init();
|
||||||
taglist_init_global();
|
taglist_init_global();
|
||||||
|
|
||||||
|
// grab the system font size before we overwrite this when we load preferences
|
||||||
|
double initial_font_size = QGuiApplication::font().pointSizeF();
|
||||||
init_ui();
|
init_ui();
|
||||||
if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE)
|
if (prefs.default_file_behavior == LOCAL_DEFAULT_FILE)
|
||||||
set_filename(prefs.default_filename);
|
set_filename(prefs.default_filename);
|
||||||
|
@ -76,7 +80,7 @@ int main(int argc, char **argv)
|
||||||
init_proxy();
|
init_proxy();
|
||||||
|
|
||||||
if (!quit)
|
if (!quit)
|
||||||
run_mobile_ui();
|
run_mobile_ui(initial_font_size);
|
||||||
exit_ui();
|
exit_ui();
|
||||||
taglist_free(g_tag_list);
|
taglist_free(g_tag_list);
|
||||||
parse_xml_exit();
|
parse_xml_exit();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue