From a98b9435579f5abef82036e81af4488d8a464b66 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 16 Oct 2012 16:35:34 +0200 Subject: Styles: revise indeterminate progress bar animations Remove dependencies to QProgressBar where possible. This makes it possible to animate for example QQuickItem based progress bars (read: the desktop components). Change-Id: If208506702365895576238c24191b8d70b90841c Reviewed-by: Jens Bache-Wiig --- src/widgets/styles/qcleanlooksstyle.cpp | 9 +++-- src/widgets/styles/qcommonstyle.cpp | 12 ++---- src/widgets/styles/qcommonstyle_p.h | 8 ++-- src/widgets/styles/qgtkstyle.cpp | 8 ++-- src/widgets/styles/qmacstyle_mac.mm | 66 +++++++++++-------------------- src/widgets/styles/qmacstyle_mac_p.h | 6 +-- src/widgets/styles/qplastiquestyle.cpp | 42 ++++---------------- src/widgets/styles/qstyleanimation.cpp | 20 +++------- src/widgets/styles/qstyleanimation_p.h | 4 -- src/widgets/styles/qstylesheetstyle.cpp | 21 +++------- src/widgets/styles/qwindowsstyle.cpp | 62 +++-------------------------- src/widgets/styles/qwindowsstyle_p.h | 3 -- src/widgets/styles/qwindowsvistastyle.cpp | 22 +++++------ 13 files changed, 76 insertions(+), 207 deletions(-) (limited to 'src') diff --git a/src/widgets/styles/qcleanlooksstyle.cpp b/src/widgets/styles/qcleanlooksstyle.cpp index 896f2ead32..5b8b5e0b9f 100644 --- a/src/widgets/styles/qcleanlooksstyle.cpp +++ b/src/widgets/styles/qcleanlooksstyle.cpp @@ -1751,20 +1751,21 @@ void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *o reverse = !reverse; QRect progressBar; + Q_D(const QCleanlooksStyle); if (!indeterminate) { if (!reverse) { progressBar.setRect(rect.left() + 1, rect.top() + 1, width + 1, rect.height() - 3); } else { progressBar.setRect(rect.right() - 1 - width, rect.top() + 1, width + 1, rect.height() - 3); } + d->stopAnimation(option->styleObject); } else { - Q_D(const QCleanlooksStyle); int slideWidth = ((rect.width() - 4) * 2) / 3; int step = 0; -#ifndef QT_NO_ANIMATION - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(widget))) + if (QProgressStyleAnimation *animation = qobject_cast(d->animation(option->styleObject))) step = animation->progressStep(slideWidth); -#endif + else + d->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject)); progressBar.setRect(rect.left() + 1 + step, rect.top() + 1, slideWidth / 2, rect.height() - 3); } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index d4e4ea22d0..dd75870437 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1062,22 +1062,19 @@ QStyleAnimation * QCommonStylePrivate::animation(const QObject *target) const } /*! \internal */ -void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) +void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) const { -#ifndef QT_NO_ANIMATION - Q_Q(QCommonStyle); + Q_Q(const QCommonStyle); stopAnimation(animation->target()); q->connect(animation, SIGNAL(finished()), SLOT(_q_removeAnimation()), Qt::UniqueConnection); q->connect(animation, SIGNAL(destroyed()), SLOT(_q_removeAnimation()), Qt::UniqueConnection); animations.insert(animation->target(), animation); animation->start(); -#endif // QT_NO_ANIMATION } /*! \internal */ -void QCommonStylePrivate::stopAnimation(const QObject *target) +void QCommonStylePrivate::stopAnimation(const QObject *target) const { -#ifndef QT_NO_ANIMATION QStyleAnimation *animation = animations.value(target); if (animation) { if (animation->state() == QAbstractAnimation::Stopped) @@ -1085,20 +1082,17 @@ void QCommonStylePrivate::stopAnimation(const QObject *target) else animation->stop(); } -#endif // QT_NO_ANIMATION } /*! \internal */ void QCommonStylePrivate::_q_removeAnimation() { -#ifndef QT_NO_ANIMATION Q_Q(QCommonStyle); QObject *animation = q->sender(); if (animation) { animations.remove(animation->parent()); animation->deleteLater(); } -#endif // QT_NO_ANIMATION } /*! diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index 2032e06e31..8f22dc7b79 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -77,9 +77,7 @@ public: ~QCommonStylePrivate() { -#ifndef QT_NO_ANIMATION qDeleteAll(animations); -#endif #ifndef QT_NO_ITEMVIEWS delete cachedOption; #endif @@ -120,11 +118,11 @@ public: QList animationTargets() const; QStyleAnimation* animation(const QObject *target) const; - void startAnimation(QStyleAnimation *animation); - void stopAnimation(const QObject *target); + void startAnimation(QStyleAnimation *animation) const; + void stopAnimation(const QObject *target) const; private: - QHash animations; + mutable QHash animations; }; QT_END_NAMESPACE diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp index 83e70d022b..2c8bc4c188 100644 --- a/src/widgets/styles/qgtkstyle.cpp +++ b/src/widgets/styles/qgtkstyle.cpp @@ -3488,15 +3488,15 @@ void QGtkStyle::drawControl(ControlElement element, progressBar.setRect(rect.left(), rect.top(), width, rect.height()); else progressBar.setRect(rect.right() - width, rect.top(), width, rect.height()); - + d->stopAnimation(option->styleObject); } else { Q_D(const QGtkStyle); int slideWidth = ((rect.width() - 4) * 2) / 3; int step = 0; -#ifndef QT_NO_ANIMATION - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(widget))) + if (QProgressStyleAnimation *animation = qobject_cast(d->animation(option->styleObject))) step = animation->progressStep(slideWidth); -#endif + else + d->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject)); progressBar.setRect(rect.left() + step, rect.top(), slideWidth / 2, rect.height()); } diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 20791d6625..54b15e39a6 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1683,15 +1683,15 @@ QMacStylePrivate::QMacStylePrivate() } -bool QMacStylePrivate::animatable(QMacStylePrivate::Animates as, const QWidget *w) const +bool QMacStylePrivate::animatable(QMacStylePrivate::Animates as, const QObject *obj) const { - if (!w) + if (!obj) return false; if (as == AquaPushButton) { - QPushButton *pb = const_cast(static_cast(w)); - if (w->window()->isActiveWindow() && pb && !mouseDown) { - if (static_cast(w) != defaultButton) { + QPushButton *pb = const_cast(qobject_cast(obj)); + if (pb && pb->window()->isActiveWindow() && !mouseDown) { + if (pb != defaultButton) { // Changed on its own, update the value. const_cast(this)->stopAnimate(as, defaultButton); const_cast(this)->startAnimate(as, pb); @@ -1699,35 +1699,28 @@ bool QMacStylePrivate::animatable(QMacStylePrivate::Animates as, const QWidget * return true; } } - return animation(w); + return animation(obj); } -void QMacStylePrivate::stopAnimate(QMacStylePrivate::Animates as, QWidget *w) +void QMacStylePrivate::stopAnimate(QMacStylePrivate::Animates as, QObject *obj) { - stopAnimation(w); + stopAnimation(obj); if (as == AquaPushButton && defaultButton) { stopAnimation(defaultButton); QPushButton *tmp = defaultButton; defaultButton = 0; tmp->update(); } else if (as == AquaScrollBar) { - scrollBarInfos.remove(w); + scrollBarInfos.remove(qobject_cast(obj)); } } -void QMacStylePrivate::startAnimate(QMacStylePrivate::Animates as, QWidget *w) +void QMacStylePrivate::startAnimate(QMacStylePrivate::Animates as, QObject *obj) { -#ifndef QT_NO_ANIMATION - if (!animation(w)) - { - if (as == AquaProgressBar) - startAnimation(new QProgressStyleAnimation(animateSpeed(as), w)); - else - startAnimation(new QStyleAnimation(w)); - } -#endif + if (!animation(obj)) + startAnimation(new QStyleAnimation(obj)); if (as == AquaPushButton) - defaultButton = static_cast(w); + defaultButton = qobject_cast(obj); } bool QMacStylePrivate::addWidget(QWidget *w) @@ -1743,12 +1736,6 @@ bool QMacStylePrivate::addWidget(QWidget *w) startAnimate(AquaPushButton, btn); return true; } else { - bool isProgressBar = (qobject_cast(w)); - if (isProgressBar) { - w->installEventFilter(q); - startAnimate(AquaProgressBar, w); - return true; - } bool isScrollBar = (qobject_cast(w)); if (isScrollBar) { w->installEventFilter(q); @@ -1768,8 +1755,6 @@ void QMacStylePrivate::removeWidget(QWidget *w) QPushButton *btn = qobject_cast(w); if (btn && btn == defaultButton) { stopAnimate(AquaPushButton, btn); - } else if (qobject_cast(w)) { - stopAnimate(AquaProgressBar, w); } else if (qobject_cast(w)) { stopAnimate(AquaScrollBar, w); } @@ -1797,19 +1782,8 @@ bool QMacStyle::eventFilter(QObject *o, QEvent *e) { //animate Q_D(QMacStyle); - if (QProgressBar *pb = qobject_cast(o)) { - switch (e->type()) { - default: - break; - case QEvent::Show: - d->startAnimate(QMacStylePrivate::AquaProgressBar, pb); - break; - case QEvent::Destroy: - case QEvent::Hide: - d->stopAnimate(QMacStylePrivate::AquaProgressBar, pb); - } + if (QScrollBar *sb = qobject_cast(o)) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - } else if (QScrollBar *sb = qobject_cast(o)) { // take care of fading out overlaying scrollbars (and only those!) when inactive const QAbstractScrollArea *scrollArea = scrollBarsScrollArea(sb); if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7 && @@ -4377,10 +4351,14 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter tdi.min = pb->minimum; tdi.value = pb->progress; tdi.attributes = vertical ? 0 : kThemeTrackHorizontal; -#ifndef QT_NO_ANIMATION - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(w))) - tdi.trackInfo.progress.phase = animation->animationStep(); -#endif + if (isIndeterminate) { + if (QProgressStyleAnimation *animation = qobject_cast(d->animation(opt->styleObject))) + tdi.trackInfo.progress.phase = animation->animationStep(); + else + d->startAnimation(new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject)); + } else { + d->stopAnimation(opt->styleObject); + } if (!(pb->state & State_Active)) tdi.enableState = kThemeTrackInactive; else if (!(pb->state & State_Enabled)) diff --git a/src/widgets/styles/qmacstyle_mac_p.h b/src/widgets/styles/qmacstyle_mac_p.h index 63cc005033..812c79e158 100644 --- a/src/widgets/styles/qmacstyle_mac_p.h +++ b/src/widgets/styles/qmacstyle_mac_p.h @@ -163,9 +163,9 @@ public: void removeWidget(QWidget *); enum Animates { AquaPushButton, AquaProgressBar, AquaListViewItemOpen, AquaScrollBar }; - bool animatable(Animates, const QWidget *) const; - void stopAnimate(Animates, QWidget *); - void startAnimate(Animates, QWidget *); + bool animatable(Animates, const QObject *) const; + void stopAnimate(Animates, QObject *); + void startAnimate(Animates, QObject *); static ThemeDrawState getDrawState(QStyle::State flags); QAquaWidgetSize aquaSizeConstrain(const QStyleOption *option, const QWidget *widg, QStyle::ContentsType ct = QStyle::CT_CustomBase, diff --git a/src/widgets/styles/qplastiquestyle.cpp b/src/widgets/styles/qplastiquestyle.cpp index fe1e5c3dc3..449783fb90 100644 --- a/src/widgets/styles/qplastiquestyle.cpp +++ b/src/widgets/styles/qplastiquestyle.cpp @@ -2396,7 +2396,7 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op } break; #endif // QT_NO_TABBAR -#ifndef QT_NO_PROGRESSBAR + case CE_ProgressBarGroove: if (const QStyleOptionProgressBar *bar = qstyleoption_cast(option)) { QRect rect = bar->rect; @@ -2566,13 +2566,14 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op } else { progressBar.setRect(rect.right() - 1 - width, rect.top() + 2, width, rect.height() - 4); } + d->stopAnimation(option->styleObject); } else { int slideWidth = ((rect.width() - 4) * 2) / 3; int step = 0; -#ifndef QT_NO_ANIMATION - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(widget))) + if (QProgressStyleAnimation *animation = qobject_cast(d->animation(option->styleObject))) step = animation->progressStep(slideWidth); -#endif + else + d->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject)); progressBar.setRect(rect.left() + 2 + step, rect.top() + 2, slideWidth / 2, rect.height() - 4); } @@ -2727,10 +2728,8 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op if (!indeterminate) { int step = 0; if (AnimateProgressBar || (indeterminate && AnimateBusyProgressBar)) { -#ifndef QT_NO_ANIMATION if (QProgressStyleAnimation *animation = qobject_cast(d->animation(widget))) step = animation->animationStep() % 20; -#endif } if (reverse) painter->drawPixmap(progressBar.left() - 25 + step, progressBar.top(), cache); @@ -2743,7 +2742,7 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op painter->restore(); } break; -#endif // QT_NO_PROGRESSBAR + case CE_HeaderSection: // Draws the header in tables. if (const QStyleOptionHeader *header = qstyleoption_cast(option)) { @@ -4956,12 +4955,10 @@ QRect QPlastiqueStyle::subElementRect(SubElement element, const QStyleOption *op rect = visualRect(option->direction, option->rect, QWindowsStyle::subElementRect(element, option, widget)).adjusted(0, 0, 1, 1); break; -#ifndef QT_NO_PROGRESSBAR case SE_ProgressBarLabel: case SE_ProgressBarContents: case SE_ProgressBarGroove: return option->rect; -#endif // QT_NO_PROGRESSBAR default: return QWindowsStyle::subElementRect(element, option, widget); } @@ -5647,11 +5644,6 @@ void QPlastiqueStyle::polish(QWidget *widget) widget->setBackgroundRole(QPalette::Window); } -#ifndef QT_NO_PROGRESSBAR - if (AnimateBusyProgressBar && qobject_cast(widget)) - widget->installEventFilter(this); -#endif - #if defined QPlastique_MaskButtons if (qobject_cast(widget) || qobject_cast(widget)) widget->installEventFilter(this); @@ -5704,11 +5696,6 @@ void QPlastiqueStyle::unpolish(QWidget *widget) widget->setBackgroundRole(QPalette::Button); } -#ifndef QT_NO_PROGRESSBAR - if (AnimateBusyProgressBar && qobject_cast(widget)) - widget->removeEventFilter(this); -#endif - #if defined QPlastique_MaskButtons if (qobject_cast(widget) || qobject_cast(widget)) widget->removeEventFilter(this); @@ -5825,20 +5812,8 @@ int QPlastiqueStyle::layoutSpacing(QSizePolicy::ControlType control1, */ bool QPlastiqueStyle::eventFilter(QObject *watched, QEvent *event) { -#ifndef QT_NO_PROGRESSBAR - Q_D(QPlastiqueStyle); - - switch (event->type()) { - case QEvent::Show: - if (QProgressBar *bar = qobject_cast(watched)) - d->startProgressAnimation(this, bar); - break; - case QEvent::Destroy: - case QEvent::Hide: - if (QProgressBar *bar = qobject_cast(watched)) - d->stopProgressAnimation(this, bar); - break; #if defined QPlastique_MaskButtons + switch (event->type()) { case QEvent::Resize: if (qobject_cast(watched) || qobject_cast(watched)) { QWidget *widget = qobject_cast(watched); @@ -5855,11 +5830,10 @@ bool QPlastiqueStyle::eventFilter(QObject *watched, QEvent *event) widget->setMask(region); } break; -#endif default: break; } -#endif // QT_NO_PROGRESSBAR +#endif return QWindowsStyle::eventFilter(watched, event); } diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 8bc8e9d241..297a929970 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -47,8 +47,6 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_ANIMATION - QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), _startTime(QTime::currentTime()) { @@ -128,21 +126,13 @@ void QProgressStyleAnimation::setSpeed(int speed) bool QProgressStyleAnimation::isUpdateNeeded() const { - QProgressBar *pb = qobject_cast(parent()); - if (pb && pb->minimum() == 0 && pb->maximum() == 0) { - int current = animationStep(); - if (_step == -1 || _step != current) - { - _step = current; - return true; - } - } else { - // the progress bar is no longer indeterminate -> stop - const_cast(this)->stop(); + int current = animationStep(); + if (_step == -1 || _step != current) + { + _step = current; + return true; } return false; } -#endif // QT_NO_ANIMATION - QT_END_NAMESPACE diff --git a/src/widgets/styles/qstyleanimation_p.h b/src/widgets/styles/qstyleanimation_p.h index 2c00048b7d..8231abbb40 100644 --- a/src/widgets/styles/qstyleanimation_p.h +++ b/src/widgets/styles/qstyleanimation_p.h @@ -58,8 +58,6 @@ QT_BEGIN_NAMESPACE // We mean it. // -#ifndef QT_NO_ANIMATION - class QStyleAnimation : public QAbstractAnimation { Q_OBJECT @@ -103,8 +101,6 @@ private: mutable int _step; }; -#endif // QT_NO_ANIMATION - QT_END_NAMESPACE #endif // QSTYLEANIMATION_P_H diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 068b7a4355..d73d25a1af 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -69,7 +69,6 @@ #include #include #include -#include #include #include #include @@ -2726,12 +2725,6 @@ void QStyleSheetStyle::polish(QWidget *w) } #endif -#ifndef QT_NO_PROGRESSBAR - if (QProgressBar *pb = qobject_cast(w)) { - QWindowsStyle::polish(pb); - } -#endif - QRenderRule rule = renderRule(w, PseudoElement_None, PseudoClass_Any); if (rule.hasDrawable() || rule.hasBox()) { if (w->metaObject() == &QWidget::staticMetaObject @@ -2825,10 +2818,6 @@ void QStyleSheetStyle::unpolish(QWidget *w) QObject::disconnect(sa->verticalScrollBar(), SIGNAL(valueChanged(int)), sa, SLOT(update())); } -#endif -#ifndef QT_NO_PROGRESSBAR - if (QProgressBar *pb = qobject_cast(w)) - QWindowsStyle::unpolish(pb); #endif baseStyle()->unpolish(w); } @@ -3830,14 +3819,14 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q } QRect r = rect; + Q_D(const QWindowsStyle); if (pb->minimum == 0 && pb->maximum == 0) { - Q_D(const QWindowsStyle); int chunkCount = fillWidth/chunkWidth; int offset = 0; -#ifndef QT_NO_ANIMATION - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(w))) + if (QProgressStyleAnimation *animation = qobject_cast(d->animation(opt->styleObject))) offset = animation->animationStep() * 8 % rect.width(); -#endif + else + d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject)); int x = reverse ? r.left() + r.width() - offset - chunkWidth : r.x() + offset; while (chunkCount > 0) { r.setRect(x, rect.y(), chunkWidth, rect.height()); @@ -3868,6 +3857,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q subRule.drawRule(p, r); x += reverse ? -chunkWidth : chunkWidth; } + + d->stopAnimation(opt->styleObject); } p->restore(); diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 714898e809..eb39790e36 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -54,7 +54,6 @@ #include #include "qpaintengine.h" #include "qpainter.h" -#include "qprogressbar.h" #include "qrubberband.h" #include "qstyleoption.h" #include "qtabbar.h" @@ -131,21 +130,6 @@ QWindowsStylePrivate::QWindowsStylePrivate() #endif } -void QWindowsStylePrivate::startProgressAnimation(QObject *o, QProgressBar *bar) -{ - Q_UNUSED(o); -#ifndef QT_NO_ANIMATION - if (!animation(bar)) - startAnimation(new QProgressStyleAnimation(animationFps, bar)); -#endif -} - -void QWindowsStylePrivate::stopProgressAnimation(QObject *o, QProgressBar *bar) -{ - Q_UNUSED(o); - stopAnimation(bar); -} - // Returns true if the toplevel parent of \a widget has seen the Alt-key bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const { @@ -204,27 +188,6 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) d->seenAlt.removeAll(widget); d->seenAlt.removeAll(widget->window()); break; -#ifndef QT_NO_PROGRESSBAR - case QEvent::StyleChange: - case QEvent::Paint: - case QEvent::Show: - if (QProgressBar *bar = qobject_cast(o)) { - // Animation by timer for progress bars that have their min and - // max values the same - if (bar->minimum() == bar->maximum()) - d->startProgressAnimation(this, bar); - else - d->stopProgressAnimation(this, bar); - } - break; - case QEvent::Destroy: - case QEvent::Hide: - // Do static_cast because there is no type info when getting - // the destroy event. We know that it is a QProgressBar, since - // we only install a widget event filter for QScrollBars. - d->stopProgressAnimation(this, static_cast(o)); - break; -#endif // QT_NO_PROGRESSBAR default: break; } @@ -315,23 +278,12 @@ void QWindowsStyle::unpolish(QApplication *app) void QWindowsStyle::polish(QWidget *widget) { QCommonStyle::polish(widget); -#ifndef QT_NO_PROGRESSBAR - if (qobject_cast(widget)) - widget->installEventFilter(this); -#endif } /*! \reimp */ void QWindowsStyle::unpolish(QWidget *widget) { QCommonStyle::unpolish(widget); -#ifndef QT_NO_PROGRESSBAR - if (QProgressBar *bar=qobject_cast(widget)) { - Q_D(QWindowsStyle); - widget->removeEventFilter(this); - d->stopProgressAnimation(this, bar); - } -#endif } /*! @@ -1582,7 +1534,6 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0); break; -#ifndef QT_NO_PROGRESSBAR case PE_IndicatorProgressChunk: { bool vertical = false, inverted = false; @@ -1616,7 +1567,6 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, } } break; -#endif // QT_NO_PROGRESSBAR case PE_FrameTabWidget: { qDrawWinButton(p, opt->rect, opt->palette, false, 0); @@ -2232,7 +2182,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai #endif // QT_NO_TOOLBAR -#ifndef QT_NO_PROGRESSBAR + case CE_ProgressBarContents: if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { QRect rect = pb->rect; @@ -2263,8 +2213,8 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai if (inverted) reverse = !reverse; int w = rect.width(); + Q_D(const QWindowsStyle); if (pb->minimum == 0 && pb->maximum == 0) { - Q_D(const QWindowsStyle); const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget); QStyleOptionProgressBarV2 pbBits = *pb; Q_ASSERT(unit_width >0); @@ -2274,10 +2224,10 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai int step = 0; int chunkCount = w / unit_width + 1; -#ifndef QT_NO_ANIMATION - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(widget))) + if (QProgressStyleAnimation *animation = qobject_cast(d->animation(opt->styleObject))) step = (animation->animationStep() / 3) % chunkCount; -#endif + else + d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject)); int chunksInRow = 5; int myY = pbBits.rect.y(); int myHeight = pbBits.rect.height(); @@ -2311,11 +2261,11 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai p->restore(); //restore state } else { + d->stopAnimation(opt->styleObject); QCommonStyle::drawControl(ce, opt, p, widget); } } break; -#endif // QT_NO_PROGRESSBAR #ifndef QT_NO_DOCKWIDGET case CE_DockWidgetTitle: diff --git a/src/widgets/styles/qwindowsstyle_p.h b/src/widgets/styles/qwindowsstyle_p.h index f24696f0bd..6d69557edd 100644 --- a/src/widgets/styles/qwindowsstyle_p.h +++ b/src/widgets/styles/qwindowsstyle_p.h @@ -63,15 +63,12 @@ QT_BEGIN_NAMESPACE class QTime; -class QProgressBar; class QWindowsStylePrivate : public QCommonStylePrivate { Q_DECLARE_PUBLIC(QWindowsStyle) public: QWindowsStylePrivate(); - void startProgressAnimation(QObject *o, QProgressBar *bar); - void stopProgressAnimation(QObject *o, QProgressBar *bar); bool hasSeenAlt(const QWidget *widget) const; bool altDown() const { return alt_down; } bool alt_down; diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index d1a0af3a91..d8bf6920ac 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -1089,7 +1089,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption return; } break; -#ifndef QT_NO_PROGRESSBAR + case CE_ProgressBarContents: if (const QStyleOptionProgressBar *bar = qstyleoption_cast(option)) { @@ -1101,11 +1101,11 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption inverted = pb2->invertedAppearance; } - if (const QProgressBar *progressbar = qobject_cast(widget)) { - if (isIndeterminate || (progressbar->value() > 0 && (progressbar->value() < progressbar->maximum()) && d->transitionsEnabled())) - d->startProgressAnimation(0, const_cast(progressbar)); - else - d->stopAnimation(progressbar); + if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) { + if (!d->animation(option->styleObject)) + d->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject)); + } else { + d->stopAnimation(option->styleObject); } XPThemeData theme(widget, painter, @@ -1116,7 +1116,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QTime current = QTime::currentTime(); if (isIndeterminate) { - if (QProgressStyleAnimation *a = qobject_cast(d->animation(widget))) { + if (QProgressStyleAnimation *a = qobject_cast(d->animation(option->styleObject))) { int glowSize = 120; int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width()); int animOffset = a->startTime().msecsTo(current) / 4; @@ -1186,7 +1186,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption } d->drawBackground(theme); - if (QProgressStyleAnimation *a = qobject_cast(d->animation(widget))) { + if (QProgressStyleAnimation *a = qobject_cast(d->animation(option->styleObject))) { int glowSize = 140; int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width()); int animOffset = a->startTime().msecsTo(current) / 4; @@ -1195,8 +1195,8 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (bar->progress < bar->maximum) a->setStartTime(QTime::currentTime()); else - d->stopAnimation(widget); //we stop the glow motion only after it has - //moved out of view + d->stopAnimation(option->styleObject); //we stop the glow motion only after it has + //moved out of view } painter->save(); painter->setClipRect(theme.rect); @@ -1215,7 +1215,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption } } break; -#endif // QT_NO_PROGRESSBAR + case CE_MenuBarItem: { -- cgit v1.2.3