From a98b60edfcdc5c84da6d34613a44da207e07d15e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 25 Jun 2013 15:58:47 +0200 Subject: QMacStyle: fix auto-default button animation Make sure to stop any previously active (auto-default button) animation when the auto-default button changes. Task-number: QTBUG-31668 Change-Id: Iaa9bfa485b11e49cd7f765d0e54b4e6391ad2f6d Reviewed-by: Jens Bache-Wiig --- src/widgets/styles/qmacstyle_mac.mm | 23 +++++++++++++++-------- src/widgets/styles/qmacstyle_mac_p_p.h | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index f8905b1b1a..dad4e57d13 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1630,6 +1630,19 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti } } +void QMacStylePrivate::setAutoDefaultButton(QObject *button) const +{ + if (autoDefaultButton != button) { + if (QStyleAnimation *anim = animation(autoDefaultButton)) { + anim->updateTarget(); + stopAnimation(autoDefaultButton); + } + autoDefaultButton = button; + } + if (autoDefaultButton && !animation(autoDefaultButton)) + startAnimation(new QStyleAnimation(autoDefaultButton)); +} + QMacStylePrivate::QMacStylePrivate() : mouseDown(false) { @@ -3497,15 +3510,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter // takes precedence over a normal default button if (btn->features & QStyleOptionButton::AutoDefaultButton && opt->state & State_Active && opt->state & State_HasFocus) { - d->autoDefaultButton = opt->styleObject; - if (!d->animation(opt->styleObject)) - d->startAnimation(new QStyleAnimation(opt->styleObject)); + d->setAutoDefaultButton(opt->styleObject); } else if (d->autoDefaultButton == opt->styleObject) { - if (QStyleAnimation *animation = d->animation(opt->styleObject)) { - animation->updateTarget(); - d->stopAnimation(opt->styleObject); - } - d->autoDefaultButton = 0; + d->setAutoDefaultButton(0); } if (!d->autoDefaultButton) { diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index bf42087fcb..efeaa66e39 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -194,6 +194,8 @@ public: HIThemeButtonDrawInfo *bdi) const; QPixmap generateBackgroundPattern() const; + void setAutoDefaultButton(QObject *button) const; + public: mutable QPointer pressedButton; mutable QPointer defaultButton; -- cgit v1.2.3