author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 5 | d3bac044e0f0 |
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 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qlayout.h> |
|
45 |
#include "qstyle.h" |
|
46 |
#include <qevent.h> |
|
47 |
#include <qpainter.h> |
|
48 |
#include <qpixmap.h> |
|
49 |
#include <qapplication.h> |
|
50 |
#include <qwidget.h> |
|
51 |
#include <qlabel.h> |
|
52 |
#include <qstyleoption.h> |
|
53 |
#include <qscrollbar.h> |
|
54 |
#include <qprogressbar.h> |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
55 |
#include <qtoolbutton.h> |
0 | 56 |
|
57 |
#include <qplastiquestyle.h> |
|
58 |
#include <qwindowsstyle.h> |
|
59 |
#include <qcdestyle.h> |
|
60 |
#include <qmotifstyle.h> |
|
61 |
#include <qcommonstyle.h> |
|
62 |
#include <qproxystyle.h> |
|
63 |
#include <qstylefactory.h> |
|
64 |
||
65 |
#include <qimagereader.h> |
|
66 |
#include <qimagewriter.h> |
|
67 |
#include <qmenu.h> |
|
68 |
#include <qpushbutton.h> |
|
69 |
#include <qspinbox.h> |
|
70 |
#include <qcombobox.h> |
|
71 |
#include <qradiobutton.h> |
|
72 |
#include <qlineedit.h> |
|
73 |
#include <qmdiarea.h> |
|
74 |
||
75 |
#if defined(Q_OS_SYMBIAN) |
|
76 |
#define SRCDIR "." |
|
77 |
#endif |
|
78 |
||
79 |
#include <QCleanlooksStyle> |
|
80 |
||
81 |
#ifdef Q_WS_MAC |
|
82 |
#include <QMacStyle> |
|
83 |
#endif |
|
84 |
||
85 |
#ifdef Q_WS_WIN |
|
86 |
#include <QWindowsXPStyle> |
|
87 |
#include <QWindowsVistaStyle> |
|
88 |
#endif |
|
89 |
||
90 |
#ifdef Q_OS_WINCE |
|
91 |
#include <QWindowsCEStyle> |
|
92 |
#endif |
|
93 |
||
94 |
#ifdef Q_OS_WINCE_WM |
|
95 |
#include <QWindowsMobileStyle> |
|
96 |
#include <windows.h> |
|
97 |
||
98 |
static bool qt_wince_is_smartphone() { |
|
99 |
wchar_t tszPlatform[64]; |
|
100 |
if (SystemParametersInfo(SPI_GETPLATFORMTYPE, |
|
101 |
sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0)) |
|
102 |
if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (QString::fromLatin1("Smartphone").utf16()), tszPlatform)) |
|
103 |
return true; |
|
104 |
return false; |
|
105 |
} |
|
106 |
#endif |
|
107 |
||
108 |
#ifdef Q_WS_S60 |
|
109 |
#include <qs60style.h> |
|
110 |
#endif |
|
111 |
||
112 |
#include <qwidget.h> |
|
113 |
||
114 |
//TESTED_CLASS= |
|
115 |
//TESTED_FILES=gui/styles/qstyle.h gui/styles/qstyle.cpp gui/styles/qplastiquestyle.cpp gui/styles/qwindowsstyle.cpp gui/styles/qwindowsxpstyle.cpp gui/styles/qwindowsvistastyle.cpp gui/styles/qmotifstyle.cpp gui/styles/qs60style.cpp |
|
116 |
||
117 |
class tst_QStyle : public QObject |
|
118 |
{ |
|
119 |
Q_OBJECT |
|
120 |
public: |
|
121 |
tst_QStyle(); |
|
122 |
virtual ~tst_QStyle(); |
|
123 |
private: |
|
124 |
void testAllFunctions(QStyle *); |
|
125 |
void testScrollBarSubControls(QStyle *); |
|
126 |
void testPainting(QStyle *style, const QString &platform); |
|
127 |
private slots: |
|
128 |
void drawItemPixmap(); |
|
129 |
void initTestCase(); |
|
130 |
void cleanupTestCase(); |
|
131 |
void init(); |
|
132 |
void cleanup(); |
|
133 |
void testMotifStyle(); |
|
134 |
void testPlastiqueStyle(); |
|
135 |
void testWindowsStyle(); |
|
136 |
void testCDEStyle(); |
|
137 |
void testWindowsXPStyle(); |
|
138 |
void testWindowsVistaStyle(); |
|
139 |
void testCleanlooksStyle(); |
|
140 |
void testMacStyle(); |
|
141 |
void testWindowsCEStyle(); |
|
142 |
void testWindowsMobileStyle(); |
|
143 |
void testS60Style(); |
|
144 |
void testStyleFactory(); |
|
145 |
void testProxyStyle(); |
|
146 |
void pixelMetric(); |
|
147 |
void progressBarChangeStyle(); |
|
148 |
void defaultFont(); |
|
149 |
private: |
|
150 |
void lineUpLayoutTest(QStyle *); |
|
151 |
QWidget *testWidget; |
|
152 |
}; |
|
153 |
||
154 |
||
155 |
tst_QStyle::tst_QStyle() |
|
156 |
{ |
|
157 |
testWidget = 0; |
|
158 |
} |
|
159 |
||
160 |
tst_QStyle::~tst_QStyle() |
|
161 |
{ |
|
162 |
} |
|
163 |
||
164 |
class MyWidget : public QWidget |
|
165 |
{ |
|
166 |
public: |
|
167 |
MyWidget( QWidget* QWidget=0, const char* name=0 ); |
|
168 |
protected: |
|
169 |
void paintEvent( QPaintEvent* ); |
|
170 |
}; |
|
171 |
||
172 |
void tst_QStyle::init() |
|
173 |
{ |
|
174 |
testWidget = new MyWidget( 0, "testObject"); |
|
175 |
} |
|
176 |
||
177 |
void tst_QStyle::cleanup() |
|
178 |
{ |
|
179 |
delete testWidget; |
|
180 |
testWidget = 0; |
|
181 |
} |
|
182 |
||
183 |
void tst_QStyle::initTestCase() |
|
184 |
{ |
|
185 |
} |
|
186 |
||
187 |
void tst_QStyle::cleanupTestCase() |
|
188 |
{ |
|
189 |
} |
|
190 |
||
191 |
void tst_QStyle::testStyleFactory() |
|
192 |
{ |
|
193 |
QStringList keys = QStyleFactory::keys(); |
|
194 |
#ifndef QT_NO_STYLE_MOTIF |
|
195 |
QVERIFY(keys.contains("Motif")); |
|
196 |
#endif |
|
197 |
#ifndef QT_NO_STYLE_CLEANLOOKS |
|
198 |
QVERIFY(keys.contains("Cleanlooks")); |
|
199 |
#endif |
|
200 |
#ifndef QT_NO_STYLE_PLASTIQUE |
|
201 |
QVERIFY(keys.contains("Plastique")); |
|
202 |
#endif |
|
203 |
#ifndef QT_NO_STYLE_CDE |
|
204 |
QVERIFY(keys.contains("CDE")); |
|
205 |
#endif |
|
206 |
#ifndef QT_NO_STYLE_WINDOWS |
|
207 |
QVERIFY(keys.contains("Windows")); |
|
208 |
#endif |
|
209 |
#ifndef QT_NO_STYLE_MOTIF |
|
210 |
QVERIFY(keys.contains("Motif")); |
|
211 |
#endif |
|
212 |
#ifdef Q_WS_WIN |
|
213 |
if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && |
|
214 |
QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) |
|
215 |
QVERIFY(keys.contains("WindowsXP")); |
|
216 |
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && |
|
217 |
QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) |
|
218 |
QVERIFY(keys.contains("WindowsVista")); |
|
219 |
#endif |
|
220 |
||
221 |
foreach (QString styleName , keys) { |
|
222 |
QStyle *style = QStyleFactory::create(styleName); |
|
223 |
QVERIFY2(style != 0, qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName))); |
|
224 |
delete style; |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
class CustomProxy : public QProxyStyle |
|
229 |
{ |
|
230 |
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, |
|
231 |
const QWidget *widget = 0) const |
|
232 |
{ |
|
233 |
if (metric == QStyle::PM_ButtonIconSize) |
|
234 |
return 13; |
|
235 |
return QProxyStyle::pixelMetric(metric, option, widget); |
|
236 |
} |
|
237 |
}; |
|
238 |
||
239 |
void tst_QStyle::testProxyStyle() |
|
240 |
{ |
|
241 |
QProxyStyle *proxyStyle = new QProxyStyle(); |
|
242 |
QVERIFY(proxyStyle->baseStyle()); |
|
243 |
QStyle *style = new QWindowsStyle; |
|
244 |
QVERIFY(style->proxy() == style); |
|
245 |
||
246 |
proxyStyle->setBaseStyle(style); |
|
247 |
QVERIFY(style->proxy() == proxyStyle); |
|
248 |
QVERIFY(style->parent() == proxyStyle); |
|
249 |
QVERIFY(proxyStyle->baseStyle() == style); |
|
250 |
||
251 |
testAllFunctions(proxyStyle); |
|
252 |
proxyStyle->setBaseStyle(0); |
|
253 |
QVERIFY(proxyStyle->baseStyle()); |
|
254 |
qApp->setStyle(proxyStyle); |
|
255 |
||
256 |
QProxyStyle doubleProxy(new QProxyStyle(new QWindowsStyle())); |
|
257 |
testAllFunctions(&doubleProxy); |
|
258 |
||
259 |
CustomProxy customStyle; |
|
260 |
QLineEdit edit; |
|
261 |
edit.setStyle(&customStyle); |
|
262 |
QVERIFY(!customStyle.parent()); |
|
263 |
QVERIFY(edit.style()->pixelMetric(QStyle::PM_ButtonIconSize) == 13); |
|
264 |
} |
|
265 |
||
266 |
void tst_QStyle::drawItemPixmap() |
|
267 |
{ |
|
268 |
testWidget->resize(300, 300); |
|
269 |
testWidget->show(); |
|
270 |
||
271 |
QPixmap p(QString(SRCDIR) + "/task_25863.png", "PNG"); |
|
272 |
QPixmap actualPix = QPixmap::grabWidget(testWidget); |
|
273 |
QVERIFY(pixmapsAreEqual(&actualPix,&p)); |
|
274 |
testWidget->hide(); |
|
275 |
} |
|
276 |
||
277 |
void tst_QStyle::testAllFunctions(QStyle *style) |
|
278 |
{ |
|
279 |
QStyleOption opt; |
|
280 |
opt.init(testWidget); |
|
281 |
||
282 |
testWidget->setStyle(style); |
|
283 |
||
284 |
//Tests styleHint with default arguments for potential crashes |
|
285 |
for ( int hint = 0 ; hint < int(QStyle::SH_Menu_Mask); ++hint) { |
|
286 |
style->styleHint(QStyle::StyleHint(hint)); |
|
287 |
style->styleHint(QStyle::StyleHint(hint), &opt, testWidget); |
|
288 |
} |
|
289 |
||
290 |
//Tests pixelMetric with default arguments for potential crashes |
|
291 |
for ( int pm = 0 ; pm < int(QStyle::PM_LayoutVerticalSpacing); ++pm) { |
|
292 |
style->pixelMetric(QStyle::PixelMetric(pm)); |
|
293 |
style->pixelMetric(QStyle::PixelMetric(pm), &opt, testWidget); |
|
294 |
} |
|
295 |
||
296 |
//Tests drawControl with default arguments for potential crashes |
|
297 |
for ( int control = 0 ; control < int(QStyle::CE_ColumnViewGrip); ++control) { |
|
298 |
QPixmap surface(QSize(200, 200)); |
|
299 |
QPainter painter(&surface); |
|
300 |
style->drawControl(QStyle::ControlElement(control), &opt, &painter, 0); |
|
301 |
} |
|
302 |
||
303 |
//Tests drawComplexControl with default arguments for potential crashes |
|
304 |
{ |
|
305 |
QPixmap surface(QSize(200, 200)); |
|
306 |
QPainter painter(&surface); |
|
307 |
QStyleOptionComboBox copt1; |
|
308 |
copt1.init(testWidget); |
|
309 |
||
310 |
QStyleOptionGroupBox copt2; |
|
311 |
copt2.init(testWidget); |
|
312 |
QStyleOptionSizeGrip copt3; |
|
313 |
copt3.init(testWidget); |
|
314 |
QStyleOptionSlider copt4; |
|
315 |
copt4.init(testWidget); |
|
316 |
copt4.minimum = 0; |
|
317 |
copt4.maximum = 100; |
|
318 |
copt4.tickInterval = 25; |
|
319 |
copt4.sliderValue = 50; |
|
320 |
QStyleOptionSpinBox copt5; |
|
321 |
copt5.init(testWidget); |
|
322 |
QStyleOptionTitleBar copt6; |
|
323 |
copt6.init(testWidget); |
|
324 |
QStyleOptionToolButton copt7; |
|
325 |
copt7.init(testWidget); |
|
326 |
QStyleOptionQ3ListView copt8; |
|
327 |
copt8.init(testWidget); |
|
328 |
copt8.items << QStyleOptionQ3ListViewItem(); |
|
329 |
QStyleOptionComplex copt9; |
|
330 |
copt9.initFrom(testWidget); |
|
331 |
||
332 |
style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, 0); |
|
333 |
style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, 0); |
|
334 |
style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, 0); |
|
335 |
style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, 0); |
|
336 |
style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, 0); |
|
337 |
style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, 0); |
|
338 |
style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, 0); |
|
339 |
style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, 0); |
|
340 |
#ifdef QT3_SUPPORT |
|
341 |
style->drawComplexControl(QStyle::CC_Q3ListView, &copt8, &painter, 0); |
|
342 |
style->drawComplexControl(QStyle::CC_MdiControls, &copt9, &painter, 0); |
|
343 |
#endif |
|
344 |
} |
|
345 |
||
346 |
//Check standard pixmaps/icons |
|
347 |
for ( int i = 0 ; i < int(QStyle::SP_ToolBarVerticalExtensionButton); ++i) { |
|
348 |
QPixmap pixmap = style->standardPixmap(QStyle::StandardPixmap(i)); |
|
349 |
if (pixmap.isNull()) { |
|
350 |
qWarning("missing StandardPixmap: %d", i); |
|
351 |
} |
|
352 |
QIcon icn = style->standardIcon(QStyle::StandardPixmap(i)); |
|
353 |
if (icn.isNull()) { |
|
354 |
qWarning("missing StandardIcon: %d", i); |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
style->itemPixmapRect(QRect(0, 0, 100, 100), Qt::AlignHCenter, QPixmap(200, 200)); |
|
359 |
style->itemTextRect(QFontMetrics(qApp->font()), QRect(0, 0, 100, 100), Qt::AlignHCenter, true, QString("Test")); |
|
360 |
||
361 |
testScrollBarSubControls(style); |
|
362 |
} |
|
363 |
||
364 |
void tst_QStyle::testScrollBarSubControls(QStyle* style) |
|
365 |
{ |
|
366 |
#ifdef Q_OS_WINCE_WM |
|
367 |
if (qobject_cast<QWindowsMobileStyle*>(style) && qt_wince_is_smartphone()) |
|
368 |
QSKIP("SmartPhone doesn't have scrollbar subcontrols.", SkipAll); |
|
369 |
#endif |
|
370 |
||
371 |
QScrollBar scrollBar; |
|
372 |
scrollBar.show(); |
|
373 |
const QStyleOptionSlider opt = qt_qscrollbarStyleOption(&scrollBar); |
|
374 |
foreach (int subControl, QList<int>() << 1 << 2 << 4 << 8) { |
|
375 |
||
376 |
#ifdef Q_WS_S60 |
|
377 |
// in s60style add line and sub line have been removed. |
|
378 |
if (subControl == QStyle::SC_ScrollBarAddLine || subControl == QStyle::SC_ScrollBarSubLine ) |
|
379 |
continue; |
|
380 |
#endif |
|
381 |
QRect sr = testWidget->style()->subControlRect(QStyle::CC_ScrollBar, &opt, |
|
382 |
QStyle::SubControl(subControl), &scrollBar); |
|
383 |
QVERIFY(sr.isNull() == false); |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
void tst_QStyle::testPlastiqueStyle() |
|
388 |
{ |
|
389 |
#if !defined(QT_NO_STYLE_PLASTIQUE) |
|
390 |
QPlastiqueStyle pstyle; |
|
391 |
testAllFunctions(&pstyle); |
|
392 |
lineUpLayoutTest(&pstyle); |
|
393 |
#else |
|
394 |
QSKIP("No Plastique style", SkipAll); |
|
395 |
#endif |
|
396 |
} |
|
397 |
||
398 |
void tst_QStyle::testCleanlooksStyle() |
|
399 |
{ |
|
400 |
#if !defined(QT_NO_STYLE_CLEANLOOKS) |
|
401 |
QCleanlooksStyle cstyle; |
|
402 |
testAllFunctions(&cstyle); |
|
403 |
lineUpLayoutTest(&cstyle); |
|
404 |
#else |
|
405 |
QSKIP("No Cleanlooks style", SkipAll); |
|
406 |
#endif |
|
407 |
} |
|
408 |
||
409 |
void tst_QStyle::testWindowsStyle() |
|
410 |
{ |
|
411 |
QWindowsStyle wstyle; |
|
412 |
testAllFunctions(&wstyle); |
|
413 |
lineUpLayoutTest(&wstyle); |
|
414 |
} |
|
415 |
||
416 |
void tst_QStyle::testWindowsXPStyle() |
|
417 |
{ |
|
418 |
#if defined(Q_WS_WIN) && !defined(QT_NO_STYLE_WINDOWSXP) |
|
419 |
QWindowsXPStyle xpstyle; |
|
420 |
testAllFunctions(&xpstyle); |
|
421 |
lineUpLayoutTest(&xpstyle); |
|
422 |
#else |
|
423 |
QSKIP("No WindowsXP style", SkipAll); |
|
424 |
#endif |
|
425 |
} |
|
426 |
||
427 |
void writeImage(const QString &fileName, QImage image) |
|
428 |
{ |
|
429 |
QImageWriter imageWriter(fileName); |
|
430 |
imageWriter.setFormat("png"); |
|
431 |
qDebug() << "result " << imageWriter.write(image); |
|
432 |
} |
|
433 |
||
434 |
QImage readImage(const QString &fileName) |
|
435 |
{ |
|
436 |
QImageReader reader(fileName); |
|
437 |
return reader.read(); |
|
438 |
} |
|
439 |
||
440 |
||
441 |
void tst_QStyle::testWindowsVistaStyle() |
|
442 |
{ |
|
443 |
#if defined(Q_WS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA) |
|
444 |
QWindowsVistaStyle vistastyle; |
|
445 |
testAllFunctions(&vistastyle); |
|
446 |
||
447 |
if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA) |
|
448 |
testPainting(&vistastyle, "vista"); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
449 |
else if (QSysInfo::WindowsVersion == QSysInfo::WV_XP) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
450 |
testPainting(&vistastyle, "xp"); |
0 | 451 |
#endif |
452 |
} |
|
453 |
||
454 |
void comparePixmap(const QString &filename, const QPixmap &pixmap) |
|
455 |
{ |
|
456 |
QImage oldFile = readImage(filename); |
|
457 |
QPixmap oldPixmap = QPixmap::fromImage(oldFile); |
|
458 |
if (!oldFile.isNull()) |
|
459 |
QVERIFY(pixmapsAreEqual(&pixmap, &oldPixmap)); |
|
460 |
else |
|
461 |
writeImage(filename, pixmap.toImage()); |
|
462 |
} |
|
463 |
||
464 |
void tst_QStyle::testPainting(QStyle *style, const QString &platform) |
|
465 |
{ |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
466 |
qDebug("TEST PAINTING"); |
0 | 467 |
//Test Menu |
468 |
QString fileName = "images/" + platform + "/menu.png"; |
|
469 |
QMenu menu; |
|
470 |
menu.setStyle(style); |
|
471 |
menu.show(); |
|
472 |
menu.addAction(new QAction("Test 1", &menu)); |
|
473 |
menu.addAction(new QAction("Test 2", &menu)); |
|
474 |
QPixmap pixmap = QPixmap::grabWidget(&menu); |
|
475 |
comparePixmap(fileName, pixmap); |
|
476 |
||
477 |
//Push button |
|
478 |
fileName = "images/" + platform + "/button.png"; |
|
479 |
QPushButton button("OK"); |
|
480 |
button.setStyle(style); |
|
481 |
button.show(); |
|
482 |
pixmap = QPixmap::grabWidget(&button); |
|
483 |
button.hide(); |
|
484 |
comparePixmap(fileName, pixmap); |
|
485 |
||
486 |
//Push button |
|
487 |
fileName = "images/" + platform + "/radiobutton.png"; |
|
488 |
QRadioButton radiobutton("Check"); |
|
489 |
radiobutton.setStyle(style); |
|
490 |
radiobutton.show(); |
|
491 |
pixmap = QPixmap::grabWidget(&radiobutton); |
|
492 |
radiobutton.hide(); |
|
493 |
comparePixmap(fileName, pixmap); |
|
494 |
||
495 |
//Combo box |
|
496 |
fileName = "images/" + platform + "/combobox.png"; |
|
497 |
QComboBox combobox; |
|
498 |
combobox.setStyle(style); |
|
499 |
combobox.addItem("Test 1"); |
|
500 |
combobox.addItem("Test 2"); |
|
501 |
combobox.show(); |
|
502 |
pixmap = QPixmap::grabWidget(&combobox); |
|
503 |
combobox.hide(); |
|
504 |
comparePixmap(fileName, pixmap); |
|
505 |
||
506 |
//Spin box |
|
507 |
fileName = "images/" + platform + "/spinbox.png"; |
|
508 |
QDoubleSpinBox spinbox; |
|
509 |
spinbox.setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); |
|
510 |
spinbox.setStyle(style); |
|
511 |
spinbox.show(); |
|
512 |
pixmap = QPixmap::grabWidget(&spinbox); |
|
513 |
spinbox.hide(); |
|
514 |
comparePixmap(fileName, pixmap); |
|
515 |
QLocale::setDefault(QLocale::system()); |
|
516 |
||
517 |
//Slider |
|
518 |
fileName = "images/" + platform + "/slider.png"; |
|
519 |
QSlider slider; |
|
520 |
slider.setStyle(style); |
|
521 |
slider.show(); |
|
522 |
pixmap = QPixmap::grabWidget(&slider); |
|
523 |
slider.hide(); |
|
524 |
comparePixmap(fileName, pixmap); |
|
525 |
||
526 |
//Line edit |
|
527 |
fileName = "images/" + platform + "/lineedit.png"; |
|
528 |
QLineEdit lineedit("Test text"); |
|
529 |
lineedit.setStyle(style); |
|
530 |
lineedit.show(); |
|
531 |
pixmap = QPixmap::grabWidget(&lineedit); |
|
532 |
lineedit.hide(); |
|
533 |
comparePixmap(fileName, pixmap); |
|
534 |
||
535 |
//MDI |
|
536 |
fileName = "images/" + platform + "/mdi.png"; |
|
537 |
QMdiArea mdiArea; |
|
538 |
mdiArea.addSubWindow(new QWidget(&mdiArea)); |
|
539 |
mdiArea.resize(200, 200); |
|
540 |
mdiArea.setStyle(style); |
|
541 |
mdiArea.show(); |
|
542 |
pixmap = QPixmap::grabWidget(&mdiArea); |
|
543 |
mdiArea.hide(); |
|
544 |
comparePixmap(fileName, pixmap); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
545 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
546 |
// QToolButton |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
547 |
fileName = "images/" + platform + "/toolbutton.png"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
548 |
QToolButton tb; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
549 |
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
550 |
tb.setText("AaQqPpXx"); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
551 |
tb.setIcon(style->standardPixmap(QStyle::SP_DirHomeIcon)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
552 |
tb.setStyle(style); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
553 |
tb.show(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
554 |
pixmap = QPixmap::grabWidget(&tb); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
555 |
tb.hide(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
556 |
comparePixmap(fileName, pixmap); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
557 |
|
0 | 558 |
} |
559 |
||
560 |
void tst_QStyle::testMacStyle() |
|
561 |
{ |
|
562 |
#ifdef Q_WS_MAC |
|
563 |
QMacStyle mstyle; |
|
564 |
testAllFunctions(&mstyle); |
|
565 |
#endif |
|
566 |
} |
|
567 |
||
568 |
void tst_QStyle::testMotifStyle() |
|
569 |
{ |
|
570 |
#if !defined(QT_NO_STYLE_MOTIF) |
|
571 |
QMotifStyle mstyle; |
|
572 |
testAllFunctions(&mstyle); |
|
573 |
#else |
|
574 |
QSKIP("No Motif style", SkipAll); |
|
575 |
#endif |
|
576 |
} |
|
577 |
||
578 |
void tst_QStyle::testCDEStyle() |
|
579 |
{ |
|
580 |
#if !defined(QT_NO_STYLE_CDE) |
|
581 |
QCDEStyle cstyle; |
|
582 |
testAllFunctions(&cstyle); |
|
583 |
#else |
|
584 |
QSKIP("No CDE style", SkipAll); |
|
585 |
#endif |
|
586 |
} |
|
587 |
||
588 |
void tst_QStyle::testWindowsCEStyle() |
|
589 |
{ |
|
590 |
#if defined(Q_OS_WINCE) |
|
591 |
QWindowsCEStyle cstyle; |
|
592 |
testAllFunctions(&cstyle); |
|
593 |
#else |
|
594 |
QSKIP("No WindowsCEStyle style", SkipAll); |
|
595 |
#endif |
|
596 |
} |
|
597 |
||
598 |
void tst_QStyle::testWindowsMobileStyle() |
|
599 |
{ |
|
600 |
#if defined(Q_OS_WINCE_WM) |
|
601 |
QWindowsMobileStyle cstyle; |
|
602 |
testAllFunctions(&cstyle); |
|
603 |
#else |
|
604 |
QSKIP("No WindowsMobileStyle style", SkipAll); |
|
605 |
#endif |
|
606 |
} |
|
607 |
||
608 |
void tst_QStyle::testS60Style() |
|
609 |
{ |
|
610 |
#if defined(Q_WS_S60) |
|
611 |
QS60Style cstyle; |
|
612 |
testAllFunctions(&cstyle); |
|
613 |
#else |
|
614 |
QSKIP("No S60Style style", SkipAll); |
|
615 |
#endif |
|
616 |
} |
|
617 |
||
618 |
// Helper class... |
|
619 |
||
620 |
MyWidget::MyWidget( QWidget* parent, const char* name ) |
|
621 |
: QWidget( parent ) |
|
622 |
{ |
|
623 |
setObjectName(name); |
|
624 |
} |
|
625 |
||
626 |
void MyWidget::paintEvent( QPaintEvent* ) |
|
627 |
{ |
|
628 |
QPainter p(this); |
|
629 |
QPixmap big(400,400); |
|
630 |
big.fill(Qt::green); |
|
631 |
style()->drawItemPixmap(&p, rect(), Qt::AlignCenter, big); |
|
632 |
} |
|
633 |
||
634 |
||
635 |
class Qt42Style : public QWindowsStyle |
|
636 |
{ |
|
637 |
Q_OBJECT |
|
638 |
public: |
|
639 |
Qt42Style() : QWindowsStyle() |
|
640 |
{ |
|
641 |
margin_toplevel = 10; |
|
642 |
margin = 5; |
|
643 |
spacing = 0; |
|
644 |
} |
|
645 |
||
646 |
virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, |
|
647 |
const QWidget * widget = 0 ) const; |
|
648 |
||
649 |
int margin_toplevel; |
|
650 |
int margin; |
|
651 |
int spacing; |
|
652 |
||
653 |
}; |
|
654 |
||
655 |
int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/, |
|
656 |
const QWidget * widget /*= 0*/ ) const |
|
657 |
{ |
|
658 |
switch (metric) { |
|
659 |
case QStyle::PM_DefaultTopLevelMargin: |
|
660 |
return margin_toplevel; |
|
661 |
break; |
|
662 |
case QStyle::PM_DefaultChildMargin: |
|
663 |
return margin; |
|
664 |
break; |
|
665 |
case QStyle::PM_DefaultLayoutSpacing: |
|
666 |
return spacing; |
|
667 |
break; |
|
668 |
default: |
|
669 |
break; |
|
670 |
} |
|
671 |
return QWindowsStyle::pixelMetric(metric, option, widget); |
|
672 |
} |
|
673 |
||
674 |
||
675 |
void tst_QStyle::pixelMetric() |
|
676 |
{ |
|
677 |
Qt42Style *style = new Qt42Style(); |
|
678 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 10); |
|
679 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 5); |
|
680 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0); |
|
681 |
||
682 |
style->margin_toplevel = 0; |
|
683 |
style->margin = 0; |
|
684 |
style->spacing = 0; |
|
685 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 0); |
|
686 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 0); |
|
687 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0); |
|
688 |
||
689 |
style->margin_toplevel = -1; |
|
690 |
style->margin = -1; |
|
691 |
style->spacing = -1; |
|
692 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), -1); |
|
693 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), -1); |
|
694 |
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), -1); |
|
695 |
||
696 |
delete style; |
|
697 |
} |
|
698 |
||
699 |
void tst_QStyle::progressBarChangeStyle() |
|
700 |
{ |
|
701 |
#if !defined(QT_NO_STYLE_PLASTIQUE) && !defined(QT_NO_STYLE_WINDOWS) |
|
702 |
//test a crashing situation (task 143530) |
|
703 |
//where changing the styles and deleting a progressbar would crash |
|
704 |
||
705 |
QWindowsStyle style1; |
|
706 |
QPlastiqueStyle style2; |
|
707 |
||
708 |
QProgressBar *progress=new QProgressBar; |
|
709 |
progress->setStyle(&style1); |
|
710 |
||
711 |
progress->show(); |
|
712 |
||
713 |
progress->setStyle(&style2); |
|
714 |
||
715 |
QTest::qWait(100); |
|
716 |
delete progress; |
|
717 |
||
718 |
QTest::qWait(100); |
|
719 |
||
720 |
//before the correction, there would be a crash here |
|
721 |
#elif !defined(QT_NO_STYLE_S60) && !defined(QT_NO_STYLE_WINDOWS) |
|
722 |
//test a crashing situation (task 143530) |
|
723 |
//where changing the styles and deleting a progressbar would crash |
|
724 |
||
725 |
QWindowsStyle style1; |
|
726 |
QS60Style style2; |
|
727 |
||
728 |
QProgressBar *progress=new QProgressBar; |
|
729 |
progress->setStyle(&style1); |
|
730 |
||
731 |
progress->show(); |
|
732 |
||
733 |
progress->setStyle(&style2); |
|
734 |
||
735 |
QTest::qWait(100); |
|
736 |
delete progress; |
|
737 |
||
738 |
QTest::qWait(100); |
|
739 |
||
740 |
//before the correction, there would be a crash here |
|
741 |
#else |
|
742 |
QSKIP("Either style Plastique or Windows or S60 missing", SkipAll); |
|
743 |
#endif |
|
744 |
} |
|
745 |
||
746 |
void tst_QStyle::lineUpLayoutTest(QStyle *style) |
|
747 |
{ |
|
748 |
QWidget widget; |
|
749 |
QHBoxLayout layout; |
|
750 |
QFont font; |
|
751 |
font.setPointSize(9); //Plastique is lined up for odd numbers... |
|
752 |
widget.setFont(font); |
|
753 |
QSpinBox spinbox(&widget); |
|
754 |
QLineEdit lineedit(&widget); |
|
755 |
QComboBox combo(&widget); |
|
756 |
combo.setEditable(true); |
|
757 |
layout.addWidget(&spinbox); |
|
758 |
layout.addWidget(&lineedit); |
|
759 |
layout.addWidget(&combo); |
|
760 |
widget.setLayout(&layout); |
|
761 |
widget.setStyle(style); |
|
762 |
// propagate the style. |
|
763 |
foreach (QWidget *w, qFindChildren<QWidget *>(&widget)) |
|
764 |
w->setStyle(style); |
|
765 |
widget.show(); |
|
766 |
QTest::qWait( 500 ); |
|
767 |
||
768 |
QVERIFY(qAbs(spinbox.height() - lineedit.height()) <= 1); |
|
769 |
QVERIFY(qAbs(spinbox.height() - combo.height()) <= 1); |
|
770 |
} |
|
771 |
||
772 |
void tst_QStyle::defaultFont() |
|
773 |
{ |
|
774 |
QFont defaultFont = qApp->font(); |
|
775 |
QFont pointFont = defaultFont; |
|
776 |
pointFont.setPixelSize(9); |
|
777 |
qApp->setFont(pointFont); |
|
778 |
QPushButton button; |
|
779 |
button.show(); |
|
780 |
qApp->processEvents(); |
|
781 |
qApp->setFont(defaultFont); |
|
782 |
} |
|
783 |
||
784 |
QTEST_MAIN(tst_QStyle) |
|
785 |
#include "tst_qstyle.moc" |