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:
parent
692bee634e
commit
e2322c885f
@ -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;
|
||||
|
@ -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()
|
||||
*/
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<int> 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;
|
||||
}
|
||||
|
||||
|
@ -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<QRubberBand> rubberBand;
|
||||
mutable QList<QSplitterLayoutStruct *> 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(); }
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user