diff options
author | Jens Bache-Wiig <jbache@trolltech.com> | 2009-06-12 14:53:40 (GMT) |
---|---|---|
committer | Jens Bache-Wiig <jbache@trolltech.com> | 2009-06-12 15:05:11 (GMT) |
commit | 4d0cc0b9600f8530bb0e8712b4bb109d1810c4a7 (patch) | |
tree | 766d2cbcad6082f794217000778b46ac8d2a7890 /tests/auto/qstyle | |
parent | 56b93b836f70e121540e8d8da9447f5dc6e1fdd6 (diff) | |
download | Qt-4d0cc0b9600f8530bb0e8712b4bb109d1810c4a7.zip Qt-4d0cc0b9600f8530bb0e8712b4bb109d1810c4a7.tar.gz Qt-4d0cc0b9600f8530bb0e8712b4bb109d1810c4a7.tar.bz2 |
Integrating QProxyStyle
This class adds convenient support for proxy styles in Qt.
Note that to support proper proxying, styles now
call their functions through proxy() so that the proxy regains control
over subcomponents. Note that there is a small price to be payed
by the extra function call which can at the cost of readability
be redirected to the private class member in the future.
Task-number: 229556
Reviewed-by: trond
Diffstat (limited to 'tests/auto/qstyle')
-rw-r--r-- | tests/auto/qstyle/tst_qstyle.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/auto/qstyle/tst_qstyle.cpp b/tests/auto/qstyle/tst_qstyle.cpp index cb30f83..46e9edc 100644 --- a/tests/auto/qstyle/tst_qstyle.cpp +++ b/tests/auto/qstyle/tst_qstyle.cpp @@ -58,6 +58,7 @@ #include <qcdestyle.h> #include <qmotifstyle.h> #include <qcommonstyle.h> +#include <qproxystyle.h> #include <qstylefactory.h> #include <qimagereader.h> @@ -131,6 +132,7 @@ private slots: void testWindowsCEStyle(); void testWindowsMobileStyle(); void testStyleFactory(); + void testProxyStyle(); void pixelMetric(); void progressBarChangeStyle(); void defaultFont(); @@ -213,6 +215,44 @@ void tst_QStyle::testStyleFactory() } } +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()); + QStyle *style = new QWindowsStyle; + QVERIFY(style->proxy() == style); + + proxyStyle->setBaseStyle(style); + QVERIFY(style->proxy() == proxyStyle); + QVERIFY(style->parent() == proxyStyle); + QVERIFY(proxyStyle->baseStyle() == style); + + testAllFunctions(proxyStyle); + proxyStyle->setBaseStyle(0); + QVERIFY(proxyStyle->baseStyle()); + qApp->setStyle(proxyStyle); + + QProxyStyle doubleProxy(new QProxyStyle(new QWindowsStyle())); + testAllFunctions(&doubleProxy); + + CustomProxy customStyle; + QLineEdit edit; + edit.setStyle(&customStyle); + QVERIFY(!customStyle.parent()); + QVERIFY(edit.style()->pixelMetric(QStyle::PM_ButtonIconSize) == 13); +} + void tst_QStyle::drawItemPixmap() { testWidget->resize(300, 300); @@ -310,7 +350,7 @@ void tst_QStyle::testAllFunctions(QStyle *style) testScrollBarSubControls(style); } -void tst_QStyle::testScrollBarSubControls(QStyle *style) +void tst_QStyle::testScrollBarSubControls(QStyle *) { #ifdef Q_OS_WINCE_WM if (qobject_cast<QWindowsMobileStyle*>(style) && qt_wince_is_smartphone()) |