summaryrefslogtreecommitdiffstats
path: root/demos/sub-attaq
diff options
context:
space:
mode:
Diffstat (limited to 'demos/sub-attaq')
-rw-r--r--demos/sub-attaq/submarine.cpp11
-rw-r--r--demos/sub-attaq/submarine.h4
-rw-r--r--demos/sub-attaq/submarine_p.h4
3 files changed, 15 insertions, 4 deletions
diff --git a/demos/sub-attaq/submarine.cpp b/demos/sub-attaq/submarine.cpp
index 78a9539..029e04b 100644
--- a/demos/sub-attaq/submarine.cpp
+++ b/demos/sub-attaq/submarine.cpp
@@ -109,7 +109,14 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem *
setZValue(5);
setFlags(QGraphicsItem::ItemIsMovable);
resize(pixmapItem->boundingRect().width(),pixmapItem->boundingRect().height());
- setTransformOrigin(boundingRect().center());
+ setTransformOriginPoint(boundingRect().center());
+
+ graphicsRotation = new QGraphicsRotation3D(this);
+ graphicsRotation->setAxis(QVector3D(0, 1, 0));
+ graphicsRotation->setOrigin(QPointF(size().width()/2, size().height()/2));
+ QList<QGraphicsTransform *> r;
+ r.append(graphicsRotation);
+ setTransformations(r);
//We setup the state machine of the submarine
QStateMachine *machine = new QStateMachine(this);
@@ -166,7 +173,7 @@ void SubMarine::setCurrentDirection(SubMarine::Movement direction)
if (this->direction == direction)
return;
if (direction == SubMarine::Right && this->direction == SubMarine::None) {
- setYRotation(180);
+ graphicsRotation->setAngle(180);
}
this->direction = direction;
}
diff --git a/demos/sub-attaq/submarine.h b/demos/sub-attaq/submarine.h
index 481e816..564e9c6 100644
--- a/demos/sub-attaq/submarine.h
+++ b/demos/sub-attaq/submarine.h
@@ -45,6 +45,7 @@
//Qt
#include <QtCore/QVariantAnimation>
#include <QtGui/QGraphicsWidget>
+#include <QtGui/QGraphicsTransform>
class PixmapItem;
@@ -75,6 +76,8 @@ public:
virtual int type() const;
+ QGraphicsRotation3D *rotation3d() const { return graphicsRotation; }
+
signals:
void subMarineDestroyed();
void subMarineExecutionFinished();
@@ -87,6 +90,7 @@ private:
int speed;
Movement direction;
PixmapItem *pixmapItem;
+ QGraphicsRotation3D *graphicsRotation;
};
#endif //__SUBMARINE__H__
diff --git a/demos/sub-attaq/submarine_p.h b/demos/sub-attaq/submarine_p.h
index e8df877..c04b25b 100644
--- a/demos/sub-attaq/submarine_p.h
+++ b/demos/sub-attaq/submarine_p.h
@@ -109,7 +109,7 @@ class ReturnState : public QAnimationState
public:
ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
{
- returnAnimation = new QPropertyAnimation(submarine, "yRotation");
+ returnAnimation = new QPropertyAnimation(submarine->rotation3d(), "angle");
AnimationManager::self()->registerAnimation(returnAnimation);
setAnimation(returnAnimation);
this->submarine = submarine;
@@ -119,7 +119,7 @@ protected:
void onEntry(QEvent *e)
{
returnAnimation->stop();
- returnAnimation->setStartValue(submarine->yRotation());
+ returnAnimation->setStartValue(submarine->rotation3d()->angle());
returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.);
returnAnimation->setDuration(500);
QAnimationState::onEntry(e);