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
|
|
|
|
{
|
|
|
|
|
2009-10-21 06:15:52 +02:00
|
|
|
class AnimationGroupPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Boolean determining if the animation is parallel. Default is false.
|
|
|
|
*/
|
|
|
|
bool parallel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map of AbstractAnimations to be run, by id.
|
|
|
|
*/
|
|
|
|
QList<AbstractAnimation *> anims;
|
|
|
|
};
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
AnimationGroup::AnimationGroup(QObject* parent)
|
2009-10-21 06:15:52 +02:00
|
|
|
: AbstractAnimation(parent),
|
|
|
|
d(new AnimationGroupPrivate)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
d->parallel = false;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
AnimationGroup::~AnimationGroup()
|
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
delete d;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
void AnimationGroup::setParallel(bool parallelness)
|
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
d->parallel = parallelness;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
bool AnimationGroup::isParallel() const
|
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
return d->parallel;
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
int AnimationGroup::add(AbstractAnimation* elem)
|
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
d->anims.insert(d->anims.count(), elem);
|
|
|
|
return d->anims.count();
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 09:51:11 +02:00
|
|
|
void AnimationGroup::remove(Plasma::AbstractAnimation* elem)
|
|
|
|
{
|
|
|
|
d->anims.removeAll(elem);
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
AbstractAnimation* AnimationGroup::at(int id) const
|
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
return d->anims.value(id);
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-16 18:36:22 +02:00
|
|
|
void AnimationGroup::remove(int id)
|
|
|
|
{
|
2009-10-21 06:15:52 +02:00
|
|
|
if (id >= d->anims.count() || id < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->anims.removeAt(id);
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
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.
|
2009-10-21 06:15:52 +02:00
|
|
|
if (!parent){
|
|
|
|
parent = this->parent();
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QAnimationGroup* g;
|
2009-10-21 06:15:52 +02:00
|
|
|
if (d->parallel) {
|
|
|
|
g = new QParallelAnimationGroup(parent);
|
2009-10-15 21:36:38 +02:00
|
|
|
} else {
|
2009-10-21 06:15:52 +02:00
|
|
|
g = new QSequentialAnimationGroup(parent);
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 06:15:52 +02:00
|
|
|
QListIterator<AbstractAnimation*> it(d->anims);
|
2009-10-15 21:36:38 +02:00
|
|
|
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>
|