diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-12-07 14:15:36 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-01-06 17:08:03 +0000 |
commit | 8cf812231405e011b422a1505d9a219618fe5cee (patch) | |
tree | 99603ff6fd301dfbdc8104fd0b470d3b9aa3262c /examples/widgets/animation/sub-attaq | |
parent | cf27d9e8a5e14ebe083f4b0fa2204d0646e7ed5e (diff) |
Cleanup Widgets examples - new signal/slot syntax
Cleanup the Widget examples - use the new signal/slot syntax where
possible - animation, effects and graphicsview subdirectory
Change-Id: I6cbaea6e628eb06f8e0ca6a0b795030a66b83878
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'examples/widgets/animation/sub-attaq')
-rw-r--r-- | examples/widgets/animation/sub-attaq/animationmanager.cpp | 4 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/boat.cpp | 10 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/bomb.cpp | 10 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/graphicsscene.cpp | 18 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/qanimationstate.cpp | 6 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/states.cpp | 12 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/submarine.cpp | 12 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/submarine_p.h | 3 | ||||
-rw-r--r-- | examples/widgets/animation/sub-attaq/torpedo.cpp | 10 |
9 files changed, 43 insertions, 42 deletions
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.cpp b/examples/widgets/animation/sub-attaq/animationmanager.cpp index b6e399967f..62dac7852a 100644 --- a/examples/widgets/animation/sub-attaq/animationmanager.cpp +++ b/examples/widgets/animation/sub-attaq/animationmanager.cpp @@ -71,7 +71,7 @@ AnimationManager *AnimationManager::self() void AnimationManager::registerAnimation(QAbstractAnimation *anim) { - QObject::connect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); + QObject::connect(anim, &QObject::destroyed, this, &AnimationManager::unregisterAnimation_helper); animations.append(anim); } @@ -82,7 +82,7 @@ void AnimationManager::unregisterAnimation_helper(QObject *obj) void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) { - QObject::disconnect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); + QObject::disconnect(anim, &QObject::destroyed, this, &AnimationManager::unregisterAnimation_helper); animations.removeAll(anim); } diff --git a/examples/widgets/animation/sub-attaq/boat.cpp b/examples/widgets/animation/sub-attaq/boat.cpp index 145d373e99..9f4feba2ec 100644 --- a/examples/widgets/animation/sub-attaq/boat.cpp +++ b/examples/widgets/animation/sub-attaq/boat.cpp @@ -148,8 +148,8 @@ Boat::Boat() : PixmapItem(QString("boat"), GraphicsScene::Big), stopState->addTransition(leftMoveStop); //The animation is finished, it means we reached the border of the screen, the boat is stopped so we move to the stop state - moveStateLeft->addTransition(movementAnimation, SIGNAL(finished()), stopState); - moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState); + moveStateLeft->addTransition(movementAnimation, &QAbstractAnimation::finished, stopState); + moveStateRight->addTransition(movementAnimation, &QAbstractAnimation::finished, stopState); //We set up the keys for dropping bombs KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); @@ -187,13 +187,13 @@ Boat::Boat() : PixmapItem(QString("boat"), GraphicsScene::Big), destroyedState->setAnimation(destroyAnimation); //Play a nice animation when the boat is destroyed - moving->addTransition(this, SIGNAL(boatDestroyed()), destroyedState); + moving->addTransition(this, &Boat::boatDestroyed, destroyedState); //Transition to final state when the destroyed animation is finished - destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); + destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final); //The machine has finished to be executed, then the boat is dead - connect(machine,SIGNAL(finished()), this, SIGNAL(boatExecutionFinished())); + connect(machine,&QState::finished, this, &Boat::boatExecutionFinished); } diff --git a/examples/widgets/animation/sub-attaq/bomb.cpp b/examples/widgets/animation/sub-attaq/bomb.cpp index a80d2d46c5..76e4575293 100644 --- a/examples/widgets/animation/sub-attaq/bomb.cpp +++ b/examples/widgets/animation/sub-attaq/bomb.cpp @@ -83,8 +83,8 @@ void Bomb::launch(Bomb::Direction direction) anim->setEndValue(QPointF(x() + delta*2,scene()->height())); anim->setDuration(y()/2*60); launchAnimation->addAnimation(anim); - connect(anim,SIGNAL(valueChanged(QVariant)),this,SLOT(onAnimationLaunchValueChanged(QVariant))); - connect(this, SIGNAL(bombExploded()), launchAnimation, SLOT(stop())); + connect(anim,&QVariantAnimation::valueChanged,this,&Bomb::onAnimationLaunchValueChanged); + connect(this, &Bomb::bombExploded, launchAnimation, &QAbstractAnimation::stop); //We setup the state machine of the bomb QStateMachine *machine = new QStateMachine(this); @@ -98,13 +98,13 @@ void Bomb::launch(Bomb::Direction direction) machine->setInitialState(launched); //### Add a nice animation when the bomb is destroyed - launched->addTransition(this, SIGNAL(bombExploded()),final); + launched->addTransition(this, &Bomb::bombExploded,final); //If the animation is finished, then we move to the final state - launched->addTransition(launched, SIGNAL(animationFinished()), final); + launched->addTransition(launched, &QAnimationState::animationFinished, final); //The machine has finished to be executed, then the boat is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished())); + connect(machine,&QState::finished,this, &Bomb::bombExecutionFinished); machine->start(); diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.cpp b/examples/widgets/animation/sub-attaq/graphicsscene.cpp index e0913f99f6..3205cdc54d 100644 --- a/examples/widgets/animation/sub-attaq/graphicsscene.cpp +++ b/examples/widgets/animation/sub-attaq/graphicsscene.cpp @@ -191,15 +191,15 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction) 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); + lettersMovingState->addTransition(newAction, &QAction::triggered, lettersFadingState); + lettersFadingState->addTransition(lettersFadingState, &QAnimationState::animationFinished, gameState); //New Game is triggered then player start playing - gameState->addTransition(newAction, SIGNAL(triggered()), gameState); + gameState->addTransition(newAction, &QAction::triggered, gameState); //Wanna quit, then connect to CTRL+Q - gameState->addTransition(quitAction, SIGNAL(triggered()), final); - lettersMovingState->addTransition(quitAction, SIGNAL(triggered()), final); + gameState->addTransition(quitAction, &QAction::triggered, final); + lettersMovingState->addTransition(quitAction, &QAction::triggered, final); //Welcome screen is the initial state machine->setInitialState(lettersMovingState); @@ -207,27 +207,27 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction) machine->start(); //We reach the final state, then we quit - connect(machine, SIGNAL(finished()), qApp, SLOT(quit())); + connect(machine, &QStateMachine::finished, qApp, &QApplication::quit); } void GraphicsScene::addItem(Bomb *bomb) { bombs.insert(bomb); - connect(bomb,SIGNAL(bombExecutionFinished()),this, SLOT(onBombExecutionFinished())); + connect(bomb,&Bomb::bombExecutionFinished,this, &GraphicsScene::onBombExecutionFinished); QGraphicsScene::addItem(bomb); } void GraphicsScene::addItem(Torpedo *torpedo) { torpedos.insert(torpedo); - connect(torpedo,SIGNAL(torpedoExecutionFinished()),this, SLOT(onTorpedoExecutionFinished())); + connect(torpedo,&Torpedo::torpedoExecutionFinished,this, &GraphicsScene::onTorpedoExecutionFinished); QGraphicsScene::addItem(torpedo); } void GraphicsScene::addItem(SubMarine *submarine) { submarines.insert(submarine); - connect(submarine,SIGNAL(subMarineExecutionFinished()),this, SLOT(onSubMarineExecutionFinished())); + connect(submarine,&SubMarine::subMarineExecutionFinished,this, &GraphicsScene::onSubMarineExecutionFinished); QGraphicsScene::addItem(submarine); } diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.cpp b/examples/widgets/animation/sub-attaq/qanimationstate.cpp index ae24af6da3..fc0da7cea2 100644 --- a/examples/widgets/animation/sub-attaq/qanimationstate.cpp +++ b/examples/widgets/animation/sub-attaq/qanimationstate.cpp @@ -73,7 +73,7 @@ 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); +s->addTransition(s, &QAnimationState::animationFinished, s2); machine.start(); \endcode @@ -107,13 +107,13 @@ void QAnimationState::setAnimation(QAbstractAnimation *animation) //Disconnect from the previous animation if exist if(m_animation) - disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); + disconnect(m_animation, &QAbstractAnimation::finished, this, &QAnimationState::animationFinished); m_animation = animation; if (m_animation) { //connect the new animation - connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); + connect(m_animation, &QAbstractAnimation::finished, this, &QAnimationState::animationFinished); } } diff --git a/examples/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp index e19704db7b..8a3a97a20f 100644 --- a/examples/widgets/animation/sub-attaq/states.cpp +++ b/examples/widgets/animation/sub-attaq/states.cpp @@ -124,7 +124,7 @@ void PlayState::onEntry(QEvent *) WinState *winState = new WinState(scene, this, machine); //The boat has been destroyed then the game is finished - levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState); + levelState->addTransition(scene->boat, &Boat::boatExecutionFinished,lostState); //This transition check if we won or not WinTransition *winTransition = new WinTransition(scene, this, winState); @@ -157,7 +157,7 @@ void PlayState::onEntry(QEvent *) winState->addTransition(spaceTransition); //We lost we should reach the final state - lostState->addTransition(lostState, SIGNAL(finished()), final); + lostState->addTransition(lostState, &QState::finished, final); machine->start(); } @@ -291,8 +291,8 @@ UpdateScoreState::UpdateScoreState(QState *parent) : QState(parent) /** Win transition */ UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) - : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int))), - game(game), scene(scene) + : QSignalTransition(scene, &GraphicsScene::subMarineDestroyed), + game(game), scene(scene) { setTargetState(target); } @@ -309,8 +309,8 @@ bool UpdateScoreTransition::eventTest(QEvent *event) /** Win transition */ WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) - : QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int))), - game(game), scene(scene) + : QSignalTransition(scene, &GraphicsScene::allSubMarineDestroyed), + game(game), scene(scene) { setTargetState(target); } diff --git a/examples/widgets/animation/sub-attaq/submarine.cpp b/examples/widgets/animation/sub-attaq/submarine.cpp index a451185ce0..775e75ceed 100644 --- a/examples/widgets/animation/sub-attaq/submarine.cpp +++ b/examples/widgets/animation/sub-attaq/submarine.cpp @@ -106,7 +106,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt //This is the initial state of the moving root state moving->setInitialState(movement); - movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving); + movement->addTransition(this, &SubMarine::subMarineStateChanged, moving); //This is the initial state of the machine machine->setInitialState(moving); @@ -115,23 +115,23 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt QFinalState *final = new QFinalState(machine); //If the moving animation is finished we move to the return state - movement->addTransition(movement, SIGNAL(animationFinished()), rotation); + movement->addTransition(movement, &QAnimationState::animationFinished, rotation); //If the return animation is finished we move to the moving state - rotation->addTransition(rotation, SIGNAL(animationFinished()), movement); + rotation->addTransition(rotation, &QAnimationState::animationFinished, movement); //This state play the destroyed animation QAnimationState *destroyedState = new QAnimationState(machine); destroyedState->setAnimation(setupDestroyAnimation(this)); //Play a nice animation when the submarine is destroyed - moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState); + moving->addTransition(this, &SubMarine::subMarineDestroyed, destroyedState); //Transition to final state when the destroyed animation is finished - destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); + destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final); //The machine has finished to be executed, then the submarine is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished())); + connect(machine,&QState::finished,this, &SubMarine::subMarineExecutionFinished); machine->start(); } diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h index 698b4b494f..1c2cb7ceac 100644 --- a/examples/widgets/animation/sub-attaq/submarine_p.h +++ b/examples/widgets/animation/sub-attaq/submarine_p.h @@ -80,7 +80,8 @@ public: explicit MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) { movementAnimation = new QPropertyAnimation(submarine, "pos"); - connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &))); + connect(movementAnimation, &QPropertyAnimation::valueChanged, + this, &MovementState::onAnimationMovementValueChanged); setAnimation(movementAnimation); AnimationManager::self()->registerAnimation(movementAnimation); this->submarine = submarine; diff --git a/examples/widgets/animation/sub-attaq/torpedo.cpp b/examples/widgets/animation/sub-attaq/torpedo.cpp index 2e9d970326..5f8ef2f2b8 100644 --- a/examples/widgets/animation/sub-attaq/torpedo.cpp +++ b/examples/widgets/animation/sub-attaq/torpedo.cpp @@ -73,8 +73,8 @@ void Torpedo::launch() launchAnimation->setEndValue(QPointF(x(),qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15)); launchAnimation->setEasingCurve(QEasingCurve::InQuad); launchAnimation->setDuration(y()/currentSpeed*10); - connect(launchAnimation,SIGNAL(valueChanged(QVariant)),this,SLOT(onAnimationLaunchValueChanged(QVariant))); - connect(this,SIGNAL(torpedoExploded()), launchAnimation, SLOT(stop())); + connect(launchAnimation,&QVariantAnimation::valueChanged,this,&Torpedo::onAnimationLaunchValueChanged); + connect(this,&Torpedo::torpedoExploded, launchAnimation, &QAbstractAnimation::stop); //We setup the state machine of the torpedo QStateMachine *machine = new QStateMachine(this); @@ -89,13 +89,13 @@ void Torpedo::launch() machine->setInitialState(launched); //### Add a nice animation when the torpedo is destroyed - launched->addTransition(this, SIGNAL(torpedoExploded()),final); + launched->addTransition(this, &Torpedo::torpedoExploded,final); //If the animation is finished, then we move to the final state - launched->addTransition(launched, SIGNAL(animationFinished()), final); + launched->addTransition(launched, &QAnimationState::animationFinished, final); //The machine has finished to be executed, then the boat is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished())); + connect(machine,&QState::finished,this, &Torpedo::torpedoExecutionFinished); machine->start(); } |