* asQAnimation (i still wonder if that's the best of names or even strictly needed?)

* coding style

svn path=/trunk/KDE/kdelibs/; revision=1036121
This commit is contained in:
Aaron J. Seigo 2009-10-16 16:36:22 +00:00
parent 82cf1ef3fb
commit cbb1a5e686
8 changed files with 72 additions and 64 deletions

View File

@ -22,15 +22,18 @@
namespace Plasma
{
AbstractAnimation::AbstractAnimation(){
AbstractAnimation::AbstractAnimation()
{
}
AbstractAnimation::~AbstractAnimation(){
AbstractAnimation::~AbstractAnimation()
{
}
void AbstractAnimation::setWidget(QGraphicsWidget* receiver){
void AbstractAnimation::setWidget(QGraphicsWidget* receiver)
{
m_object = receiver;
}

View File

@ -58,7 +58,7 @@ public:
* Take an AbstractAnimation and turn it into a
* QAbstractAnimation.
*/
virtual QAbstractAnimation* getQtAnimation(QObject* parent) = 0;
virtual QAbstractAnimation* asQAnimation(QObject* parent) = 0;
public slots:

View File

@ -59,27 +59,29 @@ Animation::~Animation()
delete d;
}
void Animation::setDuration(int duration){
void Animation::setDuration(int duration)
{
d->m_duration = duration;
}
void Animation::start(){
QAbstractAnimation* anim = getQtAnimation(d->m_parent);
if (anim){
void Animation::start()
{
QAbstractAnimation* anim = asQAnimation(d->m_parent);
if (anim) {
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
}
QAbstractAnimation* Animation::getQtAnimation(QObject* parent){
QAbstractAnimation* Animation::asQAnimation(QObject* parent)
{
//check if .setObject() was done
if (!getAnimatedObject()){
if (!getAnimatedObject()) {
kDebug() << "Object not set.";
return NULL;
}
//check which parent to use
if (parent){
if (parent) {
return render(parent);
} else {
return render(d->m_parent);
@ -87,10 +89,9 @@ QAbstractAnimation* Animation::getQtAnimation(QObject* parent){
}
int Animation::getDuration() {
int Animation::getDuration()
{
return d->m_duration;
}
} //namespace Plasma

View File

@ -60,7 +60,7 @@ public:
* NULL on error. This function just does some boilerplate checking and then
* calls render().
*/
QAbstractAnimation* getQtAnimation(QObject* parent = 0);
QAbstractAnimation* asQAnimation(QObject* parent = 0);
protected:

View File

@ -32,43 +32,49 @@ AnimationGroup::AnimationGroup(QObject* parent)
{
}
AnimationGroup::~AnimationGroup(){
AnimationGroup::~AnimationGroup()
{
}
void AnimationGroup::setParallel(bool parallelness){
void AnimationGroup::setParallel(bool parallelness)
{
m_parallel = parallelness;
}
bool AnimationGroup::isParallel() const{
bool AnimationGroup::isParallel() const
{
return m_parallel;
}
int AnimationGroup::add(AbstractAnimation* elem){
int AnimationGroup::add(AbstractAnimation* elem)
{
anims.insert(anims.count(), elem);
return anims.count();
}
AbstractAnimation* AnimationGroup::at(int id) const{
AbstractAnimation* AnimationGroup::at(int id) const
{
return anims[id];
}
void AnimationGroup::remove(int id){
void AnimationGroup::remove(int id)
{
anims.removeAt(id);
}
void AnimationGroup::start(){
QAbstractAnimation* anim = getQtAnimation(m_parent);
void AnimationGroup::start()
{
QAbstractAnimation* anim = asQAnimation(m_parent);
if (anim){
/* FIXME: why to create and delete all the animations
* every single time it runs?
*/
/* FIXME: why to create and delete all the animations
* every single time it runs?
*/
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
}
QAnimationGroup* AnimationGroup::getQtAnimation(QObject* parent){
QAnimationGroup* AnimationGroup::asQAnimation(QObject* parent)
{
//if supplied, use parent given in args.
QObject* correctParent;
if (parent){
@ -78,7 +84,7 @@ QAnimationGroup* AnimationGroup::getQtAnimation(QObject* parent){
}
QAnimationGroup* g;
if(m_parallel){
if (m_parallel) {
g = new QParallelAnimationGroup(correctParent);
} else {
g = new QSequentialAnimationGroup(correctParent);
@ -87,7 +93,7 @@ QAnimationGroup* AnimationGroup::getQtAnimation(QObject* parent){
QListIterator<AbstractAnimation*> it(anims);
while (it.hasNext()) {
//add with group as owner
g->addAnimation(it.next()->getQtAnimation(g));
g->addAnimation(it.next()->asQAnimation(g));
}
return g;

View File

@ -92,7 +92,7 @@ public:
* specifically, a QSerialAnimation or QParallelAnimation depending on
* the value of m_parallel at the time of invocation. Returns NULL on error.
*/
QAnimationGroup* getQtAnimation(QObject* parent = 0);
QAnimationGroup* asQAnimation(QObject* parent = 0);
private:

View File

@ -31,10 +31,15 @@
namespace Plasma
{
PulseAnimation::PulseAnimation(): animation(0),
under(0), pulseGeometry(0),
zvalue(0), mscale(0),
anim1(0), anim2(0), anim3(0)
PulseAnimation::PulseAnimation()
: animation(0),
under(0),
pulseGeometry(0),
zvalue(0),
mscale(0),
opacityAnimation(0),
geometryAnimation(0),
scaleAnimation(0)
{
}
@ -72,13 +77,8 @@ void PulseAnimation::updateGeometry(QRectF updated, qreal zCoordinate, qreal sca
QRectF initial(under->geometry());
qreal W = initial.width() * scale * 0.33;
qreal H = initial.height() * scale * 0.33;
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
initial.height() * scale);
anim2->setEndValue(end);
anim2->setEndValue(end);
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale, initial.height() * scale);
geometryAnimation->setEndValue(end);
}
void PulseAnimation::resetPulser()
@ -93,31 +93,32 @@ void PulseAnimation::resetPulser()
void PulseAnimation::createAnimation(qreal duration, qreal scale)
{
/* Fallback to parent widget if we don't have one 'shadow' widget */
if (!under)
setCopy(getAnimatedObject());
if (!under) {
setCopy(getAnimatedObject());
}
pulseGeometry = new QRectF(under->geometry());
QParallelAnimationGroup *group = new QParallelAnimationGroup(this);
anim1 = new QPropertyAnimation(under, "opacity");
anim1->setDuration(duration);
anim1->setEndValue(0);
group->addAnimation(anim1);
opacityAnimation = new QPropertyAnimation(under, "opacity");
opacityAnimation->setDuration(duration);
opacityAnimation->setEndValue(0);
group->addAnimation(opacityAnimation);
/* TODO: move this to a function */
anim2 = new QPropertyAnimation(under, "geometry");
anim2->setDuration(duration);
geometryAnimation = new QPropertyAnimation(under, "geometry");
geometryAnimation->setDuration(duration);
QRectF initial(under->geometry());
qreal W = initial.width() * scale * 0.33;
qreal H = initial.height() * scale * 0.33;
QRectF end(initial.x() - W, initial.y() - H, initial.width() * scale,
initial.height() * scale);
anim2->setEndValue(end);
group->addAnimation(anim2);
geometryAnimation->setEndValue(end);
group->addAnimation(geometryAnimation);
anim3 = new QPropertyAnimation(under, "scale");
anim3->setDuration(duration);
anim3->setEndValue(scale);
group->addAnimation(anim3);
scaleAnimation = new QPropertyAnimation(under, "scale");
scaleAnimation->setDuration(duration);
scaleAnimation->setEndValue(scale);
group->addAnimation(scaleAnimation);
animation = group;
@ -139,7 +140,4 @@ void PulseAnimation::start()
animation->start();
}
} //namespace Plasma

View File

@ -47,14 +47,14 @@ protected:
virtual QAbstractAnimation* render(QObject* parent = 0);
private:
void createAnimation(qreal _duration = 500, qreal _scale = 1.5);
QAbstractAnimation *animation;
QGraphicsWidget *under;
QRectF *pulseGeometry;
qreal zvalue, mscale;
QPropertyAnimation *anim1, *anim2, *anim3;
QPropertyAnimation *opacityAnimation;
QPropertyAnimation *geometryAnimation;
QPropertyAnimation *scaleAnimation;
};
}