mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
mobile-widgets: move basePointSize to themeinterface
Check defaultfont and calculate basepointsize in themeinterface instead of in QML. Signed-off-by: jan Iversen <jan@casacondor.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
08e39f9d2d
commit
a3e3a30b70
5 changed files with 17 additions and 21 deletions
|
@ -318,7 +318,7 @@ Kirigami.ScrollablePage {
|
||||||
enabled: subsurfaceTheme.currentScale !== 0.85
|
enabled: subsurfaceTheme.currentScale !== 0.85
|
||||||
onClicked: {
|
onClicked: {
|
||||||
PrefDisplay.mobile_scale = 0.85
|
PrefDisplay.mobile_scale = 0.85
|
||||||
fontMetrics.font.pointSize = subsurfaceTheme.basePointSize * PrefDisplay.mobile_scale;
|
fontMetrics.font.pointSize = themeNew.basePointSize * PrefDisplay.mobile_scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SsrfButton {
|
SsrfButton {
|
||||||
|
@ -326,7 +326,7 @@ Kirigami.ScrollablePage {
|
||||||
enabled: subsurfaceTheme.currentScale !== 1.0
|
enabled: subsurfaceTheme.currentScale !== 1.0
|
||||||
onClicked: {
|
onClicked: {
|
||||||
PrefDisplay.mobile_scale = 1.0
|
PrefDisplay.mobile_scale = 1.0
|
||||||
fontMetrics.font.pointSize = subsurfaceTheme.basePointSize * PrefDisplay.mobile_scale;
|
fontMetrics.font.pointSize = themeNew.basePointSize * PrefDisplay.mobile_scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SsrfButton {
|
SsrfButton {
|
||||||
|
@ -334,7 +334,7 @@ Kirigami.ScrollablePage {
|
||||||
enabled: subsurfaceTheme.currentScale !== 1.15
|
enabled: subsurfaceTheme.currentScale !== 1.15
|
||||||
onClicked: {
|
onClicked: {
|
||||||
PrefDisplay.mobile_scale = 1.15
|
PrefDisplay.mobile_scale = 1.15
|
||||||
fontMetrics.font.pointSize = subsurfaceTheme.basePointSize * PrefDisplay.mobile_scale;
|
fontMetrics.font.pointSize = themeNew.basePointSize * PrefDisplay.mobile_scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ Kirigami.Page {
|
||||||
text: "basePointSize:"
|
text: "basePointSize:"
|
||||||
}
|
}
|
||||||
Controls.Label {
|
Controls.Label {
|
||||||
text: subsurfaceTheme.basePointSize
|
text: ThemeNew.basePointSize
|
||||||
}
|
}
|
||||||
|
|
||||||
Controls.Label {
|
Controls.Label {
|
||||||
|
|
|
@ -48,11 +48,6 @@ Kirigami.ApplicationWindow {
|
||||||
}
|
}
|
||||||
FontMetrics {
|
FontMetrics {
|
||||||
id: fontMetrics
|
id: fontMetrics
|
||||||
Component.onCompleted: {
|
|
||||||
manager.appendTextToLog("Using the following font: " + fontMetrics.font.family +
|
|
||||||
" at " + subsurfaceTheme.basePointSize + "pt" +
|
|
||||||
" with mobile_scale: " + PrefDisplay.mobile_scale)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
|
@ -595,24 +590,12 @@ if you have network connectivity and want to sync your data to cloud storage."),
|
||||||
// change our glabal grid unit
|
// change our glabal grid unit
|
||||||
Kirigami.Units.gridUnit = kirigamiGridUnit
|
Kirigami.Units.gridUnit = kirigamiGridUnit
|
||||||
}
|
}
|
||||||
// break binding explicitly. Now we have a basePointSize that we can
|
|
||||||
// use to easily scale against
|
|
||||||
subsurfaceTheme.basePointSize = subsurfaceTheme.basePointSize * factor;
|
|
||||||
|
|
||||||
// set the initial UI scaling as in the the preferences
|
|
||||||
fontMetrics.font.pointSize = subsurfaceTheme.basePointSize * PrefDisplay.mobile_scale;
|
|
||||||
manager.appendTextToLog("Done setting up sizes")
|
manager.appendTextToLog("Done setting up sizes")
|
||||||
}
|
}
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: subsurfaceTheme
|
id: subsurfaceTheme
|
||||||
|
|
||||||
// basePointSize is determinded based on the width of the screen (typically at start of the app)
|
|
||||||
// and must not be changed if we change font size. This is tricky in QML. In order to break the
|
|
||||||
// binding between basePointSize and fontMetrics.font.pointSize we explicitly multipy it by 1.0
|
|
||||||
// in the onComplete handler of this object.
|
|
||||||
property double basePointSize: fontMetrics.font.pointSize;
|
|
||||||
|
|
||||||
property double regularPointSize: fontMetrics.font.pointSize
|
property double regularPointSize: fontMetrics.font.pointSize
|
||||||
property double titlePointSize: regularPointSize * 1.5
|
property double titlePointSize: regularPointSize * 1.5
|
||||||
property double headingPointSize: regularPointSize * 1.2
|
property double headingPointSize: regularPointSize * 1.2
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "themeinterface.h"
|
#include "themeinterface.h"
|
||||||
|
#include "qmlmanager.h"
|
||||||
|
#include "core/metrics.h"
|
||||||
#include "core/settings/qPrefDisplay.h"
|
#include "core/settings/qPrefDisplay.h"
|
||||||
|
|
||||||
themeInterface *themeInterface::instance()
|
themeInterface *themeInterface::instance()
|
||||||
|
@ -16,6 +18,12 @@ void themeInterface::setup(QQmlContext *ct)
|
||||||
// get current theme
|
// get current theme
|
||||||
instance()->m_currentTheme = qPrefDisplay::theme();
|
instance()->m_currentTheme = qPrefDisplay::theme();
|
||||||
instance()->update_theme();
|
instance()->update_theme();
|
||||||
|
|
||||||
|
// check system font
|
||||||
|
instance()->m_basePointSize = defaultModelFont().pointSize();
|
||||||
|
|
||||||
|
// set initial font size
|
||||||
|
defaultModelFont().setPointSize(m_basePointSize * qPrefDisplay::mobile_scale());
|
||||||
}
|
}
|
||||||
|
|
||||||
void themeInterface::set_currentTheme(const QString &theme)
|
void themeInterface::set_currentTheme(const QString &theme)
|
||||||
|
|
|
@ -23,6 +23,9 @@ class themeInterface : public QObject {
|
||||||
Q_PROPERTY(QColor secondaryTextColor MEMBER m_secondaryTextColor NOTIFY secondaryTextColorChanged)
|
Q_PROPERTY(QColor secondaryTextColor MEMBER m_secondaryTextColor NOTIFY secondaryTextColorChanged)
|
||||||
Q_PROPERTY(QColor textColor MEMBER m_textColor NOTIFY textColorChanged)
|
Q_PROPERTY(QColor textColor MEMBER m_textColor NOTIFY textColorChanged)
|
||||||
|
|
||||||
|
// Font
|
||||||
|
Q_PROPERTY(double basePointSize MEMBER m_basePointSize CONSTANT)
|
||||||
|
|
||||||
// Support
|
// Support
|
||||||
Q_PROPERTY(QString currentTheme MEMBER m_currentTheme WRITE set_currentTheme NOTIFY currentThemeChanged)
|
Q_PROPERTY(QString currentTheme MEMBER m_currentTheme WRITE set_currentTheme NOTIFY currentThemeChanged)
|
||||||
Q_PROPERTY(QString iconStyle MEMBER m_iconStyle CONSTANT)
|
Q_PROPERTY(QString iconStyle MEMBER m_iconStyle CONSTANT)
|
||||||
|
@ -108,6 +111,8 @@ private:
|
||||||
QColor m_secondaryTextColor;
|
QColor m_secondaryTextColor;
|
||||||
QColor m_textColor;
|
QColor m_textColor;
|
||||||
|
|
||||||
|
double m_basePointSize;
|
||||||
|
|
||||||
QString m_currentTheme;
|
QString m_currentTheme;
|
||||||
QString m_iconStyle;
|
QString m_iconStyle;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue