summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-10-15 14:05:24 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-10-22 08:58:42 +0200
commit763a48fe1af5b0482f929a79ded05ea21456a916 (patch)
treea35edb782fd9abba99ffbedc0ebe4d9a3a6161de /src/widgets
parentff98c440603e94ae284ad08d289418f4b5cca89e (diff)
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>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp20
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp33
-rw-r--r--src/widgets/styles/qwindowsxpstyle_p_p.h1
3 files changed, 17 insertions, 37 deletions
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index 044394747c..007952192a 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -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();
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index 624023f627..c18bbb3431 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -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();
diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h
index 4f42b60681..5027588c93 100644
--- a/src/widgets/styles/qwindowsxpstyle_p_p.h
+++ b/src/widgets/styles/qwindowsxpstyle_p_p.h
@@ -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);