2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 08:44:43 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2014-08-21 13:51:22 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-21 13:51:22 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2015-01-28 08:44:43 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <qlayout.h>
|
|
|
|
#include "qstyle.h"
|
|
|
|
#include <qevent.h>
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qwidget.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qstyleoption.h>
|
|
|
|
#include <qscrollbar.h>
|
|
|
|
#include <qprogressbar.h>
|
|
|
|
#include <qtoolbutton.h>
|
|
|
|
#include <qtoolbar.h>
|
|
|
|
|
|
|
|
#include <qcommonstyle.h>
|
|
|
|
#include <qproxystyle.h>
|
|
|
|
#include <qstylefactory.h>
|
|
|
|
|
|
|
|
#include <qimagereader.h>
|
|
|
|
#include <qimagewriter.h>
|
|
|
|
#include <qmenu.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qspinbox.h>
|
|
|
|
#include <qcombobox.h>
|
|
|
|
#include <qradiobutton.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qmdiarea.h>
|
2012-09-19 15:45:25 +00:00
|
|
|
#include <qscrollarea.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_WINCE_WM
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
static bool qt_wince_is_smartphone() {
|
|
|
|
wchar_t tszPlatform[64];
|
|
|
|
if (SystemParametersInfo(SPI_GETPLATFORMTYPE,
|
|
|
|
sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
|
|
|
|
if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (QString::fromLatin1("Smartphone").utf16()), tszPlatform))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <qwidget.h>
|
|
|
|
|
2012-12-17 10:47:12 +00:00
|
|
|
// Make a widget frameless to prevent size constraints of title bars
|
|
|
|
// from interfering (Windows).
|
|
|
|
static inline void setFrameless(QWidget *w)
|
|
|
|
{
|
|
|
|
Qt::WindowFlags flags = w->windowFlags();
|
|
|
|
flags |= Qt::FramelessWindowHint;
|
|
|
|
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
|
|
|
|
w->setWindowFlags(flags);
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class tst_QStyle : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_QStyle();
|
|
|
|
virtual ~tst_QStyle();
|
|
|
|
private:
|
2011-10-24 05:55:41 +00:00
|
|
|
bool testAllFunctions(QStyle *);
|
|
|
|
bool testScrollBarSubControls(QStyle *);
|
2011-04-27 10:05:43 +00:00
|
|
|
void testPainting(QStyle *style, const QString &platform);
|
|
|
|
private slots:
|
|
|
|
void drawItemPixmap();
|
|
|
|
void initTestCase();
|
2012-10-18 13:22:15 +00:00
|
|
|
void cleanup();
|
2011-04-27 10:05:43 +00:00
|
|
|
void cleanupTestCase();
|
|
|
|
void init();
|
2012-10-18 13:22:15 +00:00
|
|
|
#ifndef QT_NO_STYLE_FUSION
|
|
|
|
void testFusionStyle();
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
void testWindowsStyle();
|
2012-10-21 19:49:43 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSXP)
|
2011-04-27 10:05:43 +00:00
|
|
|
void testWindowsXPStyle();
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2012-10-21 19:49:43 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA)
|
2011-04-27 10:05:43 +00:00
|
|
|
void testWindowsVistaStyle();
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MAC
|
2011-04-27 10:05:43 +00:00
|
|
|
void testMacStyle();
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_WINCE
|
2011-04-27 10:05:43 +00:00
|
|
|
void testWindowsCEStyle();
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_WINCE_WM
|
2011-04-27 10:05:43 +00:00
|
|
|
void testWindowsMobileStyle();
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
void testStyleFactory();
|
|
|
|
void testProxyStyle();
|
|
|
|
void pixelMetric();
|
2012-10-21 19:49:43 +00:00
|
|
|
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
|
2011-04-27 10:05:43 +00:00
|
|
|
void progressBarChangeStyle();
|
2011-10-04 04:22:40 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
void defaultFont();
|
|
|
|
void testDrawingShortcuts();
|
2012-09-19 15:45:25 +00:00
|
|
|
void testFrameOnlyAroundContents();
|
2011-04-27 10:05:43 +00:00
|
|
|
private:
|
|
|
|
void lineUpLayoutTest(QStyle *);
|
|
|
|
QWidget *testWidget;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tst_QStyle::tst_QStyle()
|
|
|
|
{
|
|
|
|
testWidget = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tst_QStyle::~tst_QStyle()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyWidget : public QWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyWidget( QWidget* QWidget=0, const char* name=0 );
|
|
|
|
protected:
|
|
|
|
void paintEvent( QPaintEvent* );
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QStyle::init()
|
|
|
|
{
|
|
|
|
testWidget = new MyWidget( 0, "testObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::cleanup()
|
|
|
|
{
|
|
|
|
delete testWidget;
|
|
|
|
testWidget = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::initTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::cleanupTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::testStyleFactory()
|
|
|
|
{
|
|
|
|
QStringList keys = QStyleFactory::keys();
|
2012-10-18 13:22:15 +00:00
|
|
|
#ifndef QT_NO_STYLE_FUSION
|
|
|
|
QVERIFY(keys.contains("Fusion"));
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
#ifndef QT_NO_STYLE_WINDOWS
|
|
|
|
QVERIFY(keys.contains("Windows"));
|
|
|
|
#endif
|
2012-07-16 12:46:08 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2011-04-27 10:05:43 +00:00
|
|
|
if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP &&
|
2012-03-22 14:00:56 +00:00
|
|
|
(QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(keys.contains("WindowsXP"));
|
|
|
|
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA &&
|
2012-03-22 14:00:56 +00:00
|
|
|
(QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(keys.contains("WindowsVista"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foreach (QString styleName , keys) {
|
|
|
|
QStyle *style = QStyleFactory::create(styleName);
|
|
|
|
QVERIFY2(style != 0, qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName)));
|
|
|
|
delete style;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomProxy : public QProxyStyle
|
|
|
|
{
|
|
|
|
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0,
|
|
|
|
const QWidget *widget = 0) const
|
|
|
|
{
|
|
|
|
if (metric == QStyle::PM_ButtonIconSize)
|
|
|
|
return 13;
|
|
|
|
return QProxyStyle::pixelMetric(metric, option, widget);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QStyle::testProxyStyle()
|
|
|
|
{
|
|
|
|
QProxyStyle *proxyStyle = new QProxyStyle();
|
|
|
|
QVERIFY(proxyStyle->baseStyle());
|
2012-11-27 17:31:06 +00:00
|
|
|
QStyle *style = QStyleFactory::create("Windows");
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(style->proxy(), style);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
proxyStyle->setBaseStyle(style);
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(style->proxy(), proxyStyle);
|
|
|
|
QCOMPARE(style->parent(), proxyStyle);
|
|
|
|
QCOMPARE(proxyStyle->baseStyle(), style);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-24 05:55:41 +00:00
|
|
|
QVERIFY(testAllFunctions(proxyStyle));
|
2011-04-27 10:05:43 +00:00
|
|
|
proxyStyle->setBaseStyle(0);
|
|
|
|
QVERIFY(proxyStyle->baseStyle());
|
|
|
|
qApp->setStyle(proxyStyle);
|
|
|
|
|
2012-11-26 23:06:14 +00:00
|
|
|
QProxyStyle* baseStyle = new QProxyStyle("Windows");
|
|
|
|
QCOMPARE(baseStyle->baseStyle()->objectName(), style->objectName());
|
|
|
|
|
|
|
|
QProxyStyle doubleProxy(baseStyle);
|
2011-10-24 05:55:41 +00:00
|
|
|
QVERIFY(testAllFunctions(&doubleProxy));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
CustomProxy customStyle;
|
|
|
|
QLineEdit edit;
|
|
|
|
edit.setStyle(&customStyle);
|
|
|
|
QVERIFY(!customStyle.parent());
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(edit.style()->pixelMetric(QStyle::PM_ButtonIconSize), 13);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::drawItemPixmap()
|
|
|
|
{
|
|
|
|
testWidget->resize(300, 300);
|
2013-05-29 20:44:37 +00:00
|
|
|
testWidget->showNormal();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-05-29 20:44:37 +00:00
|
|
|
const QString imageFileName = QFINDTESTDATA("task_25863.png");
|
|
|
|
QVERIFY(!imageFileName.isEmpty());
|
|
|
|
|
|
|
|
QPixmap p(imageFileName, "PNG");
|
2012-07-20 14:11:05 +00:00
|
|
|
const QPixmap actualPix = testWidget->grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-12-19 05:22:51 +00:00
|
|
|
QCOMPARE(actualPix, p);
|
2011-04-27 10:05:43 +00:00
|
|
|
testWidget->hide();
|
|
|
|
}
|
|
|
|
|
2011-10-24 05:55:41 +00:00
|
|
|
bool tst_QStyle::testAllFunctions(QStyle *style)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(testWidget);
|
|
|
|
|
|
|
|
testWidget->setStyle(style);
|
|
|
|
|
|
|
|
//Tests styleHint with default arguments for potential crashes
|
|
|
|
for ( int hint = 0 ; hint < int(QStyle::SH_Menu_Mask); ++hint) {
|
|
|
|
style->styleHint(QStyle::StyleHint(hint));
|
|
|
|
style->styleHint(QStyle::StyleHint(hint), &opt, testWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Tests pixelMetric with default arguments for potential crashes
|
|
|
|
for ( int pm = 0 ; pm < int(QStyle::PM_LayoutVerticalSpacing); ++pm) {
|
|
|
|
style->pixelMetric(QStyle::PixelMetric(pm));
|
|
|
|
style->pixelMetric(QStyle::PixelMetric(pm), &opt, testWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Tests drawControl with default arguments for potential crashes
|
|
|
|
for ( int control = 0 ; control < int(QStyle::CE_ColumnViewGrip); ++control) {
|
|
|
|
QPixmap surface(QSize(200, 200));
|
|
|
|
QPainter painter(&surface);
|
|
|
|
style->drawControl(QStyle::ControlElement(control), &opt, &painter, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Tests drawComplexControl with default arguments for potential crashes
|
|
|
|
{
|
|
|
|
QPixmap surface(QSize(200, 200));
|
|
|
|
QPainter painter(&surface);
|
|
|
|
QStyleOptionComboBox copt1;
|
|
|
|
copt1.init(testWidget);
|
|
|
|
|
|
|
|
QStyleOptionGroupBox copt2;
|
|
|
|
copt2.init(testWidget);
|
|
|
|
QStyleOptionSizeGrip copt3;
|
|
|
|
copt3.init(testWidget);
|
|
|
|
QStyleOptionSlider copt4;
|
|
|
|
copt4.init(testWidget);
|
|
|
|
copt4.minimum = 0;
|
|
|
|
copt4.maximum = 100;
|
|
|
|
copt4.tickInterval = 25;
|
|
|
|
copt4.sliderValue = 50;
|
|
|
|
QStyleOptionSpinBox copt5;
|
|
|
|
copt5.init(testWidget);
|
|
|
|
QStyleOptionTitleBar copt6;
|
|
|
|
copt6.init(testWidget);
|
|
|
|
QStyleOptionToolButton copt7;
|
|
|
|
copt7.init(testWidget);
|
|
|
|
QStyleOptionComplex copt9;
|
|
|
|
copt9.initFrom(testWidget);
|
|
|
|
|
|
|
|
style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, 0);
|
|
|
|
style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check standard pixmaps/icons
|
|
|
|
for ( int i = 0 ; i < int(QStyle::SP_ToolBarVerticalExtensionButton); ++i) {
|
|
|
|
QPixmap pixmap = style->standardPixmap(QStyle::StandardPixmap(i));
|
|
|
|
if (pixmap.isNull()) {
|
|
|
|
qWarning("missing StandardPixmap: %d", i);
|
|
|
|
}
|
|
|
|
QIcon icn = style->standardIcon(QStyle::StandardPixmap(i));
|
|
|
|
if (icn.isNull()) {
|
|
|
|
qWarning("missing StandardIcon: %d", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
style->itemPixmapRect(QRect(0, 0, 100, 100), Qt::AlignHCenter, QPixmap(200, 200));
|
|
|
|
style->itemTextRect(QFontMetrics(qApp->font()), QRect(0, 0, 100, 100), Qt::AlignHCenter, true, QString("Test"));
|
|
|
|
|
2011-10-24 05:55:41 +00:00
|
|
|
return testScrollBarSubControls(style);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-10-24 05:55:41 +00:00
|
|
|
bool tst_QStyle::testScrollBarSubControls(QStyle* style)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-10-24 05:55:41 +00:00
|
|
|
// WinCE SmartPhone doesn't have scrollbar subcontrols, so skip the rest of the test.
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifdef Q_OS_WINCE_WM
|
2012-11-20 12:50:40 +00:00
|
|
|
if (style->inherits("QWindowsMobileStyle") && qt_wince_is_smartphone())
|
2011-10-24 05:55:41 +00:00
|
|
|
return true;
|
2011-05-19 14:19:01 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(style);
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QScrollBar scrollBar;
|
2012-12-17 10:47:12 +00:00
|
|
|
setFrameless(&scrollBar);
|
2011-04-27 10:05:43 +00:00
|
|
|
scrollBar.show();
|
|
|
|
const QStyleOptionSlider opt = qt_qscrollbarStyleOption(&scrollBar);
|
|
|
|
foreach (int subControl, QList<int>() << 1 << 2 << 4 << 8) {
|
|
|
|
QRect sr = testWidget->style()->subControlRect(QStyle::CC_ScrollBar, &opt,
|
|
|
|
QStyle::SubControl(subControl), &scrollBar);
|
2011-10-24 05:55:41 +00:00
|
|
|
if (sr.isNull()) {
|
|
|
|
qWarning("Null rect for subcontrol %d", subControl);
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-10-24 05:55:41 +00:00
|
|
|
return true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 13:22:15 +00:00
|
|
|
#ifndef QT_NO_STYLE_FUSION
|
|
|
|
void tst_QStyle::testFusionStyle()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-11-16 16:39:24 +00:00
|
|
|
QStyle *fstyle = QStyleFactory::create("Fusion");
|
|
|
|
QVERIFY(testAllFunctions(fstyle));
|
|
|
|
lineUpLayoutTest(fstyle);
|
|
|
|
delete fstyle;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QStyle::testWindowsStyle()
|
|
|
|
{
|
2012-11-27 17:31:06 +00:00
|
|
|
QStyle *wstyle = QStyleFactory::create("Windows");
|
|
|
|
QVERIFY(testAllFunctions(wstyle));
|
|
|
|
lineUpLayoutTest(wstyle);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// Tests drawing indeterminate progress with 0 size: QTBUG-15973
|
|
|
|
QStyleOptionProgressBar pb;
|
|
|
|
pb.rect = QRect(0,0,-9,0);
|
|
|
|
QPixmap surface(QSize(200, 200));
|
|
|
|
QPainter painter(&surface);
|
2012-11-27 17:31:06 +00:00
|
|
|
wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, 0);
|
|
|
|
delete wstyle;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 19:49:43 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSXP)
|
|
|
|
// WindowsXP style
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::testWindowsXPStyle()
|
|
|
|
{
|
2012-11-16 16:22:40 +00:00
|
|
|
QStyle *xpstyle = QStyleFactory::create("WindowsXP");
|
|
|
|
QVERIFY(testAllFunctions(xpstyle));
|
|
|
|
lineUpLayoutTest(xpstyle);
|
|
|
|
delete xpstyle;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void writeImage(const QString &fileName, QImage image)
|
|
|
|
{
|
|
|
|
QImageWriter imageWriter(fileName);
|
|
|
|
imageWriter.setFormat("png");
|
|
|
|
qDebug() << "result " << imageWriter.write(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage readImage(const QString &fileName)
|
|
|
|
{
|
|
|
|
QImageReader reader(fileName);
|
|
|
|
return reader.read();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-21 19:49:43 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA)
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::testWindowsVistaStyle()
|
|
|
|
{
|
2012-11-16 15:54:43 +00:00
|
|
|
QStyle *vistastyle = QStyleFactory::create("WindowsVista");
|
|
|
|
QVERIFY(testAllFunctions(vistastyle));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA)
|
2012-11-16 15:54:43 +00:00
|
|
|
testPainting(vistastyle, "vista");
|
2011-04-27 10:05:43 +00:00
|
|
|
else if (QSysInfo::WindowsVersion == QSysInfo::WV_XP)
|
2012-11-16 15:54:43 +00:00
|
|
|
testPainting(vistastyle, "xp");
|
|
|
|
delete vistastyle;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void comparePixmap(const QString &filename, const QPixmap &pixmap)
|
|
|
|
{
|
|
|
|
QImage oldFile = readImage(filename);
|
|
|
|
QPixmap oldPixmap = QPixmap::fromImage(oldFile);
|
|
|
|
if (!oldFile.isNull())
|
2011-12-19 05:22:51 +00:00
|
|
|
QCOMPARE(pixmap, oldPixmap);
|
2011-04-27 10:05:43 +00:00
|
|
|
else
|
|
|
|
writeImage(filename, pixmap.toImage());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::testPainting(QStyle *style, const QString &platform)
|
|
|
|
{
|
|
|
|
qDebug("TEST PAINTING");
|
|
|
|
//Test Menu
|
|
|
|
QString fileName = "images/" + platform + "/menu.png";
|
|
|
|
QMenu menu;
|
|
|
|
menu.setStyle(style);
|
|
|
|
menu.show();
|
|
|
|
menu.addAction(new QAction("Test 1", &menu));
|
|
|
|
menu.addAction(new QAction("Test 2", &menu));
|
2012-07-20 14:11:05 +00:00
|
|
|
QPixmap pixmap = menu.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
//Push button
|
|
|
|
fileName = "images/" + platform + "/button.png";
|
|
|
|
QPushButton button("OK");
|
|
|
|
button.setStyle(style);
|
|
|
|
button.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = button.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
button.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
//Push button
|
|
|
|
fileName = "images/" + platform + "/radiobutton.png";
|
|
|
|
QRadioButton radiobutton("Check");
|
|
|
|
radiobutton.setStyle(style);
|
|
|
|
radiobutton.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = radiobutton.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
radiobutton.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
//Combo box
|
|
|
|
fileName = "images/" + platform + "/combobox.png";
|
|
|
|
QComboBox combobox;
|
|
|
|
combobox.setStyle(style);
|
|
|
|
combobox.addItem("Test 1");
|
|
|
|
combobox.addItem("Test 2");
|
|
|
|
combobox.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = combobox.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
combobox.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
//Spin box
|
|
|
|
fileName = "images/" + platform + "/spinbox.png";
|
|
|
|
QDoubleSpinBox spinbox;
|
|
|
|
spinbox.setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
|
|
|
|
spinbox.setStyle(style);
|
|
|
|
spinbox.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = spinbox.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
spinbox.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
QLocale::setDefault(QLocale::system());
|
|
|
|
|
|
|
|
//Slider
|
|
|
|
fileName = "images/" + platform + "/slider.png";
|
|
|
|
QSlider slider;
|
|
|
|
slider.setStyle(style);
|
|
|
|
slider.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = slider.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
slider.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
//Line edit
|
|
|
|
fileName = "images/" + platform + "/lineedit.png";
|
|
|
|
QLineEdit lineedit("Test text");
|
|
|
|
lineedit.setStyle(style);
|
|
|
|
lineedit.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = lineedit.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
lineedit.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
//MDI
|
|
|
|
fileName = "images/" + platform + "/mdi.png";
|
|
|
|
QMdiArea mdiArea;
|
|
|
|
mdiArea.addSubWindow(new QWidget(&mdiArea));
|
|
|
|
mdiArea.resize(200, 200);
|
|
|
|
mdiArea.setStyle(style);
|
|
|
|
mdiArea.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = mdiArea.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
mdiArea.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
// QToolButton
|
|
|
|
fileName = "images/" + platform + "/toolbutton.png";
|
|
|
|
QToolButton tb;
|
|
|
|
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
tb.setText("AaQqPpXx");
|
|
|
|
tb.setIcon(style->standardPixmap(QStyle::SP_DirHomeIcon));
|
|
|
|
tb.setStyle(style);
|
|
|
|
tb.show();
|
2012-07-20 14:11:05 +00:00
|
|
|
pixmap = tb.grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
tb.hide();
|
|
|
|
comparePixmap(fileName, pixmap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-21 19:49:43 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::testMacStyle()
|
|
|
|
{
|
2012-11-16 23:52:26 +00:00
|
|
|
QStyle *mstyle = QStyleFactory::create("Macintosh");
|
|
|
|
QVERIFY(testAllFunctions(mstyle));
|
|
|
|
delete mstyle;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-10-21 19:49:43 +00:00
|
|
|
#ifdef Q_OS_WINCE
|
|
|
|
// WindowsCEStyle style
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::testWindowsCEStyle()
|
|
|
|
{
|
2012-11-20 12:41:59 +00:00
|
|
|
QStyle *cstyle = QStyleFactory::create("WindowsCE");
|
2013-04-17 12:56:16 +00:00
|
|
|
QVERIFY(testAllFunctions(cstyle));
|
2012-11-20 12:41:59 +00:00
|
|
|
delete cstyle;
|
2011-11-15 01:36:18 +00:00
|
|
|
}
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-10-21 19:49:43 +00:00
|
|
|
#ifdef Q_OS_WINCE_WM
|
|
|
|
// WindowsMobileStyle style
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::testWindowsMobileStyle()
|
|
|
|
{
|
2012-11-20 12:50:40 +00:00
|
|
|
QStyle *cstyle = QStyleFactory::create("WindowsMobile");
|
2013-04-17 12:56:16 +00:00
|
|
|
QVERIFY(testAllFunctions(cstyle));
|
2012-11-20 12:50:40 +00:00
|
|
|
delete cstyle;
|
2011-11-15 01:36:18 +00:00
|
|
|
}
|
2012-10-21 19:49:43 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// Helper class...
|
|
|
|
|
|
|
|
MyWidget::MyWidget( QWidget* parent, const char* name )
|
|
|
|
: QWidget( parent )
|
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyWidget::paintEvent( QPaintEvent* )
|
|
|
|
{
|
|
|
|
QPainter p(this);
|
|
|
|
QPixmap big(400,400);
|
|
|
|
big.fill(Qt::green);
|
|
|
|
style()->drawItemPixmap(&p, rect(), Qt::AlignCenter, big);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-27 17:31:06 +00:00
|
|
|
class Qt42Style : public QCommonStyle
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-11-27 17:31:06 +00:00
|
|
|
Qt42Style() : QCommonStyle()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
margin_toplevel = 10;
|
|
|
|
margin = 5;
|
|
|
|
spacing = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
|
|
|
|
const QWidget * widget = 0 ) const;
|
|
|
|
|
|
|
|
int margin_toplevel;
|
|
|
|
int margin;
|
|
|
|
int spacing;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-12-17 10:51:18 +00:00
|
|
|
int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option = 0*/,
|
|
|
|
const QWidget * /* widget = 0*/ ) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
switch (metric) {
|
|
|
|
case QStyle::PM_DefaultTopLevelMargin:
|
|
|
|
return margin_toplevel;
|
|
|
|
break;
|
|
|
|
case QStyle::PM_DefaultChildMargin:
|
|
|
|
return margin;
|
|
|
|
break;
|
|
|
|
case QStyle::PM_DefaultLayoutSpacing:
|
|
|
|
return spacing;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-27 17:31:06 +00:00
|
|
|
return -1;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QStyle::pixelMetric()
|
|
|
|
{
|
|
|
|
Qt42Style *style = new Qt42Style();
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 10);
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 5);
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0);
|
|
|
|
|
|
|
|
style->margin_toplevel = 0;
|
|
|
|
style->margin = 0;
|
|
|
|
style->spacing = 0;
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 0);
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 0);
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0);
|
|
|
|
|
|
|
|
style->margin_toplevel = -1;
|
|
|
|
style->margin = -1;
|
|
|
|
style->spacing = -1;
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), -1);
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), -1);
|
|
|
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), -1);
|
|
|
|
|
|
|
|
delete style;
|
|
|
|
}
|
|
|
|
|
2012-10-21 19:49:43 +00:00
|
|
|
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::progressBarChangeStyle()
|
|
|
|
{
|
|
|
|
//test a crashing situation (task 143530)
|
|
|
|
//where changing the styles and deleting a progressbar would crash
|
|
|
|
|
2012-11-27 17:31:06 +00:00
|
|
|
QStyle *style1 = QStyleFactory::create("Windows");
|
2012-11-16 16:39:24 +00:00
|
|
|
QStyle *style2 = QStyleFactory::create("Fusion");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QProgressBar *progress=new QProgressBar;
|
2012-11-27 17:31:06 +00:00
|
|
|
progress->setStyle(style1);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
progress->show();
|
|
|
|
|
2012-11-16 16:39:24 +00:00
|
|
|
progress->setStyle(style2);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTest::qWait(100);
|
|
|
|
delete progress;
|
|
|
|
|
|
|
|
QTest::qWait(100);
|
|
|
|
|
|
|
|
//before the correction, there would be a crash here
|
2012-11-27 17:31:06 +00:00
|
|
|
delete style1;
|
2012-11-16 16:39:24 +00:00
|
|
|
delete style2;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-10-04 04:22:40 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QStyle::lineUpLayoutTest(QStyle *style)
|
|
|
|
{
|
|
|
|
QWidget widget;
|
2012-12-17 10:47:12 +00:00
|
|
|
setFrameless(&widget);
|
2011-04-27 10:05:43 +00:00
|
|
|
QHBoxLayout layout;
|
|
|
|
QFont font;
|
|
|
|
font.setPointSize(9); //Plastique is lined up for odd numbers...
|
|
|
|
widget.setFont(font);
|
|
|
|
QSpinBox spinbox(&widget);
|
|
|
|
QLineEdit lineedit(&widget);
|
|
|
|
QComboBox combo(&widget);
|
|
|
|
combo.setEditable(true);
|
|
|
|
layout.addWidget(&spinbox);
|
|
|
|
layout.addWidget(&lineedit);
|
|
|
|
layout.addWidget(&combo);
|
|
|
|
widget.setLayout(&layout);
|
|
|
|
widget.setStyle(style);
|
|
|
|
// propagate the style.
|
2013-03-27 14:16:32 +00:00
|
|
|
foreach (QWidget *w, widget.findChildren<QWidget *>())
|
2011-04-27 10:05:43 +00:00
|
|
|
w->setStyle(style);
|
|
|
|
widget.show();
|
2012-12-17 10:47:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-12-17 10:47:12 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
const int limit = 2; // Aero style has larger margins
|
|
|
|
#else
|
|
|
|
const int limit = 1;
|
|
|
|
#endif
|
|
|
|
const int slDiff = qAbs(spinbox.height() - lineedit.height());
|
|
|
|
const int scDiff = qAbs(spinbox.height() - combo.height());
|
|
|
|
QVERIFY2(slDiff <= limit,
|
|
|
|
qPrintable(QString::fromLatin1("%1 exceeds %2 for %3")
|
|
|
|
.arg(slDiff).arg(limit).arg(style->objectName())));
|
|
|
|
QVERIFY2(scDiff <= limit,
|
|
|
|
qPrintable(QString::fromLatin1("%1 exceeds %2 for %3")
|
|
|
|
.arg(scDiff).arg(limit).arg(style->objectName())));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QStyle::defaultFont()
|
|
|
|
{
|
|
|
|
QFont defaultFont = qApp->font();
|
|
|
|
QFont pointFont = defaultFont;
|
|
|
|
pointFont.setPixelSize(9);
|
|
|
|
qApp->setFont(pointFont);
|
|
|
|
QPushButton button;
|
2012-12-17 10:47:12 +00:00
|
|
|
setFrameless(&button);
|
2011-04-27 10:05:43 +00:00
|
|
|
button.show();
|
|
|
|
qApp->processEvents();
|
|
|
|
qApp->setFont(defaultFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
class DrawTextStyle : public QProxyStyle
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DrawTextStyle(QStyle *base = 0) : QProxyStyle(), alignment(0) { setBaseStyle(base); }
|
|
|
|
void drawItemText(QPainter *painter, const QRect &rect,
|
|
|
|
int flags, const QPalette &pal, bool enabled,
|
|
|
|
const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const
|
|
|
|
{
|
|
|
|
DrawTextStyle *that = (DrawTextStyle *)this;
|
|
|
|
that->alignment = flags;
|
|
|
|
QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
|
|
|
|
}
|
|
|
|
int alignment;
|
|
|
|
};
|
|
|
|
|
2012-09-19 15:45:25 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QStyle::testDrawingShortcuts()
|
|
|
|
{
|
2013-03-14 23:42:15 +00:00
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget w;
|
2012-12-17 10:47:12 +00:00
|
|
|
setFrameless(&w);
|
2011-04-27 10:05:43 +00:00
|
|
|
QToolButton *tb = new QToolButton(&w);
|
|
|
|
tb->setText("&abc");
|
|
|
|
DrawTextStyle *dts = new DrawTextStyle;
|
|
|
|
w.show();
|
|
|
|
tb->setStyle(dts);
|
2012-07-20 14:11:05 +00:00
|
|
|
tb->grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
QStyleOptionToolButton sotb;
|
|
|
|
sotb.initFrom(tb);
|
|
|
|
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
|
|
|
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
|
|
|
delete dts;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QToolBar w;
|
2012-12-17 10:47:12 +00:00
|
|
|
setFrameless(&w);
|
2011-04-27 10:05:43 +00:00
|
|
|
QToolButton *tb = new QToolButton(&w);
|
|
|
|
tb->setText("&abc");
|
|
|
|
DrawTextStyle *dts = new DrawTextStyle;
|
|
|
|
w.addWidget(tb);
|
|
|
|
w.show();
|
|
|
|
tb->setStyle(dts);
|
2012-07-20 14:11:05 +00:00
|
|
|
tb->grab();
|
2011-04-27 10:05:43 +00:00
|
|
|
QStyleOptionToolButton sotb;
|
|
|
|
sotb.initFrom(tb);
|
|
|
|
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
|
|
|
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
|
|
|
delete dts;
|
2013-03-14 23:42:15 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 15:45:25 +00:00
|
|
|
#define SCROLLBAR_SPACING 33
|
|
|
|
|
2012-11-27 17:31:06 +00:00
|
|
|
class FrameTestStyle : public QProxyStyle {
|
|
|
|
public:
|
2012-11-26 23:06:14 +00:00
|
|
|
FrameTestStyle() : QProxyStyle("Windows") { }
|
2012-09-19 15:45:25 +00:00
|
|
|
int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const {
|
|
|
|
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
|
|
|
|
return 1;
|
2012-11-27 17:31:06 +00:00
|
|
|
return QProxyStyle ::styleHint(hint, opt, widget, returnData);
|
2012-09-19 15:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const {
|
|
|
|
if (pm == QStyle::PM_ScrollView_ScrollBarSpacing)
|
|
|
|
return SCROLLBAR_SPACING;
|
2012-11-27 17:31:06 +00:00
|
|
|
return QProxyStyle ::pixelMetric(pm, option ,widget);
|
2012-09-19 15:45:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QStyle::testFrameOnlyAroundContents()
|
|
|
|
{
|
|
|
|
QScrollArea area;
|
|
|
|
area.setGeometry(0, 0, 200, 200);
|
2012-11-27 17:31:06 +00:00
|
|
|
QStyle *winStyle = QStyleFactory::create("Windows");
|
2012-09-19 15:45:25 +00:00
|
|
|
FrameTestStyle frameStyle;
|
|
|
|
QWidget *widget = new QWidget(&area);
|
|
|
|
widget->setGeometry(0, 0, 400, 400);
|
2012-11-27 17:31:06 +00:00
|
|
|
area.setStyle(winStyle);
|
|
|
|
area.verticalScrollBar()->setStyle(winStyle);
|
2012-09-19 15:45:25 +00:00
|
|
|
area.setWidget(widget);
|
|
|
|
area.setVisible(true);
|
|
|
|
int viewPortWidth = area.viewport()->width();
|
|
|
|
area.verticalScrollBar()->setStyle(&frameStyle);
|
|
|
|
area.setStyle(&frameStyle);
|
|
|
|
// Test that we reserve space for scrollbar spacing
|
|
|
|
QVERIFY(viewPortWidth == area.viewport()->width() + SCROLLBAR_SPACING);
|
2012-11-27 17:31:06 +00:00
|
|
|
delete winStyle;
|
2012-09-19 15:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_QStyle)
|
|
|
|
#include "tst_qstyle.moc"
|