diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2012-10-16 16:35:34 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-17 20:47:08 +0200 |
commit | a98b9435579f5abef82036e81af4488d8a464b66 (patch) | |
tree | d647030face0d45f51c39f9c56ad77574871f4fe /src/widgets/styles/qwindowsstyle.cpp | |
parent | 037d1e18e39f24b8ebb2772c20444d4b44cfb12b (diff) |
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 <jens.bache-wiig@digia.com>
Diffstat (limited to 'src/widgets/styles/qwindowsstyle.cpp')
-rw-r--r-- | src/widgets/styles/qwindowsstyle.cpp | 62 |
1 files changed, 6 insertions, 56 deletions
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 <private/qmenubar_p.h> #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<QProgressBar *>(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<QProgressBar *>(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<QProgressBar *>(widget)) - widget->installEventFilter(this); -#endif } /*! \reimp */ void QWindowsStyle::unpolish(QWidget *widget) { QCommonStyle::unpolish(widget); -#ifndef QT_NO_PROGRESSBAR - if (QProgressBar *bar=qobject_cast<QProgressBar *>(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<const QStyleOptionProgressBar *>(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<QProgressStyleAnimation*>(d->animation(widget))) + if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(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: |