Brush up tst_QStyle
- Remove member m_testWidget; instantiate test widget on the stack where needed - Introduce nullptr - Use range-based for - Streamline some code - Fix static invocation - Fix class structure, add override - Use initializer lists - Fix some style issues Task-number: QTBUG-76493 Change-Id: If339d51a16bb77565cf10404ad1266c8f63a68b4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
194d4946c7
commit
efbba1e54a
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2019 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -67,15 +67,9 @@ using namespace QTestPrivate;
|
|||||||
class tst_QStyle : public QObject
|
class tst_QStyle : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
|
||||||
tst_QStyle();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool testAllFunctions(QStyle *);
|
|
||||||
bool testScrollBarSubControls();
|
|
||||||
private slots:
|
private slots:
|
||||||
void drawItemPixmap();
|
void drawItemPixmap();
|
||||||
void init();
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
#ifndef QT_NO_STYLE_FUSION
|
#ifndef QT_NO_STYLE_FUSION
|
||||||
void testFusionStyle();
|
void testFusionStyle();
|
||||||
@ -100,38 +94,29 @@ private slots:
|
|||||||
void testProxyCalled();
|
void testProxyCalled();
|
||||||
void testStyleOptionInit();
|
void testStyleOptionInit();
|
||||||
private:
|
private:
|
||||||
|
bool testAllFunctions(QStyle *);
|
||||||
|
bool testScrollBarSubControls(const QStyle *style);
|
||||||
|
void testPainting(QStyle *style, const QString &platform);
|
||||||
void lineUpLayoutTest(QStyle *);
|
void lineUpLayoutTest(QStyle *);
|
||||||
QWidget *testWidget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
tst_QStyle::tst_QStyle()
|
|
||||||
{
|
|
||||||
testWidget = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyWidget : public QWidget
|
class MyWidget : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyWidget( QWidget* QWidget=0, const char* name=0 );
|
using QWidget::QWidget;
|
||||||
protected:
|
|
||||||
void paintEvent( QPaintEvent* );
|
|
||||||
};
|
|
||||||
|
|
||||||
void tst_QStyle::init()
|
protected:
|
||||||
{
|
void paintEvent(QPaintEvent *) override;
|
||||||
testWidget = new MyWidget( 0, "testObject");
|
};
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QStyle::cleanup()
|
void tst_QStyle::cleanup()
|
||||||
{
|
{
|
||||||
delete testWidget;
|
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
||||||
testWidget = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QStyle::testStyleFactory()
|
void tst_QStyle::testStyleFactory()
|
||||||
{
|
{
|
||||||
QStringList keys = QStyleFactory::keys();
|
const QStringList keys = QStyleFactory::keys();
|
||||||
#ifndef QT_NO_STYLE_FUSION
|
#ifndef QT_NO_STYLE_FUSION
|
||||||
QVERIFY(keys.contains("Fusion"));
|
QVERIFY(keys.contains("Fusion"));
|
||||||
#endif
|
#endif
|
||||||
@ -139,17 +124,17 @@ void tst_QStyle::testStyleFactory()
|
|||||||
QVERIFY(keys.contains("Windows"));
|
QVERIFY(keys.contains("Windows"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
foreach (QString styleName , keys) {
|
for (const QString &styleName : keys) {
|
||||||
QStyle *style = QStyleFactory::create(styleName);
|
QScopedPointer<QStyle> style(QStyleFactory::create(styleName));
|
||||||
QVERIFY2(style != 0, qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName)));
|
QVERIFY2(!style.isNull(),
|
||||||
delete style;
|
qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomProxy : public QProxyStyle
|
class CustomProxy : public QProxyStyle
|
||||||
{
|
{
|
||||||
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0,
|
int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
|
||||||
const QWidget *widget = 0) const
|
const QWidget *widget = nullptr) const override
|
||||||
{
|
{
|
||||||
if (metric == QStyle::PM_ButtonIconSize)
|
if (metric == QStyle::PM_ButtonIconSize)
|
||||||
return 13;
|
return 13;
|
||||||
@ -170,9 +155,9 @@ void tst_QStyle::testProxyStyle()
|
|||||||
QCOMPARE(proxyStyle->baseStyle(), style);
|
QCOMPARE(proxyStyle->baseStyle(), style);
|
||||||
|
|
||||||
QVERIFY(testAllFunctions(proxyStyle));
|
QVERIFY(testAllFunctions(proxyStyle));
|
||||||
proxyStyle->setBaseStyle(0);
|
proxyStyle->setBaseStyle(nullptr);
|
||||||
QVERIFY(proxyStyle->baseStyle());
|
QVERIFY(proxyStyle->baseStyle());
|
||||||
qApp->setStyle(proxyStyle);
|
QApplication::setStyle(proxyStyle);
|
||||||
|
|
||||||
QProxyStyle* baseStyle = new QProxyStyle("Windows");
|
QProxyStyle* baseStyle = new QProxyStyle("Windows");
|
||||||
QCOMPARE(baseStyle->baseStyle()->objectName(), style->objectName());
|
QCOMPARE(baseStyle->baseStyle()->objectName(), style->objectName());
|
||||||
@ -189,10 +174,12 @@ void tst_QStyle::testProxyStyle()
|
|||||||
|
|
||||||
void tst_QStyle::drawItemPixmap()
|
void tst_QStyle::drawItemPixmap()
|
||||||
{
|
{
|
||||||
testWidget->resize(300, 300);
|
MyWidget testWidget;
|
||||||
testWidget->showNormal();
|
testWidget.setObjectName("testObject");
|
||||||
|
testWidget.resize(300, 300);
|
||||||
|
testWidget.showNormal();
|
||||||
|
|
||||||
QImage image = testWidget->grab().toImage();
|
QImage image = testWidget.grab().toImage();
|
||||||
const QRgb green = QColor(Qt::green).rgb();
|
const QRgb green = QColor(Qt::green).rgb();
|
||||||
QVERIFY(image.reinterpretAsFormat(QImage::Format_RGB32));
|
QVERIFY(image.reinterpretAsFormat(QImage::Format_RGB32));
|
||||||
const QRgb *bits = reinterpret_cast<const QRgb *>(image.constBits());
|
const QRgb *bits = reinterpret_cast<const QRgb *>(image.constBits());
|
||||||
@ -201,33 +188,33 @@ void tst_QStyle::drawItemPixmap()
|
|||||||
QEXPECT_FAIL("", "QWidget::resize does not work on WinRT", Continue);
|
QEXPECT_FAIL("", "QWidget::resize does not work on WinRT", Continue);
|
||||||
#endif
|
#endif
|
||||||
QVERIFY(std::all_of(bits, end, [green] (QRgb r) { return r == green; }));
|
QVERIFY(std::all_of(bits, end, [green] (QRgb r) { return r == green; }));
|
||||||
testWidget->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tst_QStyle::testAllFunctions(QStyle *style)
|
bool tst_QStyle::testAllFunctions(QStyle *style)
|
||||||
{
|
{
|
||||||
QStyleOption opt;
|
QStyleOption opt;
|
||||||
opt.init(testWidget);
|
QWidget testWidget;
|
||||||
|
opt.init(&testWidget);
|
||||||
|
|
||||||
testWidget->setStyle(style);
|
testWidget.setStyle(style);
|
||||||
|
|
||||||
//Tests styleHint with default arguments for potential crashes
|
//Tests styleHint with default arguments for potential crashes
|
||||||
for ( int hint = 0 ; hint < int(QStyle::SH_Menu_Mask); ++hint) {
|
for ( int hint = 0 ; hint < int(QStyle::SH_Menu_Mask); ++hint) {
|
||||||
style->styleHint(QStyle::StyleHint(hint));
|
style->styleHint(QStyle::StyleHint(hint));
|
||||||
style->styleHint(QStyle::StyleHint(hint), &opt, testWidget);
|
style->styleHint(QStyle::StyleHint(hint), &opt, &testWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tests pixelMetric with default arguments for potential crashes
|
//Tests pixelMetric with default arguments for potential crashes
|
||||||
for ( int pm = 0 ; pm < int(QStyle::PM_LayoutVerticalSpacing); ++pm) {
|
for ( int pm = 0 ; pm < int(QStyle::PM_LayoutVerticalSpacing); ++pm) {
|
||||||
style->pixelMetric(QStyle::PixelMetric(pm));
|
style->pixelMetric(QStyle::PixelMetric(pm));
|
||||||
style->pixelMetric(QStyle::PixelMetric(pm), &opt, testWidget);
|
style->pixelMetric(QStyle::PixelMetric(pm), &opt, &testWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tests drawControl with default arguments for potential crashes
|
//Tests drawControl with default arguments for potential crashes
|
||||||
for ( int control = 0 ; control < int(QStyle::CE_ColumnViewGrip); ++control) {
|
for ( int control = 0 ; control < int(QStyle::CE_ColumnViewGrip); ++control) {
|
||||||
QPixmap surface(QSize(200, 200));
|
QPixmap surface(QSize(200, 200));
|
||||||
QPainter painter(&surface);
|
QPainter painter(&surface);
|
||||||
style->drawControl(QStyle::ControlElement(control), &opt, &painter, 0);
|
style->drawControl(QStyle::ControlElement(control), &opt, &painter, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tests drawComplexControl with default arguments for potential crashes
|
//Tests drawComplexControl with default arguments for potential crashes
|
||||||
@ -235,35 +222,35 @@ bool tst_QStyle::testAllFunctions(QStyle *style)
|
|||||||
QPixmap surface(QSize(200, 200));
|
QPixmap surface(QSize(200, 200));
|
||||||
QPainter painter(&surface);
|
QPainter painter(&surface);
|
||||||
QStyleOptionComboBox copt1;
|
QStyleOptionComboBox copt1;
|
||||||
copt1.init(testWidget);
|
copt1.init(&testWidget);
|
||||||
|
|
||||||
QStyleOptionGroupBox copt2;
|
QStyleOptionGroupBox copt2;
|
||||||
copt2.init(testWidget);
|
copt2.init(&testWidget);
|
||||||
QStyleOptionSizeGrip copt3;
|
QStyleOptionSizeGrip copt3;
|
||||||
copt3.init(testWidget);
|
copt3.init(&testWidget);
|
||||||
QStyleOptionSlider copt4;
|
QStyleOptionSlider copt4;
|
||||||
copt4.init(testWidget);
|
copt4.init(&testWidget);
|
||||||
copt4.minimum = 0;
|
copt4.minimum = 0;
|
||||||
copt4.maximum = 100;
|
copt4.maximum = 100;
|
||||||
copt4.tickInterval = 25;
|
copt4.tickInterval = 25;
|
||||||
copt4.sliderValue = 50;
|
copt4.sliderValue = 50;
|
||||||
QStyleOptionSpinBox copt5;
|
QStyleOptionSpinBox copt5;
|
||||||
copt5.init(testWidget);
|
copt5.init(&testWidget);
|
||||||
QStyleOptionTitleBar copt6;
|
QStyleOptionTitleBar copt6;
|
||||||
copt6.init(testWidget);
|
copt6.init(&testWidget);
|
||||||
QStyleOptionToolButton copt7;
|
QStyleOptionToolButton copt7;
|
||||||
copt7.init(testWidget);
|
copt7.init(&testWidget);
|
||||||
QStyleOptionComplex copt9;
|
QStyleOptionComplex copt9;
|
||||||
copt9.initFrom(testWidget);
|
copt9.initFrom(&testWidget);
|
||||||
|
|
||||||
style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, 0);
|
style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, 0);
|
style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, 0);
|
style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, 0);
|
style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, 0);
|
style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, 0);
|
style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, 0);
|
style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, nullptr);
|
||||||
style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, 0);
|
style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check standard pixmaps/icons
|
//Check standard pixmaps/icons
|
||||||
@ -279,20 +266,21 @@ bool tst_QStyle::testAllFunctions(QStyle *style)
|
|||||||
}
|
}
|
||||||
|
|
||||||
style->itemPixmapRect(QRect(0, 0, 100, 100), Qt::AlignHCenter, QPixmap(200, 200));
|
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"));
|
style->itemTextRect(QFontMetrics(QApplication::font()), QRect(0, 0, 100, 100),
|
||||||
|
Qt::AlignHCenter, true, QLatin1String("Test"));
|
||||||
|
|
||||||
return testScrollBarSubControls();
|
return testScrollBarSubControls(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tst_QStyle::testScrollBarSubControls()
|
bool tst_QStyle::testScrollBarSubControls(const QStyle *style)
|
||||||
{
|
{
|
||||||
const auto *style = testWidget->style();
|
const bool isMacStyle = style->objectName().compare(QLatin1String("macintosh"),
|
||||||
const bool isMacStyle = style->objectName().toLower() == "macintosh";
|
Qt::CaseInsensitive) == 0;
|
||||||
QScrollBar scrollBar;
|
QScrollBar scrollBar;
|
||||||
setFrameless(&scrollBar);
|
setFrameless(&scrollBar);
|
||||||
scrollBar.show();
|
scrollBar.show();
|
||||||
const QStyleOptionSlider opt = qt_qscrollbarStyleOption(&scrollBar);
|
const QStyleOptionSlider opt = qt_qscrollbarStyleOption(&scrollBar);
|
||||||
foreach (int sc, QList<int>() << 1 << 2 << 4 << 8) {
|
for (int sc : {1, 2, 4, 8}) {
|
||||||
const auto subControl = static_cast<QStyle::SubControl>(sc);
|
const auto subControl = static_cast<QStyle::SubControl>(sc);
|
||||||
const QRect sr = style->subControlRect(QStyle::CC_ScrollBar, &opt, subControl, &scrollBar);
|
const QRect sr = style->subControlRect(QStyle::CC_ScrollBar, &opt, subControl, &scrollBar);
|
||||||
if (sr.isNull()) {
|
if (sr.isNull()) {
|
||||||
@ -310,34 +298,34 @@ bool tst_QStyle::testScrollBarSubControls()
|
|||||||
#ifndef QT_NO_STYLE_FUSION
|
#ifndef QT_NO_STYLE_FUSION
|
||||||
void tst_QStyle::testFusionStyle()
|
void tst_QStyle::testFusionStyle()
|
||||||
{
|
{
|
||||||
QStyle *fstyle = QStyleFactory::create("Fusion");
|
QScopedPointer<QStyle> fstyle(QStyleFactory::create("Fusion"));
|
||||||
QVERIFY(testAllFunctions(fstyle));
|
QVERIFY(!fstyle.isNull());
|
||||||
lineUpLayoutTest(fstyle);
|
QVERIFY(testAllFunctions(fstyle.data()));
|
||||||
delete fstyle;
|
lineUpLayoutTest(fstyle.data());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void tst_QStyle::testWindowsStyle()
|
void tst_QStyle::testWindowsStyle()
|
||||||
{
|
{
|
||||||
QStyle *wstyle = QStyleFactory::create("Windows");
|
QScopedPointer<QStyle> wstyle(QStyleFactory::create("Windows"));
|
||||||
QVERIFY(testAllFunctions(wstyle));
|
QVERIFY(!wstyle.isNull());
|
||||||
lineUpLayoutTest(wstyle);
|
QVERIFY(testAllFunctions(wstyle.data()));
|
||||||
|
lineUpLayoutTest(wstyle.data());
|
||||||
|
|
||||||
// Tests drawing indeterminate progress with 0 size: QTBUG-15973
|
// Tests drawing indeterminate progress with 0 size: QTBUG-15973
|
||||||
QStyleOptionProgressBar pb;
|
QStyleOptionProgressBar pb;
|
||||||
pb.rect = QRect(0,0,-9,0);
|
pb.rect = QRect(0,0,-9,0);
|
||||||
QPixmap surface(QSize(200, 200));
|
QPixmap surface(QSize(200, 200));
|
||||||
QPainter painter(&surface);
|
QPainter painter(&surface);
|
||||||
wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, 0);
|
wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, nullptr);
|
||||||
delete wstyle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA) && !defined(Q_OS_WINRT)
|
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA) && !defined(Q_OS_WINRT)
|
||||||
void tst_QStyle::testWindowsVistaStyle()
|
void tst_QStyle::testWindowsVistaStyle()
|
||||||
{
|
{
|
||||||
QStyle *vistastyle = QStyleFactory::create("WindowsVista");
|
QScopedPointer<QStyle> vistastyle(QStyleFactory::create("WindowsVista"));
|
||||||
QVERIFY(testAllFunctions(vistastyle));
|
QVERIFY(!vistastyle.isNull());
|
||||||
delete vistastyle;
|
QVERIFY(testAllFunctions(vistastyle.data()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -351,14 +339,7 @@ void tst_QStyle::testMacStyle()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Helper class...
|
// Helper class...
|
||||||
|
void MyWidget::paintEvent(QPaintEvent *)
|
||||||
MyWidget::MyWidget( QWidget* parent, const char* name )
|
|
||||||
: QWidget( parent )
|
|
||||||
{
|
|
||||||
setObjectName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyWidget::paintEvent( QPaintEvent* )
|
|
||||||
{
|
{
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
QPixmap big(400,400);
|
QPixmap big(400,400);
|
||||||
@ -371,20 +352,12 @@ class Qt42Style : public QCommonStyle
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Qt42Style() : QCommonStyle()
|
int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
|
||||||
{
|
const QWidget *widget = nullptr) const override;
|
||||||
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;
|
|
||||||
|
|
||||||
|
int margin_toplevel = 10;
|
||||||
|
int margin = 5;
|
||||||
|
int spacing = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option = 0*/,
|
int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option = 0*/,
|
||||||
@ -393,13 +366,10 @@ int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option =
|
|||||||
switch (metric) {
|
switch (metric) {
|
||||||
case QStyle::PM_DefaultTopLevelMargin:
|
case QStyle::PM_DefaultTopLevelMargin:
|
||||||
return margin_toplevel;
|
return margin_toplevel;
|
||||||
break;
|
|
||||||
case QStyle::PM_DefaultChildMargin:
|
case QStyle::PM_DefaultChildMargin:
|
||||||
return margin;
|
return margin;
|
||||||
break;
|
|
||||||
case QStyle::PM_DefaultLayoutSpacing:
|
case QStyle::PM_DefaultLayoutSpacing:
|
||||||
return spacing;
|
return spacing;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -409,7 +379,7 @@ int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option =
|
|||||||
|
|
||||||
void tst_QStyle::pixelMetric()
|
void tst_QStyle::pixelMetric()
|
||||||
{
|
{
|
||||||
Qt42Style *style = new Qt42Style();
|
QScopedPointer<Qt42Style> style(new Qt42Style);
|
||||||
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 10);
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 10);
|
||||||
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 5);
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 5);
|
||||||
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0);
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0);
|
||||||
@ -427,8 +397,6 @@ void tst_QStyle::pixelMetric()
|
|||||||
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), -1);
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), -1);
|
||||||
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), -1);
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), -1);
|
||||||
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), -1);
|
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), -1);
|
||||||
|
|
||||||
delete style;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
|
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
|
||||||
@ -474,10 +442,11 @@ void tst_QStyle::lineUpLayoutTest(QStyle *style)
|
|||||||
layout.addWidget(&lineedit);
|
layout.addWidget(&lineedit);
|
||||||
layout.addWidget(&combo);
|
layout.addWidget(&combo);
|
||||||
widget.setLayout(&layout);
|
widget.setLayout(&layout);
|
||||||
widget.setStyle(style);
|
widget.setStyle(style);
|
||||||
// propagate the style.
|
// propagate the style.
|
||||||
foreach (QWidget *w, widget.findChildren<QWidget *>())
|
const auto children = widget.findChildren<QWidget *>();
|
||||||
w->setStyle(style);
|
for (QWidget *w : children)
|
||||||
|
w->setStyle(style);
|
||||||
widget.show();
|
widget.show();
|
||||||
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
||||||
|
|
||||||
@ -498,31 +467,32 @@ void tst_QStyle::lineUpLayoutTest(QStyle *style)
|
|||||||
|
|
||||||
void tst_QStyle::defaultFont()
|
void tst_QStyle::defaultFont()
|
||||||
{
|
{
|
||||||
QFont defaultFont = qApp->font();
|
QFont defaultFont = QApplication::font();
|
||||||
QFont pointFont = defaultFont;
|
QFont pointFont = defaultFont;
|
||||||
pointFont.setPixelSize(9);
|
pointFont.setPixelSize(9);
|
||||||
qApp->setFont(pointFont);
|
QApplication::setFont(pointFont);
|
||||||
QPushButton button;
|
QPushButton button;
|
||||||
setFrameless(&button);
|
setFrameless(&button);
|
||||||
button.show();
|
button.show();
|
||||||
qApp->processEvents();
|
QCoreApplication::processEvents();
|
||||||
qApp->setFont(defaultFont);
|
QApplication::setFont(defaultFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DrawTextStyle : public QProxyStyle
|
class DrawTextStyle : public QProxyStyle
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DrawTextStyle(QStyle *base = 0) : QProxyStyle(), alignment(0) { setBaseStyle(base); }
|
using QProxyStyle::QProxyStyle;
|
||||||
|
|
||||||
void drawItemText(QPainter *painter, const QRect &rect,
|
void drawItemText(QPainter *painter, const QRect &rect,
|
||||||
int flags, const QPalette &pal, bool enabled,
|
int flags, const QPalette &pal, bool enabled,
|
||||||
const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const
|
const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override
|
||||||
{
|
{
|
||||||
DrawTextStyle *that = (DrawTextStyle *)this;
|
alignment = flags;
|
||||||
that->alignment = flags;
|
|
||||||
QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
|
QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
|
||||||
}
|
}
|
||||||
int alignment;
|
|
||||||
|
mutable int alignment = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -533,46 +503,48 @@ void tst_QStyle::testDrawingShortcuts()
|
|||||||
setFrameless(&w);
|
setFrameless(&w);
|
||||||
QToolButton *tb = new QToolButton(&w);
|
QToolButton *tb = new QToolButton(&w);
|
||||||
tb->setText("&abc");
|
tb->setText("&abc");
|
||||||
DrawTextStyle *dts = new DrawTextStyle;
|
QScopedPointer<DrawTextStyle> dts(new DrawTextStyle);
|
||||||
w.show();
|
w.show();
|
||||||
tb->setStyle(dts);
|
tb->setStyle(dts.data());
|
||||||
tb->grab();
|
tb->grab();
|
||||||
QStyleOptionToolButton sotb;
|
QStyleOptionToolButton sotb;
|
||||||
sotb.initFrom(tb);
|
sotb.initFrom(tb);
|
||||||
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
||||||
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
||||||
delete dts;
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
QToolBar w;
|
QToolBar w;
|
||||||
setFrameless(&w);
|
setFrameless(&w);
|
||||||
QToolButton *tb = new QToolButton(&w);
|
QToolButton *tb = new QToolButton(&w);
|
||||||
tb->setText("&abc");
|
tb->setText("&abc");
|
||||||
DrawTextStyle *dts = new DrawTextStyle;
|
QScopedPointer<DrawTextStyle> dts(new DrawTextStyle);
|
||||||
w.addWidget(tb);
|
w.addWidget(tb);
|
||||||
w.show();
|
w.show();
|
||||||
tb->setStyle(dts);
|
tb->setStyle(dts.data());
|
||||||
tb->grab();
|
tb->grab();
|
||||||
QStyleOptionToolButton sotb;
|
QStyleOptionToolButton sotb;
|
||||||
sotb.initFrom(tb);
|
sotb.initFrom(tb);
|
||||||
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
||||||
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
||||||
delete dts;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SCROLLBAR_SPACING 33
|
static const int SCROLLBAR_SPACING = 33;
|
||||||
|
|
||||||
class FrameTestStyle : public QProxyStyle {
|
class FrameTestStyle : public QProxyStyle {
|
||||||
public:
|
public:
|
||||||
FrameTestStyle() : QProxyStyle("Windows") { }
|
FrameTestStyle() : QProxyStyle("Windows") { }
|
||||||
int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const {
|
|
||||||
|
int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
|
||||||
|
QStyleHintReturn *returnData) const override
|
||||||
|
{
|
||||||
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
|
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
|
||||||
return 1;
|
return 1;
|
||||||
return QProxyStyle ::styleHint(hint, opt, widget, returnData);
|
return QProxyStyle ::styleHint(hint, opt, widget, returnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const {
|
int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const override
|
||||||
|
{
|
||||||
if (pm == QStyle::PM_ScrollView_ScrollBarSpacing)
|
if (pm == QStyle::PM_ScrollView_ScrollBarSpacing)
|
||||||
return SCROLLBAR_SPACING;
|
return SCROLLBAR_SPACING;
|
||||||
return QProxyStyle ::pixelMetric(pm, option ,widget);
|
return QProxyStyle ::pixelMetric(pm, option ,widget);
|
||||||
@ -583,12 +555,12 @@ void tst_QStyle::testFrameOnlyAroundContents()
|
|||||||
{
|
{
|
||||||
QScrollArea area;
|
QScrollArea area;
|
||||||
area.setGeometry(0, 0, 200, 200);
|
area.setGeometry(0, 0, 200, 200);
|
||||||
QStyle *winStyle = QStyleFactory::create("Windows");
|
QScopedPointer<QStyle> winStyle(QStyleFactory::create("Windows"));
|
||||||
FrameTestStyle frameStyle;
|
FrameTestStyle frameStyle;
|
||||||
QWidget *widget = new QWidget(&area);
|
QWidget *widget = new QWidget(&area);
|
||||||
widget->setGeometry(0, 0, 400, 400);
|
widget->setGeometry(0, 0, 400, 400);
|
||||||
area.setStyle(winStyle);
|
area.setStyle(winStyle.data());
|
||||||
area.verticalScrollBar()->setStyle(winStyle);
|
area.verticalScrollBar()->setStyle(winStyle.data());
|
||||||
area.setWidget(widget);
|
area.setWidget(widget);
|
||||||
area.setVisible(true);
|
area.setVisible(true);
|
||||||
int viewPortWidth = area.viewport()->width();
|
int viewPortWidth = area.viewport()->width();
|
||||||
@ -598,8 +570,7 @@ void tst_QStyle::testFrameOnlyAroundContents()
|
|||||||
#ifdef Q_OS_WINRT
|
#ifdef Q_OS_WINRT
|
||||||
QEXPECT_FAIL("", "QWidget::setGeometry does not work on WinRT", Continue);
|
QEXPECT_FAIL("", "QWidget::setGeometry does not work on WinRT", Continue);
|
||||||
#endif
|
#endif
|
||||||
QVERIFY(viewPortWidth == area.viewport()->width() + SCROLLBAR_SPACING);
|
QCOMPARE(viewPortWidth, area.viewport()->width() + SCROLLBAR_SPACING);
|
||||||
delete winStyle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -607,16 +578,16 @@ class ProxyTest: public QProxyStyle
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ProxyTest(QStyle *style = 0)
|
using QProxyStyle::QProxyStyle;
|
||||||
:QProxyStyle(style)
|
|
||||||
, called(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
|
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
|
||||||
|
const QWidget *w) const override
|
||||||
|
{
|
||||||
called = true;
|
called = true;
|
||||||
return QProxyStyle::drawPrimitive(pe, opt, p, w);
|
return QProxyStyle::drawPrimitive(pe, opt, p, w);
|
||||||
}
|
}
|
||||||
mutable bool called;
|
|
||||||
|
mutable bool called = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -630,17 +601,16 @@ void tst_QStyle::testProxyCalled()
|
|||||||
QPixmap surface(QSize(200, 200));
|
QPixmap surface(QSize(200, 200));
|
||||||
QPainter painter(&surface);
|
QPainter painter(&surface);
|
||||||
|
|
||||||
QStringList keys = QStyleFactory::keys();
|
const QStringList keys = QStyleFactory::keys();
|
||||||
QVector<QStyle*> styles;
|
QVector<QStyle*> styles;
|
||||||
styles.reserve(keys.size() + 1);
|
styles.reserve(keys.size() + 1);
|
||||||
|
|
||||||
styles << new QCommonStyle();
|
styles << new QCommonStyle();
|
||||||
|
|
||||||
Q_FOREACH (const QString &key, keys) {
|
for (const QString &key : keys)
|
||||||
styles << QStyleFactory::create(key);
|
styles << QStyleFactory::create(key);
|
||||||
}
|
|
||||||
|
|
||||||
Q_FOREACH (QStyle *style, styles) {
|
for (QStyle *style : styles) {
|
||||||
ProxyTest testStyle;
|
ProxyTest testStyle;
|
||||||
testStyle.setBaseStyle(style);
|
testStyle.setBaseStyle(style);
|
||||||
style->drawControl(QStyle::CE_ToolButtonLabel, &opt, &painter, &b);
|
style->drawControl(QStyle::CE_ToolButtonLabel, &opt, &painter, &b);
|
||||||
@ -654,11 +624,9 @@ class TestStyleOptionInitProxy: public QProxyStyle
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
mutable bool invalidOptionsDetected;
|
mutable bool invalidOptionsDetected = false;
|
||||||
explicit TestStyleOptionInitProxy(QStyle *style = nullptr)
|
|
||||||
: QProxyStyle(style),
|
using QProxyStyle::QProxyStyle;
|
||||||
invalidOptionsDetected(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
|
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
|
||||||
checkStyleEnum<QStyle::PrimitiveElement>(pe, opt);
|
checkStyleEnum<QStyle::PrimitiveElement>(pe, opt);
|
||||||
@ -743,7 +711,7 @@ void tst_QStyle::testStyleOptionInit()
|
|||||||
QStringList keys = QStyleFactory::keys();
|
QStringList keys = QStyleFactory::keys();
|
||||||
keys.prepend(QString()); // QCommonStyle marker
|
keys.prepend(QString()); // QCommonStyle marker
|
||||||
|
|
||||||
Q_FOREACH (const QString &key, keys) {
|
for (const QString &key : qAsConst(keys)) {
|
||||||
QStyle* style = key.isEmpty() ? new QCommonStyle : QStyleFactory::create(key);
|
QStyle* style = key.isEmpty() ? new QCommonStyle : QStyleFactory::create(key);
|
||||||
TestStyleOptionInitProxy testStyle;
|
TestStyleOptionInitProxy testStyle;
|
||||||
testStyle.setBaseStyle(style);
|
testStyle.setBaseStyle(style);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user