From a35824a3319ae9c304263185c4efc449e2c2cf73 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 4 Apr 2011 11:27:54 +0200 Subject: added simple pacman animation --- pacman-c++/animationmanager.cpp | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pacman-c++/animationmanager.cpp (limited to 'pacman-c++/animationmanager.cpp') diff --git a/pacman-c++/animationmanager.cpp b/pacman-c++/animationmanager.cpp new file mode 100644 index 0000000..69bec53 --- /dev/null +++ b/pacman-c++/animationmanager.cpp @@ -0,0 +1,56 @@ +#include "animationmanager.h" +#include +#include + +// the universe's only animation manager +AnimationManager *AnimationManager::instance = 0; + +AnimationManager::AnimationManager() +{ +} + +AnimationManager *AnimationManager::self() +{ + if (!instance) + instance = new AnimationManager; + return instance; +} + +void AnimationManager::registerAnimation(QAbstractAnimation *anim) +{ + QObject::connect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); + animations.append(anim); +} + +void AnimationManager::unregisterAnimation_helper(QObject *obj) +{ + unregisterAnimation(static_cast(obj)); +} + +void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) +{ + QObject::disconnect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); + animations.removeAll(anim); +} + +void AnimationManager::unregisterAllAnimations() +{ + animations.clear(); +} + +void AnimationManager::pauseAll() +{ + foreach (QAbstractAnimation* animation, animations) + { + if (animation->state() == QAbstractAnimation::Running) + animation->pause(); + } +} +void AnimationManager::resumeAll() +{ + foreach (QAbstractAnimation* animation, animations) + { + if (animation->state() == QAbstractAnimation::Paused) + animation->resume(); + } +} -- cgit v1.2.3