2009-10-15 21:36:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "animationgroup.h"
|
|
|
|
|
|
|
|
#include <QMapIterator>
|
|
|
|
#include <QParallelAnimationGroup>
|
|
|
|
#include <QSequentialAnimationGroup>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
AnimationGroup::AnimationGroup(QObject* parent)
|
|
|
|
: m_parent(parent),
|
|
|
|
m_parallel(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
AnimationGroup::~AnimationGroup()
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
void AnimationGroup::setParallel(bool parallelness)
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
m_parallel = parallelness;
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
bool AnimationGroup::isParallel() const
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
return m_parallel;
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
int AnimationGroup::add(AbstractAnimation* elem)
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
anims.insert(anims.count(), elem);
|
|
|
|
return anims.count();
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
AbstractAnimation* AnimationGroup::at(int id) const
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
return anims[id];
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
void AnimationGroup::remove(int id)
|
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
anims.removeAt(id);
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
void AnimationGroup::start()
|
|
|
|
{
|
2009-10-16 23:27:35 +02:00
|
|
|
QAbstractAnimation* anim = toQAbstractAnimation(m_parent);
|
2009-10-15 21:36:38 +02:00
|
|
|
if (anim){
|
2009-10-16 18:36:22 +02:00
|
|
|
/* FIXME: why to create and delete all the animations
|
|
|
|
* every single time it runs?
|
|
|
|
*/
|
2009-10-15 21:36:38 +02:00
|
|
|
anim->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 23:27:35 +02:00
|
|
|
QAnimationGroup* AnimationGroup::toQAbstractAnimation(QObject* parent)
|
2009-10-16 18:36:22 +02:00
|
|
|
{
|
2009-10-15 21:36:38 +02:00
|
|
|
//if supplied, use parent given in args.
|
|
|
|
QObject* correctParent;
|
|
|
|
if (parent){
|
|
|
|
correctParent = parent;
|
|
|
|
} else {
|
|
|
|
correctParent = m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAnimationGroup* g;
|
2009-10-16 18:36:22 +02:00
|
|
|
if (m_parallel) {
|
2009-10-15 21:36:38 +02:00
|
|
|
g = new QParallelAnimationGroup(correctParent);
|
|
|
|
} else {
|
|
|
|
g = new QSequentialAnimationGroup(correctParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
QListIterator<AbstractAnimation*> it(anims);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
//add with group as owner
|
2009-10-16 23:27:35 +02:00
|
|
|
g->addAnimation(it.next()->toQAbstractAnimation(g));
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|
|
|
|
#include <../animationgroup.moc>
|