From 34a984c80739d034b6c0c9e0f29c73b03ddc5aa1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 1 Mar 2016 15:40:52 +0100 Subject: Windows XP style: Change theme logic to use qreal. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid rounding errors, thus preventing sizes becoming too small when High DPI scaling is in effect. Also fix division by zero crashes should a scale factor be below 1. Task-number: QTBUG-49374 Task-number: QTBUG-51552 Change-Id: I72718521bc3c7f6b0e42392ea2d2d3bbc61e2faa Reviewed-by: Marko Kangas Reviewed-by: Morten Johan Sørvig Reviewed-by: Alessandro Portale --- src/widgets/styles/qwindowsxpstyle.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/widgets/styles/qwindowsxpstyle.cpp') diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index e68acdf5cf..88b1b41f15 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -423,7 +423,7 @@ const QPixmap *QWindowsXPStylePrivate::tabBody(QWidget *widget) { if (!tabbody) { XPThemeData theme(0, 0, QWindowsXPStylePrivate::TabTheme, TABP_BODY); - const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget); + const QSize size = (theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget)).toSize(); tabbody = new QPixmap(size.width(), QApplication::desktop()->screenGeometry().height()); QPainter painter(tabbody); @@ -2042,7 +2042,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op themeNumber = QWindowsXPStylePrivate::StatusTheme; partId = SP_GRIPPER; XPThemeData theme(0, p, themeNumber, partId, 0); - QSize size = theme.size() / QWindowsStylePrivate::devicePixelRatio(widget); + QSize size = (theme.size() / QWindowsStylePrivate::devicePixelRatio(widget)).toSize(); size.rheight()--; if (const QStyleOptionSizeGrip *sg = qstyleoption_cast(option)) { switch (sg->corner) { @@ -2113,7 +2113,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op QWindowsXPStylePrivate::ToolBarTheme, TP_SPLITBUTTONDROPDOWN); if (theme.isValid()) { - const QSize size = theme.size() / QWindowsStylePrivate::devicePixelRatio(widget); + const QSize size = (theme.size() / QWindowsStylePrivate::devicePixelRatio(widget)).toSize(); mbiw = size.width(); mbih = size.height(); } @@ -2576,10 +2576,10 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op 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); + const QMargins contentsMargin = (theme->margins(theme->rect, TMT_SIZINGMARGINS) + / QWindowsStylePrivate::devicePixelRatio(widget)).toMargins(); theme->partId = horizontal ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT; - const QSize size = theme->size() / QWindowsStylePrivate::devicePixelRatio(widget); + const QSize size = (theme->size() / QWindowsStylePrivate::devicePixelRatio(widget)).toSize(); const int hSpace = theme->rect.width() - size.width(); const int vSpace = theme->rect.height() - size.height(); @@ -3394,7 +3394,7 @@ int QWindowsXPStyle::pixelMetric(PixelMetric pm, const QStyleOption *option, con int res = QWindowsXPStylePrivate::pixelMetricFromSystemDp(pm, option, widget); if (res != QWindowsStylePrivate::InvalidMetric) - return res / QWindowsStylePrivate::devicePixelRatio(widget); + return qRound(qreal(res) / QWindowsStylePrivate::devicePixelRatio(widget)); res = 0; switch (pm) { @@ -3540,9 +3540,9 @@ QRect QWindowsXPStyle::subControlRect(ComplexControl cc, const QStyleOptionCompl const int height = tb->rect.height(); const int width = tb->rect.width(); const int buttonMargin = int(QStyleHelper::dpiScaled(4)); - int buttonHeight = GetSystemMetrics(SM_CYSIZE) / QWindowsStylePrivate::devicePixelRatio(widget) + int buttonHeight = qRound(qreal(GetSystemMetrics(SM_CYSIZE)) / QWindowsStylePrivate::devicePixelRatio(widget)) - buttonMargin; - int buttonWidth = GetSystemMetrics(SM_CXSIZE) / QWindowsStylePrivate::devicePixelRatio(widget) + int buttonWidth = qRound(qreal(GetSystemMetrics(SM_CXSIZE)) / QWindowsStylePrivate::devicePixelRatio(widget)) - buttonMargin; const int delta = buttonWidth + 2; int controlTop = option->rect.bottom() - buttonHeight - 2; @@ -3737,10 +3737,10 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt { XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); if (buttontheme.isValid()) { - const QMargins borderSize = buttontheme.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget); + const QMarginsF borderSize = buttontheme.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget); if (!borderSize.isNull()) { - sz.rwidth() += borderSize.left() + borderSize.right() - 2; - sz.rheight() += borderSize.bottom() + borderSize.top() - 2; + sz.rwidth() += qRound(borderSize.left() + borderSize.right() - 2); + sz.rheight() += qRound(borderSize.bottom() + borderSize.top() - 2); } const int textMargins = 2*(proxy()->pixelMetric(PM_FocusFrameHMargin) + 1); sz += QSize(qMax(pixelMetric(QStyle::PM_ScrollBarExtent, option, widget) @@ -3910,7 +3910,7 @@ QPixmap QWindowsXPStyle::standardPixmap(StandardPixmap standardPixmap, const QSt if (widget && widget->isWindow()) { XPThemeData theme(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { - const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget); + const QSize size = (theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget)).toSize(); return QIcon(QWindowsStyle::standardPixmap(standardPixmap, option, widget)).pixmap(size); } } @@ -3944,7 +3944,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, WP_MAXBUTTON, MAXBS_NORMAL); if (theme.isValid()) { - const QSize size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget); + const QSize size = (themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget)).toSize(); QPixmap pm(size); pm.fill(Qt::transparent); QPainter p(&pm); @@ -3978,7 +3978,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { - const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget); + const QSize size = (theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget)).toSize(); QPixmap pm(size); pm.fill(Qt::transparent); QPainter p(&pm); @@ -4014,7 +4014,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, WP_RESTOREBUTTON, RBS_NORMAL); if (theme.isValid()) { - const QSize size = themeSize.size() / QWindowsStylePrivate::devicePixelRatio(widget); + const QSize size = (themeSize.size() / QWindowsStylePrivate::devicePixelRatio(widget)).toSize(); QPixmap pm(size); pm.fill(Qt::transparent); QPainter p(&pm); -- cgit v1.2.3