From 4fffdabc948ff6afc6008d4cb723a6a2e10eef79 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 10 Nov 2011 11:36:04 +0100 Subject: Compile fix for Mac OS X 10.7 with 10.6 sdk Since it is an example it is cleaner to just include the header file as it will be available on other platforms anyway. Also ensured that the Qt includes were first before the system ones. Task-number: QTBUG-22641 Merge-request: 1462 Reviewed-by: Oswald Buddenhagen --- examples/opengl/cube/mainwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/opengl/cube/mainwidget.cpp b/examples/opengl/cube/mainwidget.cpp index 1116526..482c78e 100644 --- a/examples/opengl/cube/mainwidget.cpp +++ b/examples/opengl/cube/mainwidget.cpp @@ -46,10 +46,10 @@ #include #include +#include #include - -#include +#include MainWidget::MainWidget(QWidget *parent) : QGLWidget(parent), -- cgit v0.12 From 72e61b127470b044e370af7017fa8a5b0538244f Mon Sep 17 00:00:00 2001 From: Tero Ahola Date: Thu, 10 Nov 2011 16:24:14 +0100 Subject: Fix QProgressBar causing timer event spam On Windows you will get a lot of timer events if you use QProgressBar widget. This is because QWindowsStyle uses a timer to animate a progress bar with unknown state (min and max values both zero). The issue was fixed by starting the timer only if needed. Task-number: QTBUG-10501 Reviewed-by: Friedemann Kleint --- src/gui/styles/qwindowsstyle.cpp | 56 ++++++++++++++++++++++++---------------- src/gui/styles/qwindowsstyle_p.h | 4 ++- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp index 2244c11..6ab29b9 100644 --- a/src/gui/styles/qwindowsstyle.cpp +++ b/src/gui/styles/qwindowsstyle.cpp @@ -133,6 +133,26 @@ QWindowsStylePrivate::QWindowsStylePrivate() startTime.start(); } +void QWindowsStylePrivate::startAnimation(QObject *o, QProgressBar *bar) +{ + if (!animatedProgressBars.contains(bar)) { + animatedProgressBars << bar; + if (!animateTimer) { + Q_ASSERT(animationFps > 0); + animateTimer = o->startTimer(1000 / animationFps); + } + } +} + +void QWindowsStylePrivate::stopAnimation(QObject *o, QProgressBar *bar) +{ + animatedProgressBars.removeAll(bar); + if (animatedProgressBars.isEmpty() && animateTimer) { + o->killTimer(animateTimer); + animateTimer = 0; + } +} + // Returns true if the toplevel parent of \a widget has seen the Alt-key bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const { @@ -150,10 +170,8 @@ void QWindowsStyle::timerEvent(QTimerEvent *event) if (event->timerId() == d->animateTimer) { Q_ASSERT(d->animationFps> 0); d->animateStep = d->startTime.elapsed() / (1000 / d->animationFps); - foreach (QProgressBar *bar, d->bars) { - if ((bar->minimum() == 0 && bar->maximum() == 0)) - bar->update(); - } + foreach (QProgressBar *bar, d->animatedProgressBars) + bar->update(); } #endif // QT_NO_PROGRESSBAR event->ignore(); @@ -215,29 +233,23 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) break; #ifndef QT_NO_PROGRESSBAR case QEvent::StyleChange: + case QEvent::Paint: case QEvent::Show: if (QProgressBar *bar = qobject_cast(o)) { - if (!d->bars.contains(bar)) { - d->bars << bar; - if (d->bars.size() == 1) { - Q_ASSERT(d->animationFps> 0); - if (d->animateTimer == 0) - d->animateTimer = startTimer(1000 / d->animationFps); - } - } + // Animation by timer for progress bars that have their min and + // max values the same + if (bar->minimum() == bar->maximum()) + d->startAnimation(this, bar); + else + d->stopAnimation(this, 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(o)) { - d->bars.removeAll(bar); - if (d->bars.isEmpty() && d->animateTimer) { - killTimer(d->animateTimer); - d->animateTimer = 0; - } - } + // 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->stopAnimation(this, static_cast(o)); break; #endif // QT_NO_PROGRESSBAR default: @@ -343,7 +355,7 @@ void QWindowsStyle::unpolish(QWidget *widget) if (QProgressBar *bar=qobject_cast(widget)) { Q_D(QWindowsStyle); widget->removeEventFilter(this); - d->bars.removeAll(bar); + d->stopAnimation(this, bar); } #endif } diff --git a/src/gui/styles/qwindowsstyle_p.h b/src/gui/styles/qwindowsstyle_p.h index b9f39a0..1e517e9 100644 --- a/src/gui/styles/qwindowsstyle_p.h +++ b/src/gui/styles/qwindowsstyle_p.h @@ -71,13 +71,15 @@ class QWindowsStylePrivate : public QCommonStylePrivate Q_DECLARE_PUBLIC(QWindowsStyle) public: QWindowsStylePrivate(); + void startAnimation(QObject *o, QProgressBar *bar); + void stopAnimation(QObject *o, QProgressBar *bar); bool hasSeenAlt(const QWidget *widget) const; bool altDown() const { return alt_down; } bool alt_down; QList seenAlt; int menuBarTimer; - QList bars; + QList animatedProgressBars; int animationFps; int animateTimer; QElapsedTimer startTime; -- cgit v0.12 From b1998f4f59c3b10700963b2d13a17a0cc77ef665 Mon Sep 17 00:00:00 2001 From: Tero Ahola Date: Thu, 10 Nov 2011 16:40:47 +0100 Subject: Repaint QProgressBar when minimum or maximum changed The implementation of QProgressBar::setMinimum and setMaximum did not repaint the widget. This caused the widget to be shown incorrectly in case you call setMinimum or setMaximum but not setValue. Task-number: QTBUG-22121 Reviewed-by: Friedemann Kleint --- src/gui/widgets/qprogressbar.cpp | 14 +++++++--- tests/auto/qprogressbar/tst_qprogressbar.cpp | 39 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/gui/widgets/qprogressbar.cpp b/src/gui/widgets/qprogressbar.cpp index 1b0a1a1..c583a78 100644 --- a/src/gui/widgets/qprogressbar.cpp +++ b/src/gui/widgets/qprogressbar.cpp @@ -341,11 +341,17 @@ int QProgressBar::value() const void QProgressBar::setRange(int minimum, int maximum) { Q_D(QProgressBar); - d->minimum = minimum; - d->maximum = qMax(minimum, maximum); - if ( d->value <(d->minimum-1) || d->value > d->maximum) - reset(); + if (minimum != d->minimum || maximum != d->maximum) { + d->minimum = minimum; + d->maximum = qMax(minimum, maximum); + + if (d->value < (d->minimum - 1) || d->value > d->maximum) + reset(); + else + update(); + } } + /*! \property QProgressBar::textVisible \brief whether the current completed percentage should be displayed diff --git a/tests/auto/qprogressbar/tst_qprogressbar.cpp b/tests/auto/qprogressbar/tst_qprogressbar.cpp index 04b7ce7..878cce8 100644 --- a/tests/auto/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/qprogressbar/tst_qprogressbar.cpp @@ -63,6 +63,7 @@ private slots: void text(); void format(); void setValueRepaint(); + void setMinMaxRepaint(); void sizeHint(); void formatedText_data(); void formatedText(); @@ -216,6 +217,44 @@ void tst_QProgressBar::setValueRepaint() } } +void tst_QProgressBar::setMinMaxRepaint() +{ + ProgressBar pbar; + pbar.setMinimum(0); + pbar.setMaximum(10); + pbar.setFormat("%v"); + pbar.show(); + QTest::qWaitForWindowShown(&pbar); + + QApplication::processEvents(); + + // No repaint when setting minimum to the current minimum + pbar.repainted = false; + pbar.setMinimum(0); + QTest::qWait(50); + QTRY_VERIFY(!pbar.repainted); + + // No repaint when setting maximum to the current maximum + pbar.repainted = false; + pbar.setMaximum(10); + QTest::qWait(50); + QTRY_VERIFY(!pbar.repainted); + + // Repaint when setting minimum + for (int i = 9; i >= 0; i--) { + pbar.repainted = false; + pbar.setMinimum(i); + QTRY_VERIFY(pbar.repainted); + } + + // Repaint when setting maximum + for (int i = 0; i < 10; ++i) { + pbar.repainted = false; + pbar.setMaximum(i); + QTRY_VERIFY(pbar.repainted); + } +} + void tst_QProgressBar::sizeHint() { ProgressBar bar; -- cgit v0.12