mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
plasma: simplify animations classes
the proxy class Plasma::EasingAnimation is simply redundant, just one more virtual function call which slows the animations Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
eb37060455
commit
935b228484
17 changed files with 71 additions and 165 deletions
|
@ -24,7 +24,6 @@ set(plasma_LIB_SRCS
|
||||||
abstracttoolbox.cpp
|
abstracttoolbox.cpp
|
||||||
animator.cpp
|
animator.cpp
|
||||||
animations/animation.cpp
|
animations/animation.cpp
|
||||||
animations/easinganimation.cpp
|
|
||||||
animations/fade.cpp
|
animations/fade.cpp
|
||||||
animations/pixmaptransition.cpp
|
animations/pixmaptransition.cpp
|
||||||
animations/pulser.cpp
|
animations/pulser.cpp
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
AnimationPrivate::AnimationPrivate()
|
AnimationPrivate::AnimationPrivate()
|
||||||
: easingCurve(QEasingCurve::Linear),
|
: easingCurve(QEasingCurve::Linear),
|
||||||
duration(250)
|
duration(250)
|
||||||
|
|
|
@ -79,18 +79,18 @@ public:
|
||||||
* \ref Animator::create factory).
|
* \ref Animator::create factory).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
explicit Animation(QObject* parent = 0);
|
explicit Animation(QObject *parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
~Animation() = 0;
|
virtual ~Animation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the widget on which the animation is to be performed.
|
* Set the widget on which the animation is to be performed.
|
||||||
* @param widget The QGraphicsWidget to be animated.
|
* @param widget The QGraphicsWidget to be animated.
|
||||||
*/
|
*/
|
||||||
void setTargetWidget(QGraphicsWidget* widget);
|
void setTargetWidget(QGraphicsWidget *widget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The widget that the animation will be performed upon
|
* @return The widget that the animation will be performed upon
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
|
||||||
*
|
|
||||||
* 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 "easinganimation_p.h"
|
|
||||||
#include <kdebug.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
|
||||||
{
|
|
||||||
|
|
||||||
EasingAnimation::EasingAnimation(QObject *parent)
|
|
||||||
: Animation(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void EasingAnimation::updateCurrentTime(int currentTime)
|
|
||||||
{
|
|
||||||
updateEffectiveTime(easingCurve().valueForProgress(currentTime / qreal(qMax(1, duration()))) * duration());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Plasma
|
|
||||||
|
|
||||||
#include "moc_easinganimation_p.cpp"
|
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PLASMA_EASINGANIMATION_H
|
|
||||||
#define PLASMA_EASINGANIMATION_H
|
|
||||||
|
|
||||||
#include "animation.h"
|
|
||||||
|
|
||||||
namespace Plasma
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
class EasingAnimation : public Animation
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit EasingAnimation(QObject *parent = 0);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void updateEffectiveTime(int currentTime) = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void updateCurrentTime(int currentTime);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Plasma
|
|
||||||
|
|
||||||
#endif // PLASMA_EASINGANIMATION_H
|
|
||||||
|
|
|
@ -18,25 +18,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "fade_p.h"
|
#include "fade_p.h"
|
||||||
|
#include "kdebug.h"
|
||||||
|
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
|
||||||
#include <kdebug.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
FadeAnimation::FadeAnimation(QObject *parent)
|
FadeAnimation::FadeAnimation(QObject *parent)
|
||||||
: EasingAnimation(parent),
|
: Animation(parent),
|
||||||
m_startOpacity(0),
|
m_startOpacity(0),
|
||||||
m_targetOpacity(1)
|
m_targetOpacity(1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FadeAnimation::~FadeAnimation()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void FadeAnimation::setStartOpacity(qreal factor)
|
void FadeAnimation::setStartOpacity(qreal factor)
|
||||||
{
|
{
|
||||||
m_startOpacity = qBound(qreal(0.0), factor, qreal(1.0));
|
m_startOpacity = qBound(qreal(0.0), factor, qreal(1.0));
|
||||||
|
@ -71,11 +66,11 @@ void FadeAnimation::updateState(QAbstractAnimation::State newState, QAbstractAni
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FadeAnimation::updateEffectiveTime(int currentTime)
|
void FadeAnimation::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *w = targetWidget();
|
QGraphicsWidget *w = targetWidget();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(qreal(currentTime) / qreal(duration()));
|
||||||
delta *= m_startOpacity - m_targetOpacity;
|
delta *= m_startOpacity - m_targetOpacity;
|
||||||
w->setOpacity(m_startOpacity - delta);
|
w->setOpacity(m_startOpacity - delta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
#ifndef PLASMA_ANIMATIONS_FADE_P_H
|
#ifndef PLASMA_ANIMATIONS_FADE_P_H
|
||||||
#define PLASMA_ANIMATIONS_FADE_P_H
|
#define PLASMA_ANIMATIONS_FADE_P_H
|
||||||
|
|
||||||
#include <plasma/animations/easinganimation_p.h>
|
#include "animations/animation.h"
|
||||||
#include <plasma/plasma_export.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -38,7 +37,7 @@ namespace Plasma
|
||||||
* value to a target value. The range is 0 (full translucent) to 1 (full
|
* value to a target value. The range is 0 (full translucent) to 1 (full
|
||||||
* opaque).
|
* opaque).
|
||||||
*/
|
*/
|
||||||
class FadeAnimation : public EasingAnimation
|
class FadeAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(qreal startOpacity READ startOpacity WRITE setStartOpacity)
|
Q_PROPERTY(qreal startOpacity READ startOpacity WRITE setStartOpacity)
|
||||||
|
@ -46,10 +45,7 @@ class FadeAnimation : public EasingAnimation
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Default constructor */
|
/** Default constructor */
|
||||||
explicit FadeAnimation(QObject *parent = 0);
|
explicit FadeAnimation(QObject *parent = nullptr);
|
||||||
|
|
||||||
/** Destructor */
|
|
||||||
virtual ~FadeAnimation();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access start opacity of the target widget.
|
* Access start opacity of the target widget.
|
||||||
|
@ -59,6 +55,7 @@ public:
|
||||||
* @return The opacity (range is 0 to 1).
|
* @return The opacity (range is 0 to 1).
|
||||||
*/
|
*/
|
||||||
qreal startOpacity() const;
|
qreal startOpacity() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the start opacity of the target widget.
|
* Set the start opacity of the target widget.
|
||||||
*
|
*
|
||||||
|
@ -75,6 +72,7 @@ public:
|
||||||
* @return The opacity (range is 0 to 1).
|
* @return The opacity (range is 0 to 1).
|
||||||
*/
|
*/
|
||||||
qreal targetOpacity() const;
|
qreal targetOpacity() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the final opacity of the target widget.
|
* Set the final opacity of the target widget.
|
||||||
*
|
*
|
||||||
|
@ -85,7 +83,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
void updateEffectiveTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Initial opacity */
|
/** Initial opacity */
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
GeometryAnimation::GeometryAnimation(QObject *parent)
|
GeometryAnimation::GeometryAnimation(QObject *parent)
|
||||||
: EasingAnimation(parent),
|
: Animation(parent),
|
||||||
m_startGeometry(-1, -1, -1, -1)
|
m_startGeometry(-1, -1, -1, -1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -70,19 +70,26 @@ void GeometryAnimation::updateState(QAbstractAnimation::State newState, QAbstrac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryAnimation::updateEffectiveTime(int currentTime)
|
void GeometryAnimation::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *w = targetWidget();
|
QGraphicsWidget *w = targetWidget();
|
||||||
if (w) {
|
if (w) {
|
||||||
const qreal delta = currentTime / qreal(duration());
|
const qreal delta = easingCurve().valueForProgress(qreal(currentTime) / qreal(duration()));
|
||||||
|
|
||||||
QRectF newGeo;
|
QRectF newGeo;
|
||||||
|
newGeo.moveTopLeft(
|
||||||
newGeo.moveTopLeft(QPointF(m_startGeometry.left()*(1-delta) + m_targetGeometry.left()*(delta),
|
QPointF(
|
||||||
m_startGeometry.top()*(1-delta) + m_targetGeometry.top()*(delta)));
|
m_startGeometry.left()*(1-delta) + m_targetGeometry.left()*(delta),
|
||||||
|
m_startGeometry.top()*(1-delta) + m_targetGeometry.top()*(delta)
|
||||||
|
)
|
||||||
|
);
|
||||||
if (m_startGeometry.size() != m_targetGeometry.size()) {
|
if (m_startGeometry.size() != m_targetGeometry.size()) {
|
||||||
newGeo.setSize(QSizeF(m_startGeometry.width()*(1-delta) + m_targetGeometry.width()*(delta),
|
newGeo.setSize(
|
||||||
m_startGeometry.height()*(1-delta) + m_targetGeometry.height()*(delta)));
|
QSizeF(
|
||||||
|
m_startGeometry.width()*(1-delta) + m_targetGeometry.width()*(delta),
|
||||||
|
m_startGeometry.height()*(1-delta) + m_targetGeometry.height()*(delta)
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
newGeo.setSize(m_targetGeometry.size());
|
newGeo.setSize(m_targetGeometry.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
#ifndef PLASMA_ANIMATIONS_GEOMETRY_P_H
|
#ifndef PLASMA_ANIMATIONS_GEOMETRY_P_H
|
||||||
#define PLASMA_ANIMATIONS_GEOMETRY_P_H
|
#define PLASMA_ANIMATIONS_GEOMETRY_P_H
|
||||||
|
|
||||||
#include <plasma/animations/easinganimation_p.h>
|
#include "animations/animation.h"
|
||||||
#include <plasma/plasma_export.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -36,7 +35,7 @@ namespace Plasma
|
||||||
* Use this class when you want to change the geometry of an QGraphicsWidget
|
* Use this class when you want to change the geometry of an QGraphicsWidget
|
||||||
* in an animated way (you should at least set the target geometry).
|
* in an animated way (you should at least set the target geometry).
|
||||||
*/
|
*/
|
||||||
class GeometryAnimation : public EasingAnimation
|
class GeometryAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QRectF startGeometry READ startGeometry WRITE setStartGeometry)
|
Q_PROPERTY(QRectF startGeometry READ startGeometry WRITE setStartGeometry)
|
||||||
|
@ -44,7 +43,7 @@ class GeometryAnimation : public EasingAnimation
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Default constructor */
|
/** Default constructor */
|
||||||
explicit GeometryAnimation(QObject *parent = 0);
|
explicit GeometryAnimation(QObject *parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the initial geometry of animated widget.
|
* Access the initial geometry of animated widget.
|
||||||
|
@ -54,6 +53,7 @@ public:
|
||||||
* @return Start geometry.
|
* @return Start geometry.
|
||||||
*/
|
*/
|
||||||
QRectF startGeometry() const;
|
QRectF startGeometry() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the initial geometry of animated widget.
|
* Set the initial geometry of animated widget.
|
||||||
*
|
*
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
void updateEffectiveTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Initial geometry */
|
/** Initial geometry */
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
PixmapTransition::PixmapTransition(QObject *parent)
|
PixmapTransition::PixmapTransition(QObject *parent)
|
||||||
: EasingAnimation(parent),
|
: Animation(parent),
|
||||||
m_cache(false),
|
m_cache(false),
|
||||||
m_dirty(false)
|
m_dirty(false)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ void PixmapTransition::setStartPixmap(const QPixmap &pixmap)
|
||||||
m_startPixmap = pixmap;
|
m_startPixmap = pixmap;
|
||||||
|
|
||||||
//this will center the pixmaps if needed
|
//this will center the pixmaps if needed
|
||||||
updateEffectiveTime(0);
|
updateCurrentTime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap PixmapTransition::startPixmap() const
|
QPixmap PixmapTransition::startPixmap() const
|
||||||
|
@ -62,7 +62,7 @@ void PixmapTransition::setTargetPixmap(const QPixmap &pixmap)
|
||||||
|
|
||||||
m_targetPixmap = pixmap;
|
m_targetPixmap = pixmap;
|
||||||
|
|
||||||
updateEffectiveTime(0);
|
updateCurrentTime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapTransition::setUsesCache(bool cache)
|
void PixmapTransition::setUsesCache(bool cache)
|
||||||
|
@ -160,7 +160,7 @@ void PixmapTransition::updateState(QAbstractAnimation::State newState, QAbstract
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapTransition::updateEffectiveTime(int currentTime)
|
void PixmapTransition::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
Q_UNUSED(currentTime)
|
Q_UNUSED(currentTime)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
#ifndef PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
|
#ifndef PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
|
||||||
#define PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
|
#define PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
|
||||||
|
|
||||||
#include <plasma/animations/easinganimation_p.h>
|
#include "animations/animation.h"
|
||||||
#include <plasma/plasma_export.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -37,7 +36,7 @@ namespace Plasma
|
||||||
*
|
*
|
||||||
* Effect that paints a transition between two pixmaps
|
* Effect that paints a transition between two pixmaps
|
||||||
*/
|
*/
|
||||||
class PixmapTransition : public EasingAnimation
|
class PixmapTransition : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QPixmap startPixmap READ startPixmap WRITE setStartPixmap)
|
Q_PROPERTY(QPixmap startPixmap READ startPixmap WRITE setStartPixmap)
|
||||||
|
@ -46,7 +45,7 @@ class PixmapTransition : public EasingAnimation
|
||||||
Q_PROPERTY(QPixmap currentPixmap READ currentPixmap)
|
Q_PROPERTY(QPixmap currentPixmap READ currentPixmap)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PixmapTransition(QObject *parent = 0);
|
explicit PixmapTransition(QObject *parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The first pixmap of the animation
|
* @return The first pixmap of the animation
|
||||||
|
@ -56,7 +55,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Set the first pixmap of the animation
|
* Set the first pixmap of the animation
|
||||||
*/
|
*/
|
||||||
void setStartPixmap(const QPixmap &);
|
void setStartPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The pixmap the animation will evolve to
|
* The pixmap the animation will evolve to
|
||||||
|
@ -66,7 +65,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Set the pixmap the animation will evolve to
|
* Set the pixmap the animation will evolve to
|
||||||
*/
|
*/
|
||||||
void setTargetPixmap(const QPixmap &);
|
void setTargetPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current pixmap
|
* @return the current pixmap
|
||||||
|
@ -87,7 +86,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
void updateEffectiveTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap alignedTargetPixmap() const;
|
QPixmap alignedTargetPixmap() const;
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
#include <QParallelAnimationGroup>
|
|
||||||
#include <QPropertyAnimation>
|
|
||||||
#include <QWeakPointer>
|
#include <QWeakPointer>
|
||||||
|
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
@ -30,7 +28,7 @@ namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
PulseAnimation::PulseAnimation(QObject *parent)
|
PulseAnimation::PulseAnimation(QObject *parent)
|
||||||
: EasingAnimation(parent),
|
: Animation(parent),
|
||||||
m_zvalue(0),
|
m_zvalue(0),
|
||||||
m_scale(0),
|
m_scale(0),
|
||||||
m_opacity(0),
|
m_opacity(0),
|
||||||
|
@ -111,16 +109,17 @@ void PulseAnimation::updateState(QAbstractAnimation::State newState, QAbstractAn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PulseAnimation::updateEffectiveTime(int currentTime)
|
void PulseAnimation::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
if (m_under.data()) {
|
if (m_under.data()) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
const qreal progress = easingCurve().valueForProgress(qreal(currentTime) / qreal(duration()));
|
||||||
|
qreal delta = progress;
|
||||||
|
|
||||||
m_under.data()->setScale(delta);
|
m_under.data()->setScale(delta);
|
||||||
delta = (1 - m_endScale) * delta;
|
delta = (1 - m_endScale) * delta;
|
||||||
m_under.data()->setScale(1 - delta);
|
m_under.data()->setScale(1 - delta);
|
||||||
|
|
||||||
delta = currentTime / qreal(duration());
|
delta = progress;
|
||||||
if (direction() == Forward) {
|
if (direction() == Forward) {
|
||||||
m_under.data()->setOpacity(1.0 - delta);
|
m_under.data()->setOpacity(1.0 - delta);
|
||||||
} else if (direction() == Backward) {
|
} else if (direction() == Backward) {
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
#ifndef PLASMA_ANIMATIONS_PULSER_P_H
|
#ifndef PLASMA_ANIMATIONS_PULSER_P_H
|
||||||
#define PLASMA_ANIMATIONS_PULSER_P_H
|
#define PLASMA_ANIMATIONS_PULSER_P_H
|
||||||
|
|
||||||
#include <plasma/animations/easinganimation_p.h>
|
#include "animations/animation.h"
|
||||||
#include <plasma/plasma_export.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -38,14 +37,14 @@ class WidgetSnapShot;
|
||||||
* Effect that pulses a shadow copy of any QGraphicsWidget making
|
* Effect that pulses a shadow copy of any QGraphicsWidget making
|
||||||
* it more translucent and bigger along the time until it vanishes.
|
* it more translucent and bigger along the time until it vanishes.
|
||||||
*/
|
*/
|
||||||
class PulseAnimation : public EasingAnimation
|
class PulseAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(qreal targetScale READ targetScale WRITE setTargetScale)
|
Q_PROPERTY(qreal targetScale READ targetScale WRITE setTargetScale)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Default Constructor */
|
/** Default Constructor */
|
||||||
explicit PulseAnimation(QObject *parent = 0);
|
explicit PulseAnimation(QObject *parent = nullptr);
|
||||||
|
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
~PulseAnimation();
|
~PulseAnimation();
|
||||||
|
@ -75,7 +74,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
void updateEffectiveTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
void setCopy();
|
void setCopy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,15 +18,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "slide_p.h"
|
#include "slide_p.h"
|
||||||
|
#include "kdebug.h"
|
||||||
|
|
||||||
#include <QtCore/qpoint.h>
|
#include <QPoint>
|
||||||
#include <kdebug.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
SlideAnimation::SlideAnimation(QObject *parent, MovementDirection direction, qreal distance)
|
SlideAnimation::SlideAnimation(QObject *parent, MovementDirection direction, qreal distance)
|
||||||
: EasingAnimation(parent)
|
: Animation(parent)
|
||||||
{
|
{
|
||||||
setMovementDirection(direction);
|
setMovementDirection(direction);
|
||||||
setDistance(distance);
|
setDistance(distance);
|
||||||
|
@ -63,11 +63,11 @@ Animation::MovementDirection SlideAnimation::movementDirection() const
|
||||||
return m_animDirection;
|
return m_animDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlideAnimation::updateEffectiveTime(int currentTime)
|
void SlideAnimation::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *w = targetWidget();
|
QGraphicsWidget *w = targetWidget();
|
||||||
if (w && state() == QAbstractAnimation::Running) {
|
if (w && state() == QAbstractAnimation::Running) {
|
||||||
const qreal delta = currentTime / qreal(duration());
|
const qreal delta = easingCurve().valueForProgress(qreal(currentTime) / qreal(duration()));
|
||||||
w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
|
w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,7 @@
|
||||||
#ifndef PLASMA_ANIMATIONS_SLIDE_P_H
|
#ifndef PLASMA_ANIMATIONS_SLIDE_P_H
|
||||||
#define PLASMA_ANIMATIONS_SLIDE_P_H
|
#define PLASMA_ANIMATIONS_SLIDE_P_H
|
||||||
|
|
||||||
#include "plasma/animations/easinganimation_p.h"
|
#include "animations/animation.h"
|
||||||
#include "plasma/plasma_export.h"
|
|
||||||
#include "plasma/plasma.h"
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -38,7 +36,7 @@ namespace Plasma
|
||||||
* Effect that moves the object a specific distance in a given direction. The
|
* Effect that moves the object a specific distance in a given direction. The
|
||||||
* object is optionally made invisible at the beginning or at the end.
|
* object is optionally made invisible at the beginning or at the end.
|
||||||
*/
|
*/
|
||||||
class SlideAnimation : public EasingAnimation
|
class SlideAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(qreal distance READ distance WRITE setDistance)
|
Q_PROPERTY(qreal distance READ distance WRITE setDistance)
|
||||||
|
@ -46,7 +44,7 @@ class SlideAnimation : public EasingAnimation
|
||||||
Q_PROPERTY(QPointF distancePointF READ distancePointF WRITE setDistancePointF)
|
Q_PROPERTY(QPointF distancePointF READ distancePointF WRITE setDistancePointF)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SlideAnimation(QObject *parent = 0, MovementDirection direction = MoveUp, qreal distance = 0);
|
explicit SlideAnimation(QObject *parent = nullptr, MovementDirection direction = MoveUp, qreal distance = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the animation distance
|
* Set the animation distance
|
||||||
|
@ -74,7 +72,7 @@ public:
|
||||||
Animation::MovementDirection movementDirection() const;
|
Animation::MovementDirection movementDirection() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateEffectiveTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,14 +18,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "zoom_p.h"
|
#include "zoom_p.h"
|
||||||
|
#include "kdebug.h"
|
||||||
#include <kdebug.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
ZoomAnimation::ZoomAnimation(QObject *parent)
|
ZoomAnimation::ZoomAnimation(QObject *parent)
|
||||||
: EasingAnimation(parent),
|
: Animation(parent),
|
||||||
m_zoom(0)
|
m_zoom(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -55,11 +54,11 @@ void ZoomAnimation::updateState(QAbstractAnimation::State newState, QAbstractAni
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoomAnimation::updateEffectiveTime(int currentTime)
|
void ZoomAnimation::updateCurrentTime(int currentTime)
|
||||||
{
|
{
|
||||||
QGraphicsWidget *w = targetWidget();
|
QGraphicsWidget *w = targetWidget();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(qreal(currentTime) / qreal(duration()));
|
||||||
if (m_zoom != 1) {
|
if (m_zoom != 1) {
|
||||||
delta = (1 - m_zoom) * delta;
|
delta = (1 - m_zoom) * delta;
|
||||||
w->setScale(1 - delta);
|
w->setScale(1 - delta);
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
#ifndef PLASMA_ANIMATIONS_ZOOM_P_H
|
#ifndef PLASMA_ANIMATIONS_ZOOM_P_H
|
||||||
#define PLASMA_ANIMATIONS_ZOOM_P_H
|
#define PLASMA_ANIMATIONS_ZOOM_P_H
|
||||||
|
|
||||||
#include <plasma/animations/easinganimation_p.h>
|
#include "animations/animation.h"
|
||||||
#include <plasma/plasma_export.h>
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
@ -35,20 +34,20 @@ namespace Plasma
|
||||||
* @short Zoom Animation
|
* @short Zoom Animation
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ZoomAnimation : public EasingAnimation
|
class ZoomAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom)
|
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ZoomAnimation(QObject *parent = 0);
|
explicit ZoomAnimation(QObject *parent = nullptr);
|
||||||
|
|
||||||
qreal zoom() const;
|
qreal zoom() const;
|
||||||
void setZoom(qreal);
|
void setZoom(qreal);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
void updateEffectiveTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qreal m_zoom;
|
qreal m_zoom;
|
||||||
|
|
Loading…
Add table
Reference in a new issue