Windows XP style: Fix size calculation of QScrollBar's grip.
Factor out function to calculate the geometry for the styles >= XP. Task-number: QTBUG-41944 Task-number: QTBUG-40277 Change-Id: Ifad1519b99fd587158c790dd241cb3e4bac3bfc3 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
parent
ff98c44060
commit
763a48fe1a
@ -1756,26 +1756,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle
|
||||
theme.stateId = stateId;
|
||||
d->drawBackground(theme);
|
||||
|
||||
// Calculate rect of gripper
|
||||
const int swidth = theme.rect.width();
|
||||
const int sheight = theme.rect.height();
|
||||
|
||||
const QMargins contentsMargin = theme.margins(theme.rect, TMT_SIZINGMARGINS)
|
||||
/ QWindowsXPStylePrivate::devicePixelRatio(widget);
|
||||
|
||||
theme.partId = flags & State_Horizontal ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT;
|
||||
const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
|
||||
|
||||
if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS8) {
|
||||
QPoint gripperBoundsPos(0, 0);
|
||||
if ((flags & State_Horizontal
|
||||
&& swidth - contentsMargin.left() - contentsMargin.right() > size.width())
|
||||
|| sheight - contentsMargin.top() - contentsMargin.bottom() > size.height()) {
|
||||
gripperBoundsPos = QPoint(theme.rect.left() + (swidth - size.width()) / 2,
|
||||
theme.rect.top() + (sheight - size.height()) / 2);
|
||||
}
|
||||
const QRect gripperBounds(gripperBoundsPos, size);
|
||||
|
||||
const QRect gripperBounds = QWindowsXPStylePrivate::scrollBarGripperBounds(flags, widget, &theme);
|
||||
// Draw gripper if there is enough space
|
||||
if (!gripperBounds.isEmpty() && flags & State_Enabled) {
|
||||
painter->save();
|
||||
|
@ -2529,6 +2529,20 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
|
||||
d->drawBackground(theme);
|
||||
}
|
||||
|
||||
QRect QWindowsXPStylePrivate::scrollBarGripperBounds(QStyle::State flags, const QWidget *widget, XPThemeData *theme)
|
||||
{
|
||||
const bool horizontal = flags & QStyle::State_Horizontal;
|
||||
const QMargins contentsMargin = theme->margins(theme->rect, TMT_SIZINGMARGINS)
|
||||
/ QWindowsStylePrivate::devicePixelRatio(widget);
|
||||
theme->partId = horizontal ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT;
|
||||
const QSize size = theme->size() / QWindowsStylePrivate::devicePixelRatio(widget);
|
||||
|
||||
const int hSpace = theme->rect.width() - size.width();
|
||||
const int vSpace = theme->rect.height() - size.height();
|
||||
const bool sufficientSpace = horizontal && hSpace > (contentsMargin.left() + contentsMargin.right())
|
||||
|| vSpace > contentsMargin.top() + contentsMargin.bottom();
|
||||
return sufficientSpace ? QRect(theme->rect.topLeft() + QPoint(hSpace, vSpace) / 2, size) : QRect();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
@ -2754,24 +2768,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
|
||||
theme.stateId = stateId;
|
||||
d->drawBackground(theme);
|
||||
|
||||
// Calculate rect of gripper
|
||||
const int swidth = theme.rect.width();
|
||||
const int sheight = theme.rect.height();
|
||||
|
||||
const QMargins contentsMargin = theme.margins(theme.rect, TMT_SIZINGMARGINS)
|
||||
/ QWindowsStylePrivate::devicePixelRatio(widget);
|
||||
|
||||
theme.partId = flags & State_Horizontal ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT;
|
||||
const QSize size = theme.size() / QWindowsStylePrivate::devicePixelRatio(widget);
|
||||
QPoint gripperBoundsPos(0, 0);
|
||||
if ((flags & State_Horizontal
|
||||
&& swidth - contentsMargin.left() - contentsMargin.right() > size.width())
|
||||
|| sheight - contentsMargin.top() - contentsMargin.bottom() > size.height()) {
|
||||
gripperBoundsPos = QPoint(theme.rect.left() + (swidth - size.width()) / 2,
|
||||
theme.rect.top() + (sheight - size.height()) /2);
|
||||
}
|
||||
const QRect gripperBounds(gripperBoundsPos, size);
|
||||
|
||||
const QRect gripperBounds = QWindowsXPStylePrivate::scrollBarGripperBounds(flags, widget, &theme);
|
||||
// Draw gripper if there is enough space
|
||||
if (!gripperBounds.isEmpty()) {
|
||||
p->save();
|
||||
|
@ -392,6 +392,7 @@ public:
|
||||
|
||||
static bool resolveSymbols();
|
||||
static bool useXP(bool update = false);
|
||||
static QRect scrollBarGripperBounds(QStyle::State flags, const QWidget *widget, XPThemeData *theme);
|
||||
|
||||
bool isTransparent(XPThemeData &themeData);
|
||||
QRegion region(XPThemeData &themeData);
|
||||
|
Loading…
Reference in New Issue
Block a user