summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles/plastique
diff options
context:
space:
mode:
authorBłażej Szczygieł <[email protected]>2017-01-11 21:45:27 +0100
committerBłażej Szczygieł <[email protected]>2017-03-11 09:23:02 +0000
commit335dbece103e2cbf6c7cf819ab6672c2956b17b3 (patch)
treef6ecc6a247235c3dae0d607694356496dcf5d767 /src/plugins/styles/plastique
parent5ef7b26b9792b5aae4d289413a3a0691766b072e (diff)
Fix plastique, cleanlooks and motif animation timerHEADmaster
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/plastique')
-rw-r--r--src/plugins/styles/plastique/qplastiquestyle.cpp75
-rw-r--r--src/plugins/styles/plastique/qplastiquestyle.h4
2 files changed, 55 insertions, 24 deletions
diff --git a/src/plugins/styles/plastique/qplastiquestyle.cpp b/src/plugins/styles/plastique/qplastiquestyle.cpp
index fbcf766..f76042f 100644
--- a/src/plugins/styles/plastique/qplastiquestyle.cpp
+++ b/src/plugins/styles/plastique/qplastiquestyle.cpp
@@ -5657,7 +5657,7 @@ void QPlastiqueStyle::unpolish(QWidget *widget)
#ifndef QT_NO_PROGRESSBAR
if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget)) {
widget->removeEventFilter(this);
- bars.removeAll(static_cast<QProgressBar*>(widget));
+ bars.removeOne(static_cast<QProgressBar*>(widget));
}
#endif
@@ -5779,25 +5779,21 @@ bool QPlastiqueStyle::eventFilter(QObject *watched, QEvent *event)
{
#ifndef QT_NO_PROGRESSBAR
switch (event->type()) {
+ case QEvent::StyleChange:
+ case QEvent::Paint:
case QEvent::Show:
if (QProgressBar *bar = qobject_cast<QProgressBar *>(watched)) {
- bars.append(bar);
- if (bars.size() == 1) {
- Q_ASSERT(ProgressBarFps > 0);
- timer.start();
- progressBarAnimateTimer = startTimer(1000 / ProgressBarFps);
- }
+ // 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:
- if (!bars.isEmpty()) {
- bars.removeAll(reinterpret_cast<QProgressBar*>(watched));
- if (bars.isEmpty()) {
- killTimer(progressBarAnimateTimer);
- progressBarAnimateTimer = 0;
- }
- }
+ stopProgressAnimation(reinterpret_cast<QProgressBar *>(watched));
break;
#if defined QPlastique_MaskButtons
case QEvent::Resize:
@@ -5828,19 +5824,52 @@ bool QPlastiqueStyle::eventFilter(QObject *watched, QEvent *event)
/*!
\reimp
*/
-void QPlastiqueStyle::timerEvent(QTimerEvent *event)
+bool QPlastiqueStyle::event(QEvent *event)
{
+ switch (event->type()) {
+ case QEvent::Timer: {
#ifndef QT_NO_PROGRESSBAR
- if (event->timerId() == progressBarAnimateTimer) {
- Q_ASSERT(ProgressBarFps > 0);
- animateStep = timer.elapsed() / (1000 / ProgressBarFps);
- foreach (QProgressBar *bar, bars) {
- if (AnimateProgressBar || (bar->minimum() == 0 && bar->maximum() == 0))
- bar->update();
+ QTimerEvent *timerEvent = reinterpret_cast<QTimerEvent *>(event);
+ if (timerEvent->timerId() == progressBarAnimateTimer) {
+ Q_ASSERT(ProgressBarFps > 0);
+ animateStep = timer.elapsed() / (1000 / ProgressBarFps);
+ foreach (QProgressBar *bar, bars) {
+ if (AnimateProgressBar || (bar->minimum() == 0 && bar->maximum() == 0))
+ bar->update();
+ }
}
- }
#endif // QT_NO_PROGRESSBAR
- event->ignore();
+ event->ignore();
+ }
+ default:
+ break;
+ }
+
+ return QProxyStyle::event(event);
+}
+
+void QPlastiqueStyle::startProgressAnimation(QProgressBar *bar)
+{
+ if (!bars.contains(bar)) {
+ bars << bar;
+ if (bars.size() == 1) {
+ Q_ASSERT(ProgressBarFps > 0);
+ animateStep = 0;
+ timer.start();
+ progressBarAnimateTimer = startTimer(1000 / ProgressBarFps);
+ }
+ }
+}
+
+void QPlastiqueStyle::stopProgressAnimation(QProgressBar *bar)
+{
+ if (!bars.isEmpty()) {
+ bars.removeOne(bar);
+ if (bars.isEmpty() && progressBarAnimateTimer) {
+ killTimer(progressBarAnimateTimer);
+ progressBarAnimateTimer = 0;
+ }
+ }
}
QT_END_NAMESPACE
diff --git a/src/plugins/styles/plastique/qplastiquestyle.h b/src/plugins/styles/plastique/qplastiquestyle.h
index 4ed6a4e..b2d2d5d 100644
--- a/src/plugins/styles/plastique/qplastiquestyle.h
+++ b/src/plugins/styles/plastique/qplastiquestyle.h
@@ -100,7 +100,9 @@ public:
protected:
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
- void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
+ void startProgressAnimation(QProgressBar *bar);
+ void stopProgressAnimation(QProgressBar *bar);
private:
int animateStep;