diff options
author | Błażej Szczygieł <[email protected]> | 2017-01-11 21:45:27 +0100 |
---|---|---|
committer | Błażej Szczygieł <[email protected]> | 2017-03-11 09:23:02 +0000 |
commit | 335dbece103e2cbf6c7cf819ab6672c2956b17b3 (patch) | |
tree | f6ecc6a247235c3dae0d607694356496dcf5d767 /src/plugins/styles/motif | |
parent | 5ef7b26b9792b5aae4d289413a3a0691766b072e (diff) |
Move plastique and cleanlooks timer event to "event()" method, because
"timerEvent()" doesn't work on class derivated from "QProxyStyle".
Also unify plastique, cleanlooks and motif animation timer methods.
This allows to kill timer for plastique and motif styles when it will
be no longer necessary (as in cleanlooks style).
Change-Id: I1365e57d56bf35bf07c3efc604482a5405608930
Reviewed-by: J-P Nurmi <[email protected]>
Diffstat (limited to 'src/plugins/styles/motif')
-rw-r--r-- | src/plugins/styles/motif/qmotifstyle.cpp | 47 | ||||
-rw-r--r-- | src/plugins/styles/motif/qmotifstyle.h | 2 |
2 files changed, 35 insertions, 14 deletions
diff --git a/src/plugins/styles/motif/qmotifstyle.cpp b/src/plugins/styles/motif/qmotifstyle.cpp index 7bc340d..508057d 100644 --- a/src/plugins/styles/motif/qmotifstyle.cpp +++ b/src/plugins/styles/motif/qmotifstyle.cpp @@ -114,7 +114,6 @@ QMotifStyle::QMotifStyle(bool useHighlightCols) : QCommonStyle(), focus(0), highlightCols(useHighlightCols), animationFps(25), animateTimer(0), animateStep(0), spinboxHCoeff(6) { - startTime.start(); } /*! @@ -136,26 +135,22 @@ bool QMotifStyle::eventFilter(QObject *o, QEvent *e) #ifndef QT_NO_PROGRESSBAR switch (e->type()) { case QEvent::StyleChange: + case QEvent::Paint: case QEvent::Show: if (QProgressBar *bar = qobject_cast<QProgressBar *>(o)) { - bars << bar; - if (bars.size() == 1) { - Q_ASSERT(animationFps> 0); - animateTimer = startTimer(1000 / animationFps); - } + // Animation by timer for progress bars that have their min and + // max values the same + if (bar->minimum() == bar->maximum()) + startProgressAnimation(bar); + else + stopProgressAnimation(bar); } break; case QEvent::Destroy: case QEvent::Hide: // reinterpret_cast because there is no type info when getting // the destroy event. We know that it is a QProgressBar. - if (QProgressBar *bar = reinterpret_cast<QProgressBar *>(o)) { - bars.removeAll(bar); - if (bars.isEmpty() && animateTimer) { - killTimer(animateTimer); - animateTimer = 0; - } - } + stopProgressAnimation(reinterpret_cast<QProgressBar *>(o)); default: break; } @@ -163,6 +158,30 @@ bool QMotifStyle::eventFilter(QObject *o, QEvent *e) return QStyle::eventFilter(o, e); } +void QMotifStyle::startProgressAnimation(QProgressBar *bar) +{ + if (!bars.contains(bar)) { + bars << bar; + if (bars.size() == 1) { + Q_ASSERT(animationFps > 0); + animateStep = 0; + startTime.start(); + animateTimer = startTimer(1000 / animationFps); + } + } +} + +void QMotifStyle::stopProgressAnimation(QProgressBar *bar) +{ + if (!bars.isEmpty()) { + bars.removeOne(bar); + if (bars.isEmpty() && animateTimer) { + killTimer(animateTimer); + animateTimer = 0; + } + } +} + /*! \reimp */ @@ -271,7 +290,7 @@ void QMotifStyle::unpolish(QWidget* widget) #ifndef QT_NO_PROGRESSBAR if (qobject_cast<QProgressBar *>(widget)) { widget->removeEventFilter(this); - bars.removeAll(static_cast<QProgressBar*>(widget)); + bars.removeOne(static_cast<QProgressBar*>(widget)); } #endif } diff --git a/src/plugins/styles/motif/qmotifstyle.h b/src/plugins/styles/motif/qmotifstyle.h index 4efabe0..96de559 100644 --- a/src/plugins/styles/motif/qmotifstyle.h +++ b/src/plugins/styles/motif/qmotifstyle.h @@ -106,6 +106,8 @@ protected: QPointer<QFocusFrame> focus; void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE; + void startProgressAnimation(QProgressBar *bar); + void stopProgressAnimation(QProgressBar *bar); private: bool highlightCols; |