1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <qtest.h>
30#include <QDebug>
31#include <QtQml/qqmlengine.h>
32#include <QtQml/qqmlcomponent.h>
33#include <QtQuick/private/qquicksystempalette_p.h>
34#include <qpalette.h>
35
36class tst_qquicksystempalette : public QObject
37{
38 Q_OBJECT
39public:
40 tst_qquicksystempalette();
41
42private slots:
43 void activePalette();
44 void inactivePalette();
45 void disabledPalette();
46#ifndef QT_NO_WIDGETS
47 void paletteChanged();
48#endif
49
50private:
51 QQmlEngine engine;
52};
53
54tst_qquicksystempalette::tst_qquicksystempalette()
55{
56}
57
58void tst_qquicksystempalette::activePalette()
59{
60 QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
61 QQmlComponent component(&engine);
62 component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: ""));
63 QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(object: component.create());
64
65 QVERIFY(object != nullptr);
66
67 QPalette palette;
68 palette.setCurrentColorGroup(QPalette::Active);
69 QCOMPARE(palette.window().color(), object->window());
70 QCOMPARE(palette.windowText().color(), object->windowText());
71 QCOMPARE(palette.base().color(), object->base());
72 QCOMPARE(palette.text().color(), object->text());
73 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
74 QCOMPARE(palette.button().color(), object->button());
75 QCOMPARE(palette.buttonText().color(), object->buttonText());
76 QCOMPARE(palette.light().color(), object->light());
77 QCOMPARE(palette.midlight().color(), object->midlight());
78 QCOMPARE(palette.dark().color(), object->dark());
79 QCOMPARE(palette.mid().color(), object->mid());
80 QCOMPARE(palette.shadow().color(), object->shadow());
81 QCOMPARE(palette.highlight().color(), object->highlight());
82 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
83
84 delete object;
85}
86
87void tst_qquicksystempalette::inactivePalette()
88{
89 QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
90 QQmlComponent component(&engine);
91 component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: ""));
92 QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(object: component.create());
93
94 QVERIFY(object != nullptr);
95 QCOMPARE(object->colorGroup(), QQuickSystemPalette::Inactive);
96
97 QPalette palette;
98 palette.setCurrentColorGroup(QPalette::Inactive);
99 QCOMPARE(palette.window().color(), object->window());
100 QCOMPARE(palette.windowText().color(), object->windowText());
101 QCOMPARE(palette.base().color(), object->base());
102 QCOMPARE(palette.text().color(), object->text());
103 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
104 QCOMPARE(palette.button().color(), object->button());
105 QCOMPARE(palette.buttonText().color(), object->buttonText());
106 QCOMPARE(palette.light().color(), object->light());
107 QCOMPARE(palette.midlight().color(), object->midlight());
108 QCOMPARE(palette.dark().color(), object->dark());
109 QCOMPARE(palette.mid().color(), object->mid());
110 QCOMPARE(palette.shadow().color(), object->shadow());
111 QCOMPARE(palette.highlight().color(), object->highlight());
112 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
113
114 delete object;
115}
116
117void tst_qquicksystempalette::disabledPalette()
118{
119 QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
120 QQmlComponent component(&engine);
121 component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: ""));
122 QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(object: component.create());
123
124 QVERIFY(object != nullptr);
125 QCOMPARE(object->colorGroup(), QQuickSystemPalette::Disabled);
126
127 QPalette palette;
128 palette.setCurrentColorGroup(QPalette::Disabled);
129 QCOMPARE(palette.window().color(), object->window());
130 QCOMPARE(palette.windowText().color(), object->windowText());
131 QCOMPARE(palette.base().color(), object->base());
132 QCOMPARE(palette.text().color(), object->text());
133 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
134 QCOMPARE(palette.button().color(), object->button());
135 QCOMPARE(palette.buttonText().color(), object->buttonText());
136 QCOMPARE(palette.light().color(), object->light());
137 QCOMPARE(palette.midlight().color(), object->midlight());
138 QCOMPARE(palette.dark().color(), object->dark());
139 QCOMPARE(palette.mid().color(), object->mid());
140 QCOMPARE(palette.shadow().color(), object->shadow());
141 QCOMPARE(palette.highlight().color(), object->highlight());
142 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
143
144 delete object;
145}
146
147#ifndef QT_NO_WIDGETS
148void tst_qquicksystempalette::paletteChanged()
149{
150 QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
151 QQmlComponent component(&engine);
152 component.setData(componentStr.toLatin1(), baseUrl: QUrl::fromLocalFile(localfile: ""));
153 QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(object: component.create());
154
155 QVERIFY(object != nullptr);
156
157 QPalette p;
158 p.setCurrentColorGroup(QPalette::Active);
159 p.setColor(acg: QPalette::Active, acr: QPalette::Text, acolor: QColor("red"));
160 p.setColor(acg: QPalette::Active, acr: QPalette::ButtonText, acolor: QColor("green"));
161 p.setColor(acg: QPalette::Active, acr: QPalette::WindowText, acolor: QColor("blue"));
162
163 qApp->setPalette(p);
164
165 object->setColorGroup(QQuickSystemPalette::Active);
166 QTRY_COMPARE(QColor("red"), object->text());
167 QTRY_COMPARE(QColor("green"), object->buttonText());
168 QTRY_COMPARE(QColor("blue"), object->windowText());
169
170 delete object;
171}
172#endif
173
174QTEST_MAIN(tst_qquicksystempalette)
175
176#include "tst_qquicksystempalette.moc"
177

source code of qtdeclarative/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp