From f5bc3fb2f0ae547081a74faeaaa80ddb3ac515a6 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 25 Oct 2012 16:16:14 +0200 Subject: Some Vista style cleanup Creates a function for cloning the style options used by Vista style. Change-Id: I4d83661acd6bdfff5c633447046a206018b537af Reviewed-by: J-P Nurmi --- src/widgets/styles/qwindowsvistastyle.cpp | 53 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 87c67dc84b..b20e6f5ea5 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -151,12 +151,36 @@ inline QObject *styleObject(const QStyleOption *option) { return option ? option->styleObject : 0; } +/* \internal + Checks if we can animate on a style option +*/ bool canAnimate(const QStyleOption *option) { return option && option->styleObject && !option->styleObject->property("_q_no_animation").toBool(); } +/* \internal + Used by animations to clone a styleoption and shift its offset +*/ +QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) { + QStyleOption *styleOption = 0; + if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) + styleOption = new QStyleOptionSlider(*slider); + else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(option)) + styleOption = new QStyleOptionSpinBox(*spinbox); + else if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast(option)) + styleOption = new QStyleOptionGroupBox(*groupBox); + else if (const QStyleOptionComboBox *combo = qstyleoption_cast(option)) + styleOption = new QStyleOptionComboBox(*combo); + else if (const QStyleOptionButton *button = qstyleoption_cast(option)) + styleOption = new QStyleOptionButton(*button); + else + styleOption = new QStyleOption(*option); + styleOption->rect = QRect(QPoint(0,0), option->rect.size()); + return styleOption; +} + /*! \class QWindowsVistaStyle @@ -402,14 +426,8 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt doTransition = false; if (doTransition) { - QStyleOption *styleOption = 0; - if (const QStyleOptionGroupBox *combo = qstyleoption_cast(option)) - styleOption = new QStyleOptionGroupBox(*combo); - else - styleOption = new QStyleOption(*option); - + QStyleOption *styleOption = clonedAnimationStyleOption(option); styleOption->state = (QStyle::State)oldState; - styleOption->rect = QRect(QPoint(0,0), newRect.size()); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); @@ -975,16 +993,8 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); - QStyleOption *styleOption = 0; - if (const QStyleOptionComboBox *combo = qstyleoption_cast(option)) - styleOption = new QStyleOptionComboBox(*combo); - else if (const QStyleOptionButton *button = qstyleoption_cast(option)) - styleOption = new QStyleOptionButton(*button); - else - styleOption = new QStyleOption(*option); - + QStyleOption *styleOption = clonedAnimationStyleOption(option); styleOption->state = (QStyle::State)oldState; - styleOption->rect = QRect(QPoint(0,0), newRect.size()); QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); startImage.fill(0); @@ -1664,6 +1674,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle } if (doTransition) { + QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); startImage.fill(0); QPainter startPainter(&startImage); @@ -1676,15 +1687,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); // Draw the image that ends the animation by using the current styleoption - QStyleOptionComplex *styleOption = 0; - if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) - styleOption = new QStyleOptionSlider(*slider); - else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(option)) - styleOption = new QStyleOptionSpinBox(*spinbox); - else - styleOption = new QStyleOptionComplex(*option); - - styleOption->rect = QRect(QPoint(0,0), option->rect.size()); + QStyleOptionComplex *styleOption = qstyleoption_cast(clonedAnimationStyleOption(option)); styleObject->setProperty("_q_no_animation", true); -- cgit v1.2.3