plasma-framework/animations/animationgroup.cpp
Aaron J. Seigo a1d93d4118 one more go at this method name; i don't think it will be in the public API anyways
svn path=/trunk/KDE/kdelibs/; revision=1036265
2009-10-16 21:27:35 +00:00

105 lines
2.4 KiB
C++

/*
* 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)
{
}
AnimationGroup::~AnimationGroup()
{
}
void AnimationGroup::setParallel(bool parallelness)
{
m_parallel = parallelness;
}
bool AnimationGroup::isParallel() const
{
return m_parallel;
}
int AnimationGroup::add(AbstractAnimation* elem)
{
anims.insert(anims.count(), elem);
return anims.count();
}
AbstractAnimation* AnimationGroup::at(int id) const
{
return anims[id];
}
void AnimationGroup::remove(int id)
{
anims.removeAt(id);
}
void AnimationGroup::start()
{
QAbstractAnimation* anim = toQAbstractAnimation(m_parent);
if (anim){
/* FIXME: why to create and delete all the animations
* every single time it runs?
*/
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
}
QAnimationGroup* AnimationGroup::toQAbstractAnimation(QObject* parent)
{
//if supplied, use parent given in args.
QObject* correctParent;
if (parent){
correctParent = parent;
} else {
correctParent = m_parent;
}
QAnimationGroup* g;
if (m_parallel) {
g = new QParallelAnimationGroup(correctParent);
} else {
g = new QSequentialAnimationGroup(correctParent);
}
QListIterator<AbstractAnimation*> it(anims);
while (it.hasNext()) {
//add with group as owner
g->addAnimation(it.next()->toQAbstractAnimation(g));
}
return g;
}
} //namespace Plasma
#include <../animationgroup.moc>