1
/****************************************************************************
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** GNU Lesser General Public License Usage
10
** This file may be used under the terms of the GNU Lesser General Public
11
** License version 2.1 as published by the Free Software Foundation and
12
** appearing in the file LICENSE.LGPL included in the packaging of this
13
** file. Please review the following information to ensure the GNU Lesser
14
** General Public License version 2.1 requirements will be met:
15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
** In addition, as a special exception, Nokia gives you certain additional
18
** rights. These rights are described in the Nokia Qt LGPL Exception
19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
** GNU General Public License Usage
22
** Alternatively, this file may be used under the terms of the GNU General
23
** Public License version 3.0 as published by the Free Software Foundation
24
** and appearing in the file LICENSE.GPL included in the packaging of this
25
** file. Please review the following information to ensure the GNU General
26
** Public License version 3.0 requirements will be met:
27
** http://www.gnu.org/copyleft/gpl.html.
30
** Alternatively, this file may be used in accordance with the terms and
31
** conditions contained in a signed written agreement between you and Nokia.
40
****************************************************************************/
44
#include <QtQml/qqmlengine.h>
45
#include <QtQml/qqmlcomponent.h>
46
#include <QtQuick/private/qquicksystempalette_p.h>
49
class tst_qquicksystempalette : public QObject
53
tst_qquicksystempalette();
57
void inactivePalette();
58
void disabledPalette();
59
void paletteChanged();
65
tst_qquicksystempalette::tst_qquicksystempalette()
69
void tst_qquicksystempalette::activePalette()
71
QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
72
QQmlComponent component(&engine);
73
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
74
QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create());
79
palette.setCurrentColorGroup(QPalette::Active);
80
QCOMPARE(palette.window().color(), object->window());
81
QCOMPARE(palette.windowText().color(), object->windowText());
82
QCOMPARE(palette.base().color(), object->base());
83
QCOMPARE(palette.text().color(), object->text());
84
QCOMPARE(palette.alternateBase().color(), object->alternateBase());
85
QCOMPARE(palette.button().color(), object->button());
86
QCOMPARE(palette.buttonText().color(), object->buttonText());
87
QCOMPARE(palette.light().color(), object->light());
88
QCOMPARE(palette.midlight().color(), object->midlight());
89
QCOMPARE(palette.dark().color(), object->dark());
90
QCOMPARE(palette.mid().color(), object->mid());
91
QCOMPARE(palette.shadow().color(), object->shadow());
92
QCOMPARE(palette.highlight().color(), object->highlight());
93
QCOMPARE(palette.highlightedText().color(), object->highlightedText());
98
void tst_qquicksystempalette::inactivePalette()
100
QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
101
QQmlComponent component(&engine);
102
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
103
QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create());
105
QVERIFY(object != 0);
106
QVERIFY(object->colorGroup() == QQuickSystemPalette::Inactive);
109
palette.setCurrentColorGroup(QPalette::Inactive);
110
QCOMPARE(palette.window().color(), object->window());
111
QCOMPARE(palette.windowText().color(), object->windowText());
112
QCOMPARE(palette.base().color(), object->base());
113
QCOMPARE(palette.text().color(), object->text());
114
QCOMPARE(palette.alternateBase().color(), object->alternateBase());
115
QCOMPARE(palette.button().color(), object->button());
116
QCOMPARE(palette.buttonText().color(), object->buttonText());
117
QCOMPARE(palette.light().color(), object->light());
118
QCOMPARE(palette.midlight().color(), object->midlight());
119
QCOMPARE(palette.dark().color(), object->dark());
120
QCOMPARE(palette.mid().color(), object->mid());
121
QCOMPARE(palette.shadow().color(), object->shadow());
122
QCOMPARE(palette.highlight().color(), object->highlight());
123
QCOMPARE(palette.highlightedText().color(), object->highlightedText());
128
void tst_qquicksystempalette::disabledPalette()
130
QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
131
QQmlComponent component(&engine);
132
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
133
QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create());
135
QVERIFY(object != 0);
136
QVERIFY(object->colorGroup() == QQuickSystemPalette::Disabled);
139
palette.setCurrentColorGroup(QPalette::Disabled);
140
QCOMPARE(palette.window().color(), object->window());
141
QCOMPARE(palette.windowText().color(), object->windowText());
142
QCOMPARE(palette.base().color(), object->base());
143
QCOMPARE(palette.text().color(), object->text());
144
QCOMPARE(palette.alternateBase().color(), object->alternateBase());
145
QCOMPARE(palette.button().color(), object->button());
146
QCOMPARE(palette.buttonText().color(), object->buttonText());
147
QCOMPARE(palette.light().color(), object->light());
148
QCOMPARE(palette.midlight().color(), object->midlight());
149
QCOMPARE(palette.dark().color(), object->dark());
150
QCOMPARE(palette.mid().color(), object->mid());
151
QCOMPARE(palette.shadow().color(), object->shadow());
152
QCOMPARE(palette.highlight().color(), object->highlight());
153
QCOMPARE(palette.highlightedText().color(), object->highlightedText());
158
void tst_qquicksystempalette::paletteChanged()
160
QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
161
QQmlComponent component(&engine);
162
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
163
QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create());
165
QVERIFY(object != 0);
168
p.setCurrentColorGroup(QPalette::Active);
169
p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
170
p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
171
p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
175
object->setColorGroup(QQuickSystemPalette::Active);
176
QTRY_COMPARE(QColor("red"), object->text());
177
QTRY_COMPARE(QColor("green"), object->buttonText());
178
QTRY_COMPARE(QColor("blue"), object->windowText());
183
QTEST_MAIN(tst_qquicksystempalette)
185
#include "tst_qquicksystempalette.moc"