diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp index b4fb4fa3f74..4d561823679 100644 --- a/examples/widgets/painting/composition/composition.cpp +++ b/examples/widgets/painting/composition/composition.cpp @@ -10,7 +10,9 @@ #include #include -const int animationInterval = 15; // update every 16 ms = ~60FPS +using namespace std::chrono_literals; + +const auto animationInterval = 15ms; // update every 16 ms = ~60FPS CompositionWidget::CompositionWidget(QWidget *parent) : QWidget(parent) @@ -189,7 +191,7 @@ CompositionRenderer::CompositionRenderer(QWidget *parent) : ArthurFrame(parent) { m_animation_enabled = true; - m_animationTimer = startTimer(animationInterval); + m_animationTimer.start(animationInterval, this); m_image = QImage(":res/composition/flower.jpg"); m_image.setAlphaChannel(QImage(":res/composition/flower_alpha.jpg")); m_circle_alpha = 127; @@ -219,11 +221,10 @@ void CompositionRenderer::setAnimationEnabled(bool enabled) return; m_animation_enabled = enabled; if (enabled) { - Q_ASSERT(!m_animationTimer); - m_animationTimer = startTimer(animationInterval); + Q_ASSERT(!m_animationTimer.isActive()); + m_animationTimer.start(animationInterval, this); } else { - killTimer(m_animationTimer); - m_animationTimer = 0; + m_animationTimer.stop(); } } @@ -326,8 +327,7 @@ void CompositionRenderer::mousePressEvent(QMouseEvent *e) m_current_object = NoObject; } if (m_animation_enabled) { - killTimer(m_animationTimer); - m_animationTimer = 0; + m_animationTimer.stop(); } } @@ -342,14 +342,14 @@ void CompositionRenderer::mouseReleaseEvent(QMouseEvent *) m_current_object = NoObject; if (m_animation_enabled) { - Q_ASSERT(!m_animationTimer); - m_animationTimer = startTimer(animationInterval); + Q_ASSERT(!m_animationTimer.isActive()); + m_animationTimer.start(animationInterval, this); } } void CompositionRenderer::timerEvent(QTimerEvent *event) { - if (event->timerId() == m_animationTimer) + if (event->matches(m_animationTimer)) updateCirclePos(); } diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h index 6a5206da083..61c43632049 100644 --- a/examples/widgets/painting/composition/composition.h +++ b/examples/widgets/painting/composition/composition.h @@ -6,6 +6,7 @@ #include "arthurwidgets.h" +#include #include #include @@ -137,7 +138,7 @@ private: ObjectType m_current_object; bool m_animation_enabled; - int m_animationTimer; + QBasicTimer m_animationTimer; }; #endif // COMPOSITION_H