diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-03-14 13:04:30 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-03-15 07:50:30 +0000 |
commit | 63773fd5363e8954e298e775bba7478d612134ef (patch) | |
tree | 6b85eecb285a010f6ba488cc631cd8107c6cdb76 | |
parent | 24750ce0624e8b6ec66d07d7d00877c4a928dfc3 (diff) |
QQuickTheme: add missing fonts and palettes
SpinBox, Switch, and Tumbler were previously not available in
QPlatformTheme, but now we have our own enums so we can add them.
Task-number: QTBUG-67062
Change-Id: Ie99a49b464fbbd25051181b75d721f537b8e3a68
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/controls/material/qquickmaterialtheme.cpp | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickspinbox.cpp | 4 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswitch.cpp | 8 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswitch_p.h | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktheme.cpp | 32 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktheme_p.h | 6 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktumbler.cpp | 4 | ||||
-rw-r--r-- | tests/auto/font/tst_font.cpp | 6 | ||||
-rw-r--r-- | tests/auto/palette/tst_palette.cpp | 6 |
9 files changed, 54 insertions, 14 deletions
diff --git a/src/imports/controls/material/qquickmaterialtheme.cpp b/src/imports/controls/material/qquickmaterialtheme.cpp index 471f5143..6b950844 100644 --- a/src/imports/controls/material/qquickmaterialtheme.cpp +++ b/src/imports/controls/material/qquickmaterialtheme.cpp @@ -116,6 +116,7 @@ const QFont *QQuickMaterialTheme::font(Font type) const case ComboMenuItemFont: return &menuItemFont; case EditorFont: + case SpinBoxFont: return &editorFont; default: return &systemFont; diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 8aa8ed5f..93cb3261 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -1024,12 +1024,12 @@ void QQuickSpinBox::localeChange(const QLocale &newLocale, const QLocale &oldLoc QFont QQuickSpinBox::defaultFont() const { - return QQuickTheme::themeFont(QQuickTheme::EditorFont); + return QQuickTheme::themeFont(QQuickTheme::SpinBoxFont); } QPalette QQuickSpinBox::defaultPalette() const { - return QQuickTheme::themePalette(QQuickTheme::TextLineEditPalette); + return QQuickTheme::themePalette(QQuickTheme::SpinBoxPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickswitch.cpp b/src/quicktemplates2/qquickswitch.cpp index db71e423..5e3ccbc9 100644 --- a/src/quicktemplates2/qquickswitch.cpp +++ b/src/quicktemplates2/qquickswitch.cpp @@ -231,10 +231,14 @@ void QQuickSwitch::buttonChange(ButtonChange change) QQuickAbstractButton::buttonChange(change); } +QFont QQuickSwitch::defaultFont() const +{ + return QQuickTheme::themeFont(QQuickTheme::SwitchFont); +} + QPalette QQuickSwitch::defaultPalette() const { - // ### TODO: add QPlatformTheme::SwitchPalette - return QQuickTheme::themePalette(QQuickTheme::CheckBoxPalette); + return QQuickTheme::themePalette(QQuickTheme::SwitchPalette); } QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickswitch_p.h b/src/quicktemplates2/qquickswitch_p.h index 0faaf114..ddc32395 100644 --- a/src/quicktemplates2/qquickswitch_p.h +++ b/src/quicktemplates2/qquickswitch_p.h @@ -83,6 +83,7 @@ protected: void nextCheckState() override; void buttonChange(ButtonChange change) override; + QFont defaultFont() const override; QPalette defaultPalette() const override; private: diff --git a/src/quicktemplates2/qquicktheme.cpp b/src/quicktemplates2/qquicktheme.cpp index 02389ed0..777480b2 100644 --- a/src/quicktemplates2/qquicktheme.cpp +++ b/src/quicktemplates2/qquicktheme.cpp @@ -44,6 +44,34 @@ QT_BEGIN_NAMESPACE QScopedPointer<QQuickTheme> QQuickThemePrivate::current; +static QPlatformTheme::Font platformFont(QQuickTheme::Font type) +{ + switch (type) { + case QQuickTheme::SpinBoxFont: + return QPlatformTheme::EditorFont; + case QQuickTheme::SwitchFont: + return QPlatformTheme::CheckBoxFont; + case QQuickTheme::TumblerFont: + return QPlatformTheme::ItemViewFont; + default: + return static_cast<QPlatformTheme::Font>(type); + } +} + +static QPlatformTheme::Palette platformPalette(QQuickTheme::Palette type) +{ + switch (type) { + case QQuickTheme::SpinBoxPalette: + return QPlatformTheme::TextLineEditPalette; + case QQuickTheme::SwitchPalette: + return QPlatformTheme::CheckBoxPalette; + case QQuickTheme::TumblerPalette: + return QPlatformTheme::ItemViewPalette; + default: + return static_cast<QPlatformTheme::Palette>(type); + } +} + QQuickTheme::QQuickTheme() : d_ptr(new QQuickThemePrivate) { @@ -69,7 +97,7 @@ QFont QQuickTheme::themeFont(Font type) if (QQuickTheme *theme = current()) font = theme->font(type); else if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) - font = theme->font(static_cast<QPlatformTheme::Font>(type)); + font = theme->font(platformFont(type)); if (font) { QFont f = *font; @@ -87,7 +115,7 @@ QPalette QQuickTheme::themePalette(Palette type) if (QQuickTheme *theme = current()) palette = theme->palette(type); else if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) - palette = theme->palette(static_cast<QPlatformTheme::Palette>(type)); + palette = theme->palette(platformPalette(type)); if (palette) { QPalette f = *palette; diff --git a/src/quicktemplates2/qquicktheme_p.h b/src/quicktemplates2/qquicktheme_p.h index f4efd359..6d37039e 100644 --- a/src/quicktemplates2/qquicktheme_p.h +++ b/src/quicktemplates2/qquicktheme_p.h @@ -94,6 +94,9 @@ public: GroupBoxTitleFont, TabButtonFont, EditorFont, + SwitchFont, + SpinBoxFont, + TumblerFont, NFonts }; @@ -116,6 +119,9 @@ public: MenuBarPalette, TextEditPalette, TextLineEditPalette, + SpinBoxPalette, + SwitchPalette, + TumblerPalette, NPalettes }; diff --git a/src/quicktemplates2/qquicktumbler.cpp b/src/quicktemplates2/qquicktumbler.cpp index fa3a5ce4..f2797c29 100644 --- a/src/quicktemplates2/qquicktumbler.cpp +++ b/src/quicktemplates2/qquicktumbler.cpp @@ -830,12 +830,12 @@ void QQuickTumbler::updatePolish() QFont QQuickTumbler::defaultFont() const { - return QQuickTheme::themeFont(QQuickTheme::ItemViewFont); + return QQuickTheme::themeFont(QQuickTheme::TumblerFont); } QPalette QQuickTumbler::defaultPalette() const { - return QQuickTheme::themePalette(QQuickTheme::ItemViewPalette); + return QQuickTheme::themePalette(QQuickTheme::TumblerPalette); } QQuickTumblerAttachedPrivate::QQuickTumblerAttachedPrivate() diff --git a/tests/auto/font/tst_font.cpp b/tests/auto/font/tst_font.cpp index 65dd4971..5b69e298 100644 --- a/tests/auto/font/tst_font.cpp +++ b/tests/auto/font/tst_font.cpp @@ -277,9 +277,9 @@ void tst_font::defaultFont_data() QTest::newRow("ScrollBar") << "ScrollBar" << QQuickTheme::SystemFont; QTest::newRow("ScrollIndicator") << "ScrollIndicator" << QQuickTheme::SystemFont; QTest::newRow("Slider") << "Slider" << QQuickTheme::SystemFont; - QTest::newRow("SpinBox") << "SpinBox" << QQuickTheme::EditorFont; + QTest::newRow("SpinBox") << "SpinBox" << QQuickTheme::SpinBoxFont; QTest::newRow("SwipeDelegate") << "SwipeDelegate" << QQuickTheme::ListViewFont; - QTest::newRow("Switch") << "Switch" << QQuickTheme::SystemFont; // ### TODO: add QQuickTheme::SwitchFont + QTest::newRow("Switch") << "Switch" << QQuickTheme::SwitchFont; QTest::newRow("SwitchDelegate") << "SwitchDelegate" << QQuickTheme::ListViewFont; QTest::newRow("TabBar") << "TabBar" << QQuickTheme::SystemFont; QTest::newRow("TabButton") << "TabButton" << QQuickTheme::TabButtonFont; @@ -289,7 +289,7 @@ void tst_font::defaultFont_data() QTest::newRow("ToolButton") << "ToolButton" << QQuickTheme::ToolButtonFont; QTest::newRow("ToolSeparator") << "ToolSeparator" << QQuickTheme::SystemFont; QTest::newRow("ToolTip") << "ToolTip" << QQuickTheme::TipLabelFont; - QTest::newRow("Tumbler") << "Tumbler" << QQuickTheme::ItemViewFont; + QTest::newRow("Tumbler") << "Tumbler" << QQuickTheme::TumblerFont; } void tst_font::defaultFont() diff --git a/tests/auto/palette/tst_palette.cpp b/tests/auto/palette/tst_palette.cpp index 3c077dbc..ee617e2c 100644 --- a/tests/auto/palette/tst_palette.cpp +++ b/tests/auto/palette/tst_palette.cpp @@ -273,9 +273,9 @@ void tst_palette::defaultPalette_data() QTest::newRow("ScrollBar") << "ScrollBar" << QQuickTheme::SystemPalette; QTest::newRow("ScrollIndicator") << "ScrollIndicator" << QQuickTheme::SystemPalette; QTest::newRow("Slider") << "Slider" << QQuickTheme::SystemPalette; - QTest::newRow("SpinBox") << "SpinBox" << QQuickTheme::TextLineEditPalette; + QTest::newRow("SpinBox") << "SpinBox" << QQuickTheme::SpinBoxPalette; QTest::newRow("SwipeDelegate") << "SwipeDelegate" << QQuickTheme::ItemViewPalette; - QTest::newRow("Switch") << "Switch" << QQuickTheme::CheckBoxPalette; // ### TODO: add QQuickTheme::SwitchPalette + QTest::newRow("Switch") << "Switch" << QQuickTheme::SwitchPalette; QTest::newRow("SwitchDelegate") << "SwitchDelegate" << QQuickTheme::ItemViewPalette; QTest::newRow("TabBar") << "TabBar" << QQuickTheme::TabBarPalette; QTest::newRow("TabButton") << "TabButton" << QQuickTheme::TabBarPalette; @@ -285,7 +285,7 @@ void tst_palette::defaultPalette_data() QTest::newRow("ToolButton") << "ToolButton" << QQuickTheme::ToolButtonPalette; QTest::newRow("ToolSeparator") << "ToolSeparator" << QQuickTheme::ToolButtonPalette; QTest::newRow("ToolTip") << "ToolTip" << QQuickTheme::ToolTipPalette; - QTest::newRow("Tumbler") << "Tumbler" << QQuickTheme::ItemViewPalette; + QTest::newRow("Tumbler") << "Tumbler" << QQuickTheme::TumblerPalette; } void tst_palette::defaultPalette() |