author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include <QtCore> |
|
42 |
#include <QtGui> |
|
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtDebug> |
|
45 |
#include <QMetaObject> |
|
46 |
#ifdef QT3_SUPPORT |
|
47 |
#include <Q3ProgressBar> |
|
48 |
#endif |
|
49 |
||
50 |
#include <private/qstylesheetstyle_p.h> |
|
51 |
||
52 |
//TESTED_CLASS= |
|
53 |
//TESTED_FILES= |
|
54 |
||
55 |
class tst_QStyleSheetStyle : public QObject |
|
56 |
{ |
|
57 |
Q_OBJECT |
|
58 |
public: |
|
59 |
tst_QStyleSheetStyle(); |
|
60 |
~tst_QStyleSheetStyle(); |
|
61 |
||
62 |
private slots: |
|
63 |
void repolish(); |
|
64 |
void numinstances(); |
|
65 |
void widgetsBeforeAppStyleSheet(); |
|
66 |
void widgetsAfterAppStyleSheet(); |
|
67 |
void applicationStyleSheet(); |
|
68 |
void windowStyleSheet(); |
|
69 |
void widgetStyleSheet(); |
|
70 |
void reparentWithNoChildStyleSheet(); |
|
71 |
void reparentWithChildStyleSheet(); |
|
72 |
void dynamicProperty(); |
|
73 |
// NB! Invoking this slot after layoutSpacing crashes on Mac. |
|
74 |
void namespaces(); |
|
75 |
#ifdef Q_OS_MAC |
|
76 |
void layoutSpacing(); |
|
77 |
#endif |
|
78 |
void qproperty(); |
|
79 |
void palettePropagation(); |
|
80 |
void fontPropagation(); |
|
81 |
void onWidgetDestroyed(); |
|
82 |
void fontPrecedence(); |
|
83 |
void focusColors(); |
|
84 |
void hoverColors(); |
|
85 |
void background(); |
|
86 |
void tabAlignement(); |
|
87 |
void attributesList(); |
|
88 |
void minmaxSizes(); |
|
89 |
void task206238_twice(); |
|
90 |
void transparent(); |
|
91 |
void proxyStyle(); |
|
92 |
void dialogButtonBox(); |
|
93 |
void emptyStyleSheet(); |
|
94 |
void toolTip(); |
|
95 |
void embeddedFonts(); |
|
96 |
void opaquePaintEvent_data(); |
|
97 |
void opaquePaintEvent(); |
|
98 |
void complexWidgetFocus(); |
|
99 |
void task188195_baseBackground(); |
|
100 |
void task232085_spinBoxLineEditBg(); |
|
101 |
||
102 |
//at the end because it mess with the style. |
|
103 |
void widgetStyle(); |
|
104 |
void appStyle(); |
|
105 |
private: |
|
106 |
QColor COLOR(const QWidget& w) { |
|
107 |
w.ensurePolished(); |
|
108 |
return w.palette().color(w.foregroundRole()); |
|
109 |
} |
|
110 |
QColor APPCOLOR(const QWidget& w) { |
|
111 |
w.ensurePolished(); |
|
112 |
return qApp->palette(&w).color(w.foregroundRole()); |
|
113 |
} |
|
114 |
QColor BACKGROUND(const QWidget& w) { |
|
115 |
w.ensurePolished(); |
|
116 |
return w.palette().color(w.backgroundRole()); |
|
117 |
} |
|
118 |
QColor APPBACKGROUND(const QWidget& w) { |
|
119 |
w.ensurePolished(); |
|
120 |
return qApp->palette(&w).color(w.backgroundRole()); |
|
121 |
} |
|
122 |
int FONTSIZE(const QWidget &w) { |
|
123 |
w.ensurePolished(); |
|
124 |
return w.font().pointSize(); |
|
125 |
} |
|
126 |
int APPFONTSIZE(const QWidget &w) { |
|
127 |
return qApp->font(&w).pointSize(); |
|
128 |
} |
|
129 |
}; |
|
130 |
||
131 |
tst_QStyleSheetStyle::tst_QStyleSheetStyle() |
|
132 |
{ |
|
133 |
} |
|
134 |
||
135 |
tst_QStyleSheetStyle::~tst_QStyleSheetStyle() |
|
136 |
{ |
|
137 |
} |
|
138 |
||
139 |
void tst_QStyleSheetStyle::numinstances() |
|
140 |
{ |
|
141 |
QWidget w; |
|
142 |
QCommonStyle *style = new QCommonStyle; |
|
143 |
style->setParent(&w); |
|
144 |
QWidget c(&w); |
|
145 |
w.show(); |
|
146 |
||
147 |
// set and unset application stylesheet |
|
148 |
QCOMPARE(QStyleSheetStyle::numinstances, 0); |
|
149 |
qApp->setStyleSheet("* { color: red; }"); |
|
150 |
QCOMPARE(QStyleSheetStyle::numinstances, 1); |
|
151 |
qApp->setStyleSheet(""); |
|
152 |
QCOMPARE(QStyleSheetStyle::numinstances, 0); |
|
153 |
||
154 |
// set and unset application stylesheet+widget |
|
155 |
qApp->setStyleSheet("* { color: red; }"); |
|
156 |
w.setStyleSheet("color: red;"); |
|
157 |
QCOMPARE(QStyleSheetStyle::numinstances, 2); |
|
158 |
w.setStyle(style); |
|
159 |
QCOMPARE(QStyleSheetStyle::numinstances, 2); |
|
160 |
qApp->setStyleSheet(""); |
|
161 |
QCOMPARE(QStyleSheetStyle::numinstances, 1); |
|
162 |
w.setStyleSheet(""); |
|
163 |
QCOMPARE(QStyleSheetStyle::numinstances, 0); |
|
164 |
||
165 |
// set and unset widget stylesheet |
|
166 |
w.setStyle(0); |
|
167 |
w.setStyleSheet("color: red"); |
|
168 |
QCOMPARE(QStyleSheetStyle::numinstances, 1); |
|
169 |
c.setStyle(style); |
|
170 |
QCOMPARE(QStyleSheetStyle::numinstances, 2); |
|
171 |
w.setStyleSheet(""); |
|
172 |
QCOMPARE(QStyleSheetStyle::numinstances, 0); |
|
173 |
} |
|
174 |
||
175 |
void tst_QStyleSheetStyle::widgetsBeforeAppStyleSheet() |
|
176 |
{ |
|
177 |
QPushButton w1; // widget with no stylesheet |
|
178 |
qApp->setStyleSheet("* { color: red; }"); |
|
179 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
180 |
w1.setStyleSheet("color: white"); |
|
181 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
182 |
qApp->setStyleSheet(""); |
|
183 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
184 |
w1.setStyleSheet(""); |
|
185 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
186 |
} |
|
187 |
||
188 |
class FriendlySpinBox : public QSpinBox { friend class tst_QStyleSheetStyle; }; |
|
189 |
||
190 |
void tst_QStyleSheetStyle::widgetsAfterAppStyleSheet() |
|
191 |
{ |
|
192 |
qApp->setStyleSheet("* { color: red; font-size: 32pt; }"); |
|
193 |
QPushButton w1; |
|
194 |
FriendlySpinBox spin; |
|
195 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
196 |
QVERIFY(COLOR(spin) == QColor("red")); |
|
197 |
QVERIFY(COLOR(*spin.lineEdit()) == QColor("red")); |
|
198 |
QCOMPARE(FONTSIZE(w1), 32); |
|
199 |
QCOMPARE(FONTSIZE(spin), 32); |
|
200 |
QCOMPARE(FONTSIZE(*spin.lineEdit()), 32); |
|
201 |
w1.setStyleSheet("color: white"); |
|
202 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
203 |
QVERIFY(COLOR(spin) == QColor("red")); |
|
204 |
QVERIFY(COLOR(*spin.lineEdit()) == QColor("red")); |
|
205 |
w1.setStyleSheet(""); |
|
206 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
207 |
QVERIFY(COLOR(spin) == QColor("red")); |
|
208 |
QVERIFY(COLOR(*spin.lineEdit()) == QColor("red")); |
|
209 |
w1.setStyleSheet("color: white"); |
|
210 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
211 |
qApp->setStyleSheet(""); |
|
212 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
213 |
QVERIFY(COLOR(spin) == APPCOLOR(spin)); |
|
214 |
QVERIFY(COLOR(*spin.lineEdit()) == APPCOLOR(*spin.lineEdit())); |
|
215 |
w1.setStyleSheet(""); |
|
216 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
217 |
// QCOMPARE(FONTSIZE(w1), APPFONTSIZE(w1)); //### task 244261 |
|
218 |
QCOMPARE(FONTSIZE(spin), APPFONTSIZE(spin)); |
|
219 |
//QCOMPARE(FONTSIZE(*spin.lineEdit()), APPFONTSIZE(*spin.lineEdit())); //### task 244261 |
|
220 |
} |
|
221 |
||
222 |
void tst_QStyleSheetStyle::applicationStyleSheet() |
|
223 |
{ |
|
224 |
QPushButton w1; |
|
225 |
qApp->setStyleSheet("* { color: red; }"); |
|
226 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
227 |
qApp->setStyleSheet("* { color: white; }"); |
|
228 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
229 |
qApp->setStyleSheet(""); |
|
230 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
231 |
qApp->setStyleSheet("* { color: red }"); |
|
232 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
233 |
} |
|
234 |
||
235 |
void tst_QStyleSheetStyle::windowStyleSheet() |
|
236 |
{ |
|
237 |
QPushButton w1; |
|
238 |
qApp->setStyleSheet(""); |
|
239 |
w1.setStyleSheet("* { color: red; }"); |
|
240 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
241 |
w1.setStyleSheet("* { color: white; }"); |
|
242 |
QVERIFY(COLOR(w1) == QColor("white")); |
|
243 |
w1.setStyleSheet(""); |
|
244 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
245 |
w1.setStyleSheet("* { color: red }"); |
|
246 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
247 |
||
248 |
qApp->setStyleSheet("* { color: green }"); |
|
249 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
250 |
w1.setStyleSheet(""); |
|
251 |
QVERIFY(COLOR(w1) == QColor("green")); |
|
252 |
qApp->setStyleSheet(""); |
|
253 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
254 |
} |
|
255 |
||
256 |
void tst_QStyleSheetStyle::widgetStyleSheet() |
|
257 |
{ |
|
258 |
QPushButton w1; |
|
259 |
QPushButton *pb = new QPushButton(&w1); |
|
260 |
QPushButton &w2 = *pb; |
|
261 |
||
262 |
qApp->setStyleSheet(""); |
|
263 |
w1.setStyleSheet("* { color: red }"); |
|
264 |
QVERIFY(COLOR(w1) == QColor("red")); |
|
265 |
QVERIFY(COLOR(w2) == QColor("red")); |
|
266 |
||
267 |
w2.setStyleSheet("* { color: white }"); |
|
268 |
QVERIFY(COLOR(w2) == QColor("white")); |
|
269 |
||
270 |
w1.setStyleSheet("* { color: blue }"); |
|
271 |
QVERIFY(COLOR(w1) == QColor("blue")); |
|
272 |
QVERIFY(COLOR(w2) == QColor("white")); |
|
273 |
||
274 |
w1.setStyleSheet(""); |
|
275 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
276 |
QVERIFY(COLOR(w2) == QColor("white")); |
|
277 |
||
278 |
w2.setStyleSheet(""); |
|
279 |
QVERIFY(COLOR(w1) == APPCOLOR(w1)); |
|
280 |
QVERIFY(COLOR(w2) == APPCOLOR(w2)); |
|
281 |
} |
|
282 |
||
283 |
void tst_QStyleSheetStyle::reparentWithNoChildStyleSheet() |
|
284 |
{ |
|
285 |
QPushButton p1, p2; |
|
286 |
QPushButton *pb = new QPushButton(&p1); |
|
287 |
QPushButton &c1 = *pb; // child with no stylesheet |
|
288 |
||
289 |
qApp->setStyleSheet(""); |
|
290 |
p1.setStyleSheet("* { color: red }"); |
|
291 |
QVERIFY(COLOR(c1) == QColor("red")); |
|
292 |
c1.setParent(&p2); |
|
293 |
QVERIFY(COLOR(c1) == APPCOLOR(c1)); |
|
294 |
||
295 |
p2.setStyleSheet("* { color: white }"); |
|
296 |
QVERIFY(COLOR(c1) == QColor("white")); |
|
297 |
||
298 |
c1.setParent(&p1); |
|
299 |
QVERIFY(COLOR(c1) == QColor("red")); |
|
300 |
||
301 |
qApp->setStyleSheet("* { color: blue }"); |
|
302 |
c1.setParent(0); |
|
303 |
QVERIFY(COLOR(c1) == QColor("blue")); |
|
304 |
delete pb; |
|
305 |
} |
|
306 |
||
307 |
void tst_QStyleSheetStyle::reparentWithChildStyleSheet() |
|
308 |
{ |
|
309 |
qApp->setStyleSheet(""); |
|
310 |
QPushButton p1, p2; |
|
311 |
QPushButton *pb = new QPushButton(&p1); |
|
312 |
QPushButton &c1 = *pb; |
|
313 |
||
314 |
c1.setStyleSheet("background: gray"); |
|
315 |
QVERIFY(BACKGROUND(c1) == QColor("gray")); |
|
316 |
c1.setParent(&p2); |
|
317 |
QVERIFY(BACKGROUND(c1) == QColor("gray")); |
|
318 |
||
319 |
qApp->setStyleSheet("* { color: white }"); |
|
320 |
c1.setParent(&p1); |
|
321 |
QVERIFY(BACKGROUND(c1) == QColor("gray")); |
|
322 |
QVERIFY(COLOR(c1) == QColor("white")); |
|
323 |
} |
|
324 |
||
325 |
void tst_QStyleSheetStyle::repolish() |
|
326 |
{ |
|
327 |
qApp->setStyleSheet(""); |
|
328 |
QPushButton p1; |
|
329 |
p1.setStyleSheet("color: red; background: white"); |
|
330 |
QVERIFY(BACKGROUND(p1) == QColor("white")); |
|
331 |
p1.setStyleSheet("background: white"); |
|
332 |
QVERIFY(COLOR(p1) == APPCOLOR(p1)); |
|
333 |
p1.setStyleSheet("color: red"); |
|
334 |
QVERIFY(COLOR(p1) == QColor("red")); |
|
335 |
QVERIFY(BACKGROUND(p1) == APPBACKGROUND(p1)); |
|
336 |
p1.setStyleSheet(""); |
|
337 |
QVERIFY(COLOR(p1) == APPCOLOR(p1)); |
|
338 |
QVERIFY(BACKGROUND(p1) == APPBACKGROUND(p1)); |
|
339 |
} |
|
340 |
||
341 |
void tst_QStyleSheetStyle::widgetStyle() |
|
342 |
{ |
|
343 |
qApp->setStyleSheet(""); |
|
344 |
||
345 |
QWidget *window1 = new QWidget; |
|
346 |
window1->setObjectName("window1"); |
|
347 |
QWidget *widget1 = new QWidget(window1); |
|
348 |
widget1->setObjectName("widget1"); |
|
349 |
QWidget *widget2 = new QWidget; |
|
350 |
widget2->setObjectName("widget2"); |
|
351 |
QWidget *window2 = new QWidget; |
|
352 |
window2->setObjectName("window2"); |
|
353 |
window1->ensurePolished(); |
|
354 |
window2->ensurePolished(); |
|
355 |
widget1->ensurePolished(); |
|
356 |
widget2->ensurePolished(); |
|
357 |
||
358 |
QWindowsStyle style1, style2; |
|
359 |
QPointer<QStyle> pstyle1 = &style1; |
|
360 |
QPointer<QStyle> pstyle2 = &style2; |
|
361 |
||
362 |
QStyle *appStyle = qApp->style(); |
|
363 |
||
364 |
// Sanity: By default, a window inherits the application style |
|
365 |
QCOMPARE(appStyle, window1->style()); |
|
366 |
||
367 |
// Setting a custom style on a widget |
|
368 |
window1->setStyle(&style1); |
|
369 |
QCOMPARE(static_cast<QStyle *>(&style1), window1->style()); |
|
370 |
||
371 |
// Setting another style must not delete the older style |
|
372 |
window1->setStyle(&style2); |
|
373 |
QCOMPARE(static_cast<QStyle *>(&style2), window1->style()); |
|
374 |
QVERIFY(!pstyle1.isNull()); // case we have not already crashed |
|
375 |
||
376 |
// Setting null style must make it follow the qApp style |
|
377 |
window1->setStyle(0); |
|
378 |
QCOMPARE(window1->style(), appStyle); |
|
379 |
QVERIFY(!pstyle2.isNull()); // case we have not already crashed |
|
380 |
QVERIFY(!pstyle2.isNull()); // case we have not already crashed |
|
381 |
||
382 |
// Sanity: Set the stylesheet |
|
383 |
window1->setStyleSheet(":x { }"); |
|
384 |
||
385 |
QPointer<QStyleSheetStyle> proxy = (QStyleSheetStyle *)window1->style(); |
|
386 |
QVERIFY(!proxy.isNull()); |
|
387 |
QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); // must be our proxy |
|
388 |
QVERIFY(proxy->base == 0); // and follows the application |
|
389 |
||
390 |
// Set the stylesheet |
|
391 |
window1->setStyle(&style1); |
|
392 |
QVERIFY(proxy.isNull()); // we create a new one each time |
|
393 |
proxy = (QStyleSheetStyle *)window1->style(); |
|
394 |
QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); // it is a proxy |
|
395 |
QCOMPARE(proxy->baseStyle(), static_cast<QStyle *>(&style1)); // must have been replaced with the new one |
|
396 |
||
397 |
// Update the stylesheet and check nothing changes |
|
398 |
window1->setStyleSheet(":y { }"); |
|
399 |
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // it is a proxy |
|
400 |
QCOMPARE(proxy->baseStyle(), static_cast<QStyle *>(&style1)); // the same guy |
|
401 |
||
402 |
// Remove the stylesheet |
|
403 |
proxy = (QStyleSheetStyle *)window1->style(); |
|
404 |
window1->setStyleSheet(""); |
|
405 |
QVERIFY(proxy.isNull()); // should have disappeared |
|
406 |
QCOMPARE(window1->style(), static_cast<QStyle *>(&style1)); // its restored |
|
407 |
||
408 |
// Style Sheet existing children propagation |
|
409 |
window1->setStyleSheet(":z { }"); |
|
410 |
proxy = (QStyleSheetStyle *)window1->style(); |
|
411 |
QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); |
|
412 |
QCOMPARE(window1->style(), widget1->style()); // proxy must have propagated |
|
413 |
QCOMPARE(widget2->style(), appStyle); // widget2 is following the app style |
|
414 |
||
415 |
// Style Sheet automatic propagation to new children |
|
416 |
widget2->setParent(window1); // reparent in! |
|
417 |
QCOMPARE(window1->style(), widget2->style()); // proxy must have propagated |
|
418 |
||
419 |
// Style Sheet automatic removal from children who abandoned their parents |
|
420 |
window2->setStyle(&style2); |
|
421 |
widget2->setParent(window2); // reparent |
|
422 |
QCOMPARE(widget2->style(), appStyle); // widget2 is following the app style |
|
423 |
||
424 |
// Style Sheet propagation on a child widget with a custom style |
|
425 |
widget2->setStyle(&style1); |
|
426 |
window2->setStyleSheet(":x { }"); |
|
427 |
proxy = (QStyleSheetStyle *)widget2->style(); |
|
428 |
QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); |
|
429 |
QCOMPARE(proxy->baseStyle(), static_cast<QStyle *>(&style1)); |
|
430 |
||
431 |
// Style Sheet propagation on a child widget with a custom style already set |
|
432 |
window2->setStyleSheet(""); |
|
433 |
QCOMPARE(window2->style(), static_cast<QStyle *>(&style2)); |
|
434 |
QCOMPARE(widget2->style(), static_cast<QStyle *>(&style1)); |
|
435 |
widget2->setStyle(0); |
|
436 |
window2->setStyleSheet(":x { }"); |
|
437 |
widget2->setStyle(&style1); |
|
438 |
proxy = (QStyleSheetStyle *)widget2->style(); |
|
439 |
QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); |
|
440 |
||
441 |
// QApplication, QWidget both having a style sheet |
|
442 |
||
443 |
// clean everything out |
|
444 |
window1->setStyle(0); |
|
445 |
window1->setStyleSheet(""); |
|
446 |
window2->setStyle(0); |
|
447 |
window2->setStyleSheet(""); |
|
448 |
qApp->setStyle(0); |
|
449 |
||
450 |
qApp->setStyleSheet("may_insanity_prevail { }"); // app has styleshet |
|
451 |
QCOMPARE(window1->style(), qApp->style()); |
|
452 |
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); |
|
453 |
QCOMPARE(widget1->style()->metaObject()->className(), "QStyleSheetStyle"); // check the child |
|
454 |
window1->setStyleSheet("may_more_insanity_prevail { }"); // window has stylesheet |
|
455 |
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // a new one |
|
456 |
QCOMPARE(widget1->style(), window1->style()); // child follows... |
|
457 |
proxy = (QStyleSheetStyle *) window1->style(); |
|
458 |
QWindowsStyle *newStyle = new QWindowsStyle; |
|
459 |
qApp->setStyle(newStyle); // set a custom style on app |
|
460 |
proxy = (QStyleSheetStyle *) window1->style(); |
|
461 |
QCOMPARE(proxy->baseStyle(), static_cast<QStyle *>(newStyle)); // magic ;) the widget still follows the application |
|
462 |
QCOMPARE(static_cast<QStyle *>(proxy), widget1->style()); // child still follows... |
|
463 |
||
464 |
window1->setStyleSheet(""); // remove stylesheet |
|
465 |
QCOMPARE(window1->style(), qApp->style()); // is this cool or what |
|
466 |
QCOMPARE(widget1->style(), qApp->style()); // annoying child follows... |
|
467 |
QWindowsStyle wndStyle; |
|
468 |
window1->setStyle(&wndStyle); |
|
469 |
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // auto wraps it |
|
470 |
QCOMPARE(widget1->style(), window1->style()); // and auto propagates to child |
|
471 |
qApp->setStyleSheet(""); // remove the app stylesheet |
|
472 |
QCOMPARE(window1->style(), static_cast<QStyle *>(&wndStyle)); // auto dewrap |
|
473 |
QCOMPARE(widget1->style(), qApp->style()); // and child state is restored |
|
474 |
window1->setStyle(0); // let sanity prevail |
|
475 |
qApp->setStyle(0); |
|
476 |
||
477 |
delete window1; |
|
478 |
delete widget2; |
|
479 |
delete window2; |
|
480 |
} |
|
481 |
||
482 |
void tst_QStyleSheetStyle::appStyle() |
|
483 |
{ |
|
484 |
qApp->setStyleSheet(""); |
|
485 |
// qApp style can never be 0 |
|
486 |
QVERIFY(QApplication::style() != 0); |
|
487 |
QPointer<QStyle> style1 = new QWindowsStyle; |
|
488 |
QPointer<QStyle> style2 = new QWindowsStyle; |
|
489 |
qApp->setStyle(style1); |
|
490 |
// Basic sanity |
|
491 |
QVERIFY(qApp->style() == style1); |
|
492 |
qApp->setStyle(style2); |
|
493 |
QVERIFY(style1.isNull()); // qApp must have taken ownership and deleted it |
|
494 |
// Setting null should not crash |
|
495 |
qApp->setStyle(0); |
|
496 |
QVERIFY(qApp->style() == style2); |
|
497 |
||
498 |
// Set the stylesheet |
|
499 |
qApp->setStyleSheet("whatever"); |
|
500 |
QPointer<QStyleSheetStyle> sss = (QStyleSheetStyle *)qApp->style(); |
|
501 |
QVERIFY(!sss.isNull()); |
|
502 |
QCOMPARE(sss->metaObject()->className(), "QStyleSheetStyle"); // must be our proxy now |
|
503 |
QVERIFY(!style2.isNull()); // this should exist as it is the base of the proxy |
|
504 |
QVERIFY(sss->baseStyle() == style2); |
|
505 |
style1 = new QWindowsStyle; |
|
506 |
qApp->setStyle(style1); |
|
507 |
QVERIFY(style2.isNull()); // should disappear automatically |
|
508 |
QVERIFY(sss.isNull()); // should disappear automatically |
|
509 |
||
510 |
// Update the stylesheet and check nothing changes |
|
511 |
sss = (QStyleSheetStyle *)qApp->style(); |
|
512 |
qApp->setStyleSheet("whatever2"); |
|
513 |
QVERIFY(qApp->style() == sss); |
|
514 |
QVERIFY(sss->baseStyle() == style1); |
|
515 |
||
516 |
// Revert the stylesheet |
|
517 |
qApp->setStyleSheet(""); |
|
518 |
QVERIFY(sss.isNull()); // should have disappeared |
|
519 |
QVERIFY(qApp->style() == style1); |
|
520 |
||
521 |
qApp->setStyleSheet(""); |
|
522 |
QVERIFY(qApp->style() == style1); |
|
523 |
} |
|
524 |
||
525 |
void tst_QStyleSheetStyle::dynamicProperty() |
|
526 |
{ |
|
527 |
qApp->setStyleSheet(QString()); |
|
528 |
||
529 |
QString appStyle = qApp->style()->metaObject()->className(); |
|
530 |
QPushButton pb1, pb2; |
|
531 |
pb1.setProperty("type", "critical"); |
|
532 |
qApp->setStyleSheet("*[class~=\"QPushButton\"] { color: red; } *[type=\"critical\"] { background: white; }"); |
|
533 |
QVERIFY(COLOR(pb1) == Qt::red); |
|
534 |
QVERIFY(BACKGROUND(pb1) == Qt::white); |
|
535 |
||
536 |
pb2.setProperty("class", "critical"); // dynamic class |
|
537 |
pb2.setStyleSheet(QLatin1String(".critical[style~=\"") + appStyle + "\"] { color: blue }"); |
|
538 |
pb2.show(); |
|
539 |
||
540 |
QVERIFY(COLOR(pb2) == Qt::blue); |
|
541 |
} |
|
542 |
||
543 |
#ifdef Q_OS_MAC |
|
544 |
#include <QtGui/QMacStyle> |
|
545 |
void tst_QStyleSheetStyle::layoutSpacing() |
|
546 |
{ |
|
547 |
qApp->setStyleSheet("* { color: red }"); |
|
548 |
QCheckBox ck1; |
|
549 |
QCheckBox ck2; |
|
550 |
QWidget window; |
|
551 |
int spacing_widgetstyle = window.style()->layoutSpacing(ck1.sizePolicy().controlType(), ck2.sizePolicy().controlType(), Qt::Vertical); |
|
552 |
int spacing_style = window.style()->layoutSpacing(ck1.sizePolicy().controlType(), ck2.sizePolicy().controlType(), Qt::Vertical); |
|
553 |
QCOMPARE(spacing_widgetstyle, spacing_style); |
|
554 |
} |
|
555 |
#endif |
|
556 |
||
557 |
void tst_QStyleSheetStyle::qproperty() |
|
558 |
{ |
|
559 |
QPushButton pb; |
|
560 |
pb.setStyleSheet("QPushButton { qproperty-text: hello; qproperty-checkable: true; qproperty-checked: 1}"); |
|
561 |
pb.ensurePolished(); |
|
562 |
QCOMPARE(pb.text(), QString("hello")); |
|
563 |
QCOMPARE(pb.isCheckable(), true); |
|
564 |
QCOMPARE(pb.isChecked(), true); |
|
565 |
} |
|
566 |
||
567 |
namespace ns { |
|
568 |
class PushButton1 : public QPushButton { |
|
569 |
Q_OBJECT |
|
570 |
public: |
|
571 |
PushButton1() { } |
|
572 |
}; |
|
573 |
class PushButton2 : public PushButton1 { |
|
574 |
Q_OBJECT |
|
575 |
public: |
|
576 |
PushButton2() { setProperty("class", "PushButtonTwo PushButtonDuo"); } |
|
577 |
}; |
|
578 |
} |
|
579 |
||
580 |
void tst_QStyleSheetStyle::namespaces() |
|
581 |
{ |
|
582 |
ns::PushButton1 pb1; |
|
583 |
qApp->setStyleSheet("ns--PushButton1 { background: white }"); |
|
584 |
QVERIFY(BACKGROUND(pb1) == QColor("white")); |
|
585 |
qApp->setStyleSheet(".ns--PushButton1 { background: red }"); |
|
586 |
QVERIFY(BACKGROUND(pb1) == QColor("red")); |
|
587 |
||
588 |
ns::PushButton2 pb2; |
|
589 |
qApp->setStyleSheet("ns--PushButton1 { background: blue}"); |
|
590 |
QVERIFY(BACKGROUND(pb2) == QColor("blue")); |
|
591 |
qApp->setStyleSheet("ns--PushButton2 { background: magenta }"); |
|
592 |
QVERIFY(BACKGROUND(pb2) == QColor("magenta")); |
|
593 |
qApp->setStyleSheet(".PushButtonTwo { background: white; }"); |
|
594 |
QVERIFY(BACKGROUND(pb2) == QColor("white")); |
|
595 |
qApp->setStyleSheet(".PushButtonDuo { background: red; }"); |
|
596 |
QVERIFY(BACKGROUND(pb2) == QColor("red")); |
|
597 |
} |
|
598 |
||
599 |
void tst_QStyleSheetStyle::palettePropagation() |
|
600 |
{ |
|
601 |
qApp->setStyleSheet(""); |
|
602 |
QGroupBox gb; |
|
603 |
QPushButton *push = new QPushButton(&gb); |
|
604 |
QPushButton &pb = *push; |
|
605 |
push->setText("AsdF"); |
|
606 |
||
607 |
gb.setStyleSheet("QGroupBox { color: red }"); |
|
608 |
QVERIFY(COLOR(gb) == Qt::red); |
|
609 |
QVERIFY(COLOR(pb) == APPCOLOR(pb)); // palette shouldn't propagate |
|
610 |
gb.setStyleSheet("QGroupBox * { color: red }"); |
|
611 |
||
612 |
QVERIFY(COLOR(pb) == Qt::red); |
|
613 |
QVERIFY(COLOR(gb) == APPCOLOR(gb)); |
|
614 |
||
615 |
QWidget window; |
|
616 |
window.setStyleSheet("* { color: white; }"); |
|
617 |
pb.setParent(&window); |
|
618 |
QVERIFY(COLOR(pb) == Qt::white); |
|
619 |
} |
|
620 |
||
621 |
void tst_QStyleSheetStyle::fontPropagation() |
|
622 |
{ |
|
623 |
qApp->setStyleSheet(""); |
|
624 |
QComboBox cb; |
|
625 |
cb.addItem("item1"); |
|
626 |
cb.addItem("item2"); |
|
627 |
||
628 |
QAbstractItemView *popup = cb.view(); |
|
629 |
int viewFontSize = FONTSIZE(*popup); |
|
630 |
||
631 |
cb.setStyleSheet("QComboBox { font-size: 20pt; }"); |
|
632 |
QVERIFY(FONTSIZE(cb) == 20); |
|
633 |
QVERIFY(FONTSIZE(*popup) == viewFontSize); |
|
634 |
QGroupBox gb; |
|
635 |
QPushButton *push = new QPushButton(&gb); |
|
636 |
QPushButton &pb = *push; |
|
637 |
int buttonFontSize = FONTSIZE(pb); |
|
638 |
int gbFontSize = FONTSIZE(gb); |
|
639 |
||
640 |
gb.setStyleSheet("QGroupBox { font-size: 20pt }"); |
|
641 |
QVERIFY(FONTSIZE(gb) == 20); |
|
642 |
QVERIFY(FONTSIZE(pb) == buttonFontSize); // font does not propagate |
|
643 |
gb.setStyleSheet("QGroupBox * { font-size: 20pt; }"); |
|
644 |
QVERIFY(FONTSIZE(gb) == gbFontSize); |
|
645 |
QVERIFY(FONTSIZE(pb) == 20); |
|
646 |
||
647 |
QWidget window; |
|
648 |
window.setStyleSheet("* { font-size: 10pt }"); |
|
649 |
pb.setParent(&window); |
|
650 |
QCOMPARE(FONTSIZE(pb), 10); |
|
651 |
window.setStyleSheet(""); |
|
652 |
QVERIFY(FONTSIZE(pb) == buttonFontSize); |
|
653 |
||
654 |
QTabWidget tw; |
|
655 |
tw.setStyleSheet("QTabWidget { font-size: 20pt; }"); |
|
656 |
QVERIFY(FONTSIZE(tw) == 20); |
|
657 |
QWidget *child = qFindChild<QWidget *>(&tw, "qt_tabwidget_tabbar"); |
|
658 |
QVERIFY2(child, "QTabWidget did not contain a widget named \"qt_tabwidget_tabbar\""); |
|
659 |
QVERIFY(FONTSIZE(*child) == 20); |
|
660 |
} |
|
661 |
||
662 |
void tst_QStyleSheetStyle::onWidgetDestroyed() |
|
663 |
{ |
|
664 |
qApp->setStyleSheet(""); |
|
665 |
QLabel *l = new QLabel; |
|
666 |
l->setStyleSheet("QLabel { color: red }"); |
|
667 |
QPointer<QStyleSheetStyle> ss = (QStyleSheetStyle *) l->style(); |
|
668 |
delete l; |
|
669 |
QVERIFY(ss.isNull()); |
|
670 |
} |
|
671 |
||
672 |
void tst_QStyleSheetStyle::fontPrecedence() |
|
673 |
{ |
|
674 |
QLineEdit edit; |
|
675 |
edit.show(); |
|
676 |
QFont font; |
|
677 |
QVERIFY(FONTSIZE(edit) != 22); // Sanity check to make sure this test makes sense. |
|
678 |
edit.setStyleSheet("QLineEdit { font-size: 22pt; }"); |
|
679 |
QCOMPARE(FONTSIZE(edit), 22); |
|
680 |
font.setPointSize(16); |
|
681 |
edit.setFont(font); |
|
682 |
QCOMPARE(FONTSIZE(edit), 22); |
|
683 |
edit.setStyleSheet(""); |
|
684 |
QCOMPARE(FONTSIZE(edit), 16); |
|
685 |
font.setPointSize(18); |
|
686 |
edit.setFont(font); |
|
687 |
QCOMPARE(FONTSIZE(edit), 18); |
|
688 |
edit.setStyleSheet("QLineEdit { font-size: 20pt; }"); |
|
689 |
QCOMPARE(FONTSIZE(edit), 20); |
|
690 |
edit.setStyleSheet(""); |
|
691 |
QCOMPARE(FONTSIZE(edit), 18); |
|
692 |
edit.hide(); |
|
693 |
||
694 |
QLineEdit edit2; |
|
695 |
edit2.setReadOnly(true); |
|
696 |
edit2.setStyleSheet("QLineEdit { font-size: 24pt; } QLineEdit:read-only { font-size: 26pt; }"); |
|
697 |
QCOMPARE(FONTSIZE(edit2), 26); |
|
698 |
} |
|
699 |
||
700 |
static bool testForColors(const QImage& image, const QColor& color) |
|
701 |
{ |
|
702 |
int count = 0; |
|
703 |
QRgb rgb = color.rgba(); |
|
704 |
for (int y = 0; y < image.height(); ++y) { |
|
705 |
for (int x = 0; x < image.width(); ++x) { |
|
706 |
// Because of antialiasing we allow a certain range of errors here. |
|
707 |
QRgb pixel = image.pixel(x, y); |
|
708 |
if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) + |
|
709 |
qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) + |
|
710 |
qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) { |
|
711 |
if (++count >= 10) { |
|
712 |
return true; |
|
713 |
} |
|
714 |
} |
|
715 |
} |
|
716 |
} |
|
717 |
||
718 |
return false; |
|
719 |
} |
|
720 |
||
721 |
void tst_QStyleSheetStyle::focusColors() |
|
722 |
{ |
|
723 |
// Tests if colors can be changed by altering the focus of the widget. |
|
724 |
// To avoid messy pixel-by-pixel comparison, we assume that the goal |
|
725 |
// is reached if at least ten pixels of the right color can be found in |
|
726 |
// the image. |
|
727 |
// For this reason, we use unusual and extremely ugly colors! :-) |
|
728 |
||
729 |
#if !defined(Q_OS_WIN32) && !defined(Q_OS_MAC) && !(defined(Q_OS_LINUX) && defined(Q_CC_GNU) \ |
|
730 |
&& !defined(Q_CC_INTEL)) |
|
731 |
QSKIP("This is a fragile test which fails on many esoteric platforms " |
|
732 |
"because of focus problems. " |
|
733 |
"That doesn't mean that the feature doesn't work in practice.", SkipAll); |
|
734 |
#endif |
|
735 |
/* Disabled changing style in order not to mess with the application style |
|
736 |
#ifdef Q_OS_MAC |
|
737 |
int styleCount = 3; |
|
738 |
QStyle *styles[3]; |
|
739 |
#else |
|
740 |
int styleCount = 2; |
|
741 |
QStyle *styles[2]; |
|
742 |
#endif |
|
743 |
||
744 |
styles[0] = new QPlastiqueStyle; |
|
745 |
styles[1] = new QWindowsStyle; |
|
746 |
||
747 |
#ifdef Q_OS_MAC |
|
748 |
styles[2] = new QMacStyle; |
|
749 |
#endif |
|
750 |
||
751 |
||
752 |
for (int i = 0; i < styleCount; ++i) { |
|
753 |
qApp->setStyle(styles[i]); |
|
754 |
*/ |
|
755 |
QList<QWidget *> widgets; |
|
756 |
widgets << new QPushButton("TESTING"); |
|
757 |
widgets << new QLineEdit("TESTING"); |
|
758 |
widgets << new QLabel("TESTING"); |
|
759 |
QSpinBox *spinbox = new QSpinBox; |
|
760 |
spinbox->setValue(8888); |
|
761 |
widgets << spinbox; |
|
762 |
QComboBox *combobox = new QComboBox; |
|
763 |
combobox->setEditable(true); |
|
764 |
combobox->addItems(QStringList() << "TESTING"); |
|
765 |
widgets << combobox; |
|
766 |
widgets << new QLabel("TESTING"); |
|
767 |
||
768 |
#ifdef Q_WS_QWS |
|
769 |
// QWS has its own special focus logic which is slightly different |
|
770 |
// and I don't dare change it at this point, because someone will |
|
771 |
// be relying on it. It means that setFocus() on a NoFocus widget (i.e. |
|
772 |
// a QLabel) will not work before the window is activated. |
|
773 |
widgets[2]->setFocusPolicy(Qt::StrongFocus); |
|
774 |
#endif |
|
775 |
||
776 |
foreach (QWidget *widget, widgets) { |
|
777 |
QDialog frame; |
|
778 |
QLayout* layout = new QGridLayout; |
|
779 |
||
780 |
QLineEdit* dummy = new QLineEdit; // Avoids initial focus. |
|
781 |
||
782 |
widget->setStyleSheet("*:focus { border:none; background: #e8ff66; color: #ff0084 }"); |
|
783 |
||
784 |
layout->addWidget(dummy); |
|
785 |
layout->addWidget(widget); |
|
786 |
frame.setLayout(layout); |
|
787 |
||
788 |
frame.show(); |
|
789 |
#ifdef Q_WS_X11 |
|
790 |
qt_x11_wait_for_window_manager(&frame); |
|
791 |
#endif |
|
792 |
QApplication::setActiveWindow(&frame); |
|
793 |
widget->setFocus(); |
|
794 |
QApplication::processEvents(); |
|
795 |
||
796 |
QImage image(frame.width(), frame.height(), QImage::Format_ARGB32); |
|
797 |
frame.render(&image); |
|
798 |
if (image.depth() < 24) { |
|
799 |
QSKIP("Test doesn't support color depth < 24", SkipAll); |
|
800 |
} |
|
801 |
||
802 |
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)), |
|
803 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
804 |
+ " did not contain background color #e8ff66, using style " |
|
805 |
+ QString::fromLatin1(qApp->style()->metaObject()->className())) |
|
806 |
.toLocal8Bit().constData()); |
|
807 |
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), |
|
808 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
809 |
+ " did not contain text color #ff0084, using style " |
|
810 |
+ QString::fromLatin1(qApp->style()->metaObject()->className())) |
|
811 |
.toLocal8Bit().constData()); |
|
812 |
} |
|
813 |
// } |
|
814 |
} |
|
815 |
||
816 |
||
817 |
void tst_QStyleSheetStyle::hoverColors() |
|
818 |
{ |
|
819 |
QList<QWidget *> widgets; |
|
820 |
widgets << new QPushButton("TESTING"); |
|
821 |
widgets << new QLineEdit("TESTING"); |
|
822 |
widgets << new QLabel("TESTING"); |
|
823 |
QSpinBox *spinbox = new QSpinBox; |
|
824 |
spinbox->setValue(8888); |
|
825 |
widgets << spinbox; |
|
826 |
QComboBox *combobox = new QComboBox; |
|
827 |
combobox->setEditable(true); |
|
828 |
combobox->addItems(QStringList() << "TESTING"); |
|
829 |
widgets << combobox; |
|
830 |
widgets << new QLabel("<b>TESTING</b>"); |
|
831 |
||
832 |
foreach (QWidget *widget, widgets) { |
|
833 |
//without Qt::X11BypassWindowManagerHint the window manager may move the window after we moved the cursor |
|
834 |
QDialog frame(0, Qt::X11BypassWindowManagerHint); |
|
835 |
QLayout* layout = new QGridLayout; |
|
836 |
||
837 |
QLineEdit* dummy = new QLineEdit; |
|
838 |
||
839 |
widget->setStyleSheet("*:hover { border:none; background: #e8ff66; color: #ff0084 }"); |
|
840 |
||
841 |
layout->addWidget(dummy); |
|
842 |
layout->addWidget(widget); |
|
843 |
frame.setLayout(layout); |
|
844 |
||
845 |
frame.show(); |
|
846 |
#ifdef Q_WS_QWS |
|
847 |
//QWS does not implement enter/leave when windows are shown underneath the cursor |
|
848 |
QCursor::setPos(QPoint(0,0)); |
|
849 |
#endif |
|
850 |
||
851 |
#ifdef Q_WS_X11 |
|
852 |
qt_x11_wait_for_window_manager(&frame); |
|
853 |
#endif |
|
854 |
QApplication::setActiveWindow(&frame); |
|
855 |
QTest::qWait(60); |
|
856 |
//move the mouse inside the widget, it should be colored |
|
857 |
QTest::mouseMove ( widget, QPoint(5,5)); |
|
858 |
QTest::qWait(60); |
|
859 |
||
860 |
QVERIFY(widget->testAttribute(Qt::WA_UnderMouse)); |
|
861 |
||
862 |
QImage image(frame.width(), frame.height(), QImage::Format_ARGB32); |
|
863 |
frame.render(&image); |
|
864 |
||
865 |
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)), |
|
866 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
867 |
+ " did not contain background color #e8ff66").toLocal8Bit().constData()); |
|
868 |
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), |
|
869 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
870 |
+ " did not contain text color #ff0084").toLocal8Bit().constData()); |
|
871 |
||
872 |
//move the mouse outside the widget, it should NOT be colored |
|
873 |
QTest::mouseMove ( dummy, QPoint(5,5)); |
|
874 |
QTest::qWait(60); |
|
875 |
||
876 |
frame.render(&image); |
|
877 |
||
878 |
QVERIFY2(!testForColors(image, QColor(0xe8, 0xff, 0x66)), |
|
879 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
880 |
+ " did contain background color #e8ff66").toLocal8Bit().constData()); |
|
881 |
QVERIFY2(!testForColors(image, QColor(0xff, 0x00, 0x84)), |
|
882 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
883 |
+ " did contain text color #ff0084").toLocal8Bit().constData()); |
|
884 |
||
885 |
//move the mouse again inside the widget, it should be colored |
|
886 |
QTest::mouseMove (widget, QPoint(5,5)); |
|
887 |
QTest::qWait(60); |
|
888 |
||
889 |
QVERIFY(widget->testAttribute(Qt::WA_UnderMouse)); |
|
890 |
||
891 |
frame.render(&image); |
|
892 |
||
893 |
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)), |
|
894 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
895 |
+ " did not contain background color #e8ff66").toLocal8Bit().constData()); |
|
896 |
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), |
|
897 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
898 |
+ " did not contain text color #ff0084").toLocal8Bit().constData()); |
|
899 |
} |
|
900 |
||
901 |
} |
|
902 |
||
903 |
class SingleInheritanceDialog : public QDialog |
|
904 |
{ |
|
905 |
Q_OBJECT |
|
906 |
public: |
|
907 |
SingleInheritanceDialog(QWidget *w = 0) : |
|
908 |
QDialog(w) |
|
909 |
{ |
|
910 |
} |
|
911 |
}; |
|
912 |
||
913 |
class DoubleInheritanceDialog : public SingleInheritanceDialog |
|
914 |
{ |
|
915 |
Q_OBJECT |
|
916 |
public: |
|
917 |
DoubleInheritanceDialog(QWidget *w = 0) : |
|
918 |
SingleInheritanceDialog(w) |
|
919 |
{ |
|
920 |
} |
|
921 |
}; |
|
922 |
||
923 |
void tst_QStyleSheetStyle::background() |
|
924 |
{ |
|
925 |
const int number = 4; |
|
926 |
QWidget* widgets[number]; |
|
927 |
// Testing inheritance styling of QDialog. |
|
928 |
widgets[0] = new SingleInheritanceDialog; |
|
929 |
widgets[0]->setStyleSheet("* { background-color: #e8ff66; }"); |
|
930 |
widgets[1] = new DoubleInheritanceDialog; |
|
931 |
widgets[1]->setStyleSheet("* { background-color: #e8ff66; }"); |
|
932 |
||
933 |
// Testing gradients in QComboBox. |
|
934 |
QLayout* layout; |
|
935 |
QComboBox* cb; |
|
936 |
// First color |
|
937 |
widgets[2] = new QDialog; |
|
938 |
layout = new QGridLayout; |
|
939 |
cb = new QComboBox; |
|
940 |
cb->setStyleSheet("* { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 #e8ff66, stop:1 #000000); }"); |
|
941 |
layout->addWidget(cb); |
|
942 |
widgets[2]->setLayout(layout); |
|
943 |
// Second color |
|
944 |
widgets[3] = new QDialog; |
|
945 |
layout = new QGridLayout; |
|
946 |
cb = new QComboBox; |
|
947 |
cb->setStyleSheet("* { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 #e8ff66, stop:1 #000000); }"); |
|
948 |
layout->addWidget(cb); |
|
949 |
widgets[3]->setLayout(layout); |
|
950 |
||
951 |
for (int c = 0; c < number; ++c) { |
|
952 |
QWidget* widget = widgets[c]; |
|
953 |
||
954 |
widget->show(); |
|
955 |
#ifdef Q_WS_X11 |
|
956 |
qt_x11_wait_for_window_manager(widget); |
|
957 |
#endif |
|
958 |
||
959 |
QImage image(widget->width(), widget->height(), QImage::Format_ARGB32); |
|
960 |
widget->render(&image); |
|
961 |
if (image.depth() < 24) { |
|
962 |
QSKIP("Test doesn't support color depth < 24", SkipAll); |
|
963 |
} |
|
964 |
||
965 |
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)), |
|
966 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
967 |
+ " did not contain background image with color #e8ff66") |
|
968 |
.toLocal8Bit().constData()); |
|
969 |
||
970 |
delete widget; |
|
971 |
} |
|
972 |
} |
|
973 |
||
974 |
void tst_QStyleSheetStyle::tabAlignement() |
|
975 |
{ |
|
976 |
QTabWidget tabWidget; |
|
977 |
tabWidget.addTab(new QLabel("tab1"),"tab1"); |
|
978 |
tabWidget.resize(QSize(400,400)); |
|
979 |
tabWidget.show(); |
|
980 |
QTest::qWaitForWindowShown(&tabWidget); |
|
981 |
QTest::qWait(50); |
|
982 |
QTabBar *bar = qFindChild<QTabBar*>(&tabWidget); |
|
983 |
QVERIFY(bar); |
|
984 |
//check the tab is on the right |
|
985 |
tabWidget.setStyleSheet("QTabWidget::tab-bar { alignment: right ; }"); |
|
986 |
qApp->processEvents(); |
|
987 |
QVERIFY(bar->geometry().right() > 380); |
|
988 |
QVERIFY(bar->geometry().left() > 200); |
|
989 |
//check the tab is on the middle |
|
990 |
tabWidget.setStyleSheet("QTabWidget::tab-bar { alignment: center ; }"); |
|
991 |
QVERIFY(bar->geometry().right() < 300); |
|
992 |
QVERIFY(bar->geometry().left() > 100); |
|
993 |
//check the tab is on the left |
|
994 |
tabWidget.setStyleSheet("QTabWidget::tab-bar { alignment: left ; }"); |
|
995 |
QVERIFY(bar->geometry().left() < 20); |
|
996 |
QVERIFY(bar->geometry().right() < 200); |
|
997 |
||
998 |
tabWidget.setTabPosition(QTabWidget::West); |
|
999 |
//check the tab is on the top |
|
1000 |
QVERIFY(bar->geometry().top() < 20); |
|
1001 |
QVERIFY(bar->geometry().bottom() < 200); |
|
1002 |
//check the tab is on the bottom |
|
1003 |
tabWidget.setStyleSheet("QTabWidget::tab-bar { alignment: right ; }"); |
|
1004 |
QVERIFY(bar->geometry().bottom() > 380); |
|
1005 |
QVERIFY(bar->geometry().top() > 200); |
|
1006 |
//check the tab is on the middle |
|
1007 |
tabWidget.setStyleSheet("QTabWidget::tab-bar { alignment: center ; }"); |
|
1008 |
QVERIFY(bar->geometry().bottom() < 300); |
|
1009 |
QVERIFY(bar->geometry().top() > 100); |
|
1010 |
} |
|
1011 |
||
1012 |
void tst_QStyleSheetStyle::attributesList() |
|
1013 |
{ |
|
1014 |
QWidget w; |
|
1015 |
QPushButton *p1=new QPushButton(&w); |
|
1016 |
QPushButton *p2=new QPushButton(&w); |
|
1017 |
QPushButton *p3=new QPushButton(&w); |
|
1018 |
QPushButton *p4=new QPushButton(&w); |
|
1019 |
p1->setProperty("prop", QStringList() << "red"); |
|
1020 |
p2->setProperty("prop", QStringList() << "foo" << "red"); |
|
1021 |
p3->setProperty("prop", QStringList() << "foo" << "bar"); |
|
1022 |
||
1023 |
w.setStyleSheet(" QPushButton{ background-color:blue; } QPushButton[prop~=red] { background-color:red; }"); |
|
1024 |
QCOMPARE(BACKGROUND(*p1) , QColor("red")); |
|
1025 |
QCOMPARE(BACKGROUND(*p2) , QColor("red")); |
|
1026 |
QCOMPARE(BACKGROUND(*p3) , QColor("blue")); |
|
1027 |
QCOMPARE(BACKGROUND(*p4) , QColor("blue")); |
|
1028 |
} |
|
1029 |
||
1030 |
void tst_QStyleSheetStyle::minmaxSizes() |
|
1031 |
{ |
|
1032 |
QTabWidget tabWidget; |
|
1033 |
tabWidget.setObjectName("tabWidget"); |
|
1034 |
int index1 = tabWidget.addTab(new QLabel("Tab1"),"a"); |
|
1035 |
||
1036 |
QWidget *page2=new QLabel("page2"); |
|
1037 |
page2->setObjectName("page2"); |
|
1038 |
page2->setStyleSheet("* {background-color: white; min-width: 250px; max-width:500px }"); |
|
1039 |
tabWidget.addTab(page2,"Tab2"); |
|
1040 |
QWidget *page3=new QLabel("plop"); |
|
1041 |
page3->setObjectName("Page3"); |
|
1042 |
page3->setStyleSheet("* {background-color: yellow; min-height: 250px; max-height:500px }"); |
|
1043 |
int index3 = tabWidget.addTab(page3,"very_long_long_long_long_caption"); |
|
1044 |
||
1045 |
tabWidget.setStyleSheet("QTabBar::tab { min-width:100px; max-width:130px; }"); |
|
1046 |
||
1047 |
tabWidget.show(); |
|
1048 |
QTest::qWait(50); |
|
1049 |
//i allow 4px additional border from the native style (hence the -2, <=2) |
|
1050 |
QVERIFY(qAbs(page2->maximumSize().width() - 500 - 2) <= 2); |
|
1051 |
QVERIFY(qAbs(page2->minimumSize().width() - 250 - 2) <= 2); |
|
1052 |
QVERIFY(qAbs(page3->maximumSize().height() - 500 - 2) <= 2); |
|
1053 |
QVERIFY(qAbs(page3->minimumSize().height() - 250 - 2) <= 2); |
|
1054 |
QVERIFY(qAbs(page3->minimumSize().height() - 250 - 2) <= 2); |
|
1055 |
QTabBar *bar = qFindChild<QTabBar*>(&tabWidget); |
|
1056 |
QVERIFY(bar); |
|
1057 |
QVERIFY(qAbs(bar->tabRect(index1).width() - 100 - 2) <= 2); |
|
1058 |
QVERIFY(qAbs(bar->tabRect(index3).width() - 130 - 2) <= 2); |
|
1059 |
} |
|
1060 |
||
1061 |
void tst_QStyleSheetStyle::task206238_twice() |
|
1062 |
{ |
|
1063 |
QMainWindow w; |
|
1064 |
QTabWidget* tw = new QTabWidget; |
|
1065 |
tw->addTab(new QLabel("foo"), "test"); |
|
1066 |
w.setCentralWidget(tw); |
|
1067 |
w.setStyleSheet("background: red;"); |
|
1068 |
w.show(); |
|
1069 |
QTest::qWait(20); |
|
1070 |
QCOMPARE(BACKGROUND(w) , QColor("red")); |
|
1071 |
QCOMPARE(BACKGROUND(*tw), QColor("red")); |
|
1072 |
w.setStyleSheet("background: red;"); |
|
1073 |
QTest::qWait(20); |
|
1074 |
QCOMPARE(BACKGROUND(w) , QColor("red")); |
|
1075 |
QCOMPARE(BACKGROUND(*tw), QColor("red")); |
|
1076 |
} |
|
1077 |
||
1078 |
void tst_QStyleSheetStyle::transparent() |
|
1079 |
{ |
|
1080 |
QWidget w; |
|
1081 |
QPushButton *p1=new QPushButton(&w); |
|
1082 |
QPushButton *p2=new QPushButton(&w); |
|
1083 |
QPushButton *p3=new QPushButton(&w); |
|
1084 |
p1->setStyleSheet("background:transparent"); |
|
1085 |
p2->setStyleSheet("background-color:transparent"); |
|
1086 |
p3->setStyleSheet("background:rgb(0,0,0,0)"); |
|
1087 |
QCOMPARE(BACKGROUND(*p1) , QColor(0,0,0,0)); |
|
1088 |
QCOMPARE(BACKGROUND(*p2) , QColor(0,0,0,0)); |
|
1089 |
QCOMPARE(BACKGROUND(*p3) , QColor(0,0,0,0)); |
|
1090 |
} |
|
1091 |
||
1092 |
||
1093 |
||
1094 |
class ProxyStyle : public QStyle |
|
1095 |
{ |
|
1096 |
public: |
|
1097 |
ProxyStyle(QStyle *s) |
|
1098 |
{ |
|
1099 |
style = s; |
|
1100 |
} |
|
1101 |
||
1102 |
void drawControl(ControlElement ce, const QStyleOption *opt, |
|
1103 |
QPainter *painter, const QWidget *widget = 0) const; |
|
1104 |
||
1105 |
void drawPrimitive(QStyle::PrimitiveElement pe, |
|
1106 |
const QStyleOption* opt, |
|
1107 |
QPainter* p , |
|
1108 |
const QWidget* w) const |
|
1109 |
{ |
|
1110 |
style->drawPrimitive(pe, opt, p, w); |
|
1111 |
} |
|
1112 |
||
1113 |
QRect subElementRect(QStyle::SubElement se, |
|
1114 |
const QStyleOption* opt, |
|
1115 |
const QWidget* w) const |
|
1116 |
{ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
Q_UNUSED(se); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1118 |
Q_UNUSED(opt); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1119 |
Q_UNUSED(w); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
return QRect(0, 0, 3, 3); |
0 | 1121 |
} |
1122 |
||
1123 |
void drawComplexControl(QStyle::ComplexControl cc, |
|
1124 |
const QStyleOptionComplex* opt, |
|
1125 |
QPainter* p, |
|
1126 |
const QWidget* w) const |
|
1127 |
{ |
|
1128 |
style->drawComplexControl(cc, opt, p, w); |
|
1129 |
} |
|
1130 |
||
1131 |
||
1132 |
SubControl hitTestComplexControl(QStyle::ComplexControl cc, |
|
1133 |
const QStyleOptionComplex* opt, |
|
1134 |
const QPoint& pt, |
|
1135 |
const QWidget* w) const |
|
1136 |
{ |
|
1137 |
return style->hitTestComplexControl(cc, opt, pt, w); |
|
1138 |
} |
|
1139 |
||
1140 |
QRect subControlRect(QStyle::ComplexControl cc, |
|
1141 |
const QStyleOptionComplex* opt, |
|
1142 |
QStyle::SubControl sc, |
|
1143 |
const QWidget* w) const |
|
1144 |
{ |
|
1145 |
return style->subControlRect(cc, opt, sc, w); |
|
1146 |
} |
|
1147 |
||
1148 |
int pixelMetric(QStyle::PixelMetric pm, |
|
1149 |
const QStyleOption* opt, |
|
1150 |
const QWidget* w) const |
|
1151 |
{ |
|
1152 |
return style->pixelMetric(pm, opt, w); |
|
1153 |
} |
|
1154 |
||
1155 |
||
1156 |
QSize sizeFromContents(QStyle::ContentsType ct, |
|
1157 |
const QStyleOption* opt, |
|
1158 |
const QSize& size, |
|
1159 |
const QWidget* w) const |
|
1160 |
{ |
|
1161 |
return style->sizeFromContents(ct, opt, size, w); |
|
1162 |
} |
|
1163 |
||
1164 |
int styleHint(QStyle::StyleHint sh, |
|
1165 |
const QStyleOption* opt, |
|
1166 |
const QWidget* w, |
|
1167 |
QStyleHintReturn* shr) const |
|
1168 |
{ |
|
1169 |
return style->styleHint(sh, opt, w, shr); |
|
1170 |
} |
|
1171 |
||
1172 |
QPixmap standardPixmap(QStyle::StandardPixmap spix, |
|
1173 |
const QStyleOption* opt, |
|
1174 |
const QWidget* w) const |
|
1175 |
{ |
|
1176 |
return style->standardPixmap(spix, opt, w); |
|
1177 |
} |
|
1178 |
||
1179 |
QPixmap generatedIconPixmap(QIcon::Mode mode, |
|
1180 |
const QPixmap& pix, |
|
1181 |
const QStyleOption* opt) const |
|
1182 |
{ |
|
1183 |
return style->generatedIconPixmap(mode, pix, opt); |
|
1184 |
} |
|
1185 |
||
1186 |
private: |
|
1187 |
QStyle *style; |
|
1188 |
}; |
|
1189 |
||
1190 |
void ProxyStyle::drawControl(ControlElement ce, const QStyleOption *opt, |
|
1191 |
QPainter *painter, const QWidget *widget) const |
|
1192 |
{ |
|
1193 |
if(ce == CE_PushButton) |
|
1194 |
{ |
|
1195 |
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) |
|
1196 |
{ |
|
1197 |
QRect r = btn->rect; |
|
1198 |
painter->fillRect(r, Qt::green); |
|
1199 |
||
1200 |
if(btn->state & QStyle::State_HasFocus) |
|
1201 |
painter->fillRect(r.adjusted(5, 5, -5, -5), Qt::yellow); |
|
1202 |
||
1203 |
||
1204 |
painter->drawText(r, Qt::AlignCenter, btn->text); |
|
1205 |
} |
|
1206 |
} |
|
1207 |
else |
|
1208 |
{ |
|
1209 |
style->drawControl(ce, opt, painter, widget); |
|
1210 |
} |
|
1211 |
} |
|
1212 |
||
1213 |
void tst_QStyleSheetStyle::proxyStyle() |
|
1214 |
{ |
|
1215 |
//Should not crash; task 158984 |
|
1216 |
||
1217 |
ProxyStyle *proxy = new ProxyStyle(qApp->style()); |
|
1218 |
QString styleSheet("QPushButton {background-color: red; }"); |
|
1219 |
||
1220 |
QWidget *w = new QWidget; |
|
1221 |
QVBoxLayout *layout = new QVBoxLayout(w); |
|
1222 |
||
1223 |
QPushButton *pb1 = new QPushButton(qApp->style()->objectName(), w); |
|
1224 |
layout->addWidget(pb1); |
|
1225 |
||
1226 |
QPushButton *pb2 = new QPushButton("ProxyStyle", w); |
|
1227 |
pb2->setStyle(proxy); |
|
1228 |
layout->addWidget(pb2); |
|
1229 |
||
1230 |
QPushButton *pb3 = new QPushButton("StyleSheet", w); |
|
1231 |
pb3->setStyleSheet(styleSheet); |
|
1232 |
layout->addWidget(pb3); |
|
1233 |
||
1234 |
QPushButton *pb4 = new QPushButton("StyleSheet then ProxyStyle ", w); |
|
1235 |
pb4->setStyleSheet(styleSheet); |
|
1236 |
||
1237 |
// We are creating our Proxy based on current style... |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1238 |
// In this case it would be the QStyleSheetStyle that is deleted |
0 | 1239 |
// later on. We need to get access to the "real" QStyle to be able to |
1240 |
// draw correctly. |
|
1241 |
ProxyStyle* newProxy = new ProxyStyle(qApp->style()); |
|
1242 |
pb4->setStyle(newProxy); |
|
1243 |
||
1244 |
layout->addWidget(pb4); |
|
1245 |
||
1246 |
QPushButton *pb5 = new QPushButton("ProxyStyle then StyleSheet ", w); |
|
1247 |
pb5->setStyle(proxy); |
|
1248 |
pb5->setStyleSheet(styleSheet); |
|
1249 |
layout->addWidget(pb5); |
|
1250 |
||
1251 |
w->show(); |
|
1252 |
||
1253 |
QTest::qWait(100); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1254 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1255 |
// Test for QTBUG-7198 - style sheet overrides custom element size |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1256 |
QStyleOptionViewItemV4 opt; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1257 |
opt.initFrom(w); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1258 |
opt.features |= QStyleOptionViewItemV2::HasCheckIndicator; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1259 |
QVERIFY(pb5->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1260 |
&opt, pb5).width() == 3); |
0 | 1261 |
delete w; |
1262 |
delete proxy; |
|
1263 |
delete newProxy; |
|
1264 |
} |
|
1265 |
||
1266 |
void tst_QStyleSheetStyle::dialogButtonBox() |
|
1267 |
{ |
|
1268 |
QDialogButtonBox box; |
|
1269 |
box.addButton(QDialogButtonBox::Ok); |
|
1270 |
box.addButton(QDialogButtonBox::Cancel); |
|
1271 |
box.setStyleSheet("/** */ "); |
|
1272 |
box.setStyleSheet(QString()); //should not crash |
|
1273 |
} |
|
1274 |
||
1275 |
void tst_QStyleSheetStyle::emptyStyleSheet() |
|
1276 |
{ |
|
1277 |
//empty stylesheet should not change anything |
|
1278 |
qApp->setStyleSheet(QString()); |
|
1279 |
QWidget w; |
|
1280 |
QHBoxLayout layout(&w); |
|
1281 |
w.setLayout(&layout); |
|
1282 |
#ifdef QT3_SUPPORT |
|
1283 |
layout.addWidget(new Q3ProgressBar(&w)); //task 231137 |
|
1284 |
#endif |
|
1285 |
layout.addWidget(new QPushButton("push", &w)); |
|
1286 |
layout.addWidget(new QToolButton(&w)); |
|
1287 |
QLabel label("toto", &w); |
|
1288 |
label.setFrameShape(QLabel::Panel); |
|
1289 |
label.setFrameShadow(QLabel::Sunken); |
|
1290 |
layout.addWidget(&label); //task 231137 |
|
1291 |
layout.addWidget(new QTableWidget(200,200, &w)); |
|
1292 |
layout.addWidget(new QProgressBar(&w)); |
|
1293 |
layout.addWidget(new QLineEdit(&w)); |
|
1294 |
layout.addWidget(new QSpinBox(&w)); |
|
1295 |
layout.addWidget(new QComboBox(&w)); |
|
1296 |
layout.addWidget(new QDateEdit(&w)); |
|
1297 |
layout.addWidget(new QGroupBox("some text", &w)); |
|
1298 |
||
1299 |
w.show(); |
|
1300 |
#ifdef Q_WS_X11 |
|
1301 |
qt_x11_wait_for_window_manager(&w); |
|
1302 |
#endif |
|
1303 |
//workaround the fact that the label sizehint is one pixel different the first time. |
|
1304 |
label.setIndent(0); //force to recompute the sizeHint: |
|
1305 |
w.setFocus(); |
|
1306 |
QTest::qWait(100); |
|
1307 |
||
1308 |
QImage img1(w.size(), QImage::Format_ARGB32); |
|
1309 |
w.render(&img1); |
|
1310 |
||
1311 |
w.setStyleSheet("/* */"); |
|
1312 |
QTest::qWait(100); |
|
1313 |
||
1314 |
QImage img2(w.size(), QImage::Format_ARGB32); |
|
1315 |
w.render(&img2); |
|
1316 |
||
1317 |
if(img1 != img2) { |
|
1318 |
img1.save("emptyStyleSheet_img1.png"); |
|
1319 |
img2.save("emptyStyleSheet_img2.png"); |
|
1320 |
} |
|
1321 |
||
1322 |
QCOMPARE(img1,img2); |
|
1323 |
} |
|
1324 |
||
1325 |
void tst_QStyleSheetStyle::toolTip() |
|
1326 |
{ |
|
1327 |
qApp->setStyleSheet(QString()); |
|
1328 |
QWidget w; |
|
1329 |
QHBoxLayout layout(&w); |
|
1330 |
w.setLayout(&layout); |
|
1331 |
||
1332 |
QWidget *wid1 = new QGroupBox(&w); |
|
1333 |
layout.addWidget(wid1); |
|
1334 |
wid1->setStyleSheet("QToolTip { background: #ae2; } #wid3 > QToolTip { background: #0b8; } "); |
|
1335 |
QVBoxLayout *layout1 = new QVBoxLayout(wid1); |
|
1336 |
wid1->setLayout(layout1); |
|
1337 |
wid1->setToolTip("this is wid1"); |
|
1338 |
wid1->setObjectName("wid1"); |
|
1339 |
||
1340 |
QWidget *wid2 = new QPushButton("wid2", wid1); |
|
1341 |
layout1->addWidget(wid2); |
|
1342 |
wid2->setStyleSheet("QToolTip { background: #f81; } "); |
|
1343 |
wid2->setToolTip("this is wid2"); |
|
1344 |
wid2->setObjectName("wid2"); |
|
1345 |
||
1346 |
QWidget *wid3 = new QPushButton("wid3", wid1); |
|
1347 |
layout1->addWidget(wid3); |
|
1348 |
wid3->setToolTip("this is wid3"); |
|
1349 |
wid3->setObjectName("wid3"); |
|
1350 |
||
1351 |
QWidget *wid4 = new QPushButton("wid4", &w); |
|
1352 |
layout.addWidget(wid4); |
|
1353 |
wid4->setToolTip("this is wid4"); |
|
1354 |
wid4->setObjectName("wid4"); |
|
1355 |
||
1356 |
w.show(); |
|
1357 |
QTest::qWait(100); |
|
1358 |
||
1359 |
QColor normalToolTip = qApp->palette().toolTipBase().color(); |
|
1360 |
QList<QWidget *> widgets; |
|
1361 |
QList<QColor> colors; |
|
1362 |
||
1363 |
||
1364 |
//tooltip on the widget without stylesheet, then to othes widget, including one without stylesheet |
|
1365 |
//(the tooltip will be reused but his colour must change) |
|
1366 |
widgets << wid4 << wid1 << wid2 << wid3 << wid4; |
|
1367 |
colors << normalToolTip << "#ae2" << "#f81" << "#0b8" << normalToolTip; |
|
1368 |
||
1369 |
for (int i = 0; i < widgets.count() ; i++) |
|
1370 |
{ |
|
1371 |
QWidget *wid = widgets.at(i); |
|
1372 |
QColor col = colors.at(i); |
|
1373 |
||
1374 |
QToolTip::showText( QPoint(0,0) , "This is " + wid->objectName(), wid); |
|
1375 |
||
1376 |
QWidget *tooltip = 0; |
|
1377 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
|
1378 |
if (widget->inherits("QTipLabel") && widget->isVisible()) { |
|
1379 |
tooltip = widget; |
|
1380 |
break; |
|
1381 |
} |
|
1382 |
} |
|
1383 |
QVERIFY(tooltip); |
|
1384 |
QCOMPARE(tooltip->palette().color(tooltip->backgroundRole()), col); |
|
1385 |
} |
|
1386 |
||
1387 |
QToolTip::showText( QPoint(0,0) , "This is " + wid3->objectName(), wid3); |
|
1388 |
QTest::qWait(100); |
|
1389 |
delete wid3; //should not crash; |
|
1390 |
QTest::qWait(10); |
|
1391 |
foreach (QWidget *widget, QApplication::topLevelWidgets()) { |
|
1392 |
widget->update(); //should not crash either |
|
1393 |
} |
|
1394 |
} |
|
1395 |
||
1396 |
void tst_QStyleSheetStyle::embeddedFonts() |
|
1397 |
{ |
|
1398 |
//task 235622 and 210551 |
|
1399 |
QSpinBox spin; |
|
1400 |
spin.show(); |
|
1401 |
spin.setStyleSheet("QSpinBox { font-size: 32px; }"); |
|
1402 |
QTest::qWait(20); |
|
1403 |
QLineEdit *embedded = spin.findChild<QLineEdit *>(); |
|
1404 |
QVERIFY(embedded); |
|
1405 |
QCOMPARE(spin.font().pixelSize(), 32); |
|
1406 |
QCOMPARE(embedded->font().pixelSize(), 32); |
|
1407 |
||
1408 |
QMenu *menu = embedded->createStandardContextMenu(); |
|
1409 |
menu->show(); |
|
1410 |
QTest::qWait(20); |
|
1411 |
QVERIFY(menu); |
|
1412 |
QVERIFY(menu->font().pixelSize() != 32); |
|
1413 |
QCOMPARE(menu->font().pixelSize(), qApp->font(menu).pixelSize()); |
|
1414 |
||
1415 |
//task 242556 |
|
1416 |
QComboBox box; |
|
1417 |
box.setEditable(true); |
|
1418 |
box.addItems(QStringList() << "First" << "Second" << "Third"); |
|
1419 |
box.setStyleSheet("QComboBox { font-size: 32px; }"); |
|
1420 |
box.show(); |
|
1421 |
embedded = box.findChild<QLineEdit *>(); |
|
1422 |
QVERIFY(embedded); |
|
1423 |
QTest::qWait(20); |
|
1424 |
QCOMPARE(box.font().pixelSize(), 32); |
|
1425 |
QCOMPARE(embedded->font().pixelSize(), 32); |
|
1426 |
} |
|
1427 |
||
1428 |
void tst_QStyleSheetStyle::opaquePaintEvent_data() |
|
1429 |
{ |
|
1430 |
QTest::addColumn<QString>("stylesheet"); |
|
1431 |
QTest::addColumn<bool>("transparent"); |
|
1432 |
QTest::addColumn<bool>("styled"); |
|
1433 |
||
1434 |
QTest::newRow("none") << QString::fromLatin1("/* */") << false << false; |
|
1435 |
QTest::newRow("background black ") << QString::fromLatin1("background: black;") << false << true; |
|
1436 |
QTest::newRow("background qrgba") << QString::fromLatin1("background: rgba(125,0,0,125);") << true << true; |
|
1437 |
QTest::newRow("background transparent") << QString::fromLatin1("background: transparent;") << true << true; |
|
1438 |
QTest::newRow("border native") << QString::fromLatin1("border: native;") << false << false; |
|
1439 |
QTest::newRow("border solid") << QString::fromLatin1("border: 2px solid black;") << true << true; |
|
1440 |
QTest::newRow("border transparent") << QString::fromLatin1("background: black; border: 2px solid rgba(125,0,0,125);") << true << true; |
|
1441 |
QTest::newRow("margin") << QString::fromLatin1("margin: 25px;") << true << true; |
|
1442 |
QTest::newRow("focus") << QString::fromLatin1("*:focus { background: rgba(125,0,0,125) }") << true << true; |
|
1443 |
} |
|
1444 |
||
1445 |
void tst_QStyleSheetStyle::opaquePaintEvent() |
|
1446 |
{ |
|
1447 |
QFETCH(QString, stylesheet); |
|
1448 |
QFETCH(bool, transparent); |
|
1449 |
QFETCH(bool, styled); |
|
1450 |
||
1451 |
QWidget tl; |
|
1452 |
QWidget cl(&tl); |
|
1453 |
cl.setAttribute(Qt::WA_OpaquePaintEvent, true); |
|
1454 |
cl.setAutoFillBackground(true); |
|
1455 |
cl.setStyleSheet(stylesheet); |
|
1456 |
cl.ensurePolished(); |
|
1457 |
QCOMPARE(cl.testAttribute(Qt::WA_OpaquePaintEvent), !transparent); |
|
1458 |
QCOMPARE(cl.testAttribute(Qt::WA_StyledBackground), styled); |
|
1459 |
QCOMPARE(cl.autoFillBackground(), !styled ); |
|
1460 |
} |
|
1461 |
||
1462 |
void tst_QStyleSheetStyle::complexWidgetFocus() |
|
1463 |
{ |
|
1464 |
// This test is a simplified version of the focusColors() test above. |
|
1465 |
||
1466 |
// Tests if colors can be changed by altering the focus of the widget. |
|
1467 |
// To avoid messy pixel-by-pixel comparison, we assume that the goal |
|
1468 |
// is reached if at least ten pixels of the right color can be found in |
|
1469 |
// the image. |
|
1470 |
// For this reason, we use unusual and extremely ugly colors! :-) |
|
1471 |
||
1472 |
QDialog frame; |
|
1473 |
frame.setStyleSheet("*:focus { background: black; color: black } " |
|
1474 |
"QSpinBox::up-arrow:focus, QSpinBox::down-arrow:focus { width: 7px; height: 7px; background: #ff0084 } " |
|
1475 |
"QComboBox::down-arrow:focus { width: 7px; height: 7px; background: #ff0084 }" |
|
1476 |
"QSlider::handle:horizontal:focus { width: 7px; height: 7px; background: #ff0084 } "); |
|
1477 |
||
1478 |
QList<QWidget *> widgets; |
|
1479 |
widgets << new QSpinBox; |
|
1480 |
widgets << new QComboBox; |
|
1481 |
widgets << new QSlider(Qt::Horizontal); |
|
1482 |
||
1483 |
QLayout* layout = new QGridLayout; |
|
1484 |
layout->addWidget(new QLineEdit); // Avoids initial focus. |
|
1485 |
foreach (QWidget *widget, widgets) |
|
1486 |
layout->addWidget(widget); |
|
1487 |
frame.setLayout(layout); |
|
1488 |
||
1489 |
frame.show(); |
|
1490 |
QTest::qWaitForWindowShown(&frame); |
|
1491 |
QApplication::setActiveWindow(&frame); |
|
1492 |
foreach (QWidget *widget, widgets) { |
|
1493 |
widget->setFocus(); |
|
1494 |
QApplication::processEvents(); |
|
1495 |
||
1496 |
QImage image(frame.width(), frame.height(), QImage::Format_ARGB32); |
|
1497 |
frame.render(&image); |
|
1498 |
if (image.depth() < 24) { |
|
1499 |
QSKIP("Test doesn't support color depth < 24", SkipAll); |
|
1500 |
} |
|
1501 |
||
1502 |
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), |
|
1503 |
(QString::fromLatin1(widget->metaObject()->className()) |
|
1504 |
+ " did not contain text color #ff0084, using style " |
|
1505 |
+ QString::fromLatin1(qApp->style()->metaObject()->className())) |
|
1506 |
.toLocal8Bit().constData()); |
|
1507 |
} |
|
1508 |
} |
|
1509 |
||
1510 |
void tst_QStyleSheetStyle::task188195_baseBackground() |
|
1511 |
{ |
|
1512 |
QTreeView tree; |
|
1513 |
tree.setStyleSheet( "QTreeView:disabled { background-color:#ab1251; }" ); |
|
1514 |
tree.show(); |
|
1515 |
QTest::qWait(20); |
|
1516 |
QImage image(tree.width(), tree.height(), QImage::Format_ARGB32); |
|
1517 |
||
1518 |
tree.render(&image); |
|
1519 |
QVERIFY(testForColors(image, tree.palette().base().color())); |
|
1520 |
QVERIFY(!testForColors(image, QColor(0xab, 0x12, 0x51))); |
|
1521 |
||
1522 |
tree.setEnabled(false); |
|
1523 |
tree.render(&image); |
|
1524 |
QVERIFY(testForColors(image, QColor(0xab, 0x12, 0x51))); |
|
1525 |
||
1526 |
tree.setEnabled(true); |
|
1527 |
tree.render(&image); |
|
1528 |
QVERIFY(testForColors(image, tree.palette().base().color())); |
|
1529 |
QVERIFY(!testForColors(image, QColor(0xab, 0x12, 0x51))); |
|
1530 |
} |
|
1531 |
||
1532 |
void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg() |
|
1533 |
{ |
|
1534 |
// This test is a simplified version of the focusColors() test above. |
|
1535 |
||
1536 |
// Tests if colors can be changed by altering the focus of the widget. |
|
1537 |
// To avoid messy pixel-by-pixel comparison, we assume that the goal |
|
1538 |
// is reached if at least ten pixels of the right color can be found in |
|
1539 |
// the image. |
|
1540 |
// For this reason, we use unusual and extremely ugly colors! :-) |
|
1541 |
||
1542 |
QSpinBox *spinbox = new QSpinBox; |
|
1543 |
spinbox->setValue(8888); |
|
1544 |
||
1545 |
QDialog frame; |
|
1546 |
QLayout* layout = new QGridLayout; |
|
1547 |
||
1548 |
QLineEdit* dummy = new QLineEdit; // Avoids initial focus. |
|
1549 |
||
1550 |
// We only want to test the line edit colors. |
|
1551 |
spinbox->setStyleSheet("QSpinBox:focus { background: #e8ff66; color: #ff0084 } " |
|
1552 |
"QSpinBox::up-button, QSpinBox::down-button { background: black; }"); |
|
1553 |
||
1554 |
layout->addWidget(dummy); |
|
1555 |
layout->addWidget(spinbox); |
|
1556 |
frame.setLayout(layout); |
|
1557 |
||
1558 |
frame.show(); |
|
1559 |
QTest::qWaitForWindowShown(&frame); |
|
1560 |
QApplication::setActiveWindow(&frame); |
|
1561 |
spinbox->setFocus(); |
|
1562 |
QApplication::processEvents(); |
|
1563 |
||
1564 |
QImage image(frame.width(), frame.height(), QImage::Format_ARGB32); |
|
1565 |
frame.render(&image); |
|
1566 |
if (image.depth() < 24) { |
|
1567 |
QSKIP("Test doesn't support color depth < 24", SkipAll); |
|
1568 |
} |
|
1569 |
||
1570 |
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)), |
|
1571 |
(QString::fromLatin1(spinbox->metaObject()->className()) |
|
1572 |
+ " did not contain background color #e8ff66, using style " |
|
1573 |
+ QString::fromLatin1(qApp->style()->metaObject()->className())) |
|
1574 |
.toLocal8Bit().constData()); |
|
1575 |
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), |
|
1576 |
(QString::fromLatin1(spinbox->metaObject()->className()) |
|
1577 |
+ " did not contain text color #ff0084, using style " |
|
1578 |
+ QString::fromLatin1(qApp->style()->metaObject()->className())) |
|
1579 |
.toLocal8Bit().constData()); |
|
1580 |
} |
|
1581 |
||
1582 |
QTEST_MAIN(tst_QStyleSheetStyle) |
|
1583 |
#include "tst_qstylesheetstyle.moc" |
|
1584 |