1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qtest.h>
43 #include <QDebug>
44 #include <QtDeclarative/qdeclarativeengine.h>
45 #include <QtDeclarative/qdeclarativecomponent.h>
46 #include <private/qdeclarativesystempalette_p.h>
47 #include <qpalette.h>
48 #include "../../../shared/util.h"
49 
50 #ifdef Q_OS_SYMBIAN
51 // In Symbian OS test data is located in applications private dir
52 #define SRCDIR "."
53 #endif
54 
55 class tst_qdeclarativesystempalette : public QObject
56 
57 {
58     Q_OBJECT
59 public:
60     tst_qdeclarativesystempalette();
61 
62 private slots:
63     void activePalette();
64     void inactivePalette();
65     void disabledPalette();
66     void paletteChanged();
67 
68 private:
69     QDeclarativeEngine engine;
70 };
71 
tst_qdeclarativesystempalette()72 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
73 {
74 }
75 
activePalette()76 void tst_qdeclarativesystempalette::activePalette()
77 {
78     QString componentStr = "import QtQuick 1.0\nSystemPalette { }";
79     QDeclarativeComponent component(&engine);
80     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
81     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
82 
83     QVERIFY(object != 0);
84 
85     QPalette palette;
86     palette.setCurrentColorGroup(QPalette::Active);
87     QCOMPARE(palette.window().color(), object->window());
88     QCOMPARE(palette.windowText().color(), object->windowText());
89     QCOMPARE(palette.base().color(), object->base());
90     QCOMPARE(palette.text().color(), object->text());
91     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
92     QCOMPARE(palette.button().color(), object->button());
93     QCOMPARE(palette.buttonText().color(), object->buttonText());
94     QCOMPARE(palette.light().color(), object->light());
95     QCOMPARE(palette.midlight().color(), object->midlight());
96     QCOMPARE(palette.dark().color(), object->dark());
97     QCOMPARE(palette.mid().color(), object->mid());
98     QCOMPARE(palette.shadow().color(), object->shadow());
99     QCOMPARE(palette.highlight().color(), object->highlight());
100     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
101 
102     delete object;
103 }
104 
inactivePalette()105 void tst_qdeclarativesystempalette::inactivePalette()
106 {
107     QString componentStr = "import QtQuick 1.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
108     QDeclarativeComponent component(&engine);
109     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
110     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
111 
112     QVERIFY(object != 0);
113     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Inactive);
114 
115     QPalette palette;
116     palette.setCurrentColorGroup(QPalette::Inactive);
117     QCOMPARE(palette.window().color(), object->window());
118     QCOMPARE(palette.windowText().color(), object->windowText());
119     QCOMPARE(palette.base().color(), object->base());
120     QCOMPARE(palette.text().color(), object->text());
121     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
122     QCOMPARE(palette.button().color(), object->button());
123     QCOMPARE(palette.buttonText().color(), object->buttonText());
124     QCOMPARE(palette.light().color(), object->light());
125     QCOMPARE(palette.midlight().color(), object->midlight());
126     QCOMPARE(palette.dark().color(), object->dark());
127     QCOMPARE(palette.mid().color(), object->mid());
128     QCOMPARE(palette.shadow().color(), object->shadow());
129     QCOMPARE(palette.highlight().color(), object->highlight());
130     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
131 
132     delete object;
133 }
134 
disabledPalette()135 void tst_qdeclarativesystempalette::disabledPalette()
136 {
137     QString componentStr = "import QtQuick 1.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
138     QDeclarativeComponent component(&engine);
139     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
140     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
141 
142     QVERIFY(object != 0);
143     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Disabled);
144 
145     QPalette palette;
146     palette.setCurrentColorGroup(QPalette::Disabled);
147     QCOMPARE(palette.window().color(), object->window());
148     QCOMPARE(palette.windowText().color(), object->windowText());
149     QCOMPARE(palette.base().color(), object->base());
150     QCOMPARE(palette.text().color(), object->text());
151     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
152     QCOMPARE(palette.button().color(), object->button());
153     QCOMPARE(palette.buttonText().color(), object->buttonText());
154     QCOMPARE(palette.light().color(), object->light());
155     QCOMPARE(palette.midlight().color(), object->midlight());
156     QCOMPARE(palette.dark().color(), object->dark());
157     QCOMPARE(palette.mid().color(), object->mid());
158     QCOMPARE(palette.shadow().color(), object->shadow());
159     QCOMPARE(palette.highlight().color(), object->highlight());
160     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
161 
162     delete object;
163 }
164 
paletteChanged()165 void tst_qdeclarativesystempalette::paletteChanged()
166 {
167     QString componentStr = "import QtQuick 1.0\nSystemPalette { }";
168     QDeclarativeComponent component(&engine);
169     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
170     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
171 
172     QVERIFY(object != 0);
173 
174     QPalette p;
175     p.setCurrentColorGroup(QPalette::Active);
176     p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
177     p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
178     p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
179 
180     qApp->setPalette(p);
181 
182     object->setColorGroup(QDeclarativeSystemPalette::Active);
183     QTRY_COMPARE(QColor("red"), object->text());
184     QTRY_COMPARE(QColor("green"), object->buttonText());
185     QTRY_COMPARE(QColor("blue"), object->windowText());
186 
187     delete object;
188 }
189 
190 QTEST_MAIN(tst_qdeclarativesystempalette)
191 
192 #include "tst_qdeclarativesystempalette.moc"
193