diff options
Diffstat (limited to 'pacman-c++/animationmanager.cpp')
| -rw-r--r-- | pacman-c++/animationmanager.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
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 @@ | |||
| 1 | #include "animationmanager.h" | ||
| 2 | #include <QtCore/QAbstractAnimation> | ||
| 3 | #include <QtCore/QDebug> | ||
| 4 | |||
| 5 | // the universe's only animation manager | ||
| 6 | AnimationManager *AnimationManager::instance = 0; | ||
| 7 | |||
| 8 | AnimationManager::AnimationManager() | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | AnimationManager *AnimationManager::self() | ||
| 13 | { | ||
| 14 | if (!instance) | ||
| 15 | instance = new AnimationManager; | ||
| 16 | return instance; | ||
| 17 | } | ||
| 18 | |||
| 19 | void AnimationManager::registerAnimation(QAbstractAnimation *anim) | ||
| 20 | { | ||
| 21 | QObject::connect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); | ||
| 22 | animations.append(anim); | ||
| 23 | } | ||
| 24 | |||
| 25 | void AnimationManager::unregisterAnimation_helper(QObject *obj) | ||
| 26 | { | ||
| 27 | unregisterAnimation(static_cast<QAbstractAnimation*>(obj)); | ||
| 28 | } | ||
| 29 | |||
| 30 | void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) | ||
| 31 | { | ||
| 32 | QObject::disconnect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); | ||
| 33 | animations.removeAll(anim); | ||
| 34 | } | ||
| 35 | |||
| 36 | void AnimationManager::unregisterAllAnimations() | ||
| 37 | { | ||
| 38 | animations.clear(); | ||
| 39 | } | ||
| 40 | |||
| 41 | void AnimationManager::pauseAll() | ||
| 42 | { | ||
| 43 | foreach (QAbstractAnimation* animation, animations) | ||
| 44 | { | ||
| 45 | if (animation->state() == QAbstractAnimation::Running) | ||
| 46 | animation->pause(); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | void AnimationManager::resumeAll() | ||
| 50 | { | ||
| 51 | foreach (QAbstractAnimation* animation, animations) | ||
| 52 | { | ||
| 53 | if (animation->state() == QAbstractAnimation::Paused) | ||
| 54 | animation->resume(); | ||
| 55 | } | ||
| 56 | } | ||
