Initial WaterAnimation implementation

This water animation uses the RippleEffect class to simulate a cool water animation on the target widget

svn path=/trunk/KDE/kdelibs/; revision=1116474
This commit is contained in:
Bruno de Oliveira Abinader 2010-04-19 15:09:36 +00:00
parent ea49b36874
commit a8975d2e2d
5 changed files with 145 additions and 1 deletions

View File

@ -62,6 +62,7 @@ set(plasma_LIB_SRCS
animations/stackedlayout.cpp
animations/geometry.cpp
animations/zoom.cpp
animations/water.cpp
applet.cpp
configloader.cpp
containment.cpp

69
animations/water.cpp Normal file
View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <plasma/private/effects/ripple_p.h>
#include "water_p.h"
namespace Plasma
{
WaterAnimation::WaterAnimation(QObject *parent)
: EasingAnimation(parent),
m_offset(1)
{
}
qint8 WaterAnimation::offset() const
{
return m_offset;
}
void WaterAnimation::setOffset(qint8 offset)
{
m_offset = offset;
}
void WaterAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
{
QGraphicsWidget *widget = targetWidget();
if (!widget) {
return;
}
RippleEffect *effect = qobject_cast<RippleEffect*>(widget->graphicsEffect());
if (!effect) {
effect = new RippleEffect(widget);
widget->setGraphicsEffect(effect);
}
if (oldState == Stopped && newState == Running) {
effect->setOffset(m_offset);
effect->setEnabled(true);
} else if (newState == Stopped) {
effect->setEnabled(false);
}
}
void WaterAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *widget = targetWidget();
if (widget && widget->graphicsEffect()) {
widget->graphicsEffect()->setProperty("opacity", currentTime / qreal(duration()));
}
}
} // namespace Plasma

68
animations/water_p.h Normal file
View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMA_ANIMATIONS_WATER_P_H
#define PLASMA_ANIMATIONS_WATER_P_H
#include <plasma/animations/easinganimation_p.h>
namespace Plasma
{
/*
* @class Water plasma/animations/water_p.h
* @short Water animation using ripple effect
*
* Simulates a water animation using ripple effect
*/
class WaterAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qint8 offset READ offset WRITE setOffset)
public:
/**
* Default constructor
* @param parent Animation object parent
*/
explicit WaterAnimation(QObject *parent = 0);
/**
* Returns the ripple offset. The ripple offset is the distance between neighbour pixels used to
* calculate the wave propagation.
* @return ripple offset
*/
qint8 offset() const;
public slots:
/**
* Sets the ripple offset
* @param offset ripple offset
*/
void setOffset(qint8 offset);
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateEffectiveTime(int currentTime);
private:
qint8 m_offset; /** Ripple offset (default is 1) */
};
} // namespace Plasma
#endif // PLASMA_ANIMATIONS_WATER_P_H

View File

@ -30,6 +30,7 @@
#include "animations/geometry_p.h"
#include "animations/zoom_p.h"
#include "animations/pixmaptransition_p.h"
#include "animations/water_p.h"
namespace Plasma
{
@ -75,6 +76,10 @@ Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent)
result = new Plasma::PixmapTransition(parent);
break;
case WaterAnimation:
result = new Plasma::WaterAnimation(parent);
break;
default:
kDebug() << "Unsupported animation type.";
}

View File

@ -66,7 +66,8 @@ public:
SlideAnimation, /*<< Move the position of animated object */
GeometryAnimation, /*<< Geometry animation*/
ZoomAnimation, /*<<Zoom animation */
PixmapTransitionAnimation /*<< Transition between two pixmaps*/
PixmapTransitionAnimation, /*<< Transition between two pixmaps*/
WaterAnimation /*<< Water animation using ripple effect */
};
enum CurveShape {