* use the qobject parent system instead of tracking it ourselves

svn path=/trunk/KDE/kdelibs/; revision=1038329
This commit is contained in:
Aaron J. Seigo 2009-10-21 04:15:52 +00:00
parent 27dbf07aec
commit 2a524aae11
2 changed files with 46 additions and 42 deletions

View File

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

View File

@ -36,26 +36,22 @@
namespace Plasma
{
class AnimationGroupPrivate;
/**
* @brief A group of Animations and / or AnimationGroups.
* @since 4.4
*/
class PLASMA_EXPORT AnimationGroup : public AbstractAnimation
{
Q_OBJECT
Q_PROPERTY(bool parallel READ isParallel WRITE setParallel)
public:
AnimationGroup(QObject* parent = 0);
virtual ~AnimationGroup();
/**
* Start the animation.
*/
virtual void start();
/**
* @arg parallelness whether the animation should be in parallel or not
*/
@ -92,23 +88,14 @@ public:
*/
QAnimationGroup* toQAbstractAnimation(QObject* parent = 0);
public Q_SLOTS:
/**
* Start the animation.
*/
virtual void start();
private:
/**
* Parent owner object to use in generated animations.
*/
QObject* m_parent;
/**
* Boolean determining if the animation is parallel. Default is false.
*/
bool m_parallel;
/**
* Map of AbstractAnimations to be run, by id.
*/
QList<AbstractAnimation *> anims;
AnimationGroupPrivate * const d;
};