summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2024-09-05 17:49:06 +0300
committerAhmad Samir <[email protected]>2024-10-03 23:03:32 +0300
commit50cdba38ad2bce0a78e5065efa1d82fb2d138527 (patch)
tree187cbe98d1e66cc13c97e494014f52837f2544b8 /examples
parent07593900dcf30ce5d70bb8b6e731e316578afbbe (diff)
CompositionWidget example: use QBasicTimer instead of raw timer IDs
Change-Id: I011645d915193c9ab1e3f001898c88fdd48e64a0 Reviewed-by: Thiago Macieira <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/painting/composition/composition.cpp22
-rw-r--r--examples/widgets/painting/composition/composition.h3
2 files changed, 13 insertions, 12 deletions
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 <QMouseEvent>
#include <qmath.h>
-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 <QBasicTimer>
#include <QPainter>
#include <QEvent>
@@ -137,7 +138,7 @@ private:
ObjectType m_current_object;
bool m_animation_enabled;
- int m_animationTimer;
+ QBasicTimer m_animationTimer;
};
#endif // COMPOSITION_H