From e2322c885f6dd67834c5110c6b7e2b63ea8b6186 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Thu, 8 Aug 2013 10:45:22 +0530 Subject: [PATCH] Extend QStyle API with a SH_Splitter_OpaqueResize styleHint Currently the default for QSplitter::opaqueResize is hard coded, which is less than ideal. Instead this should be provided as a style hint via QStyle so as to give a more uniform look to all applications. Change-Id: I5711811f7b672e36aafcd292ed320308570a0390 Reviewed-by: Kevin Ottens Reviewed-by: Frederik Gladhorn Reviewed-by: Olivier Goffart --- src/widgets/styles/qcommonstyle.cpp | 3 +++ src/widgets/styles/qstyle.cpp | 3 +++ src/widgets/styles/qstyle.h | 1 + src/widgets/widgets/qsplitter.cpp | 19 ++++++++++++++----- src/widgets/widgets/qsplitter_p.h | 3 ++- .../widgets/qsplitter/tst_qsplitter.cpp | 2 ++ 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index f5b61ea6f3..0c1ae56349 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5124,6 +5124,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = true; } break; + case SH_Splitter_OpaqueResize: + ret = true; + break; default: ret = 0; break; diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 8d8eb3aa46..99bbf2f363 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -1904,6 +1904,9 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, a transition between checked and unchecked statuses in a checkbox. This enum value has been introduced in Qt 5.2. + \value SH_Splitter_OpaqueResize Determines if resizing is opaque + This enum value has been introduced in Qt 5.2 + \sa styleHint() */ diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index fffd423c8a..bbb216bf92 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -701,6 +701,7 @@ public: SH_ToolTip_WakeUpDelay, SH_ToolTip_FallAsleepDelay, SH_Widget_Animate, + SH_Splitter_OpaqueResize, // Add new style hint values here SH_CustomBase = 0xf0000000 diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index 031763b80c..1f3646ea6e 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1404,19 +1404,24 @@ int QSplitter::closestLegalPosition(int pos, int index) \property QSplitter::opaqueResize \brief whether resizing is opaque - Opaque resizing is on by default. + The default resize behavior is style dependent (determined by the + SH_Splitter_OpaqueResize style hint). However, you can override it + by calling setOpaqueResize() + + \sa QStyle::StyleHint */ bool QSplitter::opaqueResize() const { Q_D(const QSplitter); - return d->opaque; + return d->opaqueResizeSet ? d->opaque : style()->styleHint(QStyle::SH_Splitter_OpaqueResize, 0, this); } void QSplitter::setOpaqueResize(bool on) { Q_D(QSplitter); + d->opaqueResizeSet = true; d->opaque = on; } @@ -1589,7 +1594,7 @@ static const qint32 SplitterMagic = 0xff; QByteArray QSplitter::saveState() const { Q_D(const QSplitter); - int version = 0; + int version = 1; QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); @@ -1605,6 +1610,7 @@ QByteArray QSplitter::saveState() const stream << qint32(handleWidth()); stream << opaqueResize(); stream << qint32(orientation()); + stream << d->opaqueResizeSet; return data; } @@ -1627,7 +1633,7 @@ QByteArray QSplitter::saveState() const bool QSplitter::restoreState(const QByteArray &state) { Q_D(QSplitter); - int version = 0; + int version = 1; QByteArray sd = state; QDataStream stream(&sd, QIODevice::ReadOnly); QList list; @@ -1638,7 +1644,7 @@ bool QSplitter::restoreState(const QByteArray &state) stream >> marker; stream >> v; - if (marker != SplitterMagic || v != version) + if (marker != SplitterMagic || v > version) return false; stream >> list; @@ -1657,6 +1663,9 @@ bool QSplitter::restoreState(const QByteArray &state) setOrientation(Qt::Orientation(i)); d->doResize(); + if (v >= 1) + stream >> d->opaqueResizeSet; + return true; } diff --git a/src/widgets/widgets/qsplitter_p.h b/src/widgets/widgets/qsplitter_p.h index f1e050b8f6..0d0e134f58 100644 --- a/src/widgets/widgets/qsplitter_p.h +++ b/src/widgets/widgets/qsplitter_p.h @@ -83,7 +83,7 @@ class QSplitterPrivate : public QFramePrivate Q_DECLARE_PUBLIC(QSplitter) public: QSplitterPrivate() : rubberBand(0), opaque(true), firstShow(true), - childrenCollapsible(true), compatMode(false), handleWidth(-1), blockChildAdd(false) {} + childrenCollapsible(true), compatMode(false), handleWidth(-1), blockChildAdd(false), opaqueResizeSet(false) {} QPointer rubberBand; mutable QList list; @@ -94,6 +94,7 @@ public: bool compatMode : 8; int handleWidth; bool blockChildAdd; + bool opaqueResizeSet; inline int pick(const QPoint &pos) const { return orient == Qt::Horizontal ? pos.x() : pos.y(); } diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index 340eefbf17..8de3291207 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -109,6 +109,8 @@ void tst_QSplitter::getSetCheck() QSplitter obj1; // bool QSplitter::opaqueResize() // void QSplitter::setOpaqueResize(bool) + bool styleHint = obj1.style()->styleHint(QStyle::SH_Splitter_OpaqueResize); + QCOMPARE(styleHint, obj1.opaqueResize()); obj1.setOpaqueResize(false); QCOMPARE(false, obj1.opaqueResize()); obj1.setOpaqueResize(true);