diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e9d19907..81054f997 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ set(plasma_LIB_SRCS animations/rotationstacked.cpp animations/stackedlayout.cpp animations/geo.cpp + animations/zoom.cpp applet.cpp configloader.cpp containment.cpp diff --git a/animations/zoom.cpp b/animations/zoom.cpp new file mode 100644 index 000000000..63e49e3f5 --- /dev/null +++ b/animations/zoom.cpp @@ -0,0 +1,74 @@ +/* + * Copyright 2009 Igor Trindade Oliveira + * + * 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 "zoom_p.h" + +#include + +namespace Plasma +{ + +ZoomAnimation::ZoomAnimation(QObject *parent) + : Animation(parent), + m_zoom(1) +{ +} + +ZoomAnimation::~ZoomAnimation() +{ +} + + +void ZoomAnimation::setZoom(qreal zoom) +{ + m_zoom = zoom; +} + +qreal ZoomAnimation::zoom() const +{ + return m_zoom; +} + +void ZoomAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) +{ + QGraphicsWidget *w = widgetToAnimate(); + if (!w) { + return; + } + + if (oldState == Stopped && newState == Running) { + w->setScale(direction() == Forward ? 1 : m_zoom); + } else if (newState == Stopped) { + w->setScale(direction() == Forward ? m_zoom : 1); + } +} + +void ZoomAnimation::updateCurrentTime(int currentTime) +{ + QGraphicsWidget *w = widgetToAnimate(); + if (w) { + qreal delta = currentTime / qreal(duration()); + delta = (1 - m_zoom) * delta; + w->setScale( 1 - delta); + } + + Animation::updateCurrentTime(currentTime); +} + +} //namespace Plasma diff --git a/animations/zoom_p.h b/animations/zoom_p.h new file mode 100644 index 000000000..cd481e2dd --- /dev/null +++ b/animations/zoom_p.h @@ -0,0 +1,60 @@ +/* + * Copyright 2009 Igor Trindade Oliveira + * + * 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 Zoom animation. + */ + +#ifndef PLASMA_ANIMATIONS_ZOOM_H +#define PLASMA_ANIMATIONS_ZOOM_H + +#include +#include + +namespace Plasma +{ + +/** + * @class ZoomAnimation plasma/animations/zoom_p.h + * @short Zoom Animation + * + */ +class ZoomAnimation : public Animation +{ + Q_OBJECT + Q_PROPERTY(qreal zoom READ zoom WRITE setZoom) + +public: + ZoomAnimation(QObject *parent = 0); + virtual ~ZoomAnimation(); + + qreal zoom() const; + void setZoom(qreal); + +protected: + void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); + void updateCurrentTime(int currentTime); + +private: + qreal m_zoom; +}; + +} + +#endif diff --git a/animator.cpp b/animator.cpp index 6df290fef..57c600bcf 100644 --- a/animator.cpp +++ b/animator.cpp @@ -30,6 +30,7 @@ #include "animations/slide_p.h" #include "animations/rotationstacked.h" #include "animations/geo_p.h" +#include "animations/zoom_p.h" namespace Plasma { @@ -66,6 +67,9 @@ Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent) case GeoAnimation: result = new Plasma::GeoAnimation; break; + case ZoomAnimation: + result = new Plasma::ZoomAnimation; + break; default: kDebug() << "Unsupported animation type."; diff --git a/animator.h b/animator.h index b0ae91ca6..4845e740c 100644 --- a/animator.h +++ b/animator.h @@ -63,7 +63,8 @@ public: RotationAnimation, /*<< Rotate an animated object */ RotationStackedAnimation, /*<< for flipping one object with another */ SlideAnimation, /*<< Move the position of animated object */ - GeoAnimation /*<< Geometry animation*/ + GeoAnimation, /*<< Geometry animation*/ + ZoomAnimation /*<