summaryrefslogtreecommitdiffstats
path: root/examples/animation
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-09-03 15:33:31 +0200
committerThierry Bastian <thierry.bastian@nokia.com>2009-09-03 16:17:32 +0200
commit99929a28df4812c86b4aabc4d02490d9fac87e85 (patch)
tree3af64ee824ae1ca2a2b53496d2ec3e99de73597a /examples/animation
parent245c63c306be18442ee9fd1178e30bfb4aad7717 (diff)
fix warnings in stickman demo on mingw
We now also use the brand-new QGraphicsObject class We also make sure we have less memory leak or bad deallocation.
Diffstat (limited to 'examples/animation')
-rw-r--r--examples/animation/stickman/lifecycle.cpp4
-rw-r--r--examples/animation/stickman/main.cpp38
-rw-r--r--examples/animation/stickman/node.cpp4
-rw-r--r--examples/animation/stickman/node.h3
-rw-r--r--examples/animation/stickman/stickman.cpp5
-rw-r--r--examples/animation/stickman/stickman.h15
6 files changed, 32 insertions, 37 deletions
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 0fff529baa..463a27d585 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -100,7 +100,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
m_animationGroup = new QParallelAnimationGroup();
const int stickManNodeCount = m_stickMan->nodeCount();
for (int i=0; i<stickManNodeCount; ++i) {
- QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "position");
+ QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "pos");
m_animationGroup->addAnimation(pa);
}
@@ -186,7 +186,7 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
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));
+ frameState->assignProperty(m_stickMan->node(j), "pos", animation.nodePos(j));
//! [1]
frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
index 799f45cc85..f363d5d66c 100644
--- a/examples/animation/stickman/main.cpp
+++ b/examples/animation/stickman/main.cpp
@@ -73,30 +73,30 @@ int main(int argc, char **argv)
QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect();
textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0);
- QGraphicsScene *scene = new QGraphicsScene();
- scene->addItem(stickMan);
- scene->addItem(textItem);
- scene->setBackgroundBrush(Qt::black);
+ QGraphicsScene scene;
+ scene.addItem(stickMan);
+ scene.addItem(textItem);
+ scene.setBackgroundBrush(Qt::black);
- GraphicsView *view = new GraphicsView();
- view->setRenderHints(QPainter::Antialiasing);
- view->setTransformationAnchor(QGraphicsView::NoAnchor);
- view->setScene(scene);
- view->show();
- view->setFocus();
+ GraphicsView view;
+ view.setRenderHints(QPainter::Antialiasing);
+ view.setTransformationAnchor(QGraphicsView::NoAnchor);
+ view.setScene(&scene);
+ view.show();
+ view.setFocus();
- QRectF sceneRect = scene->sceneRect();
+ QRectF sceneRect = scene.sceneRect();
// making enough room in the scene for stickman to jump and die
- view->resize(sceneRect.width() + 100, sceneRect.height() + 100);
- view->setSceneRect(sceneRect);
+ view.resize(sceneRect.width() + 100, sceneRect.height() + 100);
+ view.setSceneRect(sceneRect);
- LifeCycle *cycle = new LifeCycle(stickMan, view);
- cycle->setDeathAnimation(":/animations/dead");
+ LifeCycle cycle(stickMan, &view);
+ cycle.setDeathAnimation(":/animations/dead");
- cycle->addActivity(":/animations/jumping", Qt::Key_J);
- cycle->addActivity(":/animations/dancing", Qt::Key_D);
- cycle->addActivity(":/animations/chilling", Qt::Key_C);
- cycle->start();
+ cycle.addActivity(":/animations/jumping", Qt::Key_J);
+ cycle.addActivity(":/animations/dancing", Qt::Key_D);
+ cycle.addActivity(":/animations/chilling", Qt::Key_C);
+ cycle.start();
return app.exec();
}
diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp
index 69ff90666f..1a138b2aaa 100644
--- a/examples/animation/stickman/node.cpp
+++ b/examples/animation/stickman/node.cpp
@@ -47,7 +47,7 @@
#include <QGraphicsSceneMouseEvent>
Node::Node(const QPointF &pos, QGraphicsItem *parent)
- : QGraphicsItem(parent), m_dragging(false)
+ : QGraphicsObject(parent), m_dragging(false)
{
setPos(pos);
setFlag(QGraphicsItem::ItemSendsGeometryChanges);
@@ -73,7 +73,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
if (change == QGraphicsItem::ItemPositionChange)
emit positionChanged();
- return QGraphicsItem::itemChange(change, value);
+ return QGraphicsObject::itemChange(change, value);
}
void Node::mousePressEvent(QGraphicsSceneMouseEvent *)
diff --git a/examples/animation/stickman/node.h b/examples/animation/stickman/node.h
index 66ee565f5c..4360d2eee9 100644
--- a/examples/animation/stickman/node.h
+++ b/examples/animation/stickman/node.h
@@ -44,10 +44,9 @@
#include <QGraphicsItem>
-class Node: public QObject, public QGraphicsItem
+class Node: public QGraphicsObject
{
Q_OBJECT
- Q_PROPERTY(QPointF position READ pos WRITE setPos)
public:
Node(const QPointF &pos, QGraphicsItem *parent = 0);
~Node();
diff --git a/examples/animation/stickman/stickman.cpp b/examples/animation/stickman/stickman.cpp
index 78e9e5b37f..67e022b9c8 100644
--- a/examples/animation/stickman/stickman.cpp
+++ b/examples/animation/stickman/stickman.cpp
@@ -52,7 +52,6 @@
#define M_PI 3.14159265358979323846
#endif
-static const int NodeCount = 16;
static const qreal Coords[NodeCount * 2] = {
0.0, -150.0, // head, #0
@@ -79,7 +78,6 @@ static const qreal Coords[NodeCount * 2] = {
};
-static const int BoneCount = 24;
static const int Bones[BoneCount * 2] = {
0, 1, // neck
@@ -116,7 +114,6 @@ static const int Bones[BoneCount * 2] = {
StickMan::StickMan()
{
- m_nodes = new Node*[NodeCount];
m_sticks = true;
m_isDead = false;
m_pixmap = QPixmap("images/head.png");
@@ -129,7 +126,6 @@ StickMan::StickMan()
connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged()));
}
- m_perfectBoneLengths = new qreal[BoneCount];
for (int i=0; i<BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -146,7 +142,6 @@ StickMan::StickMan()
StickMan::~StickMan()
{
- delete m_nodes;
}
void StickMan::childPositionChanged()
diff --git a/examples/animation/stickman/stickman.h b/examples/animation/stickman/stickman.h
index e8eedfa70e..d663c045b2 100644
--- a/examples/animation/stickman/stickman.h
+++ b/examples/animation/stickman/stickman.h
@@ -42,15 +42,15 @@
#ifndef STICKMAN_H
#define STICKMAN_H
-#include <QGraphicsItem>
+#include <QGraphicsObject>
-const int LimbCount = 16;
+static const int NodeCount = 16;
+static const int BoneCount = 24;
class Node;
QT_BEGIN_NAMESPACE
-class QTimer;
QT_END_NAMESPACE
-class StickMan: public QObject, public QGraphicsItem
+class StickMan: public QGraphicsObject
{
Q_OBJECT
Q_PROPERTY(QColor penColor WRITE setPenColor READ penColor)
@@ -77,7 +77,7 @@ public:
bool isDead() const { return m_isDead; }
void setIsDead(bool isDead) { m_isDead = isDead; }
-
+
public slots:
void stabilize();
void childPositionChanged();
@@ -86,10 +86,11 @@ protected:
void timerEvent(QTimerEvent *e);
private:
+
QPointF posFor(int idx) const;
- Node **m_nodes;
- qreal *m_perfectBoneLengths;
+ Node *m_nodes[NodeCount];
+ qreal m_perfectBoneLengths[BoneCount];
uint m_sticks : 1;
uint m_isDead : 1;