summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-04-22 04:52:44 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-04-22 04:52:44 (GMT)
commitf2c5ea07b2ed5f96bd32f9a1d71ec9613c240fa6 (patch)
tree390ae15f24cd5b6af85b9bc74c39fd90ba03144b /examples
parent1139eb432a18d556efb4ecfc079e82c2e2093b96 (diff)
parent3f39c3380f97339a1ffb9d13d7b184a8315d3821 (diff)
downloadQt-f2c5ea07b2ed5f96bd32f9a1d71ec9613c240fa6.zip
Qt-f2c5ea07b2ed5f96bd32f9a1d71ec9613c240fa6.tar.gz
Qt-f2c5ea07b2ed5f96bd32f9a1d71ec9613c240fa6.tar.bz2
Merge branch 'kinetic-animations' of ../../qt/kinetic into kinetic-declarativeui
Conflicts: src/gui/graphicsview/qgraphicsitem.cpp
Diffstat (limited to 'examples')
-rw-r--r--examples/animation/animatedtiles/main.cpp29
-rw-r--r--examples/animation/appchooser/main.cpp23
-rw-r--r--examples/animation/easing/window.cpp2
-rw-r--r--examples/animation/example/mainwindow.cpp70
-rw-r--r--examples/animation/moveblocks/main.cpp15
-rw-r--r--examples/animation/research/memberfunctions/qvalueanimation.cpp4
-rw-r--r--examples/animation/states/main.cpp127
-rw-r--r--examples/animation/stickman/editor/animationdialog.cpp151
-rw-r--r--examples/animation/stickman/editor/animationdialog.h41
-rw-r--r--examples/animation/stickman/editor/editor.pri2
-rw-r--r--examples/animation/stickman/editor/mainwindow.cpp35
-rw-r--r--examples/animation/stickman/editor/mainwindow.h17
-rw-r--r--examples/animation/stickman/graphicsview.cpp27
-rw-r--r--examples/animation/stickman/graphicsview.h4
-rw-r--r--examples/animation/stickman/lifecycle.cpp72
-rw-r--r--examples/animation/stickman/lifecycle.h2
-rw-r--r--examples/animation/stickman/main.cpp2
-rw-r--r--examples/animation/stickman/node.cpp9
-rw-r--r--examples/animation/stickman/node.h5
-rw-r--r--examples/animation/stickman/stickman.cpp37
-rw-r--r--examples/animation/stickman/stickman.h1
-rw-r--r--examples/animation/stickman/stickman.pro2
-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
-rw-r--r--examples/statemachine/citizenquartz/citizenquartz.qrc1
-rw-r--r--examples/statemachine/citizenquartz/clock.cpp44
-rw-r--r--examples/statemachine/citizenquartz/clock.h4
-rw-r--r--examples/statemachine/citizenquartz/clockdisplay.cpp3
-rw-r--r--examples/statemachine/citizenquartz/clockdisplay.h16
-rw-r--r--examples/statemachine/citizenquartz/propertyaddstate.cpp2
-rw-r--r--examples/statemachine/citizenquartz/propertyaddstate.h2
-rw-r--r--examples/statemachine/citizenquartz/timeperiod.h2
-rw-r--r--examples/statemachine/clockticking/main.cpp36
-rw-r--r--examples/statemachine/composition/main.cpp42
-rw-r--r--examples/statemachine/eventtransitions/main.cpp40
-rw-r--r--examples/statemachine/factorial/main.cpp36
-rw-r--r--examples/statemachine/helloworld/main.cpp34
-rw-r--r--examples/statemachine/pauseandresume/main.cpp34
-rw-r--r--examples/statemachine/pingpong/main.cpp36
-rw-r--r--examples/statemachine/trafficlight/main.cpp42
-rw-r--r--examples/statemachine/twowaybutton/main.cpp38
52 files changed, 1151 insertions, 326 deletions
diff --git a/examples/animation/animatedtiles/main.cpp b/examples/animation/animatedtiles/main.cpp
index e4a774c..cfaa4ce 100644
--- a/examples/animation/animatedtiles/main.cpp
+++ b/examples/animation/animatedtiles/main.cpp
@@ -3,6 +3,7 @@
# include "qgraphicswidget.h"
# include "qstate.h"
# include "qstatemachine.h"
+# include "qabstracttransition.h"
# include "qgraphicswidget.h"
# include "qparallelanimationgroup.h"
# include "qpropertyanimation.h"
@@ -147,27 +148,27 @@ int main(int argc, char **argv)
for (int i = 0; i < 64; ++i) {
Pixmap *item = items.at(i);
// Ellipse
- ellipseState->setPropertyOnEntry(item, "pos",
+ ellipseState->assignProperty(item, "pos",
QPointF(cos((i / 63.0) * 6.28) * 250,
sin((i / 63.0) * 6.28) * 250));
// Figure 8
- figure8State->setPropertyOnEntry(item, "pos",
+ figure8State->assignProperty(item, "pos",
QPointF(sin((i / 63.0) * 6.28) * 250,
sin(((i * 2)/63.0) * 6.28) * 250));
// Random
- randomState->setPropertyOnEntry(item, "pos",
+ randomState->assignProperty(item, "pos",
QPointF(-250 + qrand() % 500,
-250 + qrand() % 500));
// Tiled
- tiledState->setPropertyOnEntry(item, "pos",
+ tiledState->assignProperty(item, "pos",
QPointF(((i % 8) - 4) * kineticPix.width() + kineticPix.width() / 2,
((i / 8) - 4) * kineticPix.height() + kineticPix.height() / 2));
// Centered
- centeredState->setPropertyOnEntry(item, "pos", QPointF());
+ centeredState->assignProperty(item, "pos", QPointF());
}
// Ui
@@ -184,7 +185,6 @@ int main(int argc, char **argv)
states.setInitialState(rootState);
rootState->setInitialState(centeredState);
- // rootState->addTransition(ellipseButton, SIGNAL(pressed()), ellipseState);
QParallelAnimationGroup *group = new QParallelAnimationGroup;
for (int i = 0; i < 64; ++i) {
QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos");
@@ -192,7 +192,8 @@ int main(int argc, char **argv)
anim->setEasingCurve(QEasingCurve::InOutBack);
group->addAnimation(anim);
}
- rootState->addAnimatedTransition(ellipseButton, SIGNAL(pressed()), ellipseState, group);
+ QAbstractTransition *trans = rootState->addTransition(ellipseButton, SIGNAL(pressed()), ellipseState);
+ trans->addAnimation(group);
group = new QParallelAnimationGroup;
for (int i = 0; i < 64; ++i) {
@@ -201,7 +202,8 @@ int main(int argc, char **argv)
anim->setEasingCurve(QEasingCurve::InOutBack);
group->addAnimation(anim);
}
- rootState->addAnimatedTransition(figure8Button, SIGNAL(pressed()), figure8State, group);
+ trans = rootState->addTransition(figure8Button, SIGNAL(pressed()), figure8State);
+ trans->addAnimation(group);
group = new QParallelAnimationGroup;
for (int i = 0; i < 64; ++i) {
@@ -210,7 +212,8 @@ int main(int argc, char **argv)
anim->setEasingCurve(QEasingCurve::InOutBack);
group->addAnimation(anim);
}
- rootState->addAnimatedTransition(randomButton, SIGNAL(pressed()), randomState, group);
+ trans = rootState->addTransition(randomButton, SIGNAL(pressed()), randomState);
+ trans->addAnimation(group);
group = new QParallelAnimationGroup;
for (int i = 0; i < 64; ++i) {
@@ -219,7 +222,8 @@ int main(int argc, char **argv)
anim->setEasingCurve(QEasingCurve::InOutBack);
group->addAnimation(anim);
}
- rootState->addAnimatedTransition(tiledButton, SIGNAL(pressed()), tiledState, group);
+ trans = rootState->addTransition(tiledButton, SIGNAL(pressed()), tiledState);
+ trans->addAnimation(group);
group = new QParallelAnimationGroup;
for (int i = 0; i < 64; ++i) {
@@ -228,13 +232,14 @@ int main(int argc, char **argv)
anim->setEasingCurve(QEasingCurve::InOutBack);
group->addAnimation(anim);
}
- rootState->addAnimatedTransition(centeredButton, SIGNAL(pressed()), centeredState, group);
+ trans = rootState->addTransition(centeredButton, SIGNAL(pressed()), centeredState);
+ trans->addAnimation(group);
states.start();
QTimer timer;
timer.start(125);
timer.setSingleShot(true);
- rootState->addAnimatedTransition(&timer, SIGNAL(timeout()), ellipseState, group);
+ rootState->addTransition(&timer, SIGNAL(timeout()), ellipseState);
return app.exec();
}
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp
index 536bbb6..1a43ed7 100644
--- a/examples/animation/appchooser/main.cpp
+++ b/examples/animation/appchooser/main.cpp
@@ -54,13 +54,19 @@ private:
QPixmap p;
};
-void createStateAndTransition(QObject *o1, const QRect &selectedRect, QState *parent)
+void createStates(const QObjectList &objects,
+ const QRect &selectedRect, QState *parent)
{
- QState *state = new QState(parent);
- state->setPropertyOnEntry(o1, "geometry", selectedRect);
-
- QPropertyAnimation *animation = new QPropertyAnimation(o1, "geometry");
- parent->addAnimatedTransition(o1, SIGNAL(clicked()), state, animation);
+ for (int i = 0; i < objects.size(); ++i) {
+ QState *state = new QState(parent);
+ state->assignProperty(objects.at(i), "geometry", selectedRect);
+ QAbstractTransition *trans = parent->addTransition(objects.at(i), SIGNAL(clicked()), state);
+ for (int j = 0; j < objects.size(); ++j) {
+ QPropertyAnimation *animation = new QPropertyAnimation(objects.at(j), "geometry");
+ animation->setDuration(2000);
+ trans->addAnimation(animation);
+ }
+ }
}
int main(int argc, char **argv)
@@ -107,10 +113,7 @@ int main(int argc, char **argv)
QState *idleState = new QState(group);
group->setInitialState(idleState);
- createStateAndTransition(p1, selectedRect, group);
- createStateAndTransition(p2, selectedRect, group);
- createStateAndTransition(p3, selectedRect, group);
- createStateAndTransition(p4, selectedRect, group);
+ createStates(QObjectList() << p1 << p2 << p3 << p4, selectedRect, group);
machine.setInitialState(group);
machine.start();
diff --git a/examples/animation/easing/window.cpp b/examples/animation/easing/window.cpp
index c6ea360..bb45770 100644
--- a/examples/animation/easing/window.cpp
+++ b/examples/animation/easing/window.cpp
@@ -88,7 +88,7 @@ void Window::startAnimation()
m_anim->setStartValue(QPointF(0, 0));
m_anim->setEndValue(QPointF(100, 100));
m_anim->setDuration(2000);
- m_anim->setIterationCount(-1); // forever
+ m_anim->setLoopCount(-1); // forever
m_anim->start();
}
diff --git a/examples/animation/example/mainwindow.cpp b/examples/animation/example/mainwindow.cpp
index dfb5c70..2b0e035 100644
--- a/examples/animation/example/mainwindow.cpp
+++ b/examples/animation/example/mainwindow.cpp
@@ -94,50 +94,50 @@ MainWindow::MainWindow() : QMainWindow(0)
machine->setInitialState(group);
// State 1
- state1->setPropertyOnEntry(button, "text", "Edit");
- state1->setPropertyOnEntry(button2, "text", "Add");
- state1->setPropertyOnEntry(button3, "text", "Remove");
- state1->setPropertyOnEntry(button4, "text", "Accept");
+ state1->assignProperty(button, "text", "Edit");
+ state1->assignProperty(button2, "text", "Add");
+ state1->assignProperty(button3, "text", "Remove");
+ state1->assignProperty(button4, "text", "Accept");
state1->addTransition(button2, SIGNAL(clicked()), state3);
- state1->setPropertyOnEntry(listProxy, "geometry", QRectF(0, 0, 700, 560));
- state1->setPropertyOnEntry(widget, "geometry", QRectF(0, 0, 700, 600));
- state1->setPropertyOnEntry(editProxy, "opacity", double(0));
- state1->setPropertyOnEntry(labelProxy, "opacity", double(0));
- state1->setPropertyOnEntry(label2Proxy, "opacity", double(0));
- state1->setPropertyOnEntry(buttonProxy4, "opacity", double(0));
- state1->setPropertyOnEntry(labelWidget, "text", "Name : ");
- state1->setPropertyOnEntry(label2Widget, "text", "Edit a contact");
- state1->setPropertyOnEntry(label2Proxy, "geometry", QRectF(375, -50, 300, 30));
- state1->setPropertyOnEntry(labelProxy, "geometry", QRectF(350, 300, 100, 30));
- state1->setPropertyOnEntry(editProxy, "geometry", QRectF(750, 300, 250, 30));
- state1->setPropertyOnEntry(buttonProxy4, "geometry", QRectF(500, 350, 80, 25));
+ state1->assignProperty(listProxy, "geometry", QRectF(0, 0, 700, 560));
+ state1->assignProperty(widget, "geometry", QRectF(0, 0, 700, 600));
+ state1->assignProperty(editProxy, "opacity", double(0));
+ state1->assignProperty(labelProxy, "opacity", double(0));
+ state1->assignProperty(label2Proxy, "opacity", double(0));
+ state1->assignProperty(buttonProxy4, "opacity", double(0));
+ state1->assignProperty(labelWidget, "text", "Name : ");
+ state1->assignProperty(label2Widget, "text", "Edit a contact");
+ state1->assignProperty(label2Proxy, "geometry", QRectF(375, -50, 300, 30));
+ state1->assignProperty(labelProxy, "geometry", QRectF(350, 300, 100, 30));
+ state1->assignProperty(editProxy, "geometry", QRectF(750, 300, 250, 30));
+ state1->assignProperty(buttonProxy4, "geometry", QRectF(500, 350, 80, 25));
// State 2
- state2->setPropertyOnEntry(button, "text", "Close Editing");
- state2->setPropertyOnEntry(listProxy, "geometry", QRectF(0, 0, 350, 560));
+ state2->assignProperty(button, "text", "Close Editing");
+ state2->assignProperty(listProxy, "geometry", QRectF(0, 0, 350, 560));
state2->addTransition(button2, SIGNAL(clicked()), state3);
state2->addTransition(button4, SIGNAL(clicked()), state1);
- state2->setPropertyOnEntry(editProxy, "opacity", double(1));
- state2->setPropertyOnEntry(labelProxy, "opacity", double(1));
- state2->setPropertyOnEntry(label2Proxy, "opacity", double(1));
- state2->setPropertyOnEntry(buttonProxy4, "opacity", double(1));
+ state2->assignProperty(editProxy, "opacity", double(1));
+ state2->assignProperty(labelProxy, "opacity", double(1));
+ state2->assignProperty(label2Proxy, "opacity", double(1));
+ state2->assignProperty(buttonProxy4, "opacity", double(1));
- state2->setPropertyOnEntry(label2Proxy, "geometry", QRectF(375, 250, 300, 30));
- state2->setPropertyOnEntry(editProxy, "geometry", QRectF(440, 300, 260, 30));
+ state2->assignProperty(label2Proxy, "geometry", QRectF(375, 250, 300, 30));
+ state2->assignProperty(editProxy, "geometry", QRectF(440, 300, 260, 30));
// State 3
- state3->setPropertyOnEntry(button4, "text", "Create New");
- state3->setPropertyOnEntry(listProxy, "geometry", QRectF(0, 0, 350, 560));
+ state3->assignProperty(button4, "text", "Create New");
+ state3->assignProperty(listProxy, "geometry", QRectF(0, 0, 350, 560));
state3->addTransition(button4, SIGNAL(clicked()), state1);
state3->addTransition(button, SIGNAL(clicked()), state1);
- state3->setPropertyOnEntry(editProxy, "opacity", double(1));
- state3->setPropertyOnEntry(labelProxy, "opacity", double(1));
- state3->setPropertyOnEntry(label2Proxy, "opacity", double(1));
- state3->setPropertyOnEntry(buttonProxy4, "opacity", double(1));
+ state3->assignProperty(editProxy, "opacity", double(1));
+ state3->assignProperty(labelProxy, "opacity", double(1));
+ state3->assignProperty(label2Proxy, "opacity", double(1));
+ state3->assignProperty(buttonProxy4, "opacity", double(1));
- state3->setPropertyOnEntry(label2Proxy, "geometry", QRectF(375, 250, 300, 30));
- state3->setPropertyOnEntry(editProxy, "geometry", QRectF(440, 300, 260, 30));
+ state3->assignProperty(label2Proxy, "geometry", QRectF(375, 250, 300, 30));
+ state3->assignProperty(editProxy, "geometry", QRectF(440, 300, 260, 30));
{
QAnimationGroup *animationGroup = new QParallelAnimationGroup;
@@ -150,7 +150,8 @@ MainWindow::MainWindow() : QMainWindow(0)
anim = new QPropertyAnimation(listProxy, "geometry");
animationGroup->addAnimation(anim);
- state1->addAnimatedTransition(button, SIGNAL(clicked()), state2, animationGroup);
+ QAbstractTransition *trans = state1->addTransition(button, SIGNAL(clicked()), state2);
+ trans->addAnimation(animationGroup);
}
{
@@ -162,7 +163,8 @@ MainWindow::MainWindow() : QMainWindow(0)
animationGroup->addAnimation(anim);
anim = new QPropertyAnimation(listProxy, "geometry");
animationGroup->addAnimation(anim);
- state2->addAnimatedTransition(button, SIGNAL(clicked()), state1, animationGroup);
+ QAbstractTransition *trans = state2->addTransition(button, SIGNAL(clicked()), state1);
+ trans->addAnimation(animationGroup);
}
currentState = state1;
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp
index f4c754d..1f253f3 100644
--- a/examples/animation/moveblocks/main.cpp
+++ b/examples/animation/moveblocks/main.cpp
@@ -13,8 +13,8 @@
#include <QtGui>
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qstatemachine.h"
+#include "qstate.h"
#include "qabstracttransition.h"
-#include "qanimationstate.h"
#include "qpropertyanimation.h"
#include "qsequentialanimationgroup.h"
#include "qparallelanimationgroup.h"
@@ -99,7 +99,8 @@ public:
void addState(QState *state, QAbstractAnimation *animation) {
StateSwitchTransition *trans = new StateSwitchTransition(++m_stateCount);
trans->setTargetState(state);
- addAnimatedTransition(trans, animation);
+ addTransition(trans);
+ trans->addAnimation(animation);
}
@@ -116,11 +117,11 @@ QState *createGeometryState(QObject *w1, const QRect &rect1,
QState *parent)
{
QState *result = new QState(parent);
- result->setPropertyOnEntry(w1, "geometry", rect1);
- result->setPropertyOnEntry(w1, "geometry", rect1);
- result->setPropertyOnEntry(w2, "geometry", rect2);
- result->setPropertyOnEntry(w3, "geometry", rect3);
- result->setPropertyOnEntry(w4, "geometry", rect4);
+ result->assignProperty(w1, "geometry", rect1);
+ result->assignProperty(w1, "geometry", rect1);
+ result->assignProperty(w2, "geometry", rect2);
+ result->assignProperty(w3, "geometry", rect3);
+ result->assignProperty(w4, "geometry", rect4);
return result;
}
diff --git a/examples/animation/research/memberfunctions/qvalueanimation.cpp b/examples/animation/research/memberfunctions/qvalueanimation.cpp
index 2fe9be9..58652ba 100644
--- a/examples/animation/research/memberfunctions/qvalueanimation.cpp
+++ b/examples/animation/research/memberfunctions/qvalueanimation.cpp
@@ -21,8 +21,8 @@ void QValueAnimationPrivate::initDefaultStartValue()
{
Q_Q(QValueAnimation);
if (animProp && !q->startValue().isValid()
- && ((currentTime == 0 && (currentIteration || currentIteration == 0))
- || (currentTime == duration && currentIteration == (iterationCount - 1)))) {
+ && (currentTime == 0
+ || (currentTime == duration && currentLoop == (loopCount - 1)))) {
setDefaultStartValue(animProp->read());
}
}
diff --git a/examples/animation/states/main.cpp b/examples/animation/states/main.cpp
index 5c004a2..da50519 100644
--- a/examples/animation/states/main.cpp
+++ b/examples/animation/states/main.cpp
@@ -109,69 +109,69 @@ int main(int argc, char *argv[])
machine.setInitialState(state1);
// State 1
- state1->setPropertyOnEntry(button, "text", "Switch to state 2");
- state1->setPropertyOnEntry(widget, "geometry", QRectF(0, 0, 400, 150));
- state1->setPropertyOnEntry(box, "geometry", QRect(-200, 150, 200, 150));
- state1->setPropertyOnEntry(p1, "geometry", QRectF(68, 185, 64, 64));
- state1->setPropertyOnEntry(p2, "geometry", QRectF(168, 185, 64, 64));
- state1->setPropertyOnEntry(p3, "geometry", QRectF(268, 185, 64, 64));
- state1->setPropertyOnEntry(p4, "geometry", QRectF(68-150, 48-150, 64, 64));
- state1->setPropertyOnEntry(p5, "geometry", QRectF(168, 48-150, 64, 64));
- state1->setPropertyOnEntry(p6, "geometry", QRectF(268+150, 48-150, 64, 64));
- state1->setPropertyOnEntry(p1, "zRotation", qreal(0));
- state1->setPropertyOnEntry(p2, "zRotation", qreal(0));
- state1->setPropertyOnEntry(p3, "zRotation", qreal(0));
- state1->setPropertyOnEntry(p4, "zRotation", qreal(-270));
- state1->setPropertyOnEntry(p5, "zRotation", qreal(-90));
- state1->setPropertyOnEntry(p6, "zRotation", qreal(270));
- state1->setPropertyOnEntry(boxProxy, "opacity", qreal(0));
- state1->setPropertyOnEntry(p1, "opacity", qreal(1));
- state1->setPropertyOnEntry(p2, "opacity", qreal(1));
- state1->setPropertyOnEntry(p3, "opacity", qreal(1));
- state1->setPropertyOnEntry(p4, "opacity", qreal(0));
- state1->setPropertyOnEntry(p5, "opacity", qreal(0));
- state1->setPropertyOnEntry(p6, "opacity", qreal(0));
+ state1->assignProperty(button, "text", "Switch to state 2");
+ state1->assignProperty(widget, "geometry", QRectF(0, 0, 400, 150));
+ state1->assignProperty(box, "geometry", QRect(-200, 150, 200, 150));
+ state1->assignProperty(p1, "geometry", QRectF(68, 185, 64, 64));
+ state1->assignProperty(p2, "geometry", QRectF(168, 185, 64, 64));
+ state1->assignProperty(p3, "geometry", QRectF(268, 185, 64, 64));
+ state1->assignProperty(p4, "geometry", QRectF(68-150, 48-150, 64, 64));
+ state1->assignProperty(p5, "geometry", QRectF(168, 48-150, 64, 64));
+ state1->assignProperty(p6, "geometry", QRectF(268+150, 48-150, 64, 64));
+ state1->assignProperty(p1, "zRotation", qreal(0));
+ state1->assignProperty(p2, "zRotation", qreal(0));
+ state1->assignProperty(p3, "zRotation", qreal(0));
+ state1->assignProperty(p4, "zRotation", qreal(-270));
+ state1->assignProperty(p5, "zRotation", qreal(-90));
+ state1->assignProperty(p6, "zRotation", qreal(270));
+ state1->assignProperty(boxProxy, "opacity", qreal(0));
+ state1->assignProperty(p1, "opacity", qreal(1));
+ state1->assignProperty(p2, "opacity", qreal(1));
+ state1->assignProperty(p3, "opacity", qreal(1));
+ state1->assignProperty(p4, "opacity", qreal(0));
+ state1->assignProperty(p5, "opacity", qreal(0));
+ state1->assignProperty(p6, "opacity", qreal(0));
// State 2
- state2->setPropertyOnEntry(button, "text", "Switch to state 3");
- state2->setPropertyOnEntry(widget, "geometry", QRectF(200, 150, 200, 150));
- state2->setPropertyOnEntry(box, "geometry", QRect(9, 150, 190, 150));
- state2->setPropertyOnEntry(p1, "geometry", QRectF(68-150, 185+150, 64, 64));
- state2->setPropertyOnEntry(p2, "geometry", QRectF(168, 185+150, 64, 64));
- state2->setPropertyOnEntry(p3, "geometry", QRectF(268+150, 185+150, 64, 64));
- state2->setPropertyOnEntry(p4, "geometry", QRectF(64, 48, 64, 64));
- state2->setPropertyOnEntry(p5, "geometry", QRectF(168, 48, 64, 64));
- state2->setPropertyOnEntry(p6, "geometry", QRectF(268, 48, 64, 64));
- state2->setPropertyOnEntry(p1, "zRotation", qreal(-270));
- state2->setPropertyOnEntry(p2, "zRotation", qreal(90));
- state2->setPropertyOnEntry(p3, "zRotation", qreal(270));
- state2->setPropertyOnEntry(p4, "zRotation", qreal(0));
- state2->setPropertyOnEntry(p5, "zRotation", qreal(0));
- state2->setPropertyOnEntry(p6, "zRotation", qreal(0));
- state2->setPropertyOnEntry(boxProxy, "opacity", qreal(1));
- state2->setPropertyOnEntry(p1, "opacity", qreal(0));
- state2->setPropertyOnEntry(p2, "opacity", qreal(0));
- state2->setPropertyOnEntry(p3, "opacity", qreal(0));
- state2->setPropertyOnEntry(p4, "opacity", qreal(1));
- state2->setPropertyOnEntry(p5, "opacity", qreal(1));
- state2->setPropertyOnEntry(p6, "opacity", qreal(1));
+ state2->assignProperty(button, "text", "Switch to state 3");
+ state2->assignProperty(widget, "geometry", QRectF(200, 150, 200, 150));
+ state2->assignProperty(box, "geometry", QRect(9, 150, 190, 150));
+ state2->assignProperty(p1, "geometry", QRectF(68-150, 185+150, 64, 64));
+ state2->assignProperty(p2, "geometry", QRectF(168, 185+150, 64, 64));
+ state2->assignProperty(p3, "geometry", QRectF(268+150, 185+150, 64, 64));
+ state2->assignProperty(p4, "geometry", QRectF(64, 48, 64, 64));
+ state2->assignProperty(p5, "geometry", QRectF(168, 48, 64, 64));
+ state2->assignProperty(p6, "geometry", QRectF(268, 48, 64, 64));
+ state2->assignProperty(p1, "zRotation", qreal(-270));
+ state2->assignProperty(p2, "zRotation", qreal(90));
+ state2->assignProperty(p3, "zRotation", qreal(270));
+ state2->assignProperty(p4, "zRotation", qreal(0));
+ state2->assignProperty(p5, "zRotation", qreal(0));
+ state2->assignProperty(p6, "zRotation", qreal(0));
+ state2->assignProperty(boxProxy, "opacity", qreal(1));
+ state2->assignProperty(p1, "opacity", qreal(0));
+ state2->assignProperty(p2, "opacity", qreal(0));
+ state2->assignProperty(p3, "opacity", qreal(0));
+ state2->assignProperty(p4, "opacity", qreal(1));
+ state2->assignProperty(p5, "opacity", qreal(1));
+ state2->assignProperty(p6, "opacity", qreal(1));
// State 3
- state3->setPropertyOnEntry(button, "text", "Switch to state 1");
- state3->setPropertyOnEntry(p1, "geometry", QRectF(5, 5, 64, 64));
- state3->setPropertyOnEntry(p2, "geometry", QRectF(5, 5 + 64 + 5, 64, 64));
- state3->setPropertyOnEntry(p3, "geometry", QRectF(5, 5 + (64 + 5) + 64, 64, 64));
- state3->setPropertyOnEntry(p4, "geometry", QRectF(5 + 64 + 5, 5, 64, 64));
- state3->setPropertyOnEntry(p5, "geometry", QRectF(5 + 64 + 5, 5 + 64 + 5, 64, 64));
- state3->setPropertyOnEntry(p6, "geometry", QRectF(5 + 64 + 5, 5 + (64 + 5) + 64, 64, 64));
- state3->setPropertyOnEntry(widget, "geometry", QRectF(138, 5, 400 - 138, 200));
- state3->setPropertyOnEntry(box, "geometry", QRect(5, 205, 400, 90));
- state3->setPropertyOnEntry(p1, "opacity", qreal(1));
- state3->setPropertyOnEntry(p2, "opacity", qreal(1));
- state3->setPropertyOnEntry(p3, "opacity", qreal(1));
- state3->setPropertyOnEntry(p4, "opacity", qreal(1));
- state3->setPropertyOnEntry(p5, "opacity", qreal(1));
- state3->setPropertyOnEntry(p6, "opacity", qreal(1));
+ state3->assignProperty(button, "text", "Switch to state 1");
+ state3->assignProperty(p1, "geometry", QRectF(5, 5, 64, 64));
+ state3->assignProperty(p2, "geometry", QRectF(5, 5 + 64 + 5, 64, 64));
+ state3->assignProperty(p3, "geometry", QRectF(5, 5 + (64 + 5) + 64, 64, 64));
+ state3->assignProperty(p4, "geometry", QRectF(5 + 64 + 5, 5, 64, 64));
+ state3->assignProperty(p5, "geometry", QRectF(5 + 64 + 5, 5 + 64 + 5, 64, 64));
+ state3->assignProperty(p6, "geometry", QRectF(5 + 64 + 5, 5 + (64 + 5) + 64, 64, 64));
+ state3->assignProperty(widget, "geometry", QRectF(138, 5, 400 - 138, 200));
+ state3->assignProperty(box, "geometry", QRect(5, 205, 400, 90));
+ state3->assignProperty(p1, "opacity", qreal(1));
+ state3->assignProperty(p2, "opacity", qreal(1));
+ state3->assignProperty(p3, "opacity", qreal(1));
+ state3->assignProperty(p4, "opacity", qreal(1));
+ state3->assignProperty(p5, "opacity", qreal(1));
+ state3->assignProperty(p6, "opacity", qreal(1));
QParallelAnimationGroup animation1;
@@ -244,9 +244,12 @@ int main(int argc, char *argv[])
animation3.addAnimation(new QPropertyAnimation(p5, "opacity"));
animation3.addAnimation(new QPropertyAnimation(p6, "opacity"));
- state1->addAnimatedTransition(button, SIGNAL(clicked()), state2, &animation1);
- state2->addAnimatedTransition(button, SIGNAL(clicked()), state3, &animation2);
- state3->addAnimatedTransition(button, SIGNAL(clicked()), state1, &animation3);
+ QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2);
+ t1->addAnimation(&animation1);
+ QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3);
+ t2->addAnimation(&animation2);
+ QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1);
+ t3->addAnimation(&animation3);
machine.start();
diff --git a/examples/animation/stickman/editor/animationdialog.cpp b/examples/animation/stickman/editor/animationdialog.cpp
new file mode 100644
index 0000000..ca0daf0
--- /dev/null
+++ b/examples/animation/stickman/editor/animationdialog.cpp
@@ -0,0 +1,151 @@
+#include "animationdialog.h"
+#include "stickman.h"
+#include "animation.h"
+#include "node.h"
+
+#include <QHBoxLayout>
+#include <QStackedWidget>
+#include <QSpinBox>
+#include <QPushButton>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QFileDialog>
+
+AnimationDialog::AnimationDialog(StickMan *stickman, QWidget *parent)
+ : QDialog(parent), m_animation(0), m_stickman(stickman)
+{
+ initUi();
+}
+
+AnimationDialog::~AnimationDialog()
+{
+ delete m_animation;
+}
+
+void AnimationDialog::initUi()
+{
+ setWindowTitle("Animation");
+ setEnabled(false);
+
+ // Second page
+ m_currentFrame = new QSpinBox();
+ m_totalFrames = new QSpinBox();
+ m_name = new QLineEdit();
+
+ connect(m_currentFrame, SIGNAL(valueChanged(int)), this, SLOT(currentFrameChanged(int)));
+ connect(m_totalFrames, SIGNAL(valueChanged(int)), this, SLOT(totalFramesChanged(int)));
+ connect(m_name, SIGNAL(textChanged(QString)), this, SLOT(setCurrentAnimationName(QString)));
+
+ QGridLayout *gridLayout = new QGridLayout(this);
+ gridLayout->addWidget(new QLabel("Name:"), 0, 0, 1, 2);
+ gridLayout->addWidget(m_name, 0, 2, 1, 2);
+ gridLayout->addWidget(new QLabel("Frame:"), 1, 0);
+ gridLayout->addWidget(m_currentFrame, 1, 1);
+ gridLayout->addWidget(new QLabel("of total # of frames: "), 1, 2);
+ gridLayout->addWidget(m_totalFrames, 1, 3);
+}
+
+void AnimationDialog::initFromAnimation()
+{
+ m_currentFrame->setRange(0, m_animation->totalFrames()-1);
+ m_currentFrame->setValue(m_animation->currentFrame());
+
+ m_totalFrames->setRange(1, 1000);
+ m_totalFrames->setValue(m_animation->totalFrames());
+
+ m_name->setText(m_animation->name());
+}
+
+void AnimationDialog::saveAnimation()
+{
+ saveCurrentFrame();
+
+ QString fileName = QFileDialog::getSaveFileName(this, "Save animation");
+
+ QFile file(fileName);
+ if (file.open(QIODevice::WriteOnly))
+ m_animation->save(&file);
+}
+
+void AnimationDialog::loadAnimation()
+{
+ if (maybeSave() != QMessageBox::Cancel) {
+ QString fileName = QFileDialog::getOpenFileName(this, "Open animation");
+
+ QFile file(fileName);
+ if (file.open(QIODevice::ReadOnly)) {
+ if (m_animation == 0)
+ newAnimation();
+
+ m_animation->load(&file);
+ stickManFromCurrentFrame();
+ initFromAnimation();
+ }
+ }
+}
+
+QMessageBox::StandardButton AnimationDialog::maybeSave()
+{
+ if (m_animation == 0)
+ return QMessageBox::No;
+
+ QMessageBox::StandardButton button = QMessageBox::question(this, "Save?", "Do you want to save your changes?",
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ if (button == QMessageBox::Save)
+ saveAnimation();
+
+ return button;
+}
+
+void AnimationDialog::newAnimation()
+{
+ if (maybeSave() != QMessageBox::Cancel) {
+ setEnabled(true);
+ delete m_animation;
+ m_animation = new Animation();
+ initFromAnimation();
+ }
+}
+
+// Gets the data from the stickman and stores it in current frame
+void AnimationDialog::saveCurrentFrame()
+{
+ int count = m_stickman->nodeCount();
+ m_animation->setNodeCount(count);
+ for (int i=0; i<count; ++i) {
+ QGraphicsItem *node = m_stickman->node(i);
+ m_animation->setNodePos(i, node->pos());
+ }
+}
+
+// Gets the data from the current frame and sets the stickman
+void AnimationDialog::stickManFromCurrentFrame()
+{
+ int count = m_animation->nodeCount();
+ for (int i=0;i<count;++i) {
+ QGraphicsItem *node = m_stickman->node(i);
+ node->setPos(m_animation->nodePos(i));
+ }
+}
+
+void AnimationDialog::currentFrameChanged(int currentFrame)
+{
+ saveCurrentFrame();
+ qDebug("currentFrame: %d", currentFrame);
+ m_animation->setCurrentFrame(currentFrame);
+ stickManFromCurrentFrame();
+ initFromAnimation();
+}
+
+void AnimationDialog::totalFramesChanged(int totalFrames)
+{
+ m_animation->setTotalFrames(totalFrames);
+ stickManFromCurrentFrame();
+ initFromAnimation();
+}
+
+void AnimationDialog::setCurrentAnimationName(const QString &name)
+{
+ m_animation->setName(name);
+} \ No newline at end of file
diff --git a/examples/animation/stickman/editor/animationdialog.h b/examples/animation/stickman/editor/animationdialog.h
new file mode 100644
index 0000000..c144fd8
--- /dev/null
+++ b/examples/animation/stickman/editor/animationdialog.h
@@ -0,0 +1,41 @@
+#ifndef ANIMATIONDIALOG_H
+#define ANIMATIONDIALOG_H
+
+#include <QDialog>
+#include <QMessageBox>
+
+class QSpinBox;
+class QLineEdit;
+class StickMan;
+class Animation;
+class AnimationDialog: public QDialog
+{
+ Q_OBJECT
+public:
+ AnimationDialog(StickMan *stickMan, QWidget *parent = 0);
+ ~AnimationDialog();
+
+public slots:
+ void currentFrameChanged(int currentFrame);
+ void totalFramesChanged(int totalFrames);
+ void setCurrentAnimationName(const QString &name);
+
+ void newAnimation();
+ void saveAnimation();
+ void loadAnimation();
+
+private:
+ void saveCurrentFrame();
+ void stickManFromCurrentFrame();
+ void initFromAnimation();
+ void initUi();
+ QMessageBox::StandardButton maybeSave();
+
+ QSpinBox *m_currentFrame;
+ QSpinBox *m_totalFrames;
+ QLineEdit *m_name;
+ Animation *m_animation;
+ StickMan *m_stickman;
+};
+
+#endif
diff --git a/examples/animation/stickman/editor/editor.pri b/examples/animation/stickman/editor/editor.pri
new file mode 100644
index 0000000..7ad9edb
--- /dev/null
+++ b/examples/animation/stickman/editor/editor.pri
@@ -0,0 +1,2 @@
+SOURCES += $$PWD/animationdialog.cpp $$PWD/mainwindow.cpp
+HEADERS += $$PWD/animationdialog.h $$PWD/mainwindow.h
diff --git a/examples/animation/stickman/editor/mainwindow.cpp b/examples/animation/stickman/editor/mainwindow.cpp
new file mode 100644
index 0000000..158c9b7
--- /dev/null
+++ b/examples/animation/stickman/editor/mainwindow.cpp
@@ -0,0 +1,35 @@
+#include "mainwindow.h"
+#include "animationdialog.h"
+#include "stickman.h"
+
+#include <QMenuBar>
+#include <QApplication>
+
+MainWindow::MainWindow(StickMan *stickMan)
+{
+ initActions(stickMan);
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::initActions(StickMan *stickMan)
+{
+ AnimationDialog *dialog = new AnimationDialog(stickMan, this);
+ dialog->show();
+
+ QMenu *fileMenu = menuBar()->addMenu("&File");
+ QAction *loadAction = fileMenu->addAction("&Open");
+ QAction *saveAction = fileMenu->addAction("&Save");
+ QAction *exitAction = fileMenu->addAction("E&xit");
+
+ QMenu *animationMenu = menuBar()->addMenu("&Animation");
+ QAction *newAnimationAction = animationMenu->addAction("&New animation");
+
+ connect(loadAction, SIGNAL(triggered()), dialog, SLOT(loadAnimation()));
+ connect(saveAction, SIGNAL(triggered()), dialog, SLOT(saveAnimation()));
+ connect(exitAction, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
+ connect(newAnimationAction, SIGNAL(triggered()), dialog, SLOT(newAnimation()));
+
+}
diff --git a/examples/animation/stickman/editor/mainwindow.h b/examples/animation/stickman/editor/mainwindow.h
new file mode 100644
index 0000000..279fc07
--- /dev/null
+++ b/examples/animation/stickman/editor/mainwindow.h
@@ -0,0 +1,17 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class StickMan;
+class MainWindow: public QMainWindow
+{
+public:
+ MainWindow(StickMan *stickMan);
+ ~MainWindow();
+
+private:
+ void initActions(StickMan *stickMan);
+};
+
+#endif
diff --git a/examples/animation/stickman/graphicsview.cpp b/examples/animation/stickman/graphicsview.cpp
index 1b6afa9..d4f0e3a 100644
--- a/examples/animation/stickman/graphicsview.cpp
+++ b/examples/animation/stickman/graphicsview.cpp
@@ -1,14 +1,39 @@
#include "graphicsview.h"
+#include "editor/mainwindow.h"
+#include "stickman.h"
#include <QtGui/QKeyEvent>
+#include <QtGui/QGraphicsScene>
+#include <QtGui/QGraphicsView>
-GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent) {}
+GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), m_editor(0) {}
void GraphicsView::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Escape)
close();
+#if 0
+ if (e->key() == Qt::Key_F1) {
+ if (m_editor == 0) {
+ QGraphicsScene *scene = new QGraphicsScene;
+ StickMan *stickMan = new StickMan;
+ stickMan->setDrawSticks(true);
+ scene->addItem(stickMan);
+
+ QGraphicsView *view = new QGraphicsView;
+ view->setBackgroundBrush(Qt::black);
+ view->setRenderHints(QPainter::Antialiasing);
+ view->setScene(scene);
+
+ m_editor = new MainWindow(stickMan);
+ m_editor->setCentralWidget(view);
+ }
+
+ m_editor->showMaximized();
+ }
+#endif
+
emit keyPressed(Qt::Key(e->key()));
}
diff --git a/examples/animation/stickman/graphicsview.h b/examples/animation/stickman/graphicsview.h
index 9ea2cfb..58ed95b 100644
--- a/examples/animation/stickman/graphicsview.h
+++ b/examples/animation/stickman/graphicsview.h
@@ -3,6 +3,7 @@
#include <QtGui/QGraphicsView>
+class MainWindow;
class GraphicsView: public QGraphicsView
{
Q_OBJECT
@@ -14,6 +15,9 @@ protected:
signals:
void keyPressed(int key);
+
+private:
+ MainWindow *m_editor;
};
#endif
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 3e92aec..9233760 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -6,6 +6,15 @@
#include <QtCore>
#include <QtGui>
+#if defined(QT_EXPERIMENTAL_SOLUTION)
+#include "qstatemachine.h"
+#include "qstate.h"
+#include "qeventtransition.h"
+#include "qsignaltransition.h"
+#include "qsignalevent.h"
+#include "qpropertyanimation.h"
+#include "qparallelanimationgroup.h"
+#endif
class KeyPressTransition: public QSignalTransition
{
@@ -69,27 +78,34 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Make it blink when lightning strikes before entering dead animation
QState *lightningBlink = new QState(m_machine->rootState());
lightningBlink->setRestorePolicy(QState::DoNotRestoreProperties);
- lightningBlink->setPropertyOnEntry(m_stickMan->scene(), "backgroundBrush", Qt::white);
- lightningBlink->setPropertyOnEntry(m_stickMan, "penColor", Qt::black);
- lightningBlink->setPropertyOnEntry(m_stickMan, "fillColor", Qt::white);
- lightningBlink->setPropertyOnEntry(m_stickMan, "isDead", true);
+ lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white);
+ lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black);
+ lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white);
+ lightningBlink->assignProperty(m_stickMan, "isDead", true);
+
+ QTimer *timer = new QTimer(lightningBlink);
+ timer->setSingleShot(true);
+ timer->setInterval(100);
+ lightningBlink->invokeMethodOnEntry(timer, "start");
+ lightningBlink->invokeMethodOnExit(timer, "stop");
m_dead = new QState(m_machine->rootState());
m_dead->setRestorePolicy(QState::DoNotRestoreProperties);
- m_dead->setPropertyOnEntry(m_stickMan->scene(), "backgroundBrush", Qt::black);
- m_dead->setPropertyOnEntry(m_stickMan, "penColor", Qt::white);
- m_dead->setPropertyOnEntry(m_stickMan, "fillColor", Qt::black);
+ m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black);
+ m_dead->assignProperty(m_stickMan, "penColor", Qt::white);
+ m_dead->assignProperty(m_stickMan, "fillColor", Qt::black);
m_dead->setObjectName("dead");
// Idle state (sets no properties)
m_idle = new QState(m_alive);
m_idle->setObjectName("idle");
+
m_alive->setInitialState(m_idle);
// Lightning strikes at random
m_alive->addTransition(new LightningStrikesTransition(lightningBlink));
- m_alive->addTransition(new KeyPressTransition(m_keyReceiver, Qt::Key_L, lightningBlink));
- connectByAnimation(m_machine->rootState(), lightningBlink, m_dead);
+ //m_alive->addTransition(new KeyPressTransition(m_keyReceiver, Qt::Key_L, lightningBlink));
+ connectByAnimation(lightningBlink, m_dead, new QSignalTransition(timer, SIGNAL(timeout())));
m_machine->setInitialState(m_alive);
}
@@ -98,7 +114,9 @@ void LifeCycle::setResetKey(Qt::Key resetKey)
{
// When resetKey is pressed, enter the idle state and do a restoration animation
// (requires no animation pointer, since no property is being set in the idle state)
- m_alive->addAnimatedTransition(new KeyPressTransition(m_keyReceiver, resetKey, m_idle));
+ KeyPressTransition *trans = new KeyPressTransition(m_keyReceiver, resetKey, m_idle);
+ trans->addAnimation(m_animationGroup);
+ m_alive->addTransition(trans);
}
void LifeCycle::setDeathAnimation(const QString &fileName)
@@ -112,26 +130,22 @@ void LifeCycle::start()
m_machine->start();
}
-void LifeCycle::connectByAnimation(QState *parentState,
- QState *s1, QAbstractState *s2,
+void LifeCycle::connectByAnimation(QState *s1, QAbstractState *s2,
QAbstractTransition *transition)
{
- QAnimationState *animationState = new QAnimationState(m_animationGroup, parentState);
-
- if (transition == 0)
- s1->addTransition(animationState);
- else {
- transition->setTargetStates(QList<QAbstractState*>() << animationState);
+ if (transition == 0) {
+ transition = s1->addTransition(s2);
+ } else {
+ transition->setTargetState(s2);
s1->addTransition(transition);
}
-
- animationState->addFinishedTransition(s2);
+ transition->addAnimation(m_animationGroup);
}
void LifeCycle::addActivity(const QString &fileName, Qt::Key key)
{
QState *state = makeState(m_alive, fileName);
- connectByAnimation(m_alive, m_alive, state, new KeyPressTransition(m_keyReceiver, key));
+ connectByAnimation(m_alive, state, new KeyPressTransition(m_keyReceiver, key));
}
QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName)
@@ -149,21 +163,25 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
QState *previousState = 0;
for (int i=0; i<frameCount; ++i) {
QState *frameState = new QState(topLevel);
-
+ frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
+
animation.setCurrentFrame(i);
const int nodeCount = animation.nodeCount();
for (int j=0; j<nodeCount; ++j)
- frameState->setPropertyOnEntry(m_stickMan->node(j), "position", animation.nodePos(j));
+ frameState->assignProperty(m_stickMan->node(j), "position", animation.nodePos(j));
- if (previousState == 0)
+ if (previousState == 0) {
topLevel->setInitialState(frameState);
- else
- connectByAnimation(topLevel, previousState, frameState);
+ } else {
+ connectByAnimation(previousState, frameState,
+ new QSignalTransition(m_machine, SIGNAL(animationsFinished())));
+ }
previousState = frameState;
}
// Loop
- connectByAnimation(topLevel, previousState, topLevel->initialState());
+ connectByAnimation(previousState, topLevel->initialState(),
+ new QSignalTransition(m_machine, SIGNAL(animationsFinished())));
return topLevel;
diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
index 8094a76..437e935 100644
--- a/examples/animation/stickman/lifecycle.h
+++ b/examples/animation/stickman/lifecycle.h
@@ -23,7 +23,7 @@ public:
void start();
private:
- void connectByAnimation(QState *parentState, QState *s1, QAbstractState *s2,
+ void connectByAnimation(QState *s1, QAbstractState *s2,
QAbstractTransition *transition = 0);
QState *makeState(QState *parentState, const QString &animationFileName);
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
index a094e28..62860ec 100644
--- a/examples/animation/stickman/main.cpp
+++ b/examples/animation/stickman/main.cpp
@@ -26,7 +26,7 @@ int main(int argc, char **argv)
"<li>Press <font color=\"purple\">Return</font> to make him return to his original position.</li>"
"<li>When you are done, press <font color=\"purple\">Escape</font>.</li>"
"</i></p>"
- "<p>If you are unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again."
+ "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again."
"</p></font>");
qreal w = textItem->boundingRect().width();
QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect();
diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp
index f3468d0..5932b60 100644
--- a/examples/animation/stickman/node.cpp
+++ b/examples/animation/stickman/node.cpp
@@ -1,4 +1,5 @@
#include "node.h"
+#include "stickman.h"
#include <QRectF>
#include <QPainter>
@@ -25,6 +26,14 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
painter->drawEllipse(QPointF(0.0, 0.0), 5.0, 5.0);
}
+QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if (change == QGraphicsItem::ItemPositionChange)
+ emit positionChanged();
+
+ return QGraphicsItem::itemChange(change, value);
+}
+
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
m_dragging = true;
diff --git a/examples/animation/stickman/node.h b/examples/animation/stickman/node.h
index b796774..e9e9190 100644
--- a/examples/animation/stickman/node.h
+++ b/examples/animation/stickman/node.h
@@ -14,7 +14,12 @@ public:
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+signals:
+ void positionChanged();
+
protected:
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+
void mousePressEvent(QGraphicsSceneMouseEvent *);
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
diff --git a/examples/animation/stickman/stickman.cpp b/examples/animation/stickman/stickman.cpp
index 22d48d3..1393836 100644
--- a/examples/animation/stickman/stickman.cpp
+++ b/examples/animation/stickman/stickman.cpp
@@ -81,6 +81,7 @@ StickMan::StickMan()
// Set up start position of limbs
for (int i=0; i<NodeCount; ++i) {
m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this);
+ connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged()));
}
m_perfectBoneLengths = new qreal[BoneCount];
@@ -103,6 +104,11 @@ StickMan::~StickMan()
delete m_nodes;
}
+void StickMan::childPositionChanged()
+{
+ prepareGeometryChange();
+}
+
void StickMan::setDrawSticks(bool on)
{
m_sticks = on;
@@ -114,8 +120,8 @@ void StickMan::setDrawSticks(bool on)
QRectF StickMan::boundingRect() const
{
- // account for head radius=50.0 plus pen which is 5.0, plus jump height :-)
- return QRectF(-125, -200, 250, 450 + 50).adjusted(-55.0, -55.0, 55.0, 55.0);
+ // account for head radius=50.0 plus pen which is 5.0
+ return childrenBoundingRect().adjusted(-55.0, -55.0, 55.0, 55.0);
}
int StickMan::nodeCount() const
@@ -125,7 +131,6 @@ int StickMan::nodeCount() const
Node *StickMan::node(int idx) const
{
- const_cast<StickMan *>(this)->prepareGeometryChange();
if (idx >= 0 && idx < NodeCount)
return m_nodes[idx];
else
@@ -134,11 +139,13 @@ Node *StickMan::node(int idx) const
void StickMan::timerEvent(QTimerEvent *e)
{
- prepareGeometryChange();
+ update();
}
void StickMan::stabilize()
{
+ static const qreal threshold = 0.001;
+
for (int i=0; i<BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -153,12 +160,14 @@ void StickMan::stabilize()
qreal length = sqrt(pow(dist.x(),2) + pow(dist.y(),2));
qreal diff = (length - m_perfectBoneLengths[i]) / length;
- pos1 -= dist * (0.5 * diff);
- pos2 += dist * (0.5 * diff);
-
- node1->setPos(pos1);
- node2->setPos(pos2);
+ QPointF p = dist * (0.5 * diff);
+ if (p.x() > threshold && p.y() > threshold) {
+ pos1 -= p;
+ pos2 += p;
+ node1->setPos(pos1);
+ node2->setPos(pos2);
+ }
}
}
@@ -245,19 +254,12 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
qreal angle = asin(sinAngle) * 180.0 / M_PI;
QPointF headPos = node1->pos();
- painter->save();
painter->translate(headPos);
painter->rotate(-angle);
painter->setBrush(m_fillColor);
painter->drawEllipse(QPointF(0,0), 50.0, 50.0);
- /*painter->drawArc(QRectF(-20.0, 0.0, 40.0, 20.0), 30.0 * 16, 120.0 * 16);
-
- painter->setBrush(m_penColor);
- painter->drawEllipse(QPointF(-30.0, -30.0), 2.5, 2.5);
- painter->drawEllipse(QPointF(30.0, -30.0), 2.5, 2.5);*/
-
painter->setBrush(m_penColor);
painter->setPen(QPen(m_penColor, 2.5, Qt::SolidLine, Qt::RoundCap));
@@ -288,9 +290,6 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
painter->drawEllipse(QPointF(-12.0, -25.0), 5.0, 5.0);
painter->drawEllipse(QPointF(22.0, -25.0), 5.0, 5.0);
}
-
-
- painter->restore();
}
}
}
diff --git a/examples/animation/stickman/stickman.h b/examples/animation/stickman/stickman.h
index ae406ca..e659cdb 100644
--- a/examples/animation/stickman/stickman.h
+++ b/examples/animation/stickman/stickman.h
@@ -37,6 +37,7 @@ public:
public slots:
void stabilize();
+ void childPositionChanged();
protected:
void timerEvent(QTimerEvent *e);
diff --git a/examples/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro
index 136cb44..bfee5b0 100644
--- a/examples/animation/stickman/stickman.pro
+++ b/examples/animation/stickman/stickman.pro
@@ -7,6 +7,8 @@ TARGET =
DEPENDPATH += .
INCLUDEPATH += .
+include(editor/editor.pri)
+
# Input
HEADERS += stickman.h animation.h node.h lifecycle.h graphicsview.h
SOURCES += main.cpp stickman.cpp animation.cpp node.cpp lifecycle.cpp graphicsview.cpp
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()));
diff --git a/examples/statemachine/citizenquartz/citizenquartz.qrc b/examples/statemachine/citizenquartz/citizenquartz.qrc
index bcc675a..fc09ef9 100644
--- a/examples/statemachine/citizenquartz/citizenquartz.qrc
+++ b/examples/statemachine/citizenquartz/citizenquartz.qrc
@@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>sound/alarm.wav</file>
+ <file>images/alarm.png</file>
</qresource>
</RCC> \ No newline at end of file
diff --git a/examples/statemachine/citizenquartz/clock.cpp b/examples/statemachine/citizenquartz/clock.cpp
index 51180f5..1b2b21e 100644
--- a/examples/statemachine/citizenquartz/clock.cpp
+++ b/examples/statemachine/citizenquartz/clock.cpp
@@ -24,6 +24,7 @@ Clock::Clock(QGraphicsItem *parent)
m_timeState(0),
m_updateState(0),
m_regularState(0),
+ m_displaysHistoryState(0),
m_alarmSound(new QSound(":/sound/alarm.wav", this))
{
}
@@ -84,9 +85,19 @@ void Clock::initializeStateMachine()
displays->setObjectName("displays");
initializeDisplaysState(displays);
- /*QState *alarmsBeep = new QState(m_stateMachine->rootState());
- alarmsBeep->setObjectName("alarmsBeep");
- initializeAlarmsBeepState(alarmsBeep);*/
+ QState *alarmsBeepState = new QState(m_stateMachine->rootState());
+ alarmsBeepState->setObjectName("alarmsBeep");
+ alarmsBeepState->invokeMethodOnEntry(this, "playSound");
+ alarmsBeepState->invokeMethodOnExit(this, "stopSound");
+
+ QTimer *alarmTimeOut = new QTimer(alarmsBeepState);
+ alarmTimeOut->setInterval(30000);
+ alarmsBeepState->invokeMethodOnEntry(alarmTimeOut, "start");
+ alarmsBeepState->invokeMethodOnExit(alarmTimeOut, "stop");
+
+ displays->addTransition(m_clockDisplay, SIGNAL(alarmTriggered()), alarmsBeepState);
+ alarmsBeepState->addTransition(this, SIGNAL(anyButtonPressed()), m_displaysHistoryState);
+ alarmsBeepState->addTransition(alarmTimeOut, SIGNAL(timeout()), m_displaysHistoryState);
m_stateMachine->setInitialState(displays);
m_stateMachine->start();
@@ -101,8 +112,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *secIncrease = new PropertyAddState(updateState);
secIncrease->setObjectName("sec ++");
- secIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setSeconds(1));
+ secIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setSeconds(1));
sec->addTransition(m_buttonD, SIGNAL(pressed()), secIncrease);
secIncrease->addTransition(sec);
@@ -113,8 +123,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *oneMinIncrease = new PropertyAddState(updateState);
oneMinIncrease->setObjectName("1 min ++");
- oneMinIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setMinutes(1));
+ oneMinIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setMinutes(1));
oneMin->addTransition(m_buttonD, SIGNAL(pressed()), oneMinIncrease);
oneMinIncrease->addTransition(oneMin);
@@ -125,8 +134,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *tenMinIncrease = new PropertyAddState(updateState);
tenMinIncrease->setObjectName("10 min ++");
- tenMinIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setMinutes(10));
+ tenMinIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setMinutes(10));
tenMin->addTransition(m_buttonD, SIGNAL(pressed()), tenMinIncrease);
tenMinIncrease->addTransition(tenMin);
@@ -137,8 +145,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *hrIncrease = new PropertyAddState(updateState);
hrIncrease->setObjectName("hr ++");
- hrIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setHours(1));
+ hrIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setHours(1));
hr->addTransition(m_buttonD, SIGNAL(pressed()), hrIncrease);
hrIncrease->addTransition(hr);
@@ -149,8 +156,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *monIncrease = new PropertyAddState(updateState);
monIncrease->setObjectName("mon ++");
- monIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setMonths(1));
+ monIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setMonths(1));
mon->addTransition(m_buttonD, SIGNAL(pressed()), monIncrease);
monIncrease->addTransition(mon);
@@ -161,8 +167,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *dayIncrease = new PropertyAddState(updateState);
dayIncrease->setObjectName("day ++");
- dayIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setDays(1));
+ dayIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setDays(1));
day->addTransition(m_buttonD, SIGNAL(pressed()), dayIncrease);
dayIncrease->addTransition(day);
@@ -173,8 +178,7 @@ void Clock::initializeUpdateState(QState *updateState)
PropertyAddState *yearIncrease = new PropertyAddState(updateState);
yearIncrease->setObjectName("year ++");
- yearIncrease->addToProperty(m_clockDisplay, "currentTime",
- TimePeriod().setYears(1));
+ yearIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setYears(1));
year->addTransition(m_buttonD, SIGNAL(pressed()), yearIncrease);
yearIncrease->addTransition(year);
year->addTransition(m_buttonC, SIGNAL(pressed()), m_timeState);
@@ -305,6 +309,8 @@ void Clock::initializeDisplaysState(QState *displays)
wait->invokeMethodOnEntry(waitTimer, "start");
wait->invokeMethodOnExit(waitTimer, "stop");
+ m_displaysHistoryState = displays->addHistoryState(QState::DeepHistory);
+
m_timeState->addTransition(m_buttonC, SIGNAL(pressed()), wait);
wait->addTransition(waitTimer, SIGNAL(timeout()), m_updateState);
wait->addTransition(m_buttonC, SIGNAL(released()), m_timeState);
@@ -324,7 +330,7 @@ void Clock::initializeAlarmState(QState *alarmState)
QHistoryState *history = alarmState->addHistoryState();
history->setObjectName("alarmHistory");
- history->setDefaultState(onState);
+ history->setDefaultState(offState);
offState->addTransition(m_buttonD, SIGNAL(pressed()), onState);
onState->addTransition(m_buttonD, SIGNAL(pressed()), offState);
@@ -371,12 +377,14 @@ void Clock::updateTime()
void Clock::playSound()
{
+ qDebug("playing sound");
m_alarmSound->stop();
m_alarmSound->play();
}
void Clock::stopSound()
{
+ qDebug("stopping sound");
m_alarmSound->stop();
}
diff --git a/examples/statemachine/citizenquartz/clock.h b/examples/statemachine/citizenquartz/clock.h
index aee1b55..afd6433 100644
--- a/examples/statemachine/citizenquartz/clock.h
+++ b/examples/statemachine/citizenquartz/clock.h
@@ -10,6 +10,7 @@ class QStateMachine ;
class QState ;
class QTimerState ;
class QSound ;
+class QHistoryState ;
class Clock: public QObject, public QGraphicsItem
{
@@ -25,7 +26,6 @@ public:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
signals:
- void alarm();
void anyButtonPressed();
public slots:
@@ -53,6 +53,8 @@ private:
QState *m_updateState;
QState *m_regularState;
+ QHistoryState *m_displaysHistoryState;
+
QSound *m_alarmSound;
QTime m_time;
};
diff --git a/examples/statemachine/citizenquartz/clockdisplay.cpp b/examples/statemachine/citizenquartz/clockdisplay.cpp
index 717b881..db026f5 100644
--- a/examples/statemachine/citizenquartz/clockdisplay.cpp
+++ b/examples/statemachine/citizenquartz/clockdisplay.cpp
@@ -124,8 +124,7 @@ QRectF ClockDisplay::boundingRect() const
void ClockDisplay::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
- if (m_alarmEnabled)
- m_alarmSymbol->setVisible(true);
+ m_alarmSymbol->setVisible(m_alarmEnabled);
updateText();
diff --git a/examples/statemachine/citizenquartz/clockdisplay.h b/examples/statemachine/citizenquartz/clockdisplay.h
index e0ac8bb..ec86509 100644
--- a/examples/statemachine/citizenquartz/clockdisplay.h
+++ b/examples/statemachine/citizenquartz/clockdisplay.h
@@ -42,7 +42,13 @@ public:
DisplayMode displayMode() const { return m_displayMode; }
QDateTime currentTime() const { return m_currentTime; }
- void setCurrentTime(const QDateTime &time) { m_currentTime = time; update(); }
+ void setCurrentTime(const QDateTime &time)
+ {
+ if (m_alarmEnabled && !alarmMatches(m_currentTime) && alarmMatches(time))
+ emit alarmTriggered();
+ m_currentTime = time;
+ update();
+ }
QTime alarm() const { return m_alarm; }
void setAlarm(const QTime &time) { m_alarm = time; update(); }
@@ -53,12 +59,20 @@ public:
virtual QRectF boundingRect() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
+signals:
+ void alarmTriggered();
+
private slots:
void toggleBlinkFlag();
private:
void updateText();
+ bool alarmMatches(const QDateTime &dt)
+ {
+ return (dt.time().hour() == m_alarm.hour() && dt.time().minute() == m_alarm.minute());
+ }
+
DisplayMode m_displayMode;
QDateTime m_currentTime;
diff --git a/examples/statemachine/citizenquartz/propertyaddstate.cpp b/examples/statemachine/citizenquartz/propertyaddstate.cpp
index f129c8d..dd23948 100644
--- a/examples/statemachine/citizenquartz/propertyaddstate.cpp
+++ b/examples/statemachine/citizenquartz/propertyaddstate.cpp
@@ -37,7 +37,7 @@ void PropertyAddState::onEntry()
{
foreach (PropertyAdder propertyAdder, m_propertyAdditions) {
QObject *object = propertyAdder.object;
- const char *propertyName = propertyAdder.propertyName;
+ QByteArray propertyName = propertyAdder.propertyName;
QVariant toAdd = propertyAdder.valueToAdd;
QVariant current = object->property(propertyName);
diff --git a/examples/statemachine/citizenquartz/propertyaddstate.h b/examples/statemachine/citizenquartz/propertyaddstate.h
index 96f45fc..4d28055 100644
--- a/examples/statemachine/citizenquartz/propertyaddstate.h
+++ b/examples/statemachine/citizenquartz/propertyaddstate.h
@@ -24,7 +24,7 @@ private:
}
QObject *object;
- const char *propertyName;
+ QByteArray propertyName;
QVariant valueToAdd;
};
QList<PropertyAdder> m_propertyAdditions;
diff --git a/examples/statemachine/citizenquartz/timeperiod.h b/examples/statemachine/citizenquartz/timeperiod.h
index a64c17c..c5a3a16 100644
--- a/examples/statemachine/citizenquartz/timeperiod.h
+++ b/examples/statemachine/citizenquartz/timeperiod.h
@@ -76,7 +76,7 @@ inline QTime operator+(const QTime &time, const TimePeriod &timePeriod)
QTime result(time);
result += timePeriod;
- return time;
+ return result;
}
Q_DECLARE_METATYPE(TimePeriod)
diff --git a/examples/statemachine/clockticking/main.cpp b/examples/statemachine/clockticking/main.cpp
index e903988..5501e2c 100644
--- a/examples/statemachine/clockticking/main.cpp
+++ b/examples/statemachine/clockticking/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -14,7 +44,7 @@
#ifdef QT_STATEMACHINE_SOLUTION
#include <qstatemachine.h>
#include <qstate.h>
-#include <qtransition.h>
+#include <qabstracttransition.h>
#endif
class ClockEvent : public QEvent
diff --git a/examples/statemachine/composition/main.cpp b/examples/statemachine/composition/main.cpp
index 892542d..24b823c 100644
--- a/examples/statemachine/composition/main.cpp
+++ b/examples/statemachine/composition/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -26,8 +56,8 @@ int main(int argc, char **argv)
QState *s1 = new QState();
s1->setObjectName("s1");
- s1->setPropertyOnEntry(&label, "text", "In S1, hang on...");
- s1->setPropertyOnEntry(&label, "geometry", QRect(100, 100, 200, 100));
+ s1->assignProperty(&label, "text", "In S1, hang on...");
+ s1->assignProperty(&label, "geometry", QRect(100, 100, 200, 100));
QState *s1_timer = new QState(s1);
s1_timer->setObjectName("s1_timer");
@@ -41,8 +71,8 @@ int main(int argc, char **argv)
QState *s2 = new QState();
s2->setObjectName("s2");
- s2->setPropertyOnEntry(&label, "text", "In S2, I'm gonna quit on you...");
- s2->setPropertyOnEntry(&label, "geometry", QRect(300, 300, 300, 100));
+ s2->assignProperty(&label, "text", "In S2, I'm gonna quit on you...");
+ s2->assignProperty(&label, "geometry", QRect(300, 300, 300, 100));
// s2->invokeMethodOnEntry(&label, "setNum", QList<QVariant>() << 123);
// s2->invokeMethodOnEntry(&label, "showMaximized");
diff --git a/examples/statemachine/eventtransitions/main.cpp b/examples/statemachine/eventtransitions/main.cpp
index 51b2d82..f564b7e 100644
--- a/examples/statemachine/eventtransitions/main.cpp
+++ b/examples/statemachine/eventtransitions/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -28,10 +58,10 @@ public:
QStateMachine *machine = new QStateMachine(this);
QState *s1 = new QState();
- s1->setPropertyOnEntry(button, "text", "Outside");
+ s1->assignProperty(button, "text", "Outside");
QState *s2 = new QState();
- s2->setPropertyOnEntry(button, "text", "Inside");
+ s2->assignProperty(button, "text", "Inside");
QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
enterTransition->setTargetState(s2);
@@ -42,7 +72,7 @@ public:
s2->addTransition(leaveTransition);
QState *s3 = new QState();
- s3->setPropertyOnEntry(button, "text", "Pressing...");
+ s3->assignProperty(button, "text", "Pressing...");
QEventTransition *pressTransition = new QEventTransition(button, QEvent::MouseButtonPress);
pressTransition->setTargetState(s3);
diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp
index 985b09f..9e39ced 100644
--- a/examples/statemachine/factorial/main.cpp
+++ b/examples/statemachine/factorial/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -124,7 +154,7 @@ int main(int argc, char **argv)
computing->addTransition(doneTransition);
QState *initialize = new QState(machine.rootState());
- initialize->setPropertyOnEntry(&factorial, "x", 6);
+ initialize->assignProperty(&factorial, "x", 6);
FactorialLoopTransition *enterLoopTransition = new FactorialLoopTransition(&factorial);
enterLoopTransition->setTargetState(computing);
initialize->addTransition(enterLoopTransition);
diff --git a/examples/statemachine/helloworld/main.cpp b/examples/statemachine/helloworld/main.cpp
index a124623..13486d4 100644
--- a/examples/statemachine/helloworld/main.cpp
+++ b/examples/statemachine/helloworld/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
diff --git a/examples/statemachine/pauseandresume/main.cpp b/examples/statemachine/pauseandresume/main.cpp
index 7aed84b..e0ebbff 100644
--- a/examples/statemachine/pauseandresume/main.cpp
+++ b/examples/statemachine/pauseandresume/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp
index d749076..00ff643 100644
--- a/examples/statemachine/pingpong/main.cpp
+++ b/examples/statemachine/pingpong/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -14,7 +44,7 @@
#ifdef QT_STATEMACHINE_SOLUTION
#include <qstate.h>
#include <qstatemachine.h>
-#include <qtransition.h>
+#include <qabstracttransition.h>
#endif
class PingEvent : public QEvent
diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
index fbb6b68..528ed00 100644
--- a/examples/statemachine/trafficlight/main.cpp
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -35,6 +65,10 @@ public:
update();
}
+public slots:
+ void turnOff() { setOn(false); }
+ void turnOn() { setOn(true); }
+
protected:
virtual void paintEvent(QPaintEvent *)
{
@@ -63,9 +97,9 @@ public:
timer->setInterval(duration);
timer->setSingleShot(true);
QState *timing = new QState(this);
- timing->setPropertyOnEntry(light, "on", true);
+ timing->invokeMethodOnEntry(light, "turnOn");
timing->invokeMethodOnEntry(timer, "start");
- timing->setPropertyOnExit(light, "on", false);
+ timing->invokeMethodOnExit(light, "turnOff");
QFinalState *done = new QFinalState(this);
timing->addTransition(timer, SIGNAL(timeout()), done);
setInitialState(timing);
diff --git a/examples/statemachine/twowaybutton/main.cpp b/examples/statemachine/twowaybutton/main.cpp
index eab0b3d..61a0f32 100644
--- a/examples/statemachine/twowaybutton/main.cpp
+++ b/examples/statemachine/twowaybutton/main.cpp
@@ -3,9 +3,39 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the $MODULE$ of the Qt Toolkit.
+** This file is part of the QtCore module of the Qt Toolkit.
**
-** $TROLLTECH_DUAL_LICENSE$
+** $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$
**
****************************************************************************/
@@ -26,13 +56,13 @@ int main(int argc, char **argv)
first->setObjectName("first");
QState *off = new QState();
- off->setPropertyOnEntry(&button, "text", "Off");
+ off->assignProperty(&button, "text", "Off");
off->setObjectName("off");
first->addTransition(off);
QState *on = new QState();
on->setObjectName("on");
- on->setPropertyOnEntry(&button, "text", "On");
+ on->assignProperty(&button, "text", "On");
off->addTransition(&button, SIGNAL(clicked()), on);
on->addTransition(&button, SIGNAL(clicked()), off);