subsurface/qt-ui/profile/animationfunctions.cpp
Tomaz Canabrava 65eefe7b59 Animation speed is a value, not a boolean
This breaks compatibility with old preferences, but it's a single
key and not that very important so I don't think it's a bigger issue
I've renamed prefs.animation to prefs.animation_speed to denote
that it's a value, and not a state.

Also, fixed the places that were treating it as a state (on/off)
to treat it like a correct value.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-23 07:50:03 -07:00

65 lines
1.8 KiB
C++

#include "animationfunctions.h"
#include "dive.h"
#include "pref.h"
#include <QPropertyAnimation>
#include <QPointF>
namespace Animations {
void hide(QObject *obj)
{
if (prefs.animation_speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
animation->setStartValue(1);
animation->setEndValue(0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
obj->setProperty("opacity", 0);
}
}
void animDelete(QObject *obj)
{
if (prefs.animation_speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
obj->connect(animation, SIGNAL(finished()), SLOT(deleteLater()));
animation->setStartValue(1);
animation->setEndValue(0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
obj->setProperty("opacity", 0);
}
}
void moveTo(QObject *obj, qreal x, qreal y)
{
if (prefs.animation_speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
animation->setDuration(prefs.animation_speed);
animation->setStartValue(obj->property("pos").toPointF());
animation->setEndValue(QPointF(x, y));
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
obj->setProperty("pos", QPointF(x, y));
}
}
void scaleTo(QObject *obj, qreal scale)
{
if (prefs.animation_speed != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale");
animation->setDuration(prefs.animation_speed);
animation->setStartValue(obj->property("scale").toReal());
animation->setEndValue(QVariant::fromValue(scale));
animation->setEasingCurve(QEasingCurve::InCubic);
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
obj->setProperty("scale", QVariant::fromValue(scale));
}
}
void moveTo(QObject *obj, const QPointF &pos)
{
moveTo(obj, pos.x(), pos.y());
}
}