summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2009-05-19 11:46:25 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2009-05-19 11:46:25 (GMT)
commit03e45a4dfb022e40d25bffad1f3b9e9a4121d4b5 (patch)
tree7c9adbb8c570cbcb78c1b8a1f0319a02cab4625d /examples
parent1c64881836a7003b20e0da97b95c94394c476525 (diff)
parenta903f9fb54f7192795abffca0a99b54d419bdb7a (diff)
downloadQt-03e45a4dfb022e40d25bffad1f3b9e9a4121d4b5.zip
Qt-03e45a4dfb022e40d25bffad1f3b9e9a4121d4b5.tar.gz
Qt-03e45a4dfb022e40d25bffad1f3b9e9a4121d4b5.tar.bz2
Merge branch 'kinetic-animations' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-animations
Diffstat (limited to 'examples')
-rw-r--r--examples/animation/stickman/lifecycle.cpp48
-rw-r--r--examples/animation/stickman/lifecycle.h2
2 files changed, 23 insertions, 27 deletions
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 423d7ad..1feb31d 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -82,6 +82,7 @@ private:
Qt::Key m_key;
};
+//! [4]
class LightningStrikesTransition: public QEventTransition
{
public:
@@ -97,6 +98,7 @@ public:
return QEventTransition::eventTest(e) && ((qrand() % 50) == 0);
}
};
+//! [4]
LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
: m_stickMan(stickMan), m_keyReceiver(keyReceiver)
@@ -110,7 +112,10 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
}
// Set up intial state graph
+//! [3]
m_machine = new QStateMachine();
+ m_machine->addDefaultAnimation(m_animationGroup);
+//! [3]
m_alive = new QState(m_machine->rootState());
m_alive->setObjectName("alive");
@@ -122,11 +127,13 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white);
lightningBlink->assignProperty(m_stickMan, "isDead", true);
+//! [5]
QTimer *timer = new QTimer(lightningBlink);
timer->setSingleShot(true);
timer->setInterval(100);
QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start()));
QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop()));
+//! [5]
m_dead = new QState(m_machine->rootState());
m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black);
@@ -142,8 +149,9 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Lightning strikes at random
m_alive->addTransition(new LightningStrikesTransition(lightningBlink));
- //m_alive->addTransition(new KeyPressTransition(m_keyReceiver, Qt::Key_L, lightningBlink));
- connectByAnimation(lightningBlink, m_dead, new QSignalTransition(timer, SIGNAL(timeout())));
+//! [0]
+ lightningBlink->addTransition(timer, SIGNAL(timeout()), m_dead);
+//! [0]
m_machine->setInitialState(m_alive);
}
@@ -159,22 +167,10 @@ void LifeCycle::start()
m_machine->start();
}
-void LifeCycle::connectByAnimation(QState *s1, QAbstractState *s2,
- QAbstractTransition *transition)
-{
- if (transition == 0) {
- transition = s1->addTransition(s2);
- } else {
- transition->setTargetState(s2);
- s1->addTransition(transition);
- }
- transition->addAnimation(m_animationGroup);
-}
-
void LifeCycle::addActivity(const QString &fileName, Qt::Key key)
{
QState *state = makeState(m_alive, fileName);
- connectByAnimation(m_alive, state, new KeyPressTransition(m_keyReceiver, key));
+ m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
}
QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName)
@@ -191,26 +187,28 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
const int frameCount = animation.totalFrames();
QState *previousState = 0;
for (int i=0; i<frameCount; ++i) {
- QState *frameState = new QState(topLevel);
- frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
-
animation.setCurrentFrame(i);
+
+//! [1]
+ QState *frameState = new QState(topLevel);
const int nodeCount = animation.nodeCount();
for (int j=0; j<nodeCount; ++j)
frameState->assignProperty(m_stickMan->node(j), "position", animation.nodePos(j));
+//! [1]
- if (previousState == 0) {
+ frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
+ if (previousState == 0)
topLevel->setInitialState(frameState);
- } else {
- connectByAnimation(previousState, frameState,
- new QSignalTransition(previousState, SIGNAL(polished())));
- }
+ else
+//! [2]
+ previousState->addTransition(previousState, SIGNAL(polished()), frameState);
+//! [2]
+
previousState = frameState;
}
// Loop
- connectByAnimation(previousState, topLevel->initialState(),
- new QSignalTransition(previousState, SIGNAL(polished())));
+ previousState->addTransition(previousState, SIGNAL(polished()), topLevel->initialState());
return topLevel;
diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
index e520402..8fd0fb2 100644
--- a/examples/animation/stickman/lifecycle.h
+++ b/examples/animation/stickman/lifecycle.h
@@ -63,8 +63,6 @@ public:
void start();
private:
- void connectByAnimation(QState *s1, QAbstractState *s2,
- QAbstractTransition *transition = 0);
QState *makeState(QState *parentState, const QString &animationFileName);
StickMan *m_stickMan;