summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qwindowsvistastyle.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-04-07 10:47:20 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2016-04-07 10:47:20 +0200
commitee0951d69b38f766e67262487be95b88501aa4a5 (patch)
tree116c334060500be340d4d61c99026316b0df3ce9 /src/widgets/styles/qwindowsvistastyle.cpp
parent0bb645b1ccc5a9d57b21cf0b2c4306b8e48c611c (diff)
parentd37239aa419ee4adff4b0a8d5c1403cadff72319 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/network/access/qftp.cpp src/widgets/itemviews/qheaderview.cpp src/widgets/itemviews/qlistview.cpp tests/auto/network/access/qftp/tst_qftp.cpp Change-Id: I9f928f25d45d8944dd60bb583f649fc1615bc5d9
Diffstat (limited to 'src/widgets/styles/qwindowsvistastyle.cpp')
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index a48417677a..2b2b919818 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -108,6 +108,15 @@ bool canAnimate(const QStyleOption *option) {
&& !option->styleObject->property("_q_no_animation").toBool();
}
+static inline QImage createAnimationBuffer(const QStyleOption *option, const QWidget *widget)
+{
+ const int devicePixelRatio = widget ? widget->devicePixelRatio() : 1;
+ QImage result(option->rect.size() * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
+ result.setDevicePixelRatio(devicePixelRatio);
+ result.fill(0);
+ return result;
+}
+
/* \internal
Used by animations to clone a styleoption and shift its offset
*/
@@ -320,12 +329,10 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
// We create separate images for the initial and final transition states and store them in the
// Transition object.
- QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- startImage.fill(0);
+ QImage startImage = createAnimationBuffer(option, widget);
QPainter startPainter(&startImage);
- QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- endImage.fill(0);
+ QImage endImage = createAnimationBuffer(option, widget);
QPainter endPainter(&endImage);
// If we have a running animation on the widget already, we will use that to paint the initial
@@ -425,8 +432,8 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
XPThemeData themeSize = theme;
themeSize.partId = TVP_HOTGLYPH;
themeSize.stateId = GLPS_OPENED;
- const QSize size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- decoration_size = qMax(size.width(), size.height());
+ const QSizeF size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ decoration_size = qRound(qMax(size.width(), size.height()));
}
int mid_h = option->rect.x() + option->rect.width() / 2;
int mid_v = option->rect.y() + option->rect.height() / 2;
@@ -873,8 +880,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
QStyleOption *styleOption = clonedAnimationStyleOption(option);
styleOption->state = (QStyle::State)oldState;
- QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- startImage.fill(0);
+ QImage startImage = createAnimationBuffer(option, widget);
QPainter startPainter(&startImage);
// Use current state of existing animation if already one is running
@@ -886,8 +892,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
}
t->setStartImage(startImage);
- QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- endImage.fill(0);
+ QImage endImage = createAnimationBuffer(option, widget);
QPainter endPainter(&endImage);
styleOption->state = option->state;
proxy()->drawControl(element, styleOption, &endPainter, widget);
@@ -949,10 +954,8 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)));
if (!anim) {
- QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- startImage.fill(0);
- QImage alternateImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- alternateImage.fill(0);
+ QImage startImage = createAnimationBuffer(option, widget);
+ QImage alternateImage = createAnimationBuffer(option, widget);
QWindowsVistaPulse *pulse = new QWindowsVistaPulse(styleObject(option));
@@ -991,10 +994,10 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ToolBarTheme,
TP_DROPDOWNBUTTON);
if (theme.isValid()) {
- const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QSizeF size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
if (!size.isEmpty()) {
- mbiw = size.width();
- mbih = size.height();
+ mbiw = qRound(size.width());
+ mbih = qRound(size.height());
}
}
QRect ir = subElementRect(SE_PushButtonContents, option, 0);
@@ -1178,17 +1181,18 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
case CE_MenuItem:
if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
// windows always has a check column, regardless whether we have an icon or not
- int checkcol = 25 / QWindowsXPStylePrivate::devicePixelRatio(widget);
- const int gutterWidth = 3 / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const qreal devicePixelRatio = QWindowsXPStylePrivate::devicePixelRatio(widget);
+ int checkcol = qRound(qreal(25) / devicePixelRatio);
+ const int gutterWidth = qRound(qreal(3) / devicePixelRatio);
{
XPThemeData theme(widget, 0, QWindowsXPStylePrivate::MenuTheme,
MENU_POPUPCHECKBACKGROUND, MBI_HOT);
XPThemeData themeSize = theme;
themeSize.partId = MENU_POPUPCHECK;
themeSize.stateId = 0;
- const QSize size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- const QMargins margins = themeSize.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- checkcol = qMax(menuitem->maxIconWidth, gutterWidth + size.width() + margins.left() + margins.right());
+ const QSizeF size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QMarginsF margins = themeSize.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
}
QRect rect = option->rect;
@@ -1245,17 +1249,17 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
XPThemeData themeSize = theme;
themeSize.partId = MENU_POPUPCHECK;
themeSize.stateId = 0;
- const QSize size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- const QMargins margins = themeSize.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- QRect checkRect(0, 0, size.width() + margins.left() + margins.right(),
- size.height() + margins.bottom() + margins.top());
+ const QSizeF size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QMarginsF margins = themeSize.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
+ qRound(size.height() + margins.bottom() + margins.top()));
checkRect.moveCenter(vCheckRect.center());
theme.rect = checkRect;
d->drawBackground(theme);
if (menuitem->icon.isNull()) {
- checkRect = QRect(QPoint(0, 0), size);
+ checkRect = QRect(QPoint(0, 0), size.toSize());
checkRect.moveCenter(theme.rect.center());
theme.rect = checkRect;
@@ -1549,13 +1553,10 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle
}
if (doTransition) {
-
- QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- startImage.fill(0);
+ QImage startImage = createAnimationBuffer(option, widget);
QPainter startPainter(&startImage);
- QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- endImage.fill(0);
+ QImage endImage = createAnimationBuffer(option, widget);
QPainter endPainter(&endImage);
QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
@@ -1861,10 +1862,10 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption
XPThemeData themeSize = theme;
themeSize.partId = MENU_POPUPCHECK;
themeSize.stateId = 0;
- const QSize size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- const QMargins margins = themeSize.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
- minimumHeight = qMax(size.height() + margins.bottom() + margins.top(), sz.height());
- sz.rwidth() += size.width() + margins.left() + margins.right();
+ const QSizeF size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QMarginsF margins = themeSize.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ minimumHeight = qMax(qRound(size.height() + margins.bottom() + margins.top()), sz.height());
+ sz.rwidth() += qRound(size.width() + margins.left() + margins.right());
}
if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
@@ -1972,10 +1973,10 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption
int arrowWidth = 13;
int arrowHeight = 5;
if (theme.isValid()) {
- const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QSizeF size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
if (!size.isEmpty()) {
- arrowWidth = size.width();
- arrowHeight = size.height();
+ arrowWidth = qRound(size.width());
+ arrowHeight = qRound(size.height());
}
}
if (option->state & State_Horizontal) {
@@ -2516,7 +2517,7 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon,
QWindowsXPStylePrivate::ButtonTheme,
BP_COMMANDLINKGLYPH, CMDLGS_NORMAL);
if (theme.isValid()) {
- const QSize size = theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QSize size = (theme.size() / QWindowsXPStylePrivate::devicePixelRatio(widget)).toSize();
QIcon linkGlyph;
QPixmap pm(size);
pm.fill(Qt::transparent);