summaryrefslogtreecommitdiffstats
path: root/examples/animation/stickman
diff options
context:
space:
mode:
Diffstat (limited to 'examples/animation/stickman')
-rw-r--r--examples/animation/stickman/graphicsview.cpp5
-rw-r--r--examples/animation/stickman/graphicsview.h1
-rw-r--r--examples/animation/stickman/lifecycle.cpp6
-rw-r--r--examples/animation/stickman/lifecycle.h3
-rw-r--r--examples/animation/stickman/main.cpp34
-rw-r--r--examples/animation/stickman/rectbutton.cpp33
-rw-r--r--examples/animation/stickman/rectbutton.h25
-rw-r--r--examples/animation/stickman/stickman.desktop11
-rw-r--r--examples/animation/stickman/stickman.pro7
9 files changed, 118 insertions, 7 deletions
diff --git a/examples/animation/stickman/graphicsview.cpp b/examples/animation/stickman/graphicsview.cpp
index 23036efe92..0f7ce5f1c6 100644
--- a/examples/animation/stickman/graphicsview.cpp
+++ b/examples/animation/stickman/graphicsview.cpp
@@ -54,4 +54,7 @@ void GraphicsView::keyPressEvent(QKeyEvent *e)
emit keyPressed(Qt::Key(e->key()));
}
-
+void GraphicsView::resizeEvent(QResizeEvent *event)
+{
+ fitInView(scene()->sceneRect());
+}
diff --git a/examples/animation/stickman/graphicsview.h b/examples/animation/stickman/graphicsview.h
index 9cf87b63e6..400e4a63d4 100644
--- a/examples/animation/stickman/graphicsview.h
+++ b/examples/animation/stickman/graphicsview.h
@@ -51,6 +51,7 @@ public:
GraphicsView(QWidget *parent = 0);
protected:
+ virtual void resizeEvent(QResizeEvent *event);
void keyPressEvent(QKeyEvent *);
signals:
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 4abcdc22e5..8e9dbe1e8b 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -159,10 +159,14 @@ void LifeCycle::start()
m_machine->start();
}
-void LifeCycle::addActivity(const QString &fileName, Qt::Key key)
+void LifeCycle::addActivity(const QString &fileName, Qt::Key key, QObject *sender, const char *signal)
{
QState *state = makeState(m_alive, fileName);
m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
+
+ if((sender != NULL) || (signal != NULL)) {
+ m_alive->addTransition(sender, signal, state);
+ }
}
QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName)
diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
index 1bf3661f6c..ca1a052c39 100644
--- a/examples/animation/stickman/lifecycle.h
+++ b/examples/animation/stickman/lifecycle.h
@@ -50,6 +50,7 @@ class QAnimationGroup;
class QState;
class QAbstractState;
class QAbstractTransition;
+class QObject;
QT_END_NAMESPACE
class GraphicsView;
class LifeCycle
@@ -59,7 +60,7 @@ public:
~LifeCycle();
void setDeathAnimation(const QString &fileName);
- void addActivity(const QString &fileName, Qt::Key key);
+ void addActivity(const QString &fileName, Qt::Key key, QObject *sender = NULL, const char *signal = NULL);
void start();
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
index 08df766509..902e572a0e 100644
--- a/examples/animation/stickman/main.cpp
+++ b/examples/animation/stickman/main.cpp
@@ -43,6 +43,7 @@
#include "lifecycle.h"
#include "stickman.h"
#include "graphicsview.h"
+#include "rectbutton.h"
#include <QtCore>
#include <QtGui>
@@ -55,6 +56,11 @@ int main(int argc, char **argv)
StickMan *stickMan = new StickMan;
stickMan->setDrawSticks(false);
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
+ RectButton *buttonJump = new RectButton("Jump"); buttonJump->setPos(100, 125);
+ RectButton *buttonDance = new RectButton("Dance"); buttonDance->setPos(100, 200);
+ RectButton *buttonChill = new RectButton("Chill"); buttonChill->setPos(100, 275);
+#else
QGraphicsTextItem *textItem = new QGraphicsTextItem();
textItem->setHtml("<font color=\"white\"><b>Stickman</b>"
"<p>"
@@ -71,31 +77,55 @@ int main(int argc, char **argv)
qreal w = textItem->boundingRect().width();
QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect();
textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0);
+#endif
QGraphicsScene scene;
scene.addItem(stickMan);
+
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
+ scene.addItem(buttonJump);
+ scene.addItem(buttonDance);
+ scene.addItem(buttonChill);
+#else
scene.addItem(textItem);
+#endif
scene.setBackgroundBrush(Qt::black);
GraphicsView view;
view.setRenderHints(QPainter::Antialiasing);
view.setTransformationAnchor(QGraphicsView::NoAnchor);
view.setScene(&scene);
- view.show();
- view.setFocus();
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);
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
+ view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view.showMaximized();
+ view.fitInView(scene.sceneRect(), Qt::KeepAspectRatio);
+#else
+ view.show();
+ view.setFocus();
+#endif
+
LifeCycle cycle(stickMan, &view);
cycle.setDeathAnimation(":/animations/dead");
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
+ cycle.addActivity(":/animations/jumping", Qt::Key_J, buttonJump, SIGNAL(clicked()));
+ cycle.addActivity(":/animations/dancing", Qt::Key_D, buttonDance, SIGNAL(clicked()));
+ cycle.addActivity(":/animations/chilling", Qt::Key_C, buttonChill, SIGNAL(clicked()));
+#else
cycle.addActivity(":/animations/jumping", Qt::Key_J);
cycle.addActivity(":/animations/dancing", Qt::Key_D);
cycle.addActivity(":/animations/chilling", Qt::Key_C);
+#endif
+
cycle.start();
+
return app.exec();
}
diff --git a/examples/animation/stickman/rectbutton.cpp b/examples/animation/stickman/rectbutton.cpp
new file mode 100644
index 0000000000..f8b00daa9d
--- /dev/null
+++ b/examples/animation/stickman/rectbutton.cpp
@@ -0,0 +1,33 @@
+#include "rectbutton.h"
+#include <QPainter>
+
+RectButton::RectButton(QString buttonText) : m_ButtonText(buttonText)
+{
+}
+
+
+RectButton::~RectButton()
+{
+}
+
+
+void RectButton::mousePressEvent (QGraphicsSceneMouseEvent *event)
+{
+ emit clicked();
+}
+
+
+QRectF RectButton::boundingRect() const
+{
+ return QRectF(0.0, 0.0, 90.0, 40.0);
+}
+
+
+void RectButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ painter->setBrush(Qt::gray);
+ painter->drawRoundedRect(boundingRect(), 5, 5);
+
+ painter->setPen(Qt::white);
+ painter->drawText(20, 25, m_ButtonText);
+}
diff --git a/examples/animation/stickman/rectbutton.h b/examples/animation/stickman/rectbutton.h
new file mode 100644
index 0000000000..95ca2e2a21
--- /dev/null
+++ b/examples/animation/stickman/rectbutton.h
@@ -0,0 +1,25 @@
+#ifndef RECTBUTTON_H
+#define RECTBUTTON_H
+
+#include <QGraphicsObject>
+
+class RectButton : public QGraphicsObject
+{
+ Q_OBJECT
+public:
+ RectButton(QString buttonText);
+ ~RectButton();
+
+ virtual QRectF boundingRect() const;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+protected:
+ QString m_ButtonText;
+
+ virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
+
+signals:
+ void clicked();
+};
+
+#endif // RECTBUTTON_H
diff --git a/examples/animation/stickman/stickman.desktop b/examples/animation/stickman/stickman.desktop
new file mode 100644
index 0000000000..1722d4db3e
--- /dev/null
+++ b/examples/animation/stickman/stickman.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Stickman
+Exec=/opt/usr/bin/stickman
+Icon=stickman
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro
index 2fefe72c4f..206321dbc8 100644
--- a/examples/animation/stickman/stickman.pro
+++ b/examples/animation/stickman/stickman.pro
@@ -2,13 +2,15 @@ HEADERS += stickman.h \
animation.h \
node.h \
lifecycle.h \
- graphicsview.h
+ graphicsview.h \
+ rectbutton.h
SOURCES += main.cpp \
stickman.cpp \
animation.cpp \
node.cpp \
lifecycle.cpp \
- graphicsview.cpp
+ graphicsview.cpp \
+ rectbutton.cpp
RESOURCES += stickman.qrc
@@ -22,3 +24,4 @@ symbian {
TARGET.UID3 = 0xA000E3F9
CONFIG += qt_example
}
+maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)