From 2cc215d3f26788974b1d5c552cb3750ad6bf8d85 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Tue, 14 Jan 2020 19:30:47 +0100 Subject: mobile-widgets: move font property to themeInterface Move setting of font properties used throughout to themeInterface. Add new settings "currentScale". The properties are kept in main (subsurfaceTheme) in order not to do a big search/replace. Update settings to use currectScale and signal changes in themeinterface. Signed-off-by: jan Iversen Signed-off-by: Dirk Hohndel --- mobile-widgets/qml/Settings.qml | 15 ++++++--------- mobile-widgets/qml/main.qml | 8 ++++---- mobile-widgets/themeinterface.cpp | 32 +++++++++++++++++++++++++++++++- mobile-widgets/themeinterface.h | 18 ++++++++++++++++++ 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/mobile-widgets/qml/Settings.qml b/mobile-widgets/qml/Settings.qml index f4bc95db3..cc2034bc9 100644 --- a/mobile-widgets/qml/Settings.qml +++ b/mobile-widgets/qml/Settings.qml @@ -315,26 +315,23 @@ Kirigami.ScrollablePage { spacing: Kirigami.Units.largeSpacing SsrfButton { text: qsTr("smaller") - enabled: subsurfaceTheme.currentScale !== 0.85 + enabled: ThemeNew.currentScale !== 0.85 onClicked: { - PrefDisplay.mobile_scale = 0.85 - fontMetrics.font.pointSize = themeNew.basePointSize * PrefDisplay.mobile_scale; + ThemeNew.currentScale = 0.85 } } SsrfButton { text: qsTr("regular") - enabled: subsurfaceTheme.currentScale !== 1.0 + enabled: ThemeNew.currentScale !== 1.0 onClicked: { - PrefDisplay.mobile_scale = 1.0 - fontMetrics.font.pointSize = themeNew.basePointSize * PrefDisplay.mobile_scale; + ThemeNew.currentScale = 1.0 } } SsrfButton { text: qsTr("larger") - enabled: subsurfaceTheme.currentScale !== 1.15 + enabled: ThemeNew.currentScale !== 1.15 onClicked: { - PrefDisplay.mobile_scale = 1.15 - fontMetrics.font.pointSize = themeNew.basePointSize * PrefDisplay.mobile_scale; + ThemeNew.currentScale = 1.15 } } } diff --git a/mobile-widgets/qml/main.qml b/mobile-widgets/qml/main.qml index ab9248ddf..be6cfaff2 100644 --- a/mobile-widgets/qml/main.qml +++ b/mobile-widgets/qml/main.qml @@ -596,10 +596,10 @@ if you have network connectivity and want to sync your data to cloud storage."), QtObject { id: subsurfaceTheme - property double regularPointSize: fontMetrics.font.pointSize - property double titlePointSize: regularPointSize * 1.5 - property double headingPointSize: regularPointSize * 1.2 - property double smallPointSize: regularPointSize * 0.8 + property double regularPointSize: ThemeNew.regularPointSize + property double titlePointSize: ThemeNew.titlePointSize + property double headingPointSize: ThemeNew.headingPointSize + property double smallPointSize: ThemeNew.smallPointSize // colors currently in use property color darkerPrimaryColor: ThemeNew.darkerPrimaryColor diff --git a/mobile-widgets/themeinterface.cpp b/mobile-widgets/themeinterface.cpp index ba72bb7f7..6419ce7ec 100644 --- a/mobile-widgets/themeinterface.cpp +++ b/mobile-widgets/themeinterface.cpp @@ -23,7 +23,7 @@ void themeInterface::setup(QQmlContext *ct) instance()->m_basePointSize = defaultModelFont().pointSize(); // set initial font size - defaultModelFont().setPointSize(m_basePointSize * qPrefDisplay::mobile_scale()); + instance()->set_currentScale(qPrefDisplay::mobile_scale()); } void themeInterface::set_currentTheme(const QString &theme) @@ -34,6 +34,36 @@ void themeInterface::set_currentTheme(const QString &theme) emit currentThemeChanged(theme); } +double themeInterface::currentScale() +{ + return qPrefDisplay::mobile_scale(); +} +void themeInterface::set_currentScale(double newScale) +{ + if (newScale != qPrefDisplay::mobile_scale()) { + qPrefDisplay::set_mobile_scale(newScale); + emit currentScaleChanged(qPrefDisplay::mobile_scale()); + } + + // Set current font size + defaultModelFont().setPointSize(m_basePointSize * qPrefDisplay::mobile_scale()); + + // adjust all used font sizes + m_regularPointSize = defaultModelFont().pointSize(); + emit regularPointSizeChanged(m_regularPointSize); + + m_headingPointSize = m_regularPointSize * 1.2; + emit headingPointSizeChanged(m_headingPointSize); + + m_smallPointSize = m_regularPointSize * 0.8; + emit smallPointSizeChanged(m_smallPointSize); + + m_titlePointSize = m_regularPointSize * 1.5; + emit titlePointSizeChanged(m_titlePointSize); +} + + + void themeInterface::update_theme() { if (m_currentTheme == "Blue") { diff --git a/mobile-widgets/themeinterface.h b/mobile-widgets/themeinterface.h index ee6a8879c..f06d834da 100644 --- a/mobile-widgets/themeinterface.h +++ b/mobile-widgets/themeinterface.h @@ -25,6 +25,11 @@ class themeInterface : public QObject { // Font Q_PROPERTY(double basePointSize MEMBER m_basePointSize CONSTANT) + Q_PROPERTY(double headingPointSize MEMBER m_headingPointSize NOTIFY headingPointSizeChanged) + Q_PROPERTY(double regularPointSize MEMBER m_regularPointSize NOTIFY regularPointSizeChanged) + Q_PROPERTY(double smallPointSize MEMBER m_smallPointSize NOTIFY smallPointSizeChanged) + Q_PROPERTY(double titlePointSize MEMBER m_titlePointSize NOTIFY titlePointSizeChanged) + Q_PROPERTY(double currentScale READ currentScale WRITE set_currentScale NOTIFY currentScaleChanged) // Support Q_PROPERTY(QString currentTheme MEMBER m_currentTheme WRITE set_currentTheme NOTIFY currentThemeChanged) @@ -78,6 +83,9 @@ public: public slots: void set_currentTheme(const QString &theme); + double currentScale(); + void set_currentScale(double); + signals: void backgroundColorChanged(QColor); void contrastAccentColorChanged(QColor); @@ -92,6 +100,12 @@ signals: void secondaryTextColorChanged(QColor); void textColorChanged(QColor); + void headingPointSizeChanged(double); + void regularPointSizeChanged(double); + void smallPointSizeChanged(double); + void titlePointSizeChanged(double); + void currentScaleChanged(double); + void currentThemeChanged(const QString &); private: @@ -112,6 +126,10 @@ private: QColor m_textColor; double m_basePointSize; + double m_headingPointSize; + double m_regularPointSize; + double m_smallPointSize; + double m_titlePointSize; QString m_currentTheme; QString m_iconStyle; -- cgit v1.2.3-70-g09d2