+Add slideIn slideDown animation in plasma
Mail me if you want a simple applet wich use this animation svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=684432
This commit is contained in:
parent
6c736f91e0
commit
fee185b328
12
animator.cpp
12
animator.cpp
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
||||||
|
* 2007 Alexis Ménard <darktears31@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
@ -19,6 +20,7 @@
|
|||||||
#include "animator.h"
|
#include "animator.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -43,7 +45,7 @@ int Animator::framesPerSecond(Plasma::Phase::Animation animation)
|
|||||||
int Animator::framesPerSecond(Plasma::Phase::Movement movement)
|
int Animator::framesPerSecond(Plasma::Phase::Movement movement)
|
||||||
{
|
{
|
||||||
Q_UNUSED(movement)
|
Q_UNUSED(movement)
|
||||||
return 5;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Animator::framesPerSecond(Plasma::Phase::ElementAnimation animation)
|
int Animator::framesPerSecond(Plasma::Phase::ElementAnimation animation)
|
||||||
@ -109,12 +111,16 @@ void Animator::frameAppear(qreal frame, QGraphicsItem* item, const QRegion& draw
|
|||||||
|
|
||||||
void Animator::slideIn(qreal progress, QGraphicsItem* item, QPoint destination)
|
void Animator::slideIn(qreal progress, QGraphicsItem* item, QPoint destination)
|
||||||
{
|
{
|
||||||
//TODO: implement
|
kDebug()<<k_funcinfo<<endl;
|
||||||
|
Q_UNUSED(progress);
|
||||||
|
item->translate(-destination.x(),-destination.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animator::slideOut(qreal progress, QGraphicsItem* item, QPoint destination)
|
void Animator::slideOut(qreal progress, QGraphicsItem* item, QPoint destination)
|
||||||
{
|
{
|
||||||
//TODO: implement
|
Q_UNUSED(progress);
|
||||||
|
//kDebug()<<k_funcinfo<<endl;
|
||||||
|
item->translate(destination.x(),destination.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animator::renderBackground(QImage& background)
|
void Animator::renderBackground(QImage& background)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
||||||
|
* 2007 Alexis Ménard <darktears31@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
|
89
phase.cpp
89
phase.cpp
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
||||||
|
* 2007 Alexis Ménard <darktears31@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
@ -103,7 +104,17 @@ class Phase::Private
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void performMovement(qreal amount, const MovementState* state)
|
||||||
|
{
|
||||||
|
switch (state->movement) {
|
||||||
|
case Phase::SlideIn:
|
||||||
|
animator->slideIn(amount, state->item, state->destination);
|
||||||
|
break;
|
||||||
|
case Phase::SlideOut:
|
||||||
|
animator->slideOut(amount, state->item,state->destination);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
Animator* animator;
|
Animator* animator;
|
||||||
int animId;
|
int animId;
|
||||||
int timerId;
|
int timerId;
|
||||||
@ -167,6 +178,7 @@ void Phase::appletDestroyed(QObject* o)
|
|||||||
|
|
||||||
void Phase::animateItem(QGraphicsItem* item, Animation animation)
|
void Phase::animateItem(QGraphicsItem* item, Animation animation)
|
||||||
{
|
{
|
||||||
|
//kDebug()<<k_funcinfo<<endl;
|
||||||
// get rid of any existing animations on this item.
|
// get rid of any existing animations on this item.
|
||||||
//TODO: shoudl we allow multiple anims per item?
|
//TODO: shoudl we allow multiple anims per item?
|
||||||
QMap<QGraphicsItem*, AnimationState*>::iterator it = d->animatedItems.find(item);
|
QMap<QGraphicsItem*, AnimationState*>::iterator it = d->animatedItems.find(item);
|
||||||
@ -205,13 +217,39 @@ void Phase::animateItem(QGraphicsItem* item, Animation animation)
|
|||||||
|
|
||||||
void Phase::moveItem(QGraphicsItem* item, Movement movement, QPoint destination)
|
void Phase::moveItem(QGraphicsItem* item, Movement movement, QPoint destination)
|
||||||
{
|
{
|
||||||
switch (movement) {
|
kDebug()<<k_funcinfo<<endl;
|
||||||
case SlideIn:
|
QMap<QGraphicsItem*, MovementState*>::iterator it = d->movingItems.find(item);
|
||||||
case SlideOut:
|
if (it != d->movingItems.end()) {
|
||||||
default:
|
delete it.value();
|
||||||
break;
|
d->movingItems.erase(it);
|
||||||
}
|
}
|
||||||
//FIXME: create movement item struct, add it to the map and call the animator methods
|
|
||||||
|
int frames = d->animator->framesPerSecond(movement);
|
||||||
|
if (frames < 1) {
|
||||||
|
// evidently this animator doesn't have an implementation
|
||||||
|
// for this Animation
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MovementState* state = new MovementState;
|
||||||
|
state->destination=destination;
|
||||||
|
state->item = item;
|
||||||
|
state->movement = movement;
|
||||||
|
state->curve = d->animator->curve(movement);
|
||||||
|
//TODO: variance in times based on the value of animation
|
||||||
|
state->frames = frames / 2;
|
||||||
|
state->currentFrame = 0;
|
||||||
|
state->interval = 500 / state->frames;
|
||||||
|
state->interval = (state->interval / 40) * 40;
|
||||||
|
state->currentInterval = state->interval;
|
||||||
|
|
||||||
|
d->movingItems[item] = state;
|
||||||
|
d->performMovement(0, state);
|
||||||
|
|
||||||
|
if (!d->timerId) {
|
||||||
|
d->timerId = startTimer(40);
|
||||||
|
d->time.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Phase::render(QGraphicsItem* item, QImage& image, RenderOp op)
|
void Phase::render(QGraphicsItem* item, QImage& image, RenderOp op)
|
||||||
@ -258,7 +296,6 @@ Phase::AnimId Phase::animateElement(QGraphicsItem *item, ElementAnimation animat
|
|||||||
d->timerId = startTimer(40);
|
d->timerId = startTimer(40);
|
||||||
d->time.restart();
|
d->time.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
return state->id;
|
return state->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +326,7 @@ QPixmap Phase::animationResult(AnimId id)
|
|||||||
QMap<AnimId, ElementAnimationState*>::const_iterator it = d->animatedElements.find(id);
|
QMap<AnimId, ElementAnimationState*>::const_iterator it = d->animatedElements.find(id);
|
||||||
|
|
||||||
if (it == d->animatedElements.constEnd()) {
|
if (it == d->animatedElements.constEnd()) {
|
||||||
kDebug() << "Phase::animationResult(" << id << ") found no entry for it!" << endl;
|
//kDebug() << "Phase::animationResult(" << id << ") found no entry for it!" << endl;
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,18 +358,18 @@ void Phase::timerEvent(QTimerEvent *event)
|
|||||||
elapsed = d->time.elapsed();
|
elapsed = d->time.elapsed();
|
||||||
}
|
}
|
||||||
d->time.restart();
|
d->time.restart();
|
||||||
// kDebug() << "timeEvent, elapsed time: " << elapsed << endl;
|
kDebug() << "timeEvent, elapsed time: " << elapsed << endl;
|
||||||
|
|
||||||
foreach (AnimationState* state, d->animatedItems) {
|
foreach (AnimationState* state, d->animatedItems) {
|
||||||
if (state->currentInterval <= elapsed) {
|
if (state->currentInterval <= elapsed) {
|
||||||
// we need to step forward!
|
// we need to step forward!
|
||||||
qreal progress = state->frames;
|
|
||||||
progress = state->currentFrame / progress;
|
|
||||||
progress = qMin(1.0, qMax(0.0, progress));
|
|
||||||
d->performAnimation(progress, state);
|
|
||||||
state->currentFrame += qMax(1, elapsed / state->interval);
|
state->currentFrame += qMax(1, elapsed / state->interval);
|
||||||
|
|
||||||
if (state->currentFrame < state->frames) {
|
if (state->currentFrame < state->frames) {
|
||||||
|
qreal progress = state->frames;
|
||||||
|
progress = state->currentFrame / progress;
|
||||||
|
progress = qMin(1.0, qMax(0.0, progress));
|
||||||
|
d->performAnimation(progress, state);
|
||||||
state->currentInterval = state->interval;
|
state->currentInterval = state->interval;
|
||||||
//TODO: calculate a proper interval based on the curve
|
//TODO: calculate a proper interval based on the curve
|
||||||
state->interval *= 1 - progress;
|
state->interval *= 1 - progress;
|
||||||
@ -349,7 +386,27 @@ void Phase::timerEvent(QTimerEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (MovementState* state, d->movingItems) {
|
foreach (MovementState* state, d->movingItems) {
|
||||||
//FIXME: implement =)
|
if (state->currentInterval <= elapsed) {
|
||||||
|
// we need to step forward!
|
||||||
|
state->currentFrame += qMax(1, elapsed / state->interval);
|
||||||
|
|
||||||
|
if (state->currentFrame < state->frames) {
|
||||||
|
qreal progress = state->frames;
|
||||||
|
progress = state->currentFrame / progress;
|
||||||
|
progress = qMin(1.0, qMax(0.0, progress));
|
||||||
|
kDebug()<<progress<<endl;
|
||||||
|
d->performMovement(progress, state);
|
||||||
|
state->currentInterval = state->interval;
|
||||||
|
animationsRemain = true;
|
||||||
|
} else {
|
||||||
|
d->performMovement(1, state);
|
||||||
|
d->movingItems.erase(d->movingItems.find(state->item));
|
||||||
|
delete state;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
state->currentInterval -= elapsed;
|
||||||
|
animationsRemain = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ElementAnimationState* state, d->animatedElements) {
|
foreach (ElementAnimationState* state, d->animatedElements) {
|
||||||
|
1
phase.h
1
phase.h
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
|
||||||
|
* 2007 Alexis Ménard <darktears31@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License version 2 as
|
* it under the terms of the GNU Library General Public License version 2 as
|
||||||
|
Loading…
Reference in New Issue
Block a user