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