add GeoAnimation to new animation api
svn path=/trunk/KDE/kdelibs/; revision=1059087
This commit is contained in:
parent
ee20613e3d
commit
49e27b8396
@ -53,6 +53,7 @@ set(plasma_LIB_SRCS
|
||||
animations/rotation.cpp
|
||||
animations/rotationstacked.cpp
|
||||
animations/stackedlayout.cpp
|
||||
animations/geo.cpp
|
||||
applet.cpp
|
||||
configloader.cpp
|
||||
containment.cpp
|
||||
|
95
animations/geo.cpp
Normal file
95
animations/geo.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "geo_p.h"
|
||||
|
||||
#include <QRect>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
GeoAnimation::GeoAnimation(QObject *parent)
|
||||
: Animation(parent),
|
||||
m_startGeometry(-1, -1, -1, -1)
|
||||
{
|
||||
}
|
||||
|
||||
GeoAnimation::~GeoAnimation()
|
||||
{
|
||||
}
|
||||
|
||||
void GeoAnimation::setStartGeometry(const QRectF &geometry)
|
||||
{
|
||||
m_startGeometry = geometry;
|
||||
}
|
||||
|
||||
QRectF GeoAnimation::startGeometry() const
|
||||
{
|
||||
return m_startGeometry;
|
||||
}
|
||||
|
||||
void GeoAnimation::setTargetGeometry(const QRectF &geometry)
|
||||
{
|
||||
m_targetGeometry = geometry;
|
||||
}
|
||||
|
||||
QRectF GeoAnimation::targetGeometry() const
|
||||
{
|
||||
return m_targetGeometry;
|
||||
}
|
||||
|
||||
void GeoAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
||||
{
|
||||
QGraphicsWidget *w = widgetToAnimate();
|
||||
if (!w) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_startGeometry == QRectF(-1, -1, -1, -1)) {
|
||||
m_startGeometry = w->geometry();
|
||||
}
|
||||
|
||||
if (oldState == Stopped && newState == Running) {
|
||||
w->setGeometry(direction() == Forward ? m_startGeometry : m_targetGeometry);
|
||||
} else if (newState == Stopped) {
|
||||
w->setGeometry(direction() == Forward ? m_targetGeometry : m_startGeometry);
|
||||
}
|
||||
}
|
||||
|
||||
void GeoAnimation::updateCurrentTime(int currentTime)
|
||||
{
|
||||
QGraphicsWidget *w = widgetToAnimate();
|
||||
if (w) {
|
||||
qreal delta = currentTime / qreal(duration());
|
||||
|
||||
QRectF newGeo = m_startGeometry;
|
||||
newGeo.adjust((-m_startGeometry.x() + m_targetGeometry.x()) * delta,
|
||||
(-m_startGeometry.y() + m_targetGeometry.y()) * delta,
|
||||
(-m_startGeometry.width() + m_targetGeometry.width()) * delta,
|
||||
(-m_startGeometry.height() + m_targetGeometry.height()) * delta);
|
||||
|
||||
w->setGeometry(newGeo);
|
||||
}
|
||||
|
||||
Animation::updateCurrentTime(currentTime);
|
||||
}
|
||||
|
||||
} //namespace Plasma
|
67
animations/geo_p.h
Normal file
67
animations/geo_p.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file This file contains the definition for the Fade effect.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATIONS_GEO_H
|
||||
#define PLASMA_ANIMATIONS_GEO_H
|
||||
|
||||
#include <plasma/animations/animation.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ZoomAnimationPrivate;
|
||||
|
||||
/**
|
||||
* @class GeoAnimation plasma/animations/geo_p.h
|
||||
* @short Geometry Animation
|
||||
*
|
||||
*/
|
||||
class GeoAnimation : public Animation
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRectF startGeometry READ startGeometry WRITE setStartGeometry)
|
||||
Q_PROPERTY(QRectF targetGeometry READ targetGeometry WRITE setTargetGeometry)
|
||||
|
||||
public:
|
||||
GeoAnimation(QObject *parent = 0);
|
||||
virtual ~GeoAnimation();
|
||||
|
||||
QRectF startGeometry() const;
|
||||
void setStartGeometry(const QRectF &);
|
||||
|
||||
QRectF targetGeometry() const;
|
||||
void setTargetGeometry(const QRectF &);
|
||||
|
||||
protected:
|
||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||
void updateCurrentTime(int currentTime);
|
||||
|
||||
private:
|
||||
QRectF m_startGeometry;
|
||||
QRectF m_targetGeometry;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -29,6 +29,7 @@
|
||||
#include "animations/rotation_p.h"
|
||||
#include "animations/slide_p.h"
|
||||
#include "animations/rotationstacked.h"
|
||||
#include "animations/geo_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -62,6 +63,9 @@ Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent)
|
||||
case SlideAnimation:
|
||||
result = new Plasma::SlideAnimation;
|
||||
break;
|
||||
case GeoAnimation:
|
||||
result = new Plasma::GeoAnimation;
|
||||
break;
|
||||
|
||||
default:
|
||||
kDebug() << "Unsupported animation type.";
|
||||
|
@ -61,8 +61,9 @@ public:
|
||||
GrowAnimation, /*<< Grow animated object geometry */
|
||||
PulseAnimation, /*<< Pulse animated object (opacity/geometry/scale) */
|
||||
RotationAnimation, /*<< Rotate an animated object */
|
||||
RotationStackedAnimation, /*<< TODO: for flipping one object with another */
|
||||
SlideAnimation /*<< Move the position of animated object */
|
||||
RotationStackedAnimation, /*<< for flipping one object with another */
|
||||
SlideAnimation, /*<< Move the position of animated object */
|
||||
GeoAnimation /*<< Geometry animation*/
|
||||
};
|
||||
|
||||
enum CurveShape {
|
||||
|
Loading…
Reference in New Issue
Block a user