mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-02 23:35:28 +08:00
qt 6.5.1 original
This commit is contained in:
13
tests/auto/widgets/styles/CMakeLists.txt
Normal file
13
tests/auto/widgets/styles/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
if(APPLE)
|
||||
add_subdirectory(qmacstyle)
|
||||
endif()
|
||||
if(QT_FEATURE_private_tests)
|
||||
add_subdirectory(qstyle)
|
||||
endif()
|
||||
add_subdirectory(qstyleoption)
|
||||
if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT QNX AND NOT UIKIT)
|
||||
add_subdirectory(qstylesheetstyle)
|
||||
endif()
|
14
tests/auto/widgets/styles/qmacstyle/CMakeLists.txt
Normal file
14
tests/auto/widgets/styles/qmacstyle/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qmacstyle Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qmacstyle
|
||||
SOURCES
|
||||
tst_qmacstyle.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::WidgetsPrivate
|
||||
)
|
377
tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp
Normal file
377
tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp
Normal file
@ -0,0 +1,377 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
|
||||
#include <QTest>
|
||||
#include <QtWidgets>
|
||||
#include <private/qstylehelper_p.h>
|
||||
|
||||
Q_DECLARE_METATYPE(QStyleHelper::WidgetSizePolicy);
|
||||
|
||||
#define CT(E) \
|
||||
static const ControlType E = QSizePolicy::E;
|
||||
|
||||
typedef QSizePolicy::ControlType ControlType;
|
||||
|
||||
CT(ButtonBox)
|
||||
CT(CheckBox)
|
||||
CT(ComboBox)
|
||||
CT(Label)
|
||||
CT(LineEdit)
|
||||
CT(PushButton)
|
||||
CT(RadioButton)
|
||||
|
||||
class tst_QMacStyle : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QMacStyle() { qRegisterMetaType<QStyleHelper::WidgetSizePolicy>("WidgetSizePolicy"); }
|
||||
|
||||
private slots:
|
||||
void sizeHints_data();
|
||||
void sizeHints();
|
||||
void layoutMargins_data();
|
||||
void layoutMargins();
|
||||
void layoutSpacings_data();
|
||||
void layoutSpacings();
|
||||
void smallMiniNormalExclusivity_data();
|
||||
void smallMiniNormalExclusivity();
|
||||
void passwordCharacter();
|
||||
|
||||
private:
|
||||
static QSize msh(QWidget *widget);
|
||||
static QSize sh(QWidget *widget);
|
||||
static QRect geo(QWidget *widget);
|
||||
static QPoint pos(QWidget *widget) { return geo(widget).topLeft(); }
|
||||
static QSize size(QWidget *widget) { return geo(widget).size(); }
|
||||
static QSize gap(QWidget *widget1, QWidget *widget2);
|
||||
static int hgap(QWidget *widget1, QWidget *widget2) { return gap(widget1, widget2).width(); }
|
||||
static int vgap(QWidget *widget1, QWidget *widget2) { return gap(widget1, widget2).height(); }
|
||||
static void setSize(QWidget *widget, QStyleHelper::WidgetSizePolicy size);
|
||||
static int spacing(ControlType control1, ControlType control2, Qt::Orientation orientation,
|
||||
QStyleOption *option = nullptr, QWidget *widget = nullptr);
|
||||
static int hspacing(ControlType control1, ControlType control2, QStyleHelper::WidgetSizePolicy size = QStyleHelper::SizeLarge);
|
||||
static int vspacing(ControlType control1, ControlType control2, QStyleHelper::WidgetSizePolicy size = QStyleHelper::SizeLarge);
|
||||
};
|
||||
|
||||
#define SIZE(x, y, z) \
|
||||
((size == QStyleHelper::SizeLarge) ? (x) : (size == QStyleHelper::SizeSmall) ? (y) : (z))
|
||||
|
||||
static bool bigSurOrAbove() {
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur;
|
||||
}
|
||||
|
||||
void tst_QMacStyle::sizeHints_data()
|
||||
{
|
||||
QTest::addColumn<QStyleHelper::WidgetSizePolicy>("size");
|
||||
QTest::newRow("normal") << QStyleHelper::SizeLarge;
|
||||
// QTest::newRow("small") << QStyleHelper::SizeSmall;
|
||||
// QTest::newRow("mini") << QStyleHelper::SizeMini;
|
||||
}
|
||||
|
||||
void tst_QMacStyle::sizeHints()
|
||||
{
|
||||
QFETCH(QStyleHelper::WidgetSizePolicy, size);
|
||||
QDialog w;
|
||||
setSize(&w, size);
|
||||
|
||||
QLineEdit lineEdit1(&w);
|
||||
QCOMPARE(sh(&lineEdit1).height(), SIZE(21, 19, 16)); // 16 in Builder, 15 in AHIG
|
||||
|
||||
QProgressBar progress1(&w);
|
||||
progress1.setOrientation(Qt::Horizontal);
|
||||
qDebug() << "sh" << progress1.sizeHint();
|
||||
QCOMPARE(sh(&progress1).height(), SIZE(16, 10, 10)); // Builder
|
||||
|
||||
progress1.setOrientation(Qt::Vertical);
|
||||
QCOMPARE(sh(&progress1).width(), SIZE(16, 10, 10)); // Builder
|
||||
|
||||
QRadioButton radio1("Radio", &w);
|
||||
QCOMPARE(sh(&radio1).height(), SIZE(14, 12, 10)); // Builder
|
||||
|
||||
QCheckBox checkBox1("Switch", &w);
|
||||
QCOMPARE(sh(&checkBox1).height(), SIZE(13, 12, 10)); // Builder
|
||||
|
||||
QComboBox comboBox1(&w);
|
||||
comboBox1.setEditable(false);
|
||||
comboBox1.addItem("Foo");
|
||||
QCOMPARE(sh(&comboBox1).height(), SIZE(26, 17, 15));
|
||||
|
||||
QComboBox comboBox2(&w);
|
||||
comboBox2.setEditable(true);
|
||||
comboBox2.addItem("Foo");
|
||||
QCOMPARE(sh(&comboBox2).height(), SIZE(26, 17, 15));
|
||||
|
||||
// Combos in toolbars use the actual widget rect to
|
||||
// avoid faulty clipping:
|
||||
QToolBar tb;
|
||||
setSize(&tb, size);
|
||||
QComboBox comboBox3(&tb);
|
||||
comboBox3.addItem("Foo");
|
||||
QCOMPARE(sh(&comboBox3).height(), SIZE(32, -1, -1));
|
||||
|
||||
QSlider slider1(Qt::Horizontal, &w);
|
||||
QCOMPARE(sh(&slider1).height(), SIZE(bigSurOrAbove() ? 18 : 15, 12, 10));
|
||||
|
||||
slider1.setTickPosition(QSlider::TicksAbove);
|
||||
QCOMPARE(sh(&slider1).height(), SIZE(24, 17, 16)); // Builder
|
||||
|
||||
slider1.setTickPosition(QSlider::TicksBelow);
|
||||
QCOMPARE(sh(&slider1).height(), SIZE(24, 17, 16)); // Builder
|
||||
|
||||
slider1.setTickPosition(QSlider::TicksBothSides);
|
||||
QVERIFY(sh(&slider1).height() > SIZE(bigSurOrAbove() ? 18 : 15, 12, 10)); // common sense
|
||||
|
||||
QPushButton ok1("OK", &w);
|
||||
QPushButton cancel1("Cancel", &w);
|
||||
|
||||
QSize s1 = sh(&ok1);
|
||||
if (size == QStyleHelper::SizeLarge) {
|
||||
// AHIG says 68, Builder does 70, and Qt seems to do 69
|
||||
QVERIFY(s1.width() >= 68 && s1.width() <= 70);
|
||||
}
|
||||
QCOMPARE(s1.height(), SIZE(20, 17, 14)); // 14 in Builder, 15 in AHIG
|
||||
|
||||
// Cancel should be identical to OK, no matter what
|
||||
QCOMPARE(s1, sh(&cancel1));
|
||||
|
||||
// Play with auto-default and default
|
||||
cancel1.setAutoDefault(false);
|
||||
QCOMPARE(s1, sh(&cancel1));
|
||||
cancel1.setAutoDefault(true);
|
||||
QCOMPARE(s1, sh(&cancel1));
|
||||
cancel1.setDefault(true);
|
||||
QCOMPARE(s1, sh(&cancel1));
|
||||
|
||||
QDialogButtonBox bbox(&w);
|
||||
bbox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
QCOMPARE(s1, sh(bbox.button(QDialogButtonBox::Ok)));
|
||||
QCOMPARE(s1, sh(bbox.button(QDialogButtonBox::Cancel)));
|
||||
|
||||
QMessageBox mbox(&w);
|
||||
mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||
QCOMPARE(s1, sh(mbox.button(QMessageBox::Ok)));
|
||||
QCOMPARE(s1, sh(mbox.button(QMessageBox::Cancel)));
|
||||
|
||||
/*
|
||||
QSpinBox spinBox1(&w);
|
||||
int h1 = sh(&spinBox1).height();
|
||||
QCOMPARE(h1, SIZE(22, 19, 15));
|
||||
|
||||
QDateEdit date1(&w);
|
||||
QCOMPARE(sh(&date1).height(), h1);
|
||||
|
||||
QTimeEdit time1(&w);
|
||||
QCOMPARE(sh(&time1).height(), h1);
|
||||
|
||||
QDateTimeEdit dateTime1(&w);
|
||||
QCOMPARE(sh(&dateTime1).height(), h1);
|
||||
|
||||
QSize s2 = sh(&ok1);
|
||||
if (size == Normal) {
|
||||
QVERIFY(s2.height() >= 21 && s2.height() <= 32);
|
||||
} else {
|
||||
QVERIFY(s2.height() >= 18 && s2.height() <= 24);
|
||||
}
|
||||
*/
|
||||
|
||||
// QMacStyle bug: label doesn't react to Small and Mini
|
||||
QLabel label1("Blah", &w);
|
||||
QCOMPARE(sh(&label1).height(), SIZE(16, 14, 11));
|
||||
}
|
||||
|
||||
void tst_QMacStyle::layoutMargins_data()
|
||||
{
|
||||
tst_QMacStyle::sizeHints_data();
|
||||
}
|
||||
|
||||
void tst_QMacStyle::layoutMargins()
|
||||
{
|
||||
QFETCH(QStyleHelper::WidgetSizePolicy, size);
|
||||
QWidget w;
|
||||
setSize(&w, size);
|
||||
|
||||
}
|
||||
|
||||
void tst_QMacStyle::layoutSpacings_data()
|
||||
{
|
||||
tst_QMacStyle::sizeHints_data();
|
||||
}
|
||||
|
||||
void tst_QMacStyle::layoutSpacings()
|
||||
{
|
||||
QFETCH(QStyleHelper::WidgetSizePolicy, size);
|
||||
|
||||
/*
|
||||
Constraints specified by AHIG.
|
||||
*/
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
ControlType c1 = (i % 2 == 0) ? PushButton : ButtonBox;
|
||||
ControlType c2 = (i / 2 == 0) ? PushButton : ButtonBox;
|
||||
QCOMPARE(hspacing(c1, c2, size), SIZE(14, 8, 8));
|
||||
QCOMPARE(vspacing(c1, c2, size), SIZE(14, 8, 8));
|
||||
}
|
||||
|
||||
QCOMPARE(hspacing(Label, RadioButton, size), SIZE(8, 6, 5));
|
||||
QCOMPARE(vspacing(RadioButton, RadioButton, size), SIZE(5, 5, 5)); // Builder, guess, AHIG
|
||||
|
||||
QCOMPARE(hspacing(Label, CheckBox, size), SIZE(8, 6, 5));
|
||||
QCOMPARE(vspacing(CheckBox, CheckBox, size), SIZE(8, 8, 7));
|
||||
|
||||
QCOMPARE(hspacing(Label, ComboBox, size), SIZE(8, 6, 5));
|
||||
|
||||
QCOMPARE(hspacing(LineEdit, LineEdit, size), SIZE(10, 8, 8));
|
||||
|
||||
/*
|
||||
Common sense constraints, for when AHIG seems to make no sense (e.g., disagrees
|
||||
too much with Builder or looks improper).
|
||||
*/
|
||||
|
||||
// Comboboxes are a special pain, because AHIG and Builder can't agree,
|
||||
// and because they can be editable or not, with two totally different looks
|
||||
QVERIFY(vspacing(ComboBox, ComboBox, size) >= SIZE(8, 6, 5));
|
||||
QVERIFY(vspacing(ComboBox, ComboBox, size) <= SIZE(12, 10, 8));
|
||||
|
||||
// Make sure button boxes get the respect they deserve, when they occur
|
||||
// in the bottom or right side of a dialog
|
||||
QCOMPARE(hspacing(ButtonBox, LineEdit), SIZE(20, 8, 8));
|
||||
QCOMPARE(vspacing(ButtonBox, LineEdit), SIZE(20, 7, 7));
|
||||
|
||||
QCOMPARE(hspacing(LineEdit, ButtonBox), SIZE(8, 8, 8));
|
||||
QCOMPARE(vspacing(LineEdit, ButtonBox), SIZE(8, 8, 8));
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
QSize tst_QMacStyle::msh(QWidget *widget)
|
||||
{
|
||||
QWidgetItem item(widget);
|
||||
return item.sizeHint();
|
||||
}
|
||||
|
||||
QSize tst_QMacStyle::sh(QWidget *widget)
|
||||
{
|
||||
QWidgetItem item(widget);
|
||||
return item.sizeHint();
|
||||
}
|
||||
|
||||
QRect tst_QMacStyle::geo(QWidget *widget)
|
||||
{
|
||||
QWidgetItem item(widget);
|
||||
return item.geometry();
|
||||
}
|
||||
|
||||
QSize tst_QMacStyle::gap(QWidget *widget1, QWidget *widget2)
|
||||
{
|
||||
QPoint d = pos(widget2) - pos(widget1);
|
||||
QSize s = size(widget1);
|
||||
return s + QSize(d.x(), d.y());
|
||||
}
|
||||
|
||||
void tst_QMacStyle::setSize(QWidget *widget, QStyleHelper::WidgetSizePolicy size)
|
||||
{
|
||||
switch (size) {
|
||||
case QStyleHelper::SizeDefault:
|
||||
break;
|
||||
case QStyleHelper::SizeLarge:
|
||||
widget->setAttribute(Qt::WA_MacNormalSize, true);
|
||||
break;
|
||||
case QStyleHelper::SizeSmall:
|
||||
widget->setAttribute(Qt::WA_MacSmallSize, true);
|
||||
break;
|
||||
case QStyleHelper::SizeMini:
|
||||
widget->setAttribute(Qt::WA_MacMiniSize, true);
|
||||
}
|
||||
}
|
||||
|
||||
int tst_QMacStyle::spacing(ControlType control1, ControlType control2, Qt::Orientation orientation,
|
||||
QStyleOption *option, QWidget *widget)
|
||||
{
|
||||
return QApplication::style()->layoutSpacing(control1, control2, orientation, option, widget);
|
||||
}
|
||||
|
||||
int tst_QMacStyle::hspacing(ControlType control1, ControlType control2, QStyleHelper::WidgetSizePolicy size)
|
||||
{
|
||||
QWidget w;
|
||||
setSize(&w, size);
|
||||
|
||||
QStyleOption opt;
|
||||
opt.initFrom(&w);
|
||||
|
||||
return spacing(control1, control2, Qt::Horizontal, &opt);
|
||||
}
|
||||
|
||||
int tst_QMacStyle::vspacing(ControlType control1, ControlType control2, QStyleHelper::WidgetSizePolicy size)
|
||||
{
|
||||
QWidget w;
|
||||
setSize(&w, size);
|
||||
|
||||
QStyleOption opt;
|
||||
opt.initFrom(&w);
|
||||
|
||||
return spacing(control1, control2, Qt::Vertical, &opt);
|
||||
}
|
||||
|
||||
|
||||
void tst_QMacStyle::smallMiniNormalExclusivity_data()
|
||||
{
|
||||
|
||||
QTest::addColumn<int>("size1");
|
||||
QTest::addColumn<int>("size2");
|
||||
QTest::addColumn<int>("size3");
|
||||
QTest::addColumn<int>("expectedHeight1");
|
||||
QTest::addColumn<int>("expectedHeight2");
|
||||
QTest::addColumn<int>("expectedHeight3");
|
||||
|
||||
QTest::newRow("normal small mini") << int(Qt::WA_MacNormalSize) << int(Qt::WA_MacSmallSize) << int(Qt::WA_MacMiniSize) << 32 << 16 << 24;
|
||||
QTest::newRow("normal mini small") << int(Qt::WA_MacNormalSize) <<int(Qt::WA_MacMiniSize) << int(Qt::WA_MacSmallSize) << 32 << 24 << 16;
|
||||
QTest::newRow("small normal mini") << int(Qt::WA_MacSmallSize) << int(Qt::WA_MacNormalSize) << int(Qt::WA_MacMiniSize) << 16 << 32 << 24;
|
||||
QTest::newRow("small mini normal") << int(Qt::WA_MacSmallSize) << int(Qt::WA_MacMiniSize) << int(Qt::WA_MacNormalSize) << 16 << 24 << 32;
|
||||
QTest::newRow("mini small normal") << int(Qt::WA_MacMiniSize) << int(Qt::WA_MacSmallSize) << int(Qt::WA_MacNormalSize) << 24 << 16 << 32;
|
||||
QTest::newRow("mini normal small") << int(Qt::WA_MacMiniSize) << int(Qt::WA_MacNormalSize) << int(Qt::WA_MacSmallSize) << 24 << 32 << 16;
|
||||
}
|
||||
|
||||
void tst_QMacStyle::smallMiniNormalExclusivity()
|
||||
{
|
||||
|
||||
QFETCH(int, size1);
|
||||
QFETCH(int, size2);
|
||||
QFETCH(int, size3);
|
||||
QFETCH(int, expectedHeight1);
|
||||
QFETCH(int, expectedHeight2);
|
||||
QFETCH(int, expectedHeight3);
|
||||
|
||||
static const int TotalSizes = 3;
|
||||
int attrs[TotalSizes] = { size1, size2, size3 };
|
||||
int expected[TotalSizes] = { expectedHeight1, expectedHeight2, expectedHeight3 };
|
||||
|
||||
QPushButton dummyWidget;
|
||||
QStyleOptionButton opt;
|
||||
|
||||
for (int i = 0; i < TotalSizes; ++i) {
|
||||
dummyWidget.setAttribute(Qt::WidgetAttribute(attrs[i]));
|
||||
opt.initFrom(&dummyWidget);
|
||||
QSize size = dummyWidget.style()->sizeFromContents(QStyle::CT_PushButton, &opt,
|
||||
QSize(0, 0), &dummyWidget);
|
||||
if (size.height() != expected[i])
|
||||
QEXPECT_FAIL("", "QTBUG-25296", Abort);
|
||||
QCOMPARE(size.height(), expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QMacStyle::passwordCharacter()
|
||||
{
|
||||
QLineEdit lineEdit;
|
||||
lineEdit.setEchoMode(QLineEdit::Password);
|
||||
QTest::keyClick(&lineEdit, Qt::Key_P);
|
||||
// Should be no password delay; text should instantly be masked.
|
||||
const QChar bullet(0x2022);
|
||||
const QString expected(1, bullet);
|
||||
QCOMPARE(lineEdit.displayText(), expected);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QMacStyle)
|
||||
#include "tst_qmacstyle.moc"
|
||||
|
15
tests/auto/widgets/styles/qstyle/CMakeLists.txt
Normal file
15
tests/auto/widgets/styles/qstyle/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qstyle Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qstyle
|
||||
SOURCES
|
||||
tst_qstyle.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::TestPrivate
|
||||
Qt::Widgets
|
||||
)
|
749
tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
Normal file
749
tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
Normal file
@ -0,0 +1,749 @@
|
||||
// Copyright (C) 2019 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
|
||||
#include <QTest>
|
||||
#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>
|
||||
#include <qscrollarea.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QtTest/private/qtesthelpers_p.h>
|
||||
|
||||
using namespace QTestPrivate;
|
||||
|
||||
class tst_QStyle : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void drawItemPixmap();
|
||||
void cleanup();
|
||||
#ifndef QT_NO_STYLE_FUSION
|
||||
void testFusionStyle();
|
||||
#endif
|
||||
void testWindowsStyle();
|
||||
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA)
|
||||
void testWindowsVistaStyle();
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
void testMacStyle();
|
||||
#endif
|
||||
void testStyleFactory();
|
||||
void testProxyStyle();
|
||||
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
|
||||
void progressBarChangeStyle();
|
||||
#endif
|
||||
void defaultFont();
|
||||
void testDrawingShortcuts();
|
||||
void testFrameOnlyAroundContents();
|
||||
|
||||
void testProxyCalled();
|
||||
void testStyleOptionInit();
|
||||
|
||||
void sliderPositionFromValue_data();
|
||||
void sliderPositionFromValue();
|
||||
void sliderValueFromPosition_data();
|
||||
void sliderValueFromPosition();
|
||||
private:
|
||||
bool testAllFunctions(QStyle *);
|
||||
bool testScrollBarSubControls(const QStyle *style);
|
||||
void testPainting(QStyle *style, const QString &platform);
|
||||
void lineUpLayoutTest(QStyle *);
|
||||
};
|
||||
|
||||
class MyWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
using QWidget::QWidget;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
};
|
||||
|
||||
void tst_QStyle::cleanup()
|
||||
{
|
||||
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
||||
}
|
||||
|
||||
void tst_QStyle::testStyleFactory()
|
||||
{
|
||||
const QStringList keys = QStyleFactory::keys();
|
||||
#ifndef QT_NO_STYLE_FUSION
|
||||
QVERIFY(keys.contains("Fusion"));
|
||||
#endif
|
||||
#ifndef QT_NO_STYLE_WINDOWS
|
||||
QVERIFY(keys.contains("Windows"));
|
||||
#endif
|
||||
|
||||
for (const QString &styleName : keys) {
|
||||
QScopedPointer<QStyle> style(QStyleFactory::create(styleName));
|
||||
QVERIFY2(!style.isNull(),
|
||||
qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName)));
|
||||
}
|
||||
}
|
||||
|
||||
class CustomProxy : public QProxyStyle
|
||||
{
|
||||
int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
|
||||
const QWidget *widget = nullptr) const override
|
||||
{
|
||||
if (metric == QStyle::PM_ButtonIconSize)
|
||||
return 13;
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QStyle::testProxyStyle()
|
||||
{
|
||||
QProxyStyle *proxyStyle = new QProxyStyle();
|
||||
QVERIFY(proxyStyle->baseStyle());
|
||||
QStyle *style = QStyleFactory::create("Windows");
|
||||
QCOMPARE(style->proxy(), style);
|
||||
|
||||
proxyStyle->setBaseStyle(style);
|
||||
QCOMPARE(style->proxy(), proxyStyle);
|
||||
QCOMPARE(style->parent(), proxyStyle);
|
||||
QCOMPARE(proxyStyle->baseStyle(), style);
|
||||
|
||||
QVERIFY(testAllFunctions(proxyStyle));
|
||||
proxyStyle->setBaseStyle(nullptr);
|
||||
QVERIFY(proxyStyle->baseStyle());
|
||||
QApplication::setStyle(proxyStyle);
|
||||
|
||||
QProxyStyle* baseStyle = new QProxyStyle("Windows");
|
||||
QCOMPARE(baseStyle->baseStyle()->objectName(), style->objectName());
|
||||
|
||||
QProxyStyle doubleProxy(baseStyle);
|
||||
QVERIFY(testAllFunctions(&doubleProxy));
|
||||
|
||||
CustomProxy customStyle;
|
||||
QLineEdit edit;
|
||||
edit.setStyle(&customStyle);
|
||||
QVERIFY(!customStyle.parent());
|
||||
QCOMPARE(edit.style()->pixelMetric(QStyle::PM_ButtonIconSize), 13);
|
||||
}
|
||||
|
||||
void tst_QStyle::drawItemPixmap()
|
||||
{
|
||||
MyWidget testWidget;
|
||||
testWidget.setObjectName("testObject");
|
||||
testWidget.resize(300, 300);
|
||||
testWidget.showNormal();
|
||||
|
||||
QImage image = testWidget.grab().toImage();
|
||||
const QRgb green = QColor(Qt::green).rgb();
|
||||
QVERIFY(image.reinterpretAsFormat(QImage::Format_RGB32));
|
||||
const QRgb *bits = reinterpret_cast<const QRgb *>(image.constBits());
|
||||
const QRgb *end = bits + image.sizeInBytes() / sizeof(QRgb);
|
||||
QVERIFY(std::all_of(bits, end, [green] (QRgb r) { return r == green; }));
|
||||
}
|
||||
|
||||
bool tst_QStyle::testAllFunctions(QStyle *style)
|
||||
{
|
||||
QStyleOption opt;
|
||||
QWidget testWidget;
|
||||
opt.initFrom(&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, nullptr);
|
||||
}
|
||||
|
||||
//Tests drawComplexControl with default arguments for potential crashes
|
||||
{
|
||||
QPixmap surface(QSize(200, 200));
|
||||
QPainter painter(&surface);
|
||||
QStyleOptionComboBox copt1;
|
||||
copt1.initFrom(&testWidget);
|
||||
|
||||
QStyleOptionGroupBox copt2;
|
||||
copt2.initFrom(&testWidget);
|
||||
QStyleOptionSizeGrip copt3;
|
||||
copt3.initFrom(&testWidget);
|
||||
QStyleOptionSlider copt4;
|
||||
copt4.initFrom(&testWidget);
|
||||
copt4.minimum = 0;
|
||||
copt4.maximum = 100;
|
||||
copt4.tickInterval = 25;
|
||||
copt4.sliderValue = 50;
|
||||
QStyleOptionSpinBox copt5;
|
||||
copt5.initFrom(&testWidget);
|
||||
QStyleOptionTitleBar copt6;
|
||||
copt6.initFrom(&testWidget);
|
||||
QStyleOptionToolButton copt7;
|
||||
copt7.initFrom(&testWidget);
|
||||
QStyleOptionComplex copt9;
|
||||
copt9.initFrom(&testWidget);
|
||||
|
||||
style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, nullptr);
|
||||
style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, nullptr);
|
||||
}
|
||||
|
||||
//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(QApplication::font()), QRect(0, 0, 100, 100),
|
||||
Qt::AlignHCenter, true, QLatin1String("Test"));
|
||||
|
||||
return testScrollBarSubControls(style);
|
||||
}
|
||||
|
||||
bool tst_QStyle::testScrollBarSubControls(const QStyle *style)
|
||||
{
|
||||
const bool isMacStyle = style->objectName().compare(QLatin1String("macos"),
|
||||
Qt::CaseInsensitive) == 0;
|
||||
QScrollBar scrollBar;
|
||||
setFrameless(&scrollBar);
|
||||
scrollBar.show();
|
||||
const QStyleOptionSlider opt = qt_qscrollbarStyleOption(&scrollBar);
|
||||
for (int sc : {1, 2, 4, 8}) {
|
||||
const auto subControl = static_cast<QStyle::SubControl>(sc);
|
||||
const QRect sr = style->subControlRect(QStyle::CC_ScrollBar, &opt, subControl, &scrollBar);
|
||||
if (sr.isNull()) {
|
||||
// macOS scrollbars no longer have these, so there's no reason to fail
|
||||
if (!(isMacStyle && (subControl == QStyle::SC_ScrollBarAddLine ||
|
||||
subControl == QStyle::SC_ScrollBarSubLine))) {
|
||||
qWarning() << "Unexpected null rect for subcontrol" << subControl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_STYLE_FUSION
|
||||
void tst_QStyle::testFusionStyle()
|
||||
{
|
||||
QScopedPointer<QStyle> fstyle(QStyleFactory::create("Fusion"));
|
||||
QVERIFY(!fstyle.isNull());
|
||||
QVERIFY(testAllFunctions(fstyle.data()));
|
||||
lineUpLayoutTest(fstyle.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QStyle::testWindowsStyle()
|
||||
{
|
||||
QScopedPointer<QStyle> wstyle(QStyleFactory::create("Windows"));
|
||||
QVERIFY(!wstyle.isNull());
|
||||
QVERIFY(testAllFunctions(wstyle.data()));
|
||||
lineUpLayoutTest(wstyle.data());
|
||||
|
||||
// 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);
|
||||
wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, nullptr);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA)
|
||||
void tst_QStyle::testWindowsVistaStyle()
|
||||
{
|
||||
QScopedPointer<QStyle> vistastyle(QStyleFactory::create("WindowsVista"));
|
||||
QVERIFY(!vistastyle.isNull());
|
||||
QVERIFY(testAllFunctions(vistastyle.data()));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
void tst_QStyle::testMacStyle()
|
||||
{
|
||||
QStyle *mstyle = QStyleFactory::create("macos");
|
||||
QVERIFY(testAllFunctions(mstyle));
|
||||
delete mstyle;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Helper class...
|
||||
void MyWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter p(this);
|
||||
QPixmap big(400,400);
|
||||
big.fill(Qt::green);
|
||||
style()->drawItemPixmap(&p, rect(), Qt::AlignCenter, big);
|
||||
}
|
||||
|
||||
|
||||
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
|
||||
void tst_QStyle::progressBarChangeStyle()
|
||||
{
|
||||
//test a crashing situation (task 143530)
|
||||
//where changing the styles and deleting a progressbar would crash
|
||||
|
||||
QStyle *style1 = QStyleFactory::create("Windows");
|
||||
QStyle *style2 = QStyleFactory::create("Fusion");
|
||||
|
||||
QProgressBar *progress=new QProgressBar;
|
||||
progress->setStyle(style1);
|
||||
|
||||
progress->show();
|
||||
|
||||
progress->setStyle(style2);
|
||||
|
||||
QTest::qWait(100);
|
||||
delete progress;
|
||||
|
||||
QTest::qWait(100);
|
||||
|
||||
//before the correction, there would be a crash here
|
||||
delete style1;
|
||||
delete style2;
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QStyle::lineUpLayoutTest(QStyle *style)
|
||||
{
|
||||
QWidget widget;
|
||||
setFrameless(&widget);
|
||||
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.
|
||||
const auto children = widget.findChildren<QWidget *>();
|
||||
for (QWidget *w : children)
|
||||
w->setStyle(style);
|
||||
widget.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
||||
|
||||
#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())));
|
||||
}
|
||||
|
||||
void tst_QStyle::defaultFont()
|
||||
{
|
||||
QFont defaultFont = QApplication::font();
|
||||
QFont pointFont = defaultFont;
|
||||
pointFont.setPixelSize(9);
|
||||
QApplication::setFont(pointFont);
|
||||
QPushButton button;
|
||||
setFrameless(&button);
|
||||
button.show();
|
||||
QCoreApplication::processEvents();
|
||||
QApplication::setFont(defaultFont);
|
||||
}
|
||||
|
||||
class DrawTextStyle : public QProxyStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QProxyStyle::QProxyStyle;
|
||||
|
||||
void drawItemText(QPainter *painter, const QRect &rect,
|
||||
int flags, const QPalette &pal, bool enabled,
|
||||
const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override
|
||||
{
|
||||
alignment = flags;
|
||||
QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
|
||||
}
|
||||
|
||||
mutable int alignment = 0;
|
||||
};
|
||||
|
||||
|
||||
void tst_QStyle::testDrawingShortcuts()
|
||||
{
|
||||
{
|
||||
QWidget w;
|
||||
setFrameless(&w);
|
||||
QToolButton *tb = new QToolButton(&w);
|
||||
tb->setText("&abc");
|
||||
QScopedPointer<DrawTextStyle> dts(new DrawTextStyle);
|
||||
w.show();
|
||||
tb->setStyle(dts.data());
|
||||
tb->grab();
|
||||
QStyleOptionToolButton sotb;
|
||||
sotb.initFrom(tb);
|
||||
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
||||
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
||||
}
|
||||
{
|
||||
QToolBar w;
|
||||
setFrameless(&w);
|
||||
QToolButton *tb = new QToolButton(&w);
|
||||
tb->setText("&abc");
|
||||
QScopedPointer<DrawTextStyle> dts(new DrawTextStyle);
|
||||
w.addWidget(tb);
|
||||
w.show();
|
||||
tb->setStyle(dts.data());
|
||||
tb->grab();
|
||||
QStyleOptionToolButton sotb;
|
||||
sotb.initFrom(tb);
|
||||
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
|
||||
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
|
||||
}
|
||||
}
|
||||
|
||||
static const int SCROLLBAR_SPACING = 33;
|
||||
|
||||
class FrameTestStyle : public QProxyStyle {
|
||||
public:
|
||||
FrameTestStyle() : QProxyStyle("Windows") { }
|
||||
|
||||
int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
|
||||
QStyleHintReturn *returnData) const override
|
||||
{
|
||||
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
|
||||
return 1;
|
||||
return QProxyStyle ::styleHint(hint, opt, widget, returnData);
|
||||
}
|
||||
|
||||
int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const override
|
||||
{
|
||||
if (pm == QStyle::PM_ScrollView_ScrollBarSpacing)
|
||||
return SCROLLBAR_SPACING;
|
||||
return QProxyStyle ::pixelMetric(pm, option ,widget);
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QStyle::testFrameOnlyAroundContents()
|
||||
{
|
||||
QScrollArea area;
|
||||
area.setGeometry(0, 0, 200, 200);
|
||||
QScopedPointer<QStyle> winStyle(QStyleFactory::create("Windows"));
|
||||
FrameTestStyle frameStyle;
|
||||
QWidget *widget = new QWidget(&area);
|
||||
widget->setGeometry(0, 0, 400, 400);
|
||||
area.setStyle(winStyle.data());
|
||||
area.verticalScrollBar()->setStyle(winStyle.data());
|
||||
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
|
||||
QCOMPARE(viewPortWidth, area.viewport()->width() + SCROLLBAR_SPACING);
|
||||
}
|
||||
|
||||
|
||||
class ProxyTest: public QProxyStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QProxyStyle::QProxyStyle;
|
||||
|
||||
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
|
||||
const QWidget *w) const override
|
||||
{
|
||||
called = true;
|
||||
return QProxyStyle::drawPrimitive(pe, opt, p, w);
|
||||
}
|
||||
|
||||
mutable bool called = false;
|
||||
};
|
||||
|
||||
|
||||
void tst_QStyle::testProxyCalled()
|
||||
{
|
||||
QToolButton b;
|
||||
b.setArrowType(Qt::DownArrow);
|
||||
QStyleOptionToolButton opt;
|
||||
opt.initFrom(&b);
|
||||
opt.features |= QStyleOptionToolButton::Arrow;
|
||||
QPixmap surface(QSize(200, 200));
|
||||
QPainter painter(&surface);
|
||||
|
||||
const QStringList keys = QStyleFactory::keys();
|
||||
QList<QStyle *> styles;
|
||||
styles.reserve(keys.size() + 1);
|
||||
|
||||
styles << new QCommonStyle();
|
||||
|
||||
for (const QString &key : keys)
|
||||
styles << QStyleFactory::create(key);
|
||||
|
||||
for (QStyle *style : styles) {
|
||||
ProxyTest testStyle;
|
||||
testStyle.setBaseStyle(style);
|
||||
style->drawControl(QStyle::CE_ToolButtonLabel, &opt, &painter, &b);
|
||||
QVERIFY(testStyle.called);
|
||||
delete style;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestStyleOptionInitProxy: public QProxyStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
mutable bool invalidOptionsDetected = false;
|
||||
|
||||
using QProxyStyle::QProxyStyle;
|
||||
|
||||
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
|
||||
checkStyleEnum<QStyle::PrimitiveElement>(pe, opt);
|
||||
return QProxyStyle::drawPrimitive(pe, opt, p, w);
|
||||
}
|
||||
|
||||
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
|
||||
checkStyleEnum<QStyle::ControlElement>(element, opt);
|
||||
return QProxyStyle::drawControl(element, opt, p, w);
|
||||
}
|
||||
|
||||
QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget) const override {
|
||||
checkStyleEnum<QStyle::SubElement>(subElement, option);
|
||||
return QProxyStyle::subElementRect(subElement, option, widget);
|
||||
}
|
||||
|
||||
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const override {
|
||||
checkStyleEnum<QStyle::ComplexControl>(cc, opt);
|
||||
return QProxyStyle::drawComplexControl(cc, opt, p, widget);
|
||||
}
|
||||
|
||||
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override {
|
||||
checkStyleEnum<QStyle::ComplexControl>(cc, opt);
|
||||
return QProxyStyle::subControlRect(cc, opt, sc, widget);
|
||||
}
|
||||
|
||||
int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override {
|
||||
checkStyleEnum<QStyle::PixelMetric>(metric, option);
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
}
|
||||
|
||||
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const override {
|
||||
checkStyleEnum<QStyle::ContentsType>(ct, opt);
|
||||
return QProxyStyle::sizeFromContents(ct, opt, contentsSize, w);
|
||||
}
|
||||
|
||||
int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override {
|
||||
checkStyleEnum<QStyle::StyleHint>(stylehint, opt);
|
||||
return QProxyStyle::styleHint(stylehint, opt, widget, returnData);
|
||||
}
|
||||
|
||||
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const override {
|
||||
checkStyleEnum<QStyle::StandardPixmap>(standardPixmap, opt);
|
||||
return QProxyStyle::standardPixmap(standardPixmap, opt, widget);
|
||||
}
|
||||
|
||||
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const override {
|
||||
checkStyleEnum<QStyle::StandardPixmap>(standardIcon, option);
|
||||
return QProxyStyle::standardIcon(standardIcon, option, widget);
|
||||
}
|
||||
|
||||
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override {
|
||||
checkStyle(QString::asprintf("QIcon::Mode(%i)", iconMode).toLatin1(), opt);
|
||||
return QProxyStyle::generatedIconPixmap(iconMode, pixmap, opt);
|
||||
}
|
||||
|
||||
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget) const override {
|
||||
checkStyle(QString::asprintf("QSizePolicy::ControlType(%i), QSizePolicy::ControlType(%i)", control1, control2).toLatin1(), option);
|
||||
return QProxyStyle::layoutSpacing(control1, control2, orientation, option, widget);
|
||||
}
|
||||
|
||||
private:
|
||||
void checkStyle(const QByteArray &info, const QStyleOption *opt) const {
|
||||
if (opt && (opt->version == 0 || opt->styleObject == nullptr) ) {
|
||||
invalidOptionsDetected = true;
|
||||
qWarning() << baseStyle()->metaObject()->className()
|
||||
<< "Invalid QStyleOption found for"
|
||||
<< info;
|
||||
qWarning() << "Version:" << opt->version << "StyleObject:" << opt->styleObject;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MEnum>
|
||||
void checkStyleEnum(MEnum element, const QStyleOption *opt) const {
|
||||
static QMetaEnum _enum = QMetaEnum::fromType<MEnum>();
|
||||
checkStyle(_enum.valueToKey(element), opt);
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QStyle::testStyleOptionInit()
|
||||
{
|
||||
QStringList keys = QStyleFactory::keys();
|
||||
keys.prepend(QString()); // QCommonStyle marker
|
||||
|
||||
for (const QString &key : std::as_const(keys)) {
|
||||
QStyle* style = key.isEmpty() ? new QCommonStyle : QStyleFactory::create(key);
|
||||
TestStyleOptionInitProxy testStyle;
|
||||
testStyle.setBaseStyle(style);
|
||||
testAllFunctions(style);
|
||||
QVERIFY(!testStyle.invalidOptionsDetected);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QStyle::sliderPositionFromValue_data()
|
||||
{
|
||||
QTest::addColumn<int>("min");
|
||||
QTest::addColumn<int>("max");
|
||||
QTest::addColumn<int>("value");
|
||||
QTest::addColumn<int>("span");
|
||||
QTest::addColumn<bool>("upsideDown");
|
||||
QTest::addColumn<int>("position");
|
||||
|
||||
QTest::addRow("no span") << 12 << 56 << 34 << 0 << false << 0;
|
||||
QTest::addRow("no span inverse") << 12 << 56 << 34 << 0 << true << 0;
|
||||
|
||||
QTest::addRow("value too small") << 34 << 56 << 12 << 2000 << false << 0;
|
||||
QTest::addRow("value too small inverse") << 34 << 56 << 12 << 2000 << true << 2000;
|
||||
|
||||
QTest::addRow("no-range") << 12 << 12 << 12 << 2000 << false << 0;
|
||||
QTest::addRow("no-range-inverse") << 12 << 12 << 12 << 2000 << true << 0;
|
||||
|
||||
QTest::addRow("close-to-max") << 12 << 34 << 33 << 2000 << false << 1909;
|
||||
QTest::addRow("at-max") << 12 << 34 << 34 << 2000 << false << 2000;
|
||||
QTest::addRow("value too large") << 12 << 34 << 35 << 2000 << false << 2000;
|
||||
QTest::addRow("close-to-max-inverse") << 12 << 34 << 33 << 2000 << true << 91;
|
||||
QTest::addRow("at-max-inverse") << 12 << 34 << 34 << 2000 << true << 0;
|
||||
QTest::addRow("value too large-inverse") << 12 << 34 << 35 << 2000 << true << 0;
|
||||
|
||||
QTest::addRow("big-range") << 100000 << 700000 << 250000 << 2000 << false << 500;
|
||||
QTest::addRow("big-range-inverse") << 100000 << 700000 << 250000 << 2000 << true << 1500;
|
||||
|
||||
QTest::addRow("across-zero") << -1000 << 1000 << -500 << 100 << false << 25;
|
||||
QTest::addRow("across-zero-inverse") << -1000 << 1000 << -500 << 100 << true << 75;
|
||||
|
||||
QTest::addRow("span>range") << 0 << 100 << 60 << 2000 << false << 1200;
|
||||
QTest::addRow("span>range-inverse") << 0 << 100 << 60 << 2000 << true << 800;
|
||||
|
||||
QTest::addRow("overflow1 (QTBUG-101581)") << -1 << INT_MAX << 235 << 891 << false << 0;
|
||||
QTest::addRow("overflow2") << INT_MIN << INT_MAX << 10 << 100 << false << 50;
|
||||
QTest::addRow("overflow2-inverse") << INT_MIN << INT_MAX << 10 << 100 << true << 49;
|
||||
QTest::addRow("overflow3") << INT_MIN << INT_MAX << -10 << 100 << false << 49;
|
||||
QTest::addRow("overflow3-inverse") << INT_MIN << INT_MAX << -10 << 100 << true << 50;
|
||||
}
|
||||
|
||||
void tst_QStyle::sliderPositionFromValue()
|
||||
{
|
||||
QFETCH(int, min);
|
||||
QFETCH(int, max);
|
||||
QFETCH(int, value);
|
||||
QFETCH(int, span);
|
||||
QFETCH(bool, upsideDown);
|
||||
QFETCH(int, position);
|
||||
|
||||
QCOMPARE(QStyle::sliderPositionFromValue(min, max, value, span, upsideDown), position);
|
||||
}
|
||||
|
||||
void tst_QStyle::sliderValueFromPosition_data()
|
||||
{
|
||||
QTest::addColumn<int>("min");
|
||||
QTest::addColumn<int>("max");
|
||||
QTest::addColumn<int>("position");
|
||||
QTest::addColumn<int>("span");
|
||||
QTest::addColumn<bool>("upsideDown");
|
||||
QTest::addColumn<int>("value");
|
||||
|
||||
QTest::addRow("position zero") << 0 << 100 << 0 << 2000 << false << 0;
|
||||
QTest::addRow("position zero inverse") << 0 << 100 << 0 << 2000 << true << 100;
|
||||
|
||||
QTest::addRow("span zero") << 0 << 100 << 1200 << 0 << false << 0;
|
||||
QTest::addRow("span zero inverse") << 0 << 100 << 1200 << 0 << true << 100;
|
||||
|
||||
QTest::addRow("position > span") << -300 << -200 << 2 << 1 << false << -200;
|
||||
QTest::addRow("position > span inverse") << -300 << -200 << 2 << 1 << true << -300;
|
||||
|
||||
QTest::addRow("large") << 0 << 100 << 1200 << 2000 << false << 60;
|
||||
QTest::addRow("large-inverse") << 0 << 100 << 1200 << 2000 << true << 40;
|
||||
|
||||
QTest::addRow("normal") << 0 << 100 << 12 << 20 << false << 60;
|
||||
QTest::addRow("inverse") << 0 << 100 << 12 << 20 << true << 40;
|
||||
|
||||
QTest::addRow("overflow1") << -1 << INT_MAX << 10 << 10 << false << INT_MAX;
|
||||
QTest::addRow("overflow1-inverse") << -1 << INT_MAX << 10 << 10 << true << -1;
|
||||
QTest::addRow("overflow2") << INT_MIN << INT_MAX << 5 << 10 << false << 0;
|
||||
QTest::addRow("overflow2-inverse") << INT_MIN << INT_MAX << 5 << 10 << true << -1;
|
||||
QTest::addRow("overflow3") << INT_MIN << 0 << 0 << 10 << false << INT_MIN;
|
||||
QTest::addRow("overflow3-inverse") << INT_MIN << 0 << 0 << 10 << true << 0;
|
||||
|
||||
QTest::addRow("overflow4") << 0 << INT_MAX << INT_MAX/2-6 << INT_MAX/2-5 << false << INT_MAX-2;
|
||||
QTest::addRow("overflow4-inverse") << 0 << INT_MAX << INT_MAX/2-6 << INT_MAX/2-5 << true << 2;
|
||||
|
||||
QTest::addRow("overflow5") << 0 << 4 << INT_MAX/4 << INT_MAX << false << 1;
|
||||
QTest::addRow("overflow5-inverse") << 0 << 4 << INT_MAX/4 << INT_MAX << true << 3;
|
||||
}
|
||||
|
||||
void tst_QStyle::sliderValueFromPosition()
|
||||
{
|
||||
QFETCH(int, min);
|
||||
QFETCH(int, max);
|
||||
QFETCH(int, position);
|
||||
QFETCH(int, span);
|
||||
QFETCH(bool, upsideDown);
|
||||
QFETCH(int, value);
|
||||
|
||||
QCOMPARE(QStyle::sliderValueFromPosition(min, max, position, span, upsideDown), value);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QStyle)
|
||||
#include "tst_qstyle.moc"
|
14
tests/auto/widgets/styles/qstyleoption/CMakeLists.txt
Normal file
14
tests/auto/widgets/styles/qstyleoption/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qstyleoption Test:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_test(tst_qstyleoption
|
||||
SOURCES
|
||||
tst_qstyleoption.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
107
tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.cpp
Normal file
107
tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
|
||||
#include <QTest>
|
||||
#include <QStyleOption>
|
||||
|
||||
|
||||
class tst_QStyleOption: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void qstyleoptioncast_data();
|
||||
void qstyleoptioncast();
|
||||
};
|
||||
|
||||
// Just a simple container for QStyleOption-pointer
|
||||
struct StyleOptionPointerBase
|
||||
{
|
||||
QStyleOption *pointer;
|
||||
|
||||
StyleOptionPointerBase(QStyleOption *p = nullptr) : pointer(p) { }
|
||||
|
||||
virtual ~StyleOptionPointerBase() { pointer = nullptr; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct StyleOptionPointer: public StyleOptionPointerBase
|
||||
{
|
||||
StyleOptionPointer(T *p = nullptr): StyleOptionPointerBase(p) {}
|
||||
~StyleOptionPointer() { delete static_cast<T *>(pointer); pointer = nullptr; }
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(StyleOptionPointerBase*)
|
||||
|
||||
template <typename T>
|
||||
inline StyleOptionPointerBase *stylePtr(T *ptr) { return new StyleOptionPointer<T>(ptr); }
|
||||
|
||||
void tst_QStyleOption::qstyleoptioncast_data()
|
||||
{
|
||||
QTest::addColumn<StyleOptionPointerBase *>("testOption");
|
||||
QTest::addColumn<bool>("canCastToComplex");
|
||||
QTest::addColumn<int>("type");
|
||||
|
||||
QTest::newRow("optionDefault") << stylePtr(new QStyleOption) << false << int(QStyleOption::SO_Default);
|
||||
QTest::newRow("optionButton") << stylePtr(new QStyleOptionButton) << false << int(QStyleOption::SO_Button);
|
||||
QTest::newRow("optionComboBox") << stylePtr(new QStyleOptionComboBox) << true << int(QStyleOption::SO_ComboBox);
|
||||
QTest::newRow("optionComplex") << stylePtr(new QStyleOptionComplex) << true << int(QStyleOption::SO_Complex);
|
||||
QTest::newRow("optionDockWidget") << stylePtr(new QStyleOptionDockWidget) << false << int(QStyleOption::SO_DockWidget);
|
||||
QTest::newRow("optionFocusRect") << stylePtr(new QStyleOptionFocusRect) << false << int(QStyleOption::SO_FocusRect);
|
||||
QTest::newRow("optionFrame") << stylePtr(new QStyleOptionFrame) << false << int(QStyleOption::SO_Frame);
|
||||
QTest::newRow("optionHeader") << stylePtr(new QStyleOptionHeader) << false << int(QStyleOption::SO_Header);
|
||||
QTest::newRow("optionMenuItem") << stylePtr(new QStyleOptionMenuItem) << false << int(QStyleOption::SO_MenuItem);
|
||||
QTest::newRow("optionProgressBar") << stylePtr(new QStyleOptionProgressBar) << false << int(QStyleOption::SO_ProgressBar);
|
||||
QTest::newRow("optionSlider") << stylePtr(new QStyleOptionSlider) << true << int(QStyleOption::SO_Slider);
|
||||
QTest::newRow("optionSpinBox") << stylePtr(new QStyleOptionSpinBox) << true << int(QStyleOption::SO_SpinBox);
|
||||
QTest::newRow("optionTab") << stylePtr(new QStyleOptionTab) << false << int(QStyleOption::SO_Tab);
|
||||
QTest::newRow("optionTitleBar") << stylePtr(new QStyleOptionTitleBar) << true << int(QStyleOption::SO_TitleBar);
|
||||
QTest::newRow("optionToolBox") << stylePtr(new QStyleOptionToolBox) << false << int(QStyleOption::SO_ToolBox);
|
||||
QTest::newRow("optionToolButton") << stylePtr(new QStyleOptionToolButton) << true << int(QStyleOption::SO_ToolButton);
|
||||
QTest::newRow("optionViewItem") << stylePtr(new QStyleOptionViewItem) << false << int(QStyleOption::SO_ViewItem);
|
||||
QTest::newRow("optionGraphicsItem") << stylePtr(new QStyleOptionGraphicsItem) << false << int(QStyleOption::SO_GraphicsItem);
|
||||
}
|
||||
|
||||
void tst_QStyleOption::qstyleoptioncast()
|
||||
{
|
||||
QFETCH(StyleOptionPointerBase *, testOption);
|
||||
QFETCH(bool, canCastToComplex);
|
||||
QFETCH(int, type);
|
||||
|
||||
QVERIFY(testOption->pointer != nullptr);
|
||||
|
||||
QCOMPARE(testOption->pointer->type, type);
|
||||
|
||||
// Cast to common base class
|
||||
QStyleOption *castOption = qstyleoption_cast<QStyleOption*>(testOption->pointer);
|
||||
QVERIFY(castOption != nullptr);
|
||||
|
||||
// Cast to complex base class
|
||||
castOption = qstyleoption_cast<QStyleOptionComplex*>(testOption->pointer);
|
||||
QCOMPARE(canCastToComplex, (castOption != nullptr));
|
||||
|
||||
// Cast to combo box
|
||||
castOption = qstyleoption_cast<QStyleOptionComboBox*>(testOption->pointer);
|
||||
QCOMPARE((castOption != nullptr),(testOption->pointer->type == QStyleOption::SO_ComboBox));
|
||||
|
||||
// Cast to button
|
||||
castOption = qstyleoption_cast<QStyleOptionButton*>(testOption->pointer);
|
||||
QCOMPARE((castOption != nullptr),(testOption->pointer->type == QStyleOption::SO_Button));
|
||||
|
||||
// Cast to lower version
|
||||
testOption->pointer->version += 1;
|
||||
castOption = qstyleoption_cast<QStyleOption*>(testOption->pointer);
|
||||
QVERIFY(castOption);
|
||||
|
||||
// Cast a null pointer
|
||||
castOption = qstyleoption_cast<QStyleOption*>((QStyleOption*)0);
|
||||
QCOMPARE(castOption, nullptr);
|
||||
|
||||
// Deallocate
|
||||
delete testOption;
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QStyleOption)
|
||||
#include "tst_qstyleoption.moc"
|
||||
|
10
tests/auto/widgets/styles/qstylesheetstyle/BLACKLIST
Normal file
10
tests/auto/widgets/styles/qstylesheetstyle/BLACKLIST
Normal file
@ -0,0 +1,10 @@
|
||||
[task232085_spinBoxLineEditBg]
|
||||
osx
|
||||
[widgetStylePropagation]
|
||||
macos # QTBUG-75786
|
||||
[focusColors]
|
||||
ci b2qt 32bit
|
||||
[hoverColors]
|
||||
ci b2qt 32bit
|
||||
[task232085_spinBoxLineEditBg]
|
||||
ci b2qt 32bit
|
27
tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt
Normal file
27
tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_qstylesheetstyle Test:
|
||||
#####################################################################
|
||||
|
||||
# Resources:
|
||||
set(resources_resource_files
|
||||
"images/testimage.png"
|
||||
"images/testimage@2x.png"
|
||||
)
|
||||
|
||||
qt_internal_add_test(tst_qstylesheetstyle
|
||||
SOURCES
|
||||
tst_qstylesheetstyle.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::TestPrivate
|
||||
Qt::Widgets
|
||||
Qt::WidgetsPrivate
|
||||
TESTDATA ${resources_resource_files}
|
||||
BUILTIN_TESTDATA
|
||||
)
|
||||
|
||||
# _REQUIREMENTS = "qtConfig(private_tests)"
|
BIN
tests/auto/widgets/styles/qstylesheetstyle/images/testimage.png
Normal file
BIN
tests/auto/widgets/styles/qstylesheetstyle/images/testimage.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 300 B |
Binary file not shown.
After Width: | Height: | Size: 318 B |
7
tests/auto/widgets/styles/qstylesheetstyle/resources.qrc
Normal file
7
tests/auto/widgets/styles/qstylesheetstyle/resources.qrc
Normal file
@ -0,0 +1,7 @@
|
||||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>images/testimage.png</file>
|
||||
<file>images/testimage@2x.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
2459
tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
Normal file
2459
tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user