summaryrefslogtreecommitdiffstats
path: root/examples/animation/sub-attaq
diff options
context:
space:
mode:
Diffstat (limited to 'examples/animation/sub-attaq')
-rw-r--r--examples/animation/sub-attaq/boat.cpp7
-rw-r--r--examples/animation/sub-attaq/bomb.cpp12
-rw-r--r--examples/animation/sub-attaq/custompropertyanimation.cpp57
-rw-r--r--examples/animation/sub-attaq/custompropertyanimation.h3
-rw-r--r--examples/animation/sub-attaq/graphicsscene.cpp19
-rw-r--r--examples/animation/sub-attaq/qanimationstate.cpp175
-rw-r--r--examples/animation/sub-attaq/qanimationstate.h (renamed from examples/animation/sub-attaq/custompropertyanimation_p.h)56
-rw-r--r--examples/animation/sub-attaq/states.cpp6
-rw-r--r--examples/animation/sub-attaq/states.h4
-rw-r--r--examples/animation/sub-attaq/sub-attaq.pro8
-rw-r--r--examples/animation/sub-attaq/submarine.cpp11
-rw-r--r--examples/animation/sub-attaq/submarine_p.h18
-rw-r--r--examples/animation/sub-attaq/torpedo.cpp12
13 files changed, 296 insertions, 92 deletions
diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp
index 6824f17..633e1b1 100644
--- a/examples/animation/sub-attaq/boat.cpp
+++ b/examples/animation/sub-attaq/boat.cpp
@@ -47,6 +47,7 @@
#include "graphicsscene.h"
#include "animationmanager.h"
#include "custompropertyanimation.h"
+#include "qanimationstate.h"
//Qt
#if defined(QT_EXPERIMENTAL_SOLUTION)
@@ -56,7 +57,6 @@
# include "qfinalstate.h"
# include "qstate.h"
#include "qsequentialanimationgroup.h"
-#include "qanimationstate.h"
#else
#include <QPropertyAnimation>
#include <QStateMachine>
@@ -64,7 +64,6 @@
#include <QFinalState>
#include <QState>
#include <QSequentialAnimationGroup>
-#include <QAnimationState>
#endif
static QAbstractAnimation *setupDestroyAnimation(Boat *boat)
@@ -208,13 +207,13 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags)
//This state play the destroyed animation
QAnimationState *destroyedState = new QAnimationState(machine->rootState());
- destroyedState->addAnimation(setupDestroyAnimation(this));
+ destroyedState->setAnimation(setupDestroyAnimation(this));
//Play a nice animation when the boat is destroyed
moving->addTransition(this, SIGNAL(boatDestroyed()),destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addFinishedTransition(final);
+ destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
//The machine has finished to be executed, then the boat is dead
connect(machine,SIGNAL(finished()),this, SIGNAL(boatExecutionFinished()));
diff --git a/examples/animation/sub-attaq/bomb.cpp b/examples/animation/sub-attaq/bomb.cpp
index b6ae5a3..04310aa 100644
--- a/examples/animation/sub-attaq/bomb.cpp
+++ b/examples/animation/sub-attaq/bomb.cpp
@@ -44,19 +44,18 @@
#include "submarine.h"
#include "pixmapitem.h"
#include "animationmanager.h"
+#include "qanimationstate.h"
//Qt
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qpropertyanimation.h"
#include "qsequentialanimationgroup.h"
-#include "qanimationstate.h"
#include "qstatemachine.h"
#include "qfinalstate.h"
#else
#include <QtCore/QSequentialAnimationGroup>
#include <QtCore/QPropertyAnimation>
-#include <QtCore/QAnimationState>
#include <QtCore/QStateMachine>
#include <QtCore/QFinalState>
#endif
@@ -94,18 +93,19 @@ void Bomb::launch(Bomb::Direction direction)
QStateMachine *machine = new QStateMachine(this);
//This state is when the launch animation is playing
- QAnimationState *launched = new QAnimationState(launchAnimation,machine->rootState());
-
- machine->setInitialState(launched);
+ QAnimationState *launched = new QAnimationState(machine->rootState());
+ launched->setAnimation(launchAnimation);
//End
QFinalState *final = new QFinalState(machine->rootState());
+ machine->setInitialState(launched);
+
//### Add a nice animation when the bomb is destroyed
launched->addTransition(this, SIGNAL(bombExplosed()),final);
//If the animation is finished, then we move to the final state
- launched->addFinishedTransition(final);
+ launched->addTransition(launched, SIGNAL(animationFinished()), final);
//The machine has finished to be executed, then the boat is dead
connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished()));
diff --git a/examples/animation/sub-attaq/custompropertyanimation.cpp b/examples/animation/sub-attaq/custompropertyanimation.cpp
index 45997af..f7ab269 100644
--- a/examples/animation/sub-attaq/custompropertyanimation.cpp
+++ b/examples/animation/sub-attaq/custompropertyanimation.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "custompropertyanimation.h"
-#include "custompropertyanimation_p.h"
// Qt
#include <QtCore/qdebug.h>
@@ -48,23 +47,8 @@
QT_BEGIN_NAMESPACE
-void CustomPropertyAnimationPrivate::initDefaultStartValue()
-{
- if (!animProp)
- return;
- QVariant def = animProp->read();
- if (def.isValid())
- convertValues(def.userType());
- if (animProp && !defaultStartValue.isValid()
- && ((currentTime == 0 && (currentIteration || currentIteration == 0))
- || (currentTime == duration && currentIteration == (iterationCount - 1)))) {
- setDefaultStartValue(def);
- }
-}
-
-
CustomPropertyAnimation::CustomPropertyAnimation(QObject *parent) :
- QVariantAnimation(*new CustomPropertyAnimationPrivate, parent)
+ QVariantAnimation(parent), animProp(0)
{
}
@@ -72,13 +56,12 @@ CustomPropertyAnimation::~CustomPropertyAnimation()
{
}
-void CustomPropertyAnimation::setProperty(AbstractProperty *animProp)
+void CustomPropertyAnimation::setProperty(AbstractProperty *_animProp)
{
- Q_D(CustomPropertyAnimation);
- if (d->animProp == animProp)
+ if (animProp == _animProp)
return;
- delete d->animProp;
- d->animProp = animProp;
+ delete animProp;
+ animProp = _animProp;
}
/*!
@@ -86,11 +69,10 @@ void CustomPropertyAnimation::setProperty(AbstractProperty *animProp)
*/
void CustomPropertyAnimation::updateCurrentValue(const QVariant &value)
{
- Q_D(CustomPropertyAnimation);
- if (!d->animProp || state() == QAbstractAnimation::Stopped)
+ if (!animProp || state() == QAbstractAnimation::Stopped)
return;
- d->animProp->write(value);
+ animProp->write(value);
}
@@ -99,10 +81,29 @@ void CustomPropertyAnimation::updateCurrentValue(const QVariant &value)
*/
void CustomPropertyAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState)
{
- Q_D(CustomPropertyAnimation);
// Initialize start value
- if (oldState == QAbstractAnimation::Stopped)
- d->initDefaultStartValue();
+ if (oldState == QAbstractAnimation::Stopped) {
+ if (!animProp)
+ return;
+ QVariant def = animProp->read();
+ if (def.isValid()) {
+ const int t = def.userType();
+ KeyValues values = keyValues();
+ //this ensures that all the keyValues are of type t
+ for (int i = 0; i < values.count(); ++i) {
+ QVariantAnimation::KeyValue &pair = values[i];
+ if (pair.second.userType() != t)
+ pair.second.convert(static_cast<QVariant::Type>(t));
+ }
+ //let's now update the key values
+ setKeyValues(values);
+ }
+
+ if (animProp && !startValue().isValid() && currentTime() == 0
+ || (currentTime() == duration() && currentLoop() == (loopCount() - 1))) {
+ setStartValue(def);
+ }
+ }
QVariantAnimation::updateState(oldState, newState);
}
diff --git a/examples/animation/sub-attaq/custompropertyanimation.h b/examples/animation/sub-attaq/custompropertyanimation.h
index ba6ef55..48a50c9 100644
--- a/examples/animation/sub-attaq/custompropertyanimation.h
+++ b/examples/animation/sub-attaq/custompropertyanimation.h
@@ -49,7 +49,6 @@
#endif
class QGraphicsItem;
-class CustomPropertyAnimationPrivate;
struct AbstractProperty
{
@@ -111,7 +110,7 @@ public:
private:
Q_DISABLE_COPY(CustomPropertyAnimation);
- Q_DECLARE_PRIVATE(CustomPropertyAnimation);
+ AbstractProperty *animProp;
};
#endif // CUSTOMPROPERTYANIMATION_H
diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp
index a7f4c1b..5dcc034 100644
--- a/examples/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/animation/sub-attaq/graphicsscene.cpp
@@ -49,6 +49,7 @@
#include "pixmapitem.h"
#include "custompropertyanimation.h"
#include "animationmanager.h"
+#include "qanimationstate.h"
//Qt
#if defined(QT_EXPERIMENTAL_SOLUTION)
@@ -56,7 +57,6 @@
#include "qsequentialanimationgroup.h"
#include "qparallelanimationgroup.h"
#include "qstatemachine.h"
-#include "qanimationstate.h"
#include "qfinalstate.h"
#include "qpauseanimation.h"
#else
@@ -64,7 +64,6 @@
#include <QSequentialAnimationGroup>
#include <QParallelAnimationGroup>
#include <QStateMachine>
-#include <QAnimationState>
#include <QFinalState>
#include <QPauseAnimation>
#endif
@@ -236,18 +235,26 @@ void GraphicsScene::setupScene(const QList<QAction *> &actions)
QFinalState *final = new QFinalState(machine->rootState());
//Animation when the player enter in the game
- QAnimationState *animationState = new QAnimationState(lettersGroupMoving, machine->rootState());
- animationState->addAnimatedTransition(newAction, SIGNAL(triggered()),gameState,lettersGroupFading);
+ QAnimationState *lettersMovingState = new QAnimationState(machine->rootState());
+ lettersMovingState->setAnimation(lettersGroupMoving);
+
+ //Animation when the welcome screen disappear
+ QAnimationState *lettersFadingState = new QAnimationState(machine->rootState());
+ lettersFadingState->setAnimation(lettersGroupFading);
+
+ //if new game then we fade out the welcome screen and start playing
+ lettersMovingState->addTransition(newAction, SIGNAL(triggered()),lettersFadingState);
+ lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()),gameState);
//New Game is triggered then player start playing
gameState->addTransition(newAction, SIGNAL(triggered()),gameState);
//Wanna quit, then connect to CTRL+Q
gameState->addTransition(quitAction, SIGNAL(triggered()),final);
- animationState->addTransition(quitAction, SIGNAL(triggered()),final);
+ lettersMovingState->addTransition(quitAction, SIGNAL(triggered()),final);
//Welcome screen is the initial state
- machine->setInitialState(animationState);
+ machine->setInitialState(lettersMovingState);
machine->start();
diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp
new file mode 100644
index 0000000..70285a8
--- /dev/null
+++ b/examples/animation/sub-attaq/qanimationstate.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qanimationstate.h"
+
+#if defined(QT_EXPERIMENTAL_SOLUTION)
+# include "qstate.h"
+#else
+# include <QtCore/qstate.h>
+#endif
+
+#include <private/qstate_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+\class QAnimationState
+
+\brief The QAnimationState class provides state that handle an animation and emit
+a signal when this animation is finished.
+
+\ingroup statemachine
+
+QAnimationState provides a state that handle an animation. It will start this animation
+when the state is entered and stop it when it is leaved. When the animation has finished the
+state emit animationFinished signal.
+QAnimationState is part of \l{The State Machine Framework}.
+
+\code
+QStateMachine machine;
+QAnimationState *s = new QAnimationState(machine->rootState());
+QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
+s->setAnimation(animation);
+QState *s2 = new QState(machine->rootState());
+s->addTransition(s, SIGNAL(animationFinished()), s2);
+machine.start();
+\endcode
+
+\sa QState, {The Animation Framework}
+*/
+
+
+#ifndef QT_NO_ANIMATION
+
+class QAnimationStatePrivate : public QStatePrivate
+{
+ Q_DECLARE_PUBLIC(QAnimationState)
+public:
+ QAnimationStatePrivate()
+ : animation(0)
+ {
+
+ }
+ ~QAnimationStatePrivate() {}
+
+ QAbstractAnimation *animation;
+};
+
+/*!
+ Constructs a new state with the given \a parent state.
+*/
+QAnimationState::QAnimationState(QState *parent)
+ : QState(*new QAnimationStatePrivate, parent)
+{
+}
+
+/*!
+ Destroys the animation state.
+*/
+QAnimationState::~QAnimationState()
+{
+}
+
+/*!
+ Set an \a animation for this QAnimationState. If an animation was previously handle by this
+ state then it won't emit animationFinished for the old animation. The QAnimationState doesn't
+ take the ownership of the animation.
+*/
+void QAnimationState::setAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QAnimationState);
+
+ if (animation == d->animation)
+ return;
+
+ //Disconnect from the previous animation if exist
+ if(d->animation)
+ disconnect(d->animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
+
+ d->animation = animation;
+
+ if (d->animation) {
+ //connect the new animation
+ connect(d->animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
+ }
+}
+
+/*!
+ Returns the animation handle by this animation state, or 0 if there is no animation.
+*/
+QAbstractAnimation* QAnimationState::animation() const
+{
+ Q_D(const QAnimationState);
+ return d->animation;
+}
+
+/*!
+ \reimp
+*/
+void QAnimationState::onEntry()
+{
+ Q_D(QAnimationState);
+ if (d->animation)
+ d->animation->start();
+}
+
+/*!
+ \reimp
+*/
+void QAnimationState::onExit()
+{
+ Q_D(QAnimationState);
+ if (d->animation)
+ d->animation->stop();
+}
+
+/*!
+ \reimp
+*/
+bool QAnimationState::event(QEvent *e)
+{
+ return QState::event(e);
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/examples/animation/sub-attaq/custompropertyanimation_p.h b/examples/animation/sub-attaq/qanimationstate.h
index 89fc757..ddf5681 100644
--- a/examples/animation/sub-attaq/custompropertyanimation_p.h
+++ b/examples/animation/sub-attaq/qanimationstate.h
@@ -3,7 +3,7 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the QtCore module of the Qt Toolkit.
+** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
@@ -39,26 +39,54 @@
**
****************************************************************************/
-#ifndef CUSTOMPROPERTYANIMATION_P_H
-#define CUSTOMPROPERTYANIMATION_P_H
+#ifndef QANIMATIONSTATE_H
+#define QANIMATIONSTATE_H
-#ifdef QT_EXPERIMENTAL_SOLUTION
-# include "qvariantanimation_p.h"
+#ifndef QT_STATEMACHINE_SOLUTION
+# include <QtCore/qstate.h>
+# include <QtCore/qabstractanimation.h>
#else
-# include <private/qvariantanimation_p.h>
+# include "qstate.h"
+# include "qabstractanimation.h"
#endif
-class CustomPropertyAnimationPrivate : public QVariantAnimationPrivate
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_ANIMATION
+
+class QAnimationStatePrivate;
+
+class QAnimationState : public QState
{
- Q_DECLARE_PUBLIC(CustomPropertyAnimation)
+ Q_OBJECT
public:
- CustomPropertyAnimationPrivate() : QVariantAnimationPrivate(), animProp(0)
- {
- }
+ QAnimationState(QState *parent = 0);
+ ~QAnimationState();
+
+ void setAnimation(QAbstractAnimation *animation);
+ QAbstractAnimation* animation() const;
- void initDefaultStartValue();
+Q_SIGNALS:
+ void animationFinished();
- AbstractProperty *animProp;
+protected:
+ void onEntry();
+ void onExit();
+ bool event(QEvent *e);
+
+private:
+ Q_DISABLE_COPY(QAnimationState)
+ Q_DECLARE_PRIVATE(QAnimationState)
};
-#endif //QTCUSTOMPROPERTYANIMATION_P_H
+#endif
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QANIMATIONSTATE_H
diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp
index 32e0bb8..f476f55 100644
--- a/examples/animation/sub-attaq/states.cpp
+++ b/examples/animation/sub-attaq/states.cpp
@@ -131,7 +131,7 @@ void PlayState::onEntry()
playState->addTransition(scoreTransition);
//We go back to play state
- scoreState->addFinishedTransition(playState);
+ scoreState->addTransition(playState);
//We start playing!!!
machine->setInitialState(playState);
@@ -242,14 +242,14 @@ void WinState::onEntry()
}
/** UpdateScore State */
-UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QAnimationState(parent)
+UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(parent)
{
this->game = game;
}
void UpdateScoreState::onEntry()
{
//### Make a nice anim to update the score in the scene
- QAnimationState::onEntry();
+ QState::onEntry();
}
/** Win transition */
diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h
index 1001827..52d4ffa 100644
--- a/examples/animation/sub-attaq/states.h
+++ b/examples/animation/sub-attaq/states.h
@@ -46,12 +46,10 @@
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qstate.h"
#include "qsignaltransition.h"
-#include "qanimationstate.h"
#include "qpropertyanimation.h"
#else
#include <QState>
#include <QSignalTransition>
-#include <QAnimationState>
#include <QPropertyAnimation>
#endif
#include <QSet>
@@ -122,7 +120,7 @@ private :
PlayState *game;
};
-class UpdateScoreState : public QAnimationState
+class UpdateScoreState : public QState
{
public:
UpdateScoreState(PlayState *game, QState *parent);
diff --git a/examples/animation/sub-attaq/sub-attaq.pro b/examples/animation/sub-attaq/sub-attaq.pro
index d8de6f5..1456d0e 100644
--- a/examples/animation/sub-attaq/sub-attaq.pro
+++ b/examples/animation/sub-attaq/sub-attaq.pro
@@ -20,8 +20,8 @@ HEADERS += boat.h \
states.h \
boat_p.h \
submarine_p.h \
- custompropertyanimation_p.h \
- custompropertyanimation.h
+ custompropertyanimation.h \
+ qanimationstate.h
SOURCES += boat.cpp \
bomb.cpp \
main.cpp \
@@ -32,5 +32,7 @@ SOURCES += boat.cpp \
graphicsscene.cpp \
animationmanager.cpp \
states.cpp \
- custompropertyanimation.cpp
+ custompropertyanimation.cpp \
+ qanimationstate.cpp
+
RESOURCES += subattaq.qrc
diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp
index 481c748..e64ffdd 100644
--- a/examples/animation/sub-attaq/submarine.cpp
+++ b/examples/animation/sub-attaq/submarine.cpp
@@ -47,18 +47,17 @@
#include "graphicsscene.h"
#include "animationmanager.h"
#include "custompropertyanimation.h"
+#include "qanimationstate.h"
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qpropertyanimation.h"
#include "qstatemachine.h"
#include "qfinalstate.h"
-#include "qanimationstate.h"
#include "qsequentialanimationgroup.h"
#else
#include <QPropertyAnimation>
#include <QStateMachine>
#include <QFinalState>
-#include <QAnimationState>
#include <QSequentialAnimationGroup>
#endif
@@ -143,20 +142,20 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem *
QFinalState *final = new QFinalState(machine->rootState());
//If the moving animation is finished we move to the return state
- movement->addFinishedTransition(rotation);
+ movement->addTransition(movement, SIGNAL(animationFinished()), rotation);
//If the return animation is finished we move to the moving state
- rotation->addFinishedTransition(movement);
+ rotation->addTransition(rotation, SIGNAL(animationFinished()), movement);
//This state play the destroyed animation
QAnimationState *destroyedState = new QAnimationState(machine->rootState());
- destroyedState->addAnimation(setupDestroyAnimation(this));
+ destroyedState->setAnimation(setupDestroyAnimation(this));
//Play a nice animation when the submarine is destroyed
moving->addTransition(this, SIGNAL(subMarineDestroyed()),destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addFinishedTransition(final);
+ destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
//The machine has finished to be executed, then the submarine is dead
connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished()));
diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h
index 5aa84b6..354a406 100644
--- a/examples/animation/sub-attaq/submarine_p.h
+++ b/examples/animation/sub-attaq/submarine_p.h
@@ -45,18 +45,16 @@
//Own
#include "animationmanager.h"
#include "submarine.h"
+#include "qanimationstate.h"
//Qt
#if defined(QT_EXPERIMENTAL_SOLUTION)
-#include "qanimationstate.h"
#include "qpropertyanimation.h"
#else
-#include <QAnimationState>
#include <QPropertyAnimation>
#endif
#include <QGraphicsScene>
-
//This state is describing when the boat is moving right
class MovementState : public QAnimationState
{
@@ -66,16 +64,18 @@ public:
{
movementAnimation = new QPropertyAnimation(submarine, "pos");
connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &)));
- addAnimation(movementAnimation);
+ setAnimation(movementAnimation);
AnimationManager::self()->registerAnimation(movementAnimation);
this->submarine = submarine;
}
+
protected slots:
void onAnimationMovementValueChanged(const QVariant &)
{
if (qrand() % 200 + 1 == 3)
submarine->launchTorpedo(qrand() % 3 + 1);
}
+
protected:
void onEntry()
{
@@ -91,11 +91,6 @@ protected:
QAnimationState::onEntry();
}
- void onExit()
- {
- movementAnimation->stop();
- QAnimationState::onExit();
- }
private:
SubMarine *submarine;
QPropertyAnimation *movementAnimation;
@@ -109,9 +104,10 @@ public:
{
returnAnimation = new QPropertyAnimation(submarine, "yRotation");
AnimationManager::self()->registerAnimation(returnAnimation);
- addAnimation(returnAnimation);
+ setAnimation(returnAnimation);
this->submarine = submarine;
}
+
protected:
void onEntry()
{
@@ -124,10 +120,10 @@ protected:
void onExit()
{
- returnAnimation->stop();
submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right);
QAnimationState::onExit();
}
+
private:
SubMarine *submarine;
QPropertyAnimation *returnAnimation;
diff --git a/examples/animation/sub-attaq/torpedo.cpp b/examples/animation/sub-attaq/torpedo.cpp
index 4964192..b24948d 100644
--- a/examples/animation/sub-attaq/torpedo.cpp
+++ b/examples/animation/sub-attaq/torpedo.cpp
@@ -45,15 +45,14 @@
#include "boat.h"
#include "graphicsscene.h"
#include "animationmanager.h"
+#include "qanimationstate.h"
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qpropertyanimation.h"
#include "qstatemachine.h"
#include "qfinalstate.h"
-#include "qanimationstate.h"
#else
#include <QPropertyAnimation>
-#include <QAnimationState>
#include <QStateMachine>
#include <QFinalState>
#endif
@@ -81,18 +80,19 @@ void Torpedo::launch()
QStateMachine *machine = new QStateMachine(this);
//This state is when the launch animation is playing
- QAnimationState *launched = new QAnimationState(launchAnimation,machine->rootState());
-
- machine->setInitialState(launched);
+ QAnimationState *launched = new QAnimationState(machine->rootState());
+ launched->setAnimation(launchAnimation);
//End
QFinalState *final = new QFinalState(machine->rootState());
+ machine->setInitialState(launched);
+
//### Add a nice animation when the torpedo is destroyed
launched->addTransition(this, SIGNAL(torpedoExplosed()),final);
//If the animation is finished, then we move to the final state
- launched->addFinishedTransition(final);
+ launched->addTransition(launched, SIGNAL(animationFinished()), final);
//The machine has finished to be executed, then the boat is dead
connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished()));