sort out the API a bit and don't have private classes that are named the same
svn path=/trunk/KDE/kdelibs/; revision=1038220
This commit is contained in:
parent
5b9120cae1
commit
b29d0a79aa
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "abstractanimation.h"
|
#include "abstractanimation.h"
|
||||||
#include "private/animationprivate_p.h"
|
#include "private/abstractanimationprivate_p.h"
|
||||||
|
|
||||||
#include <QEasingCurve>
|
#include <QEasingCurve>
|
||||||
|
|
||||||
@ -26,7 +26,8 @@ namespace Plasma
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
AbstractAnimation::AbstractAnimation(): d(new AnimationPrivate)
|
AbstractAnimation::AbstractAnimation()
|
||||||
|
: d(new AbstractAnimationPrivate)
|
||||||
{
|
{
|
||||||
d->easingCurve = QEasingCurve::Linear;
|
d->easingCurve = QEasingCurve::Linear;
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ void AbstractAnimation::setWidget(QGraphicsWidget* receiver)
|
|||||||
d->animObject = receiver;
|
d->animObject = receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsWidget* AbstractAnimation::getAnimatedObject()
|
QGraphicsWidget* AbstractAnimation::animatedObject()
|
||||||
{
|
{
|
||||||
return d->animObject;
|
return d->animObject;
|
||||||
}
|
}
|
||||||
@ -86,11 +87,6 @@ bool AbstractAnimation::animationVisible() const
|
|||||||
return d->animVisible;
|
return d->animVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationPrivate* AbstractAnimation::getAnimationPrivate()
|
|
||||||
{
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
} //namespace Plasma
|
} //namespace Plasma
|
||||||
|
|
||||||
#include <../abstractanimation.moc>
|
#include <../abstractanimation.moc>
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class AnimationPrivate;
|
class AbstractAnimationPrivate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for AnimationGroup and Animation.
|
* Abstract base class for AnimationGroup and Animation.
|
||||||
@ -119,14 +119,10 @@ public slots:
|
|||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QGraphicsWidget *animatedObject();
|
||||||
QGraphicsWidget *getAnimatedObject();
|
|
||||||
|
|
||||||
AnimationPrivate *getAnimationPrivate();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AbstractAnimationPrivate *d;
|
||||||
AnimationPrivate *d;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace Plasma
|
} //namespace Plasma
|
||||||
|
@ -47,8 +47,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Animation::Animation(QObject* parent)
|
Animation::Animation(QObject* parent)
|
||||||
|
: d(new AnimationPrivate)
|
||||||
{
|
{
|
||||||
d = new AnimationPrivate;
|
|
||||||
d->m_parent = parent;
|
d->m_parent = parent;
|
||||||
d->m_duration = 250;
|
d->m_duration = 250;
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ void Animation::start()
|
|||||||
QAbstractAnimation* Animation::toQAbstractAnimation(QObject* parent)
|
QAbstractAnimation* Animation::toQAbstractAnimation(QObject* parent)
|
||||||
{
|
{
|
||||||
//check if .setObject() was done
|
//check if .setObject() was done
|
||||||
if (!getAnimatedObject()) {
|
if (!animatedObject()) {
|
||||||
kDebug() << "Object not set.";
|
kDebug() << "Object not set.";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ QAbstractAnimation* Animation::toQAbstractAnimation(QObject* parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Animation::getDuration()
|
int Animation::duration() const
|
||||||
{
|
{
|
||||||
return d->m_duration;
|
return d->m_duration;
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,11 @@ protected:
|
|||||||
* Get the animation duration.
|
* Get the animation duration.
|
||||||
* @return duration in ms.
|
* @return duration in ms.
|
||||||
*/
|
*/
|
||||||
int getDuration();
|
int duration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
AnimationPrivate *d;
|
AnimationPrivate * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace Plasma
|
} //namespace Plasma
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "expand.h"
|
#include "expand.h"
|
||||||
#include "private/animationprivate_p.h"
|
|
||||||
|
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
@ -28,35 +27,33 @@ namespace Plasma
|
|||||||
|
|
||||||
ExpandAnimation::ExpandAnimation(AnimationDirection direction, qreal distance)
|
ExpandAnimation::ExpandAnimation(AnimationDirection direction, qreal distance)
|
||||||
{
|
{
|
||||||
AnimationPrivate *obj = getAnimationPrivate();
|
setAnimationDirection(direction);
|
||||||
obj->animDirection = direction;
|
setAnimationDistance(distance);
|
||||||
obj->animDistance = distance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractAnimation* ExpandAnimation::render(QObject* parent){
|
QAbstractAnimation* ExpandAnimation::render(QObject* parent){
|
||||||
|
|
||||||
//get current geometry values
|
//get current geometry values
|
||||||
QGraphicsWidget *m_object = getAnimatedObject();
|
QGraphicsWidget *m_object = animatedObject();
|
||||||
QRectF geometry = m_object->geometry();
|
QRectF geometry = m_object->geometry();
|
||||||
AnimationPrivate *obj = getAnimationPrivate();
|
|
||||||
|
|
||||||
//compute new geometry values
|
//compute new geometry values
|
||||||
switch (obj->animDirection) {
|
switch (animationDirection()) {
|
||||||
|
|
||||||
case MoveUp:
|
case MoveUp:
|
||||||
geometry.setTop(geometry.y() - obj->animDistance);
|
geometry.setTop(geometry.y() - animationDistance());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveRight:
|
case MoveRight:
|
||||||
geometry.setRight(geometry.x() + geometry.width() - 1 + obj->animDistance);
|
geometry.setRight(geometry.x() + geometry.width() - 1 + animationDistance());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveDown:
|
case MoveDown:
|
||||||
geometry.setBottom(geometry.y() + geometry.height() - 1 + obj->animDistance);
|
geometry.setBottom(geometry.y() + geometry.height() - 1 + animationDistance());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveLeft:
|
case MoveLeft:
|
||||||
geometry.setLeft(geometry.x() - obj->animDistance);
|
geometry.setLeft(geometry.x() - animationDistance());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveUpRight:
|
case MoveUpRight:
|
||||||
@ -69,12 +66,11 @@ QAbstractAnimation* ExpandAnimation::render(QObject* parent){
|
|||||||
//create animation
|
//create animation
|
||||||
QPropertyAnimation* anim = new QPropertyAnimation(m_object, "geometry", parent);
|
QPropertyAnimation* anim = new QPropertyAnimation(m_object, "geometry", parent);
|
||||||
anim->setEndValue(geometry);
|
anim->setEndValue(geometry);
|
||||||
anim->setDuration(getDuration());
|
anim->setDuration(duration());
|
||||||
|
|
||||||
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||||
|
|
||||||
return anim;
|
return anim;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace Plasma
|
} //namespace Plasma
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "fade.h"
|
#include "fade.h"
|
||||||
#include "private/animationprivate_p.h"
|
|
||||||
|
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
@ -27,25 +26,17 @@ namespace Plasma
|
|||||||
{
|
{
|
||||||
|
|
||||||
FadeAnimation::FadeAnimation(qreal factor)
|
FadeAnimation::FadeAnimation(qreal factor)
|
||||||
|
: m_animFactor(qBound(qreal(0.0), factor, qreal(1.0)))
|
||||||
{
|
{
|
||||||
AnimationPrivate *obj = getAnimationPrivate();
|
|
||||||
obj->animFactor = factor;
|
|
||||||
if (obj->animFactor > 1.0) {
|
|
||||||
kDebug() << "Opacity must be between 0 and 1.0. Reducing to 1.0.";
|
|
||||||
obj->animFactor = 1.0;
|
|
||||||
} else if (obj->animFactor < 0) {
|
|
||||||
kDebug() << "Opacity must be between 0 and 1.0. Increasing to 0.";
|
|
||||||
obj->animFactor = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractAnimation* FadeAnimation::render(QObject* parent){
|
QAbstractAnimation* FadeAnimation::render(QObject* parent){
|
||||||
|
|
||||||
//create animation
|
//create animation
|
||||||
QGraphicsWidget *m_object = getAnimatedObject();
|
QGraphicsWidget *m_object = animatedObject();
|
||||||
QPropertyAnimation* anim = new QPropertyAnimation(m_object, "opacity", parent);
|
QPropertyAnimation* anim = new QPropertyAnimation(m_object, "opacity", parent);
|
||||||
anim->setEndValue(getAnimationPrivate()->animFactor);
|
anim->setEndValue(m_animFactor);
|
||||||
anim->setDuration(getDuration());
|
anim->setDuration(duration());
|
||||||
|
|
||||||
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace Plasma
|
|||||||
*
|
*
|
||||||
* Effect that slowly transforms the opacity of the object to the given value.
|
* Effect that slowly transforms the opacity of the object to the given value.
|
||||||
*/
|
*/
|
||||||
class PLASMA_EXPORT FadeAnimation : public Animation
|
class FadeAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -47,6 +47,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual QAbstractAnimation* render(QObject* parent = 0);
|
virtual QAbstractAnimation* render(QObject* parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
qreal m_animFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "grow.h"
|
#include "grow.h"
|
||||||
#include "private/animationprivate_p.h"
|
|
||||||
|
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
@ -27,20 +26,20 @@ namespace Plasma
|
|||||||
{
|
{
|
||||||
|
|
||||||
GrowAnimation::GrowAnimation(qreal factor)
|
GrowAnimation::GrowAnimation(qreal factor)
|
||||||
|
: m_animFactor(factor)
|
||||||
{
|
{
|
||||||
getAnimationPrivate()->animFactor = factor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractAnimation* GrowAnimation::render(QObject* parent){
|
QAbstractAnimation* GrowAnimation::render(QObject* parent){
|
||||||
|
|
||||||
//get current geometry values
|
//get current geometry values
|
||||||
QGraphicsWidget *m_object = getAnimatedObject();
|
QGraphicsWidget *m_object = animatedObject();
|
||||||
QRectF geometry = m_object->geometry();
|
QRectF geometry = m_object->geometry();
|
||||||
qreal w = geometry.width();
|
qreal w = geometry.width();
|
||||||
qreal h = geometry.height();
|
qreal h = geometry.height();
|
||||||
|
|
||||||
//compute new geometry values
|
//compute new geometry values
|
||||||
qreal factor = getAnimationPrivate()->animFactor;
|
qreal factor = m_animFactor;
|
||||||
qreal newWidth = w * factor;
|
qreal newWidth = w * factor;
|
||||||
qreal newHeight = h * factor;
|
qreal newHeight = h * factor;
|
||||||
//locfactor is factor by which object must move up and left
|
//locfactor is factor by which object must move up and left
|
||||||
@ -55,7 +54,7 @@ QAbstractAnimation* GrowAnimation::render(QObject* parent){
|
|||||||
anim->setEndValue(QRectF(
|
anim->setEndValue(QRectF(
|
||||||
newX, newY,
|
newX, newY,
|
||||||
newWidth, newHeight));
|
newWidth, newHeight));
|
||||||
anim->setDuration(getDuration());
|
anim->setDuration(duration());
|
||||||
|
|
||||||
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ namespace Plasma
|
|||||||
* constructor. The center of the object stays in place while the sides grow.
|
* constructor. The center of the object stays in place while the sides grow.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PLASMA_EXPORT GrowAnimation : public Animation
|
class GrowAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -50,6 +50,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual QAbstractAnimation* render(QObject* parent = 0);
|
virtual QAbstractAnimation* render(QObject* parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
qreal m_animFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ PulseAnimation::~PulseAnimation()
|
|||||||
|
|
||||||
void PulseAnimation::setCopy(QGraphicsWidget *copy)
|
void PulseAnimation::setCopy(QGraphicsWidget *copy)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *target = getAnimatedObject();
|
QGraphicsWidget *target = animatedObject();
|
||||||
d->under = copy;
|
d->under = copy;
|
||||||
if (d->under != target) {
|
if (d->under != target) {
|
||||||
d->under->setParentItem(target);
|
d->under->setParentItem(target);
|
||||||
@ -116,7 +116,7 @@ void PulseAnimation::resetPulser()
|
|||||||
|
|
||||||
void PulseAnimation::createAnimation(qreal duration, qreal scale)
|
void PulseAnimation::createAnimation(qreal duration, qreal scale)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *target = getAnimatedObject();
|
QGraphicsWidget *target = animatedObject();
|
||||||
/* Fallback to parent widget if we don't have one 'shadow' widget */
|
/* Fallback to parent widget if we don't have one 'shadow' widget */
|
||||||
if (!d->under) {
|
if (!d->under) {
|
||||||
setCopy(target);
|
setCopy(target);
|
||||||
|
@ -91,7 +91,7 @@ void RotationAnimation::setAngle(const qreal &angle)
|
|||||||
QPropertyAnimation *RotationAnimation::render(QObject *parent)
|
QPropertyAnimation *RotationAnimation::render(QObject *parent)
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
QGraphicsWidget *m_object = getAnimatedObject();
|
QGraphicsWidget *m_object = animatedObject();
|
||||||
|
|
||||||
QVector3D vector(0, 0, 0);
|
QVector3D vector(0, 0, 0);
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent)
|
|||||||
QPropertyAnimation *rotationAnimation= new QPropertyAnimation(d->rotation,
|
QPropertyAnimation *rotationAnimation= new QPropertyAnimation(d->rotation,
|
||||||
"angle", m_object);
|
"angle", m_object);
|
||||||
rotationAnimation->setEndValue(d->angle);
|
rotationAnimation->setEndValue(d->angle);
|
||||||
rotationAnimation->setDuration(getDuration());
|
rotationAnimation->setDuration(duration());
|
||||||
|
|
||||||
return rotationAnimation;
|
return rotationAnimation;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "slide.h"
|
#include "slide.h"
|
||||||
#include "private/animationprivate_p.h"
|
|
||||||
|
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
@ -28,38 +27,35 @@ namespace Plasma
|
|||||||
|
|
||||||
SlideAnimation::SlideAnimation(AnimationDirection direction, qreal distance)
|
SlideAnimation::SlideAnimation(AnimationDirection direction, qreal distance)
|
||||||
{
|
{
|
||||||
AnimationPrivate *obj = getAnimationPrivate();
|
setAnimationDirection(direction);
|
||||||
obj->animDirection = direction;
|
setAnimationDistance(distance);
|
||||||
obj->animDistance = distance;
|
setAnimationVisible(true);
|
||||||
obj->animVisible = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractAnimation* SlideAnimation::render(QObject* parent)
|
QAbstractAnimation* SlideAnimation::render(QObject* parent)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *m_object = getAnimatedObject();
|
QGraphicsWidget *m_object = animatedObject();
|
||||||
qreal x = m_object->x();
|
qreal x = m_object->x();
|
||||||
qreal y = m_object->y();
|
qreal y = m_object->y();
|
||||||
|
|
||||||
qreal newX = x;
|
qreal newX = x;
|
||||||
qreal newY = y;
|
qreal newY = y;
|
||||||
|
|
||||||
AnimationPrivate *obj = getAnimationPrivate();
|
switch (animationDirection()) {
|
||||||
switch (obj->animDirection) {
|
|
||||||
|
|
||||||
case MoveUp:
|
case MoveUp:
|
||||||
newY = y - obj->animDistance;
|
newY = y - animationDistance();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveRight:
|
case MoveRight:
|
||||||
newX = x + obj->animDistance;
|
newX = x + animationDistance();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveDown:
|
case MoveDown:
|
||||||
newY = y + obj->animDistance;
|
newY = y + animationDistance();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveLeft:
|
case MoveLeft:
|
||||||
newX = x - obj->animDistance;
|
newX = x - animationDistance();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveUpRight:
|
case MoveUpRight:
|
||||||
@ -67,18 +63,17 @@ QAbstractAnimation* SlideAnimation::render(QObject* parent)
|
|||||||
case MoveDownLeft:
|
case MoveDownLeft:
|
||||||
case MoveUpLeft:
|
case MoveUpLeft:
|
||||||
/* TODO: support compound directions */
|
/* TODO: support compound directions */
|
||||||
kDebug() << "Compound directions (UpRight, DownRight, DownLeft, \
|
kDebug() << "Compound directions (UpRight, DownRight, DownLeft, UpLeft) are not supported";
|
||||||
UpLeft) are not supported\n";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPropertyAnimation* anim = new QPropertyAnimation(m_object, "pos", parent);
|
QPropertyAnimation* anim = new QPropertyAnimation(m_object, "pos", parent);
|
||||||
anim->setEndValue(QPointF(newX, newY));
|
anim->setEndValue(QPointF(newX, newY));
|
||||||
anim->setDuration(getDuration());
|
anim->setDuration(duration());
|
||||||
|
|
||||||
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||||
|
|
||||||
if (obj->animVisible) {
|
if (animationVisible()) {
|
||||||
QObject::connect(anim, SIGNAL(finished()), m_object, SLOT(show()));
|
QObject::connect(anim, SIGNAL(finished()), m_object, SLOT(show()));
|
||||||
} else {
|
} else {
|
||||||
QObject::connect(anim, SIGNAL(finished()), m_object, SLOT(hide()));
|
QObject::connect(anim, SIGNAL(finished()), m_object, SLOT(hide()));
|
||||||
@ -90,7 +85,7 @@ UpLeft) are not supported\n";
|
|||||||
|
|
||||||
void SlideAnimation::setVisibleAtEnd(bool visibility)
|
void SlideAnimation::setVisibleAtEnd(bool visibility)
|
||||||
{
|
{
|
||||||
getAnimationPrivate()->animVisible = visibility;
|
setAnimationVisible(visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace Plasma
|
} //namespace Plasma
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class AnimationPrivate
|
class AbstractAnimationPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -34,12 +34,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
QGraphicsWidget* animObject;
|
QGraphicsWidget* animObject;
|
||||||
|
|
||||||
/**
|
|
||||||
* Animation factor: its meaning depends on the animation class
|
|
||||||
* (e.g. opacity in FadeAnimation, scale in GrowAnimation, etc)
|
|
||||||
*/
|
|
||||||
qreal animFactor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animation direction: where the animation will move.
|
* Animation direction: where the animation will move.
|
||||||
*/
|
*/
|
Loading…
Reference in New Issue
Block a user