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 <kevin.ottens@kdab.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Rohan Garg 2013-08-08 10:45:22 +05:30 committed by The Qt Project
parent 692bee634e
commit e2322c885f
6 changed files with 25 additions and 6 deletions

View File

@ -5124,6 +5124,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
ret = true; ret = true;
} }
break; break;
case SH_Splitter_OpaqueResize:
ret = true;
break;
default: default:
ret = 0; ret = 0;
break; break;

View File

@ -1904,6 +1904,9 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
a transition between checked and unchecked statuses in a checkbox. a transition between checked and unchecked statuses in a checkbox.
This enum value has been introduced in Qt 5.2. 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() \sa styleHint()
*/ */

View File

@ -701,6 +701,7 @@ public:
SH_ToolTip_WakeUpDelay, SH_ToolTip_WakeUpDelay,
SH_ToolTip_FallAsleepDelay, SH_ToolTip_FallAsleepDelay,
SH_Widget_Animate, SH_Widget_Animate,
SH_Splitter_OpaqueResize,
// Add new style hint values here // Add new style hint values here
SH_CustomBase = 0xf0000000 SH_CustomBase = 0xf0000000

View File

@ -1404,19 +1404,24 @@ int QSplitter::closestLegalPosition(int pos, int index)
\property QSplitter::opaqueResize \property QSplitter::opaqueResize
\brief whether resizing is opaque \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 bool QSplitter::opaqueResize() const
{ {
Q_D(const QSplitter); 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) void QSplitter::setOpaqueResize(bool on)
{ {
Q_D(QSplitter); Q_D(QSplitter);
d->opaqueResizeSet = true;
d->opaque = on; d->opaque = on;
} }
@ -1589,7 +1594,7 @@ static const qint32 SplitterMagic = 0xff;
QByteArray QSplitter::saveState() const QByteArray QSplitter::saveState() const
{ {
Q_D(const QSplitter); Q_D(const QSplitter);
int version = 0; int version = 1;
QByteArray data; QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly); QDataStream stream(&data, QIODevice::WriteOnly);
@ -1605,6 +1610,7 @@ QByteArray QSplitter::saveState() const
stream << qint32(handleWidth()); stream << qint32(handleWidth());
stream << opaqueResize(); stream << opaqueResize();
stream << qint32(orientation()); stream << qint32(orientation());
stream << d->opaqueResizeSet;
return data; return data;
} }
@ -1627,7 +1633,7 @@ QByteArray QSplitter::saveState() const
bool QSplitter::restoreState(const QByteArray &state) bool QSplitter::restoreState(const QByteArray &state)
{ {
Q_D(QSplitter); Q_D(QSplitter);
int version = 0; int version = 1;
QByteArray sd = state; QByteArray sd = state;
QDataStream stream(&sd, QIODevice::ReadOnly); QDataStream stream(&sd, QIODevice::ReadOnly);
QList<int> list; QList<int> list;
@ -1638,7 +1644,7 @@ bool QSplitter::restoreState(const QByteArray &state)
stream >> marker; stream >> marker;
stream >> v; stream >> v;
if (marker != SplitterMagic || v != version) if (marker != SplitterMagic || v > version)
return false; return false;
stream >> list; stream >> list;
@ -1657,6 +1663,9 @@ bool QSplitter::restoreState(const QByteArray &state)
setOrientation(Qt::Orientation(i)); setOrientation(Qt::Orientation(i));
d->doResize(); d->doResize();
if (v >= 1)
stream >> d->opaqueResizeSet;
return true; return true;
} }

View File

@ -83,7 +83,7 @@ class QSplitterPrivate : public QFramePrivate
Q_DECLARE_PUBLIC(QSplitter) Q_DECLARE_PUBLIC(QSplitter)
public: public:
QSplitterPrivate() : rubberBand(0), opaque(true), firstShow(true), 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<QRubberBand> rubberBand; QPointer<QRubberBand> rubberBand;
mutable QList<QSplitterLayoutStruct *> list; mutable QList<QSplitterLayoutStruct *> list;
@ -94,6 +94,7 @@ public:
bool compatMode : 8; bool compatMode : 8;
int handleWidth; int handleWidth;
bool blockChildAdd; bool blockChildAdd;
bool opaqueResizeSet;
inline int pick(const QPoint &pos) const inline int pick(const QPoint &pos) const
{ return orient == Qt::Horizontal ? pos.x() : pos.y(); } { return orient == Qt::Horizontal ? pos.x() : pos.y(); }

View File

@ -109,6 +109,8 @@ void tst_QSplitter::getSetCheck()
QSplitter obj1; QSplitter obj1;
// bool QSplitter::opaqueResize() // bool QSplitter::opaqueResize()
// void QSplitter::setOpaqueResize(bool) // void QSplitter::setOpaqueResize(bool)
bool styleHint = obj1.style()->styleHint(QStyle::SH_Splitter_OpaqueResize);
QCOMPARE(styleHint, obj1.opaqueResize());
obj1.setOpaqueResize(false); obj1.setOpaqueResize(false);
QCOMPARE(false, obj1.opaqueResize()); QCOMPARE(false, obj1.opaqueResize());
obj1.setOpaqueResize(true); obj1.setOpaqueResize(true);