diff options
Diffstat (limited to 'examples')
19 files changed, 34 insertions, 474 deletions
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp index fe4be1f..97751b2 100644 --- a/examples/animation/appchooser/main.cpp +++ b/examples/animation/appchooser/main.cpp @@ -134,7 +134,7 @@ int main(int argc, char **argv) QStateMachine machine; machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties); - QState *group = new QState(machine.rootState()); + QState *group = new QState(&machine); group->setObjectName("group"); QRect selectedRect(86, 86, 128, 128); diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp index c43e841..97d3f81 100644 --- a/examples/animation/moveblocks/main.cpp +++ b/examples/animation/moveblocks/main.cpp @@ -108,8 +108,7 @@ class StateSwitcher : public QState Q_OBJECT public: StateSwitcher(QStateMachine *machine) - : QState(machine->rootState()), m_machine(machine), - m_stateCount(0), m_lastIndex(0) + : QState(machine), m_stateCount(0), m_lastIndex(0) { } //![10] @@ -120,7 +119,7 @@ public: while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex) { } m_lastIndex = n; - m_machine->postEvent(new StateSwitchEvent(n)); + machine()->postEvent(new StateSwitchEvent(n)); } virtual void onExit(QEvent *) {} //![11] @@ -135,7 +134,6 @@ public: //![12] private: - QStateMachine *m_machine; int m_stateCount; int m_lastIndex; }; diff --git a/examples/animation/states/main.cpp b/examples/animation/states/main.cpp index b3c28f2..99e04c3 100644 --- a/examples/animation/states/main.cpp +++ b/examples/animation/states/main.cpp @@ -124,10 +124,9 @@ int main(int argc, char *argv[]) scene.addItem(p6); QStateMachine machine; - QState *root = machine.rootState(); - QState *state1 = new QState(root); - QState *state2 = new QState(root); - QState *state3 = new QState(root); + QState *state1 = new QState(&machine); + QState *state2 = new QState(&machine); + QState *state3 = new QState(&machine); machine.setInitialState(state1); // State 1 diff --git a/examples/animation/stickman/editor/animationdialog.cpp b/examples/animation/stickman/editor/animationdialog.cpp deleted file mode 100644 index 853046d..0000000 --- a/examples/animation/stickman/editor/animationdialog.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#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); -} diff --git a/examples/animation/stickman/editor/animationdialog.h b/examples/animation/stickman/editor/animationdialog.h deleted file mode 100644 index 293f0d4..0000000 --- a/examples/animation/stickman/editor/animationdialog.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANIMATIONDIALOG_H -#define ANIMATIONDIALOG_H - -#include <QDialog> -#include <QMessageBox> - -QT_BEGIN_NAMESPACE -class QSpinBox; -class QLineEdit; -QT_END_NAMESPACE -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 deleted file mode 100644 index 7ad9edb..0000000 --- a/examples/animation/stickman/editor/editor.pri +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index e1d08cc..0000000 --- a/examples/animation/stickman/editor/mainwindow.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#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 deleted file mode 100644 index ef122d9..0000000 --- a/examples/animation/stickman/editor/mainwindow.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#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 760c31b..89f2430 100644 --- a/examples/animation/stickman/graphicsview.cpp +++ b/examples/animation/stickman/graphicsview.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "graphicsview.h" -#include "editor/mainwindow.h" #include "stickman.h" #include <QtGui/QKeyEvent> @@ -53,28 +52,6 @@ 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/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp index 2a54c82..c761d87 100644 --- a/examples/animation/stickman/lifecycle.cpp +++ b/examples/animation/stickman/lifecycle.cpp @@ -108,11 +108,11 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver) m_machine->addDefaultAnimation(m_animationGroup); //! [3] - m_alive = new QState(m_machine->rootState()); + m_alive = new QState(m_machine); m_alive->setObjectName("alive"); // Make it blink when lightning strikes before entering dead animation - QState *lightningBlink = new QState(m_machine->rootState()); + QState *lightningBlink = new QState(m_machine); lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white); lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black); lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white); @@ -126,7 +126,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver) QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop())); //! [5] - m_dead = new QState(m_machine->rootState()); + m_dead = new QState(m_machine); 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); diff --git a/examples/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro index 1dbbce9..7f8be33 100644 --- a/examples/animation/stickman/stickman.pro +++ b/examples/animation/stickman/stickman.pro @@ -12,8 +12,6 @@ SOURCES += main.cpp \ INCLUDEPATH += $$PWD -include(editor/editor.pri) - # install target.path = $$[QT_INSTALL_EXAMPLES]/animation/stickman sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stickman.pro diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp index d286be5..68e646e 100644 --- a/examples/animation/sub-attaq/boat.cpp +++ b/examples/animation/sub-attaq/boat.cpp @@ -142,14 +142,14 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags) //We setup the state machien of the boat machine = new QStateMachine(this); - QState *moving = new QState(machine->rootState()); + QState *moving = new QState(machine); StopState *stopState = new StopState(this, moving); machine->setInitialState(moving); moving->setInitialState(stopState); MoveStateRight *moveStateRight = new MoveStateRight(this, moving); MoveStateLeft *moveStateLeft = new MoveStateLeft(this, moving); - LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine->rootState()); - LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine->rootState()); + LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine); + LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine); //then setup the transitions for the rightMove state KeyStopTransition *leftStopRight = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Left); @@ -216,10 +216,10 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags) launchStateLeft->addTransition(historyState); launchStateRight->addTransition(historyState); - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); //This state play the destroyed animation - QAnimationState *destroyedState = new QAnimationState(machine->rootState()); + QAnimationState *destroyedState = new QAnimationState(machine); destroyedState->setAnimation(destroyAnimation); //Play a nice animation when the boat is destroyed diff --git a/examples/animation/sub-attaq/bomb.cpp b/examples/animation/sub-attaq/bomb.cpp index 454970a..e92a723 100644 --- a/examples/animation/sub-attaq/bomb.cpp +++ b/examples/animation/sub-attaq/bomb.cpp @@ -85,11 +85,11 @@ void Bomb::launch(Bomb::Direction direction) QStateMachine *machine = new QStateMachine(this); //This state is when the launch animation is playing - QAnimationState *launched = new QAnimationState(machine->rootState()); + QAnimationState *launched = new QAnimationState(machine); launched->setAnimation(launchAnimation); //End - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); machine->setInitialState(launched); diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp index bd37ce2..fcbc1b3 100644 --- a/examples/animation/sub-attaq/graphicsscene.cpp +++ b/examples/animation/sub-attaq/graphicsscene.cpp @@ -230,17 +230,17 @@ void GraphicsScene::setupScene(const QList<QAction *> &actions) QStateMachine *machine = new QStateMachine(this); //This state is when the player is playing - PlayState *gameState = new PlayState(this,machine->rootState()); + PlayState *gameState = new PlayState(this,machine); //Final state - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); //Animation when the player enter in the game - QAnimationState *lettersMovingState = new QAnimationState(machine->rootState()); + QAnimationState *lettersMovingState = new QAnimationState(machine); lettersMovingState->setAnimation(lettersGroupMoving); //Animation when the welcome screen disappear - QAnimationState *lettersFadingState = new QAnimationState(machine->rootState()); + QAnimationState *lettersFadingState = new QAnimationState(machine); lettersFadingState->setAnimation(lettersGroupFading); //if new game then we fade out the welcome screen and start playing diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp index 81fd2de..d63737f 100644 --- a/examples/animation/sub-attaq/states.cpp +++ b/examples/animation/sub-attaq/states.cpp @@ -83,7 +83,7 @@ void PlayState::onEntry(QEvent *) machine = new QStateMachine(this); //This state is when player is playing - LevelState *levelState = new LevelState(scene, this, machine->rootState()); + LevelState *levelState = new LevelState(scene, this, machine); //This state is when the player is actually playing but the game is not paused QState *playingState = new QState(levelState); @@ -105,10 +105,10 @@ void PlayState::onEntry(QEvent *) pauseState->addTransition(pressPpause); //This state is when player have lost - LostState *lostState = new LostState(scene, this, machine->rootState()); + LostState *lostState = new LostState(scene, this, machine); //This state is when player have won - WinState *winState = new WinState(scene, this, machine->rootState()); + WinState *winState = new WinState(scene, this, machine); //The boat has been destroyed then the game is finished levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState); @@ -136,7 +136,7 @@ void PlayState::onEntry(QEvent *) machine->setInitialState(levelState); //Final state - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); //This transition is triggered when the player press space after completing a level CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space); diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp index 04b7916..78a9539 100644 --- a/examples/animation/sub-attaq/submarine.cpp +++ b/examples/animation/sub-attaq/submarine.cpp @@ -115,7 +115,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * QStateMachine *machine = new QStateMachine(this); //This state is when the boat is moving/rotating - QState *moving = new QState(machine->rootState()); + QState *moving = new QState(machine); //This state is when the boat is moving from left to right MovementState *movement = new MovementState(this, moving); @@ -132,7 +132,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * machine->setInitialState(moving); //End - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); //If the moving animation is finished we move to the return state movement->addTransition(movement, SIGNAL(animationFinished()), rotation); @@ -141,7 +141,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * rotation->addTransition(rotation, SIGNAL(animationFinished()), movement); //This state play the destroyed animation - QAnimationState *destroyedState = new QAnimationState(machine->rootState()); + QAnimationState *destroyedState = new QAnimationState(machine); destroyedState->setAnimation(setupDestroyAnimation(this)); //Play a nice animation when the submarine is destroyed diff --git a/examples/animation/sub-attaq/torpedo.cpp b/examples/animation/sub-attaq/torpedo.cpp index 5ef237a..fe79488 100644 --- a/examples/animation/sub-attaq/torpedo.cpp +++ b/examples/animation/sub-attaq/torpedo.cpp @@ -74,11 +74,11 @@ void Torpedo::launch() QStateMachine *machine = new QStateMachine(this); //This state is when the launch animation is playing - QAnimationState *launched = new QAnimationState(machine->rootState()); + QAnimationState *launched = new QAnimationState(machine); launched->setAnimation(launchAnimation); //End - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); machine->setInitialState(launched); diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp index 18a9521..5050347 100644 --- a/examples/statemachine/factorial/main.cpp +++ b/examples/statemachine/factorial/main.cpp @@ -151,14 +151,14 @@ int main(int argc, char **argv) //! [3] //! [4] - QState *compute = new QState(machine.rootState()); + QState *compute = new QState(&machine); compute->assignProperty(&factorial, "fac", 1); compute->assignProperty(&factorial, "x", 6); compute->addTransition(new FactorialLoopTransition(&factorial)); //! [4] //! [5] - QFinalState *done = new QFinalState(machine.rootState()); + QFinalState *done = new QFinalState(&machine); FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial); doneTransition->setTargetState(done); compute->addTransition(doneTransition); diff --git a/examples/statemachine/tankgame/mainwindow.cpp b/examples/statemachine/tankgame/mainwindow.cpp index 68a8d68..596cdfe 100644 --- a/examples/statemachine/tankgame/mainwindow.cpp +++ b/examples/statemachine/tankgame/mainwindow.cpp @@ -160,7 +160,7 @@ void MainWindow::init() connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); m_machine = new QStateMachine(this); - QState *stoppedState = new QState(m_machine->rootState()); + QState *stoppedState = new QState(m_machine); stoppedState->setObjectName("stoppedState"); stoppedState->assignProperty(runGameAction, "enabled", true); stoppedState->assignProperty(stopGameAction, "enabled", false); @@ -188,14 +188,14 @@ void MainWindow::init() stoppedState->setInitialState(hs); //! [0] - m_runningState = new QState(QState::ParallelStates, m_machine->rootState()); + m_runningState = new QState(QState::ParallelStates, m_machine); //! [0] m_runningState->setObjectName("runningState"); m_runningState->assignProperty(addTankAction, "enabled", false); m_runningState->assignProperty(runGameAction, "enabled", false); m_runningState->assignProperty(stopGameAction, "enabled", true); - QState *gameOverState = new QState(m_machine->rootState()); + QState *gameOverState = new QState(m_machine); gameOverState->setObjectName("gameOverState"); gameOverState->assignProperty(stopGameAction, "enabled", false); connect(gameOverState, SIGNAL(entered()), this, SLOT(gameOver())); |