summaryrefslogtreecommitdiffstats
path: root/demos/sub-attaq/bomb.cpp
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-10-05 09:49:54 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-10-05 09:51:38 (GMT)
commit32a9237c49fd126bee0cbe02c3c5bff5145a6e21 (patch)
tree6fc313f62e0eafeda35483c9f3630f4275a472ec /demos/sub-attaq/bomb.cpp
parent429c7c6760c100685e9800b89fca7f0afd2d8abc (diff)
downloadQt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.zip
Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.tar.gz
Qt-32a9237c49fd126bee0cbe02c3c5bff5145a6e21.tar.bz2
Simplification and use of QGraphicsObject in sub-attas demo
Reviewed-by: alexis
Diffstat (limited to 'demos/sub-attaq/bomb.cpp')
-rw-r--r--demos/sub-attaq/bomb.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/demos/sub-attaq/bomb.cpp b/demos/sub-attaq/bomb.cpp
index d17024f..acc3475 100644
--- a/demos/sub-attaq/bomb.cpp
+++ b/demos/sub-attaq/bomb.cpp
@@ -52,19 +52,14 @@
#include <QtCore/QStateMachine>
#include <QtCore/QFinalState>
-Bomb::Bomb(QGraphicsItem * parent, Qt::WindowFlags wFlags)
- : QGraphicsWidget(parent,wFlags), launchAnimation(0)
+Bomb::Bomb() : PixmapItem(QString("bomb"), GraphicsScene::Big)
{
- pixmapItem = new PixmapItem(QString("bomb"),GraphicsScene::Big, this);
- setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- setFlags(QGraphicsItem::ItemIsMovable);
setZValue(2);
- resize(pixmapItem->boundingRect().size());
}
void Bomb::launch(Bomb::Direction direction)
{
- launchAnimation = new QSequentialAnimationGroup();
+ QSequentialAnimationGroup *launchAnimation = new QSequentialAnimationGroup;
AnimationManager::self()->registerAnimation(launchAnimation);
qreal delta = direction == Right ? 20 : - 20;
QPropertyAnimation *anim = new QPropertyAnimation(this, "pos");
@@ -80,7 +75,7 @@ void Bomb::launch(Bomb::Direction direction)
anim->setDuration(y()/2*60);
launchAnimation->addAnimation(anim);
connect(anim,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &)));
-
+ connect(this, SIGNAL(bombExploded()), launchAnimation, SLOT(stop()));
//We setup the state machine of the bomb
QStateMachine *machine = new QStateMachine(this);
@@ -94,7 +89,7 @@ void Bomb::launch(Bomb::Direction direction)
machine->setInitialState(launched);
//### Add a nice animation when the bomb is destroyed
- launched->addTransition(this, SIGNAL(bombExplosed()),final);
+ launched->addTransition(this, SIGNAL(bombExploded()),final);
//If the animation is finished, then we move to the final state
launched->addTransition(launched, SIGNAL(animationFinished()), final);
@@ -119,6 +114,5 @@ void Bomb::onAnimationLaunchValueChanged(const QVariant &)
void Bomb::destroy()
{
- launchAnimation->stop();
- emit bombExplosed();
+ emit bombExploded();
}