diff options
| author | Doris Verria <doris.verria@qt.io> | 2025-11-27 17:53:53 +0100 |
|---|---|---|
| committer | Doris Verria <doris.verria@qt.io> | 2025-12-01 13:03:28 +0100 |
| commit | caeaa6bdd10d1d5b2bcd3b59f629583905197267 (patch) | |
| tree | a06bea62a507686de54f428168b858f1509bdb77 /src/labs/stylekit/qqstylekitstyle.cpp | |
| parent | 49f14263cd587282f77b0fac761de74483e52485 (diff) | |
Add a fonts property to the style that allows you to set fonts per
control, similarily to what we do in QQuickTheme.
The fonts are propagated from the style to the theme, and from the
fallback style to the style. That means that if a font is not set
for a theme or style, it will be resolved against its fallback font.
Since both the QQStyleKitTheme and QQStyleKitStyle should have a
fonts property, introduce a common base class: QQStyleKitThemeProperties
that contains the fonts property. Later, the palettes can be moved
there as well.
Also add a font property to the QQStyleKitReader that is suposed to
return the font for the current control being read.
Change-Id: I116c1ab9bc426570756476ee409513587c475a0d
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/labs/stylekit/qqstylekitstyle.cpp')
| -rw-r--r-- | src/labs/stylekit/qqstylekitstyle.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/labs/stylekit/qqstylekitstyle.cpp b/src/labs/stylekit/qqstylekitstyle.cpp index 624294fc03..e15fa8674d 100644 --- a/src/labs/stylekit/qqstylekitstyle.cpp +++ b/src/labs/stylekit/qqstylekitstyle.cpp @@ -21,7 +21,7 @@ static const QString kLight = "Light"_L1; static const QString kDark = "Dark"_L1; QQStyleKitStyle::QQStyleKitStyle(QObject *parent) - : QQStyleKitControls(parent) + : QQStyleKitStyleAndThemeBase(parent) , m_themeName(kSystem) { } @@ -62,6 +62,12 @@ void QQStyleKitStyle::setFallbackStyle(QQStyleKitStyle *fallbackStyle) m_fallbackStyle = fallbackStyle; emit fallbackStyleChanged(); + + if (fonts()) + fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() : nullptr); + + if (m_theme && m_theme->fonts()) + m_theme->fonts()->setFallbackFont(fonts()); } void QQStyleKitStyle::setLight(QQmlComponent *lightTheme) @@ -234,8 +240,14 @@ void QQStyleKitStyle::recreateTheme() m_theme->setParent(this); } + if (m_theme && m_theme->fonts()) + m_theme->fonts()->setFallbackFont(fonts()); if (this == current()) { m_theme->updateQuickTheme(); + if (m_theme->fonts()) + m_theme->fonts()->setFallbackFont(fonts()); + if (fonts()) + fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() : nullptr); QQStyleKitReader::resetAll(); } @@ -247,6 +259,38 @@ QQStyleKitStyle* QQStyleKitStyle::current() return QQStyleKit::qmlAttachedProperties()->style(); } +QFont QQStyleKitStyle::fontForReader(QQStyleKitReader *reader) const +{ + switch (reader->type()) { + case QQStyleKitReader::ControlType::Control: + return m_theme->fonts()->systemFont(); + case QQStyleKitReader::ControlType::AbstractButton: + case QQStyleKitReader::ControlType::Button: + case QQStyleKitReader::ControlType::FlatButton: { + return m_theme->fonts()->buttonFont(); + } + case QQStyleKitReader::ControlType::CheckBox: + return m_theme->fonts()->checkBoxFont(); + case QQStyleKitReader::ControlType::ComboBox: + return m_theme->fonts()->comboBoxFont(); + case QQStyleKitReader::ControlType::RadioButton: + return m_theme->fonts()->radioButtonFont(); + case QQStyleKitReader::ControlType::SpinBox: + return m_theme->fonts()->spinBoxFont(); + case QQStyleKitReader::ControlType::SwitchControl: + return m_theme->fonts()->switchControlFont(); + case QQStyleKitReader::ControlType::TextInput: + case QQStyleKitReader::ControlType::TextField: + return m_theme->fonts()->textFieldFont(); + case QQStyleKitReader::ControlType::TextArea: + return m_theme->fonts()->textAreaFont(); + case QQStyleKitReader::ControlType::ItemDelegate: + return m_theme->fonts()->itemViewFont(); + default: + return m_theme->fonts()->systemFont(); + } +} + bool QQStyleKitStyle::loaded() const { /* Before both the style and theme has completed loading |
