1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QtDeclarative/qdeclarativeengine.h>
45 #include <QtDeclarative/qdeclarativecomponent.h>
46 #include <QtDeclarative/private/qdeclarativesystempalette_p.h>
48 #include "../../../shared/util.h"
50 class tst_qdeclarativesystempalette : public QObject
54 tst_qdeclarativesystempalette();
58 void inactivePalette();
59 void disabledPalette();
60 void paletteChanged();
63 QDeclarativeEngine engine;
66 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
70 void tst_qdeclarativesystempalette::activePalette()
72 QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
73 QDeclarativeComponent component(&engine);
74 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
75 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
80 palette.setCurrentColorGroup(QPalette::Active);
81 QCOMPARE(palette.window().color(), object->window());
82 QCOMPARE(palette.windowText().color(), object->windowText());
83 QCOMPARE(palette.base().color(), object->base());
84 QCOMPARE(palette.text().color(), object->text());
85 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
86 QCOMPARE(palette.button().color(), object->button());
87 QCOMPARE(palette.buttonText().color(), object->buttonText());
88 QCOMPARE(palette.light().color(), object->light());
89 QCOMPARE(palette.midlight().color(), object->midlight());
90 QCOMPARE(palette.dark().color(), object->dark());
91 QCOMPARE(palette.mid().color(), object->mid());
92 QCOMPARE(palette.shadow().color(), object->shadow());
93 QCOMPARE(palette.highlight().color(), object->highlight());
94 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
99 void tst_qdeclarativesystempalette::inactivePalette()
101 QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
102 QDeclarativeComponent component(&engine);
103 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
104 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
106 QVERIFY(object != 0);
107 QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Inactive);
110 palette.setCurrentColorGroup(QPalette::Inactive);
111 QCOMPARE(palette.window().color(), object->window());
112 QCOMPARE(palette.windowText().color(), object->windowText());
113 QCOMPARE(palette.base().color(), object->base());
114 QCOMPARE(palette.text().color(), object->text());
115 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
116 QCOMPARE(palette.button().color(), object->button());
117 QCOMPARE(palette.buttonText().color(), object->buttonText());
118 QCOMPARE(palette.light().color(), object->light());
119 QCOMPARE(palette.midlight().color(), object->midlight());
120 QCOMPARE(palette.dark().color(), object->dark());
121 QCOMPARE(palette.mid().color(), object->mid());
122 QCOMPARE(palette.shadow().color(), object->shadow());
123 QCOMPARE(palette.highlight().color(), object->highlight());
124 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
129 void tst_qdeclarativesystempalette::disabledPalette()
131 QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
132 QDeclarativeComponent component(&engine);
133 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
134 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
136 QVERIFY(object != 0);
137 QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Disabled);
140 palette.setCurrentColorGroup(QPalette::Disabled);
141 QCOMPARE(palette.window().color(), object->window());
142 QCOMPARE(palette.windowText().color(), object->windowText());
143 QCOMPARE(palette.base().color(), object->base());
144 QCOMPARE(palette.text().color(), object->text());
145 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
146 QCOMPARE(palette.button().color(), object->button());
147 QCOMPARE(palette.buttonText().color(), object->buttonText());
148 QCOMPARE(palette.light().color(), object->light());
149 QCOMPARE(palette.midlight().color(), object->midlight());
150 QCOMPARE(palette.dark().color(), object->dark());
151 QCOMPARE(palette.mid().color(), object->mid());
152 QCOMPARE(palette.shadow().color(), object->shadow());
153 QCOMPARE(palette.highlight().color(), object->highlight());
154 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
159 void tst_qdeclarativesystempalette::paletteChanged()
161 QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
162 QDeclarativeComponent component(&engine);
163 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
164 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
166 QVERIFY(object != 0);
169 p.setCurrentColorGroup(QPalette::Active);
170 p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
171 p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
172 p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
176 object->setColorGroup(QDeclarativeSystemPalette::Active);
177 QTRY_COMPARE(QColor("red"), object->text());
178 QTRY_COMPARE(QColor("green"), object->buttonText());
179 QTRY_COMPARE(QColor("blue"), object->windowText());
184 QTEST_MAIN(tst_qdeclarativesystempalette)
186 #include "tst_qdeclarativesystempalette.moc"