aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/palette/tst_palette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/palette/tst_palette.cpp')
-rw-r--r--tests/auto/palette/tst_palette.cpp179
1 files changed, 61 insertions, 118 deletions
diff --git a/tests/auto/palette/tst_palette.cpp b/tests/auto/palette/tst_palette.cpp
index f74e358a..e91fd732 100644
--- a/tests/auto/palette/tst_palette.cpp
+++ b/tests/auto/palette/tst_palette.cpp
@@ -38,7 +38,6 @@
#include "../shared/visualtestutil.h"
#include <QtGui/qpalette.h>
-#include <QtGui/qpa/qplatformtheme.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
@@ -46,7 +45,7 @@
#include <QtQuickTemplates2/private/qquickcontrol_p.h>
#include <QtQuickTemplates2/private/qquickcontrol_p_p.h>
#include <QtQuickTemplates2/private/qquickpopup_p.h>
-#include <QtQuickControls2/private/qquickproxytheme_p.h>
+#include <QtQuickTemplates2/private/qquicktheme_p_p.h>
using namespace QQuickVisualTestUtil;
@@ -88,7 +87,7 @@ void tst_palette::palette_data()
QTest::addColumn<QString>("testFile");
QTest::addColumn<QPalette>("expectedPalette");
- QPalette defaultPalette = QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette);
+ QPalette defaultPalette = QQuickTheme::palette(QQuickTheme::System);
defaultPalette.setColor(QPalette::Base, QColor("#efefef"));
defaultPalette.setColor(QPalette::Text, QColor("#101010"));
@@ -172,7 +171,7 @@ void tst_palette::inheritance()
QObject *grandChild = window->property("grandChild").value<QObject *>();
QVERIFY(control && child && grandChild);
- QPalette defaultPalette = QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette);
+ QPalette defaultPalette = QQuickTheme::palette(QQuickTheme::System);
defaultPalette.setColor(QPalette::Base, QColor("#efefef"));
defaultPalette.setColor(QPalette::Text, QColor("#101010"));
@@ -217,148 +216,92 @@ void tst_palette::inheritance()
QCOMPARE(grandChild->property("palette").value<QPalette>(), windowPalette);
}
-class TestTheme : public QQuickProxyTheme
+class TestTheme : public QQuickTheme
{
public:
- TestTheme(QPlatformTheme *theme) : QQuickProxyTheme(theme)
- {
- std::fill(palettes, palettes + QPlatformTheme::NPalettes, static_cast<QPalette *>(0));
-
- QPalette palette = QPalette();
- palette.setColor(QPalette::Window, Qt::gray);
- palettes[QPlatformTheme::SystemPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::ToolTipBase, Qt::yellow);
- palettes[QPlatformTheme::ToolTipPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::ButtonText, Qt::blue);
- palettes[QPlatformTheme::ToolButtonPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::Button, Qt::red);
- palettes[QPlatformTheme::ButtonPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::Text, Qt::green);
- palettes[QPlatformTheme::CheckBoxPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::Text, Qt::blue);
- palettes[QPlatformTheme::RadioButtonPalette] = new QPalette(palette);
-
- // HeaderPalette unused
-
- palette.setColor(QPalette::Base, Qt::darkGray);
- palettes[QPlatformTheme::ComboBoxPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::Base, Qt::lightGray);
- palettes[QPlatformTheme::ItemViewPalette] = new QPalette(palette);
-
- // MessageBoxLabelPalette unused
-
- palette.setColor(QPalette::ButtonText, Qt::white);
- palettes[QPlatformTheme::TabBarPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::WindowText, Qt::darkGray);
- palettes[QPlatformTheme::LabelPalette] = new QPalette(palette);
+ static const int NPalettes = QQuickTheme::Tumbler + 1;
- palette.setColor(QPalette::Mid, Qt::gray);
- palettes[QPlatformTheme::GroupBoxPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::Shadow, Qt::darkYellow);
- palettes[QPlatformTheme::MenuPalette] = new QPalette(palette);
-
- // MenuBarPalette unused
-
- palette.setColor(QPalette::Base, Qt::cyan);
- palettes[QPlatformTheme::TextEditPalette] = new QPalette(palette);
-
- palette.setColor(QPalette::Base, Qt::magenta);
- palettes[QPlatformTheme::TextLineEditPalette] = new QPalette(palette);
-
- QGuiApplicationPrivate::platform_theme = this;
- }
-
- const QPalette *palette(Palette type = SystemPalette) const override
+ TestTheme()
{
- return palettes[type];
+ for (int i = 0; i < NPalettes; ++i)
+ setPalette(static_cast<Scope>(i), QPalette(QColor::fromRgb(i)));
}
-
-private:
- QPalette *palettes[QPlatformTheme::NPalettes];
};
-Q_DECLARE_METATYPE(QPlatformTheme::Palette)
+Q_DECLARE_METATYPE(QQuickTheme::Scope)
void tst_palette::defaultPalette_data()
{
QTest::addColumn<QString>("control");
- QTest::addColumn<QPlatformTheme::Palette>("paletteType");
-
- QTest::newRow("AbstractButton") << "AbstractButton" << QPlatformTheme::SystemPalette;
- QTest::newRow("ApplicationWindow") << "ApplicationWindow" << QPlatformTheme::SystemPalette;
- QTest::newRow("Button") << "Button" << QPlatformTheme::ButtonPalette;
- QTest::newRow("CheckBox") << "CheckBox" << QPlatformTheme::CheckBoxPalette;
- QTest::newRow("CheckDelegate") << "CheckDelegate" << QPlatformTheme::ItemViewPalette;
- QTest::newRow("ComboBox") << "ComboBox" << QPlatformTheme::ComboBoxPalette;
- QTest::newRow("Container") << "Container" << QPlatformTheme::SystemPalette;
- QTest::newRow("Control") << "Control" << QPlatformTheme::SystemPalette;
- QTest::newRow("Dial") << "Dial" << QPlatformTheme::SystemPalette;
- QTest::newRow("Dialog") << "Dialog" << QPlatformTheme::SystemPalette;
- QTest::newRow("DialogButtonBox") << "DialogButtonBox" << QPlatformTheme::SystemPalette;
- QTest::newRow("Drawer") << "Drawer" << QPlatformTheme::SystemPalette;
- QTest::newRow("Frame") << "Frame" << QPlatformTheme::SystemPalette;
- QTest::newRow("GroupBox") << "GroupBox" << QPlatformTheme::GroupBoxPalette;
- QTest::newRow("ItemDelegate") << "ItemDelegate" << QPlatformTheme::ItemViewPalette;
- QTest::newRow("Label") << "Label" << QPlatformTheme::LabelPalette;
- QTest::newRow("Menu") << "Menu" << QPlatformTheme::MenuPalette;
- QTest::newRow("MenuItem") << "MenuItem" << QPlatformTheme::MenuPalette;
- QTest::newRow("MenuSeparator") << "MenuSeparator" << QPlatformTheme::MenuPalette;
- QTest::newRow("Page") << "Page" << QPlatformTheme::SystemPalette;
- QTest::newRow("Pane") << "Pane" << QPlatformTheme::SystemPalette;
- QTest::newRow("Popup") << "Popup" << QPlatformTheme::SystemPalette;
- QTest::newRow("ProgressBar") << "ProgressBar" << QPlatformTheme::SystemPalette;
- QTest::newRow("RadioButton") << "RadioButton" << QPlatformTheme::RadioButtonPalette;
- QTest::newRow("RadioDelegate") << "RadioDelegate" << QPlatformTheme::ItemViewPalette;
- QTest::newRow("RangeSlider") << "RangeSlider" << QPlatformTheme::SystemPalette;
- QTest::newRow("RoundButton") << "RoundButton" << QPlatformTheme::ButtonPalette;
- QTest::newRow("ScrollBar") << "ScrollBar" << QPlatformTheme::SystemPalette;
- QTest::newRow("ScrollIndicator") << "ScrollIndicator" << QPlatformTheme::SystemPalette;
- QTest::newRow("Slider") << "Slider" << QPlatformTheme::SystemPalette;
- QTest::newRow("SpinBox") << "SpinBox" << QPlatformTheme::TextLineEditPalette;
- QTest::newRow("SwipeDelegate") << "SwipeDelegate" << QPlatformTheme::ItemViewPalette;
- QTest::newRow("Switch") << "Switch" << QPlatformTheme::CheckBoxPalette; // ### TODO: add QPlatformTheme::SwitchPalette
- QTest::newRow("SwitchDelegate") << "SwitchDelegate" << QPlatformTheme::ItemViewPalette;
- QTest::newRow("TabBar") << "TabBar" << QPlatformTheme::TabBarPalette;
- QTest::newRow("TabButton") << "TabButton" << QPlatformTheme::TabBarPalette;
- QTest::newRow("TextArea") << "TextArea" << QPlatformTheme::TextEditPalette;
- QTest::newRow("TextField") << "TextField" << QPlatformTheme::TextLineEditPalette;
- QTest::newRow("ToolBar") << "ToolBar" << QPlatformTheme::ToolButtonPalette;
- QTest::newRow("ToolButton") << "ToolButton" << QPlatformTheme::ToolButtonPalette;
- QTest::newRow("ToolSeparator") << "ToolSeparator" << QPlatformTheme::ToolButtonPalette;
- QTest::newRow("ToolTip") << "ToolTip" << QPlatformTheme::ToolTipPalette;
- QTest::newRow("Tumbler") << "Tumbler" << QPlatformTheme::ItemViewPalette;
+ QTest::addColumn<QQuickTheme::Scope>("scope");
+
+ QTest::newRow("AbstractButton") << "AbstractButton" << QQuickTheme::System;
+ QTest::newRow("ApplicationWindow") << "ApplicationWindow" << QQuickTheme::System;
+ QTest::newRow("Button") << "Button" << QQuickTheme::Button;
+ QTest::newRow("CheckBox") << "CheckBox" << QQuickTheme::CheckBox;
+ QTest::newRow("CheckDelegate") << "CheckDelegate" << QQuickTheme::ListView;
+ QTest::newRow("ComboBox") << "ComboBox" << QQuickTheme::ComboBox;
+ QTest::newRow("Container") << "Container" << QQuickTheme::System;
+ QTest::newRow("Control") << "Control" << QQuickTheme::System;
+ QTest::newRow("Dial") << "Dial" << QQuickTheme::System;
+ QTest::newRow("Dialog") << "Dialog" << QQuickTheme::System;
+ QTest::newRow("DialogButtonBox") << "DialogButtonBox" << QQuickTheme::System;
+ QTest::newRow("Drawer") << "Drawer" << QQuickTheme::System;
+ QTest::newRow("Frame") << "Frame" << QQuickTheme::System;
+ QTest::newRow("GroupBox") << "GroupBox" << QQuickTheme::GroupBox;
+ QTest::newRow("ItemDelegate") << "ItemDelegate" << QQuickTheme::ItemView;
+ QTest::newRow("Label") << "Label" << QQuickTheme::Label;
+ QTest::newRow("Menu") << "Menu" << QQuickTheme::Menu;
+ QTest::newRow("MenuItem") << "MenuItem" << QQuickTheme::Menu;
+ QTest::newRow("MenuSeparator") << "MenuSeparator" << QQuickTheme::Menu;
+ QTest::newRow("Page") << "Page" << QQuickTheme::System;
+ QTest::newRow("Pane") << "Pane" << QQuickTheme::System;
+ QTest::newRow("Popup") << "Popup" << QQuickTheme::System;
+ QTest::newRow("ProgressBar") << "ProgressBar" << QQuickTheme::System;
+ QTest::newRow("RadioButton") << "RadioButton" << QQuickTheme::RadioButton;
+ QTest::newRow("RadioDelegate") << "RadioDelegate" << QQuickTheme::ListView;
+ QTest::newRow("RangeSlider") << "RangeSlider" << QQuickTheme::System;
+ QTest::newRow("RoundButton") << "RoundButton" << QQuickTheme::Button;
+ QTest::newRow("ScrollBar") << "ScrollBar" << QQuickTheme::System;
+ QTest::newRow("ScrollIndicator") << "ScrollIndicator" << QQuickTheme::System;
+ QTest::newRow("Slider") << "Slider" << QQuickTheme::System;
+ QTest::newRow("SpinBox") << "SpinBox" << QQuickTheme::SpinBox;
+ QTest::newRow("SwipeDelegate") << "SwipeDelegate" << QQuickTheme::ListView;
+ QTest::newRow("Switch") << "Switch" << QQuickTheme::Switch;
+ QTest::newRow("SwitchDelegate") << "SwitchDelegate" << QQuickTheme::ListView;
+ QTest::newRow("TabBar") << "TabBar" << QQuickTheme::TabBar;
+ QTest::newRow("TabButton") << "TabButton" << QQuickTheme::TabBar;
+ QTest::newRow("TextArea") << "TextArea" << QQuickTheme::TextArea;
+ QTest::newRow("TextField") << "TextField" << QQuickTheme::TextField;
+ QTest::newRow("ToolBar") << "ToolBar" << QQuickTheme::ToolBar;
+ QTest::newRow("ToolButton") << "ToolButton" << QQuickTheme::ToolBar;
+ QTest::newRow("ToolSeparator") << "ToolSeparator" << QQuickTheme::ToolBar;
+ QTest::newRow("ToolTip") << "ToolTip" << QQuickTheme::ToolTip;
+ QTest::newRow("Tumbler") << "Tumbler" << QQuickTheme::Tumbler;
}
void tst_palette::defaultPalette()
{
QFETCH(QString, control);
- QFETCH(QPlatformTheme::Palette, paletteType);
-
- TestTheme theme(QGuiApplicationPrivate::platform_theme);
+ QFETCH(QQuickTheme::Scope, scope);
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData(QString("import QtQuick.Controls 2.3; %1 { }").arg(control).toUtf8(), QUrl());
+ // The call to setData() above causes QQuickDefaultTheme to be set as the current theme,
+ // so we must make sure we only set our theme afterwards.
+ QQuickThemePrivate::instance.reset(new TestTheme);
+
QScopedPointer<QObject> object(component.create());
QVERIFY2(!object.isNull(), qPrintable(component.errorString()));
QVariant var = object->property("palette");
QVERIFY(var.isValid());
- const QPalette *expectedPalette = theme.palette(paletteType);
- QVERIFY(expectedPalette);
-
+ QPalette expectedPalette = QQuickTheme::palette(scope);
QPalette actualPalette = var.value<QPalette>();
- QCOMPARE(actualPalette, *expectedPalette);
+ QCOMPARE(actualPalette, expectedPalette);
}
void tst_palette::listView_data()