summaryrefslogtreecommitdiffstats
path: root/demos/composition/composition.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-22 09:19:12 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-22 09:19:12 (GMT)
commitdab883be81f6037361e5c870d957686961515f4e (patch)
tree1aa67b8652108c74467da9e4bea411c15d85745c /demos/composition/composition.cpp
parentf25f7a2a19ba4c21b7a5d9fee02a9ae71c9f60ef (diff)
parent9462e7966b5b7db20249c9cb077f425c631afebf (diff)
downloadQt-dab883be81f6037361e5c870d957686961515f4e.zip
Qt-dab883be81f6037361e5c870d957686961515f4e.tar.gz
Qt-dab883be81f6037361e5c870d957686961515f4e.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/oslo-staging-2
Diffstat (limited to 'demos/composition/composition.cpp')
-rw-r--r--demos/composition/composition.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/demos/composition/composition.cpp b/demos/composition/composition.cpp
index e03f3e6..deca5dc 100644
--- a/demos/composition/composition.cpp
+++ b/demos/composition/composition.cpp
@@ -48,6 +48,8 @@
#include <QMouseEvent>
#include <qmath.h>
+const int animationInterval = 15; // update every 16 ms = ~60FPS
+
CompositionWidget::CompositionWidget(QWidget *parent)
: QWidget(parent)
{
@@ -236,6 +238,7 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
: ArthurFrame(parent)
{
m_animation_enabled = true;
+ m_animationTimer = startTimer(animationInterval);
#ifdef Q_WS_QWS
m_image = QPixmap(":res/composition/flower.jpg");
m_image.setAlphaChannel(QPixmap(":res/composition/flower_alpha.jpg"));
@@ -264,6 +267,20 @@ QRectF rectangle_around(const QPointF &p, const QSizeF &size = QSize(250, 200))
return rect;
}
+void CompositionRenderer::setAnimationEnabled(bool enabled)
+{
+ if (m_animation_enabled == enabled)
+ return;
+ m_animation_enabled = enabled;
+ if (enabled) {
+ Q_ASSERT(!m_animationTimer);
+ m_animationTimer = startTimer(animationInterval);
+ } else {
+ killTimer(m_animationTimer);
+ m_animationTimer = 0;
+ }
+}
+
void CompositionRenderer::updateCirclePos()
{
if (m_current_object != NoObject)
@@ -471,10 +488,6 @@ void CompositionRenderer::paint(QPainter *painter)
painter->drawImage(0, 0, m_buffer);
#endif
}
-
- if (m_animation_enabled && m_current_object == NoObject) {
- updateCirclePos();
- }
}
void CompositionRenderer::mousePressEvent(QMouseEvent *e)
@@ -489,6 +502,10 @@ void CompositionRenderer::mousePressEvent(QMouseEvent *e)
} else {
m_current_object = NoObject;
}
+ if (m_animation_enabled) {
+ killTimer(m_animationTimer);
+ m_animationTimer = 0;
+ }
}
void CompositionRenderer::mouseMoveEvent(QMouseEvent *e)
@@ -500,7 +517,15 @@ void CompositionRenderer::mouseReleaseEvent(QMouseEvent *)
{
m_current_object = NoObject;
- if (m_animation_enabled)
+ if (m_animation_enabled) {
+ Q_ASSERT(!m_animationTimer);
+ m_animationTimer = startTimer(animationInterval);
+ }
+}
+
+void CompositionRenderer::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == m_animationTimer)
updateCirclePos();
}