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