diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2016-03-04 15:55:35 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2016-04-05 07:27:40 +0000 |
commit | 16e7bcc4cddf31bb2d13d5c6dfbe9184b66d5b06 (patch) | |
tree | ac1503ec7fc8d5d3ac4cca81e4536bb93cc652a1 | |
parent | 34a984c80739d034b6c0c9e0f29c73b03ddc5aa1 (diff) |
Vista style animation: Create images with device pixel ratio.
Change-Id: Ic404c8ac8b0e4c1b8d0dd7877611443e0afac270
Task-number: QTBUG-49374
Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
-rw-r--r-- | src/widgets/styles/qstyleanimation.cpp | 1 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 34 |
2 files changed, 18 insertions, 17 deletions
diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 922a1e5ffb..eaaf923b25 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -267,6 +267,7 @@ static QImage blendedImage(const QImage &start, const QImage &end, float alpha) case 32: { blended = QImage(sw, sh, start.format()); + blended.setDevicePixelRatio(start.devicePixelRatio()); uchar *mixed_data = blended.bits(); const uchar *back_data = start.bits(); const uchar *front_data = end.bits(); diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 2266c03484..70623a9250 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -102,6 +102,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 */ @@ -314,12 +323,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 @@ -867,8 +874,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 @@ -880,8 +886,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); @@ -943,10 +948,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)); @@ -1544,13 +1547,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)); |