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 Qt Data Visualization module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
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 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <QtTest/QtTest> |
31 | |
32 | #include <QtDataVisualization/Q3DTheme> |
33 | |
34 | using namespace QtDataVisualization; |
35 | |
36 | class tst_theme: public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | private slots: |
41 | void initTestCase(); |
42 | void cleanupTestCase(); |
43 | void init(); |
44 | void cleanup(); |
45 | |
46 | void construct(); |
47 | |
48 | void initialProperties(); |
49 | void initializeProperties(); |
50 | void invalidProperties(); |
51 | |
52 | private: |
53 | Q3DTheme *m_theme; |
54 | }; |
55 | |
56 | void tst_theme::initTestCase() |
57 | { |
58 | } |
59 | |
60 | void tst_theme::cleanupTestCase() |
61 | { |
62 | } |
63 | |
64 | void tst_theme::init() |
65 | { |
66 | m_theme = new Q3DTheme(); |
67 | } |
68 | |
69 | void tst_theme::cleanup() |
70 | { |
71 | delete m_theme; |
72 | } |
73 | |
74 | void tst_theme::construct() |
75 | { |
76 | Q3DTheme *theme = new Q3DTheme(); |
77 | QVERIFY(theme); |
78 | delete theme; |
79 | |
80 | theme = new Q3DTheme(Q3DTheme::ThemeEbony); |
81 | QVERIFY(theme); |
82 | QCOMPARE(theme->ambientLightStrength(), 0.5f); |
83 | QCOMPARE(theme->backgroundColor(), QColor(Qt::black)); |
84 | QCOMPARE(theme->isBackgroundEnabled(), true); |
85 | QCOMPARE(theme->baseColors().length(), 5); |
86 | QCOMPARE(theme->baseColors().at(0), QColor(Qt::white)); |
87 | QCOMPARE(theme->baseColors().at(4), QColor(QRgb(0x6b6b6b))); |
88 | QCOMPARE(theme->baseGradients().length(), 5); |
89 | QCOMPARE(theme->baseGradients().at(0).stops().at(1).second, QColor(Qt::white)); |
90 | QCOMPARE(theme->baseGradients().at(4).stops().at(1).second, QColor(QRgb(0x6b6b6b))); |
91 | QCOMPARE(theme->colorStyle(), Q3DTheme::ColorStyleUniform); |
92 | QCOMPARE(theme->font(), QFont("Arial" )); |
93 | QCOMPARE(theme->isGridEnabled(), true); |
94 | QCOMPARE(theme->gridLineColor(), QColor(QRgb(0x35322f))); |
95 | QCOMPARE(theme->highlightLightStrength(), 5.0f); |
96 | QCOMPARE(theme->labelBackgroundColor(), QColor(0x00, 0x00, 0x00, 0xcd)); |
97 | QCOMPARE(theme->isLabelBackgroundEnabled(), true); |
98 | QCOMPARE(theme->isLabelBorderEnabled(), false); |
99 | QCOMPARE(theme->labelTextColor(), QColor(QRgb(0xaeadac))); |
100 | QCOMPARE(theme->lightColor(), QColor(Qt::white)); |
101 | QCOMPARE(theme->lightStrength(), 5.0f); |
102 | QCOMPARE(theme->multiHighlightColor(), QColor(QRgb(0xd72222))); |
103 | QCOMPARE(theme->multiHighlightGradient().stops().at(1).second, QColor(QRgb(0xd72222))); |
104 | QCOMPARE(theme->singleHighlightColor(), QColor(QRgb(0xf5dc0d))); |
105 | QCOMPARE(theme->singleHighlightGradient().stops().at(1).second, QColor(QRgb(0xf5dc0d))); |
106 | QCOMPARE(theme->type(), Q3DTheme::ThemeEbony); |
107 | QCOMPARE(theme->windowColor(), QColor(Qt::black)); |
108 | delete theme; |
109 | } |
110 | |
111 | void tst_theme::initialProperties() |
112 | { |
113 | QVERIFY(m_theme); |
114 | |
115 | QCOMPARE(m_theme->ambientLightStrength(), 0.25f); |
116 | QCOMPARE(m_theme->backgroundColor(), QColor(Qt::black)); |
117 | QCOMPARE(m_theme->isBackgroundEnabled(), true); |
118 | QCOMPARE(m_theme->baseColors().length(), 1); |
119 | QCOMPARE(m_theme->baseColors().at(0), QColor(Qt::black)); |
120 | QCOMPARE(m_theme->baseGradients().length(), 1); |
121 | QCOMPARE(m_theme->baseGradients().at(0).stops().at(0).second, QColor(Qt::black)); |
122 | QCOMPARE(m_theme->baseGradients().at(0).stops().at(1).second, QColor(Qt::white)); |
123 | QCOMPARE(m_theme->colorStyle(), Q3DTheme::ColorStyleUniform); |
124 | QCOMPARE(m_theme->font(), QFont()); |
125 | QCOMPARE(m_theme->isGridEnabled(), true); |
126 | QCOMPARE(m_theme->gridLineColor(), QColor(Qt::white)); |
127 | QCOMPARE(m_theme->highlightLightStrength(), 7.5f); |
128 | QCOMPARE(m_theme->labelBackgroundColor(), QColor(Qt::gray)); |
129 | QCOMPARE(m_theme->isLabelBackgroundEnabled(), true); |
130 | QCOMPARE(m_theme->isLabelBorderEnabled(), true); |
131 | QCOMPARE(m_theme->labelTextColor(), QColor(Qt::white)); |
132 | QCOMPARE(m_theme->lightColor(), QColor(Qt::white)); |
133 | QCOMPARE(m_theme->lightStrength(), 5.0f); |
134 | QCOMPARE(m_theme->multiHighlightColor(), QColor(Qt::blue)); |
135 | QCOMPARE(m_theme->multiHighlightGradient().stops(), QLinearGradient().stops()); |
136 | QCOMPARE(m_theme->singleHighlightColor(), QColor(Qt::red)); |
137 | QCOMPARE(m_theme->singleHighlightGradient().stops(), QLinearGradient().stops()); |
138 | QCOMPARE(m_theme->type(), Q3DTheme::ThemeUserDefined); |
139 | QCOMPARE(m_theme->windowColor(), QColor(Qt::black)); |
140 | } |
141 | |
142 | void tst_theme::initializeProperties() |
143 | { |
144 | QVERIFY(m_theme); |
145 | |
146 | QLinearGradient gradient1; |
147 | QLinearGradient gradient2; |
148 | QLinearGradient gradient3; |
149 | QLinearGradient gradient4; |
150 | |
151 | QList<QColor> basecolors; |
152 | basecolors << QColor(Qt::red) << QColor(Qt::blue); |
153 | |
154 | QList<QLinearGradient> basegradients; |
155 | basegradients << gradient1 << gradient2; |
156 | |
157 | m_theme->setType(Q3DTheme::ThemeQt); // We'll override default values with the following setters |
158 | m_theme->setAmbientLightStrength(0.3f); |
159 | m_theme->setBackgroundColor(QColor(Qt::red)); |
160 | m_theme->setBackgroundEnabled(false); |
161 | m_theme->setBaseColors(basecolors); |
162 | m_theme->setBaseGradients(basegradients); |
163 | m_theme->setColorStyle(Q3DTheme::ColorStyleRangeGradient); |
164 | m_theme->setFont(QFont("Arial" )); |
165 | m_theme->setGridEnabled(false); |
166 | m_theme->setGridLineColor(QColor(Qt::green)); |
167 | m_theme->setHighlightLightStrength(5.0f); |
168 | m_theme->setLabelBackgroundColor(QColor(Qt::gray)); |
169 | m_theme->setLabelBackgroundEnabled(false); |
170 | m_theme->setLabelBorderEnabled(false); |
171 | m_theme->setLabelTextColor(QColor(Qt::cyan)); |
172 | m_theme->setLightColor(QColor(Qt::yellow)); |
173 | m_theme->setLightStrength(2.5f); |
174 | m_theme->setMultiHighlightColor(QColor(Qt::darkBlue)); |
175 | m_theme->setMultiHighlightGradient(gradient3); |
176 | m_theme->setSingleHighlightColor(QColor(Qt::darkRed)); |
177 | m_theme->setSingleHighlightGradient(gradient4); |
178 | m_theme->setWindowColor(QColor(Qt::darkYellow)); |
179 | |
180 | QCOMPARE(m_theme->ambientLightStrength(), 0.3f); |
181 | QCOMPARE(m_theme->backgroundColor(), QColor(Qt::red)); |
182 | QCOMPARE(m_theme->isBackgroundEnabled(), false); |
183 | QCOMPARE(m_theme->baseColors().length(), 2); |
184 | QCOMPARE(m_theme->baseColors().at(0), QColor(Qt::red)); |
185 | QCOMPARE(m_theme->baseColors().at(1), QColor(Qt::blue)); |
186 | QCOMPARE(m_theme->baseGradients().length(), 2); |
187 | QCOMPARE(m_theme->baseGradients().at(0), gradient1); |
188 | QCOMPARE(m_theme->baseGradients().at(0), gradient2); |
189 | QCOMPARE(m_theme->colorStyle(), Q3DTheme::ColorStyleRangeGradient); |
190 | QCOMPARE(m_theme->font(), QFont("Arial" )); |
191 | QCOMPARE(m_theme->isGridEnabled(), false); |
192 | QCOMPARE(m_theme->gridLineColor(), QColor(Qt::green)); |
193 | QCOMPARE(m_theme->highlightLightStrength(), 5.0f); |
194 | QCOMPARE(m_theme->labelBackgroundColor(), QColor(Qt::gray)); |
195 | QCOMPARE(m_theme->isLabelBackgroundEnabled(), false); |
196 | QCOMPARE(m_theme->isLabelBorderEnabled(), false); |
197 | QCOMPARE(m_theme->labelTextColor(), QColor(Qt::cyan)); |
198 | QCOMPARE(m_theme->lightColor(), QColor(Qt::yellow)); |
199 | QCOMPARE(m_theme->lightStrength(), 2.5f); |
200 | QCOMPARE(m_theme->multiHighlightColor(), QColor(Qt::darkBlue)); |
201 | QCOMPARE(m_theme->multiHighlightGradient(), gradient3); |
202 | QCOMPARE(m_theme->singleHighlightColor(), QColor(Qt::darkRed)); |
203 | QCOMPARE(m_theme->singleHighlightGradient(), gradient4); |
204 | QCOMPARE(m_theme->type(), Q3DTheme::ThemeQt); |
205 | QCOMPARE(m_theme->windowColor(), QColor(Qt::darkYellow)); |
206 | } |
207 | |
208 | void tst_theme::invalidProperties() |
209 | { |
210 | m_theme->setAmbientLightStrength(-1.0f); |
211 | QCOMPARE(m_theme->ambientLightStrength(), 0.25f); |
212 | m_theme->setAmbientLightStrength(1.1f); |
213 | QCOMPARE(m_theme->ambientLightStrength(), 0.25f); |
214 | |
215 | m_theme->setHighlightLightStrength(-1.0f); |
216 | QCOMPARE(m_theme->highlightLightStrength(), 7.5f); |
217 | m_theme->setHighlightLightStrength(10.1f); |
218 | QCOMPARE(m_theme->highlightLightStrength(), 7.5f); |
219 | |
220 | m_theme->setLightStrength(-1.0f); |
221 | QCOMPARE(m_theme->lightStrength(), 5.0f); |
222 | m_theme->setLightStrength(10.1f); |
223 | QCOMPARE(m_theme->lightStrength(), 5.0f); |
224 | } |
225 | |
226 | QTEST_MAIN(tst_theme) |
227 | #include "tst_theme.moc" |
228 | |