mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Added a new Namespace to deal with Animations and related functions.
Since the animation methods are fairly the same for any QGraphicsItem, I created a new namespace named 'Animations' that should handle all of the specific Animation Functions there, and the programmer has to call those functions from the objects. Good thing is that this reduces boilerplate code. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
408b7dd5e5
commit
ca07f45561
5 changed files with 46 additions and 20 deletions
24
qt-ui/profile/animationfunctions.cpp
Normal file
24
qt-ui/profile/animationfunctions.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "animationfunctions.h"
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPointF>
|
||||
|
||||
namespace Animations{
|
||||
|
||||
void hide(QObject* obj)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
|
||||
obj->connect(animation, SIGNAL(finished()), SLOT(deleteLater()));
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void moveTo(QObject* obj, qreal x, qreal y)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
|
||||
animation->setStartValue(obj->property("pos").toPointF());
|
||||
animation->setEndValue(QPointF(x, y));
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
}
|
12
qt-ui/profile/animationfunctions.h
Normal file
12
qt-ui/profile/animationfunctions.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef ANIMATIONFUNCTIONS_H
|
||||
#define ANIMATIONFUNCTIONS_H
|
||||
|
||||
#include <QtGlobal>
|
||||
class QObject;
|
||||
|
||||
namespace Animations{
|
||||
void hide(QObject *obj);
|
||||
void moveTo(QObject *obj, qreal x, qreal y);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
#include "divelineitem.h"
|
||||
#include "animationfunctions.h"
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
DiveLineItem::DiveLineItem(QGraphicsItem *parent) : QGraphicsLineItem(parent)
|
||||
|
@ -8,17 +9,10 @@ DiveLineItem::DiveLineItem(QGraphicsItem *parent) : QGraphicsLineItem(parent)
|
|||
|
||||
void DiveLineItem::animatedHide()
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "opacity");
|
||||
connect(animation, SIGNAL(finished()), SLOT(deleteLater()));
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
Animations::hide(this);
|
||||
}
|
||||
|
||||
void DiveLineItem::animateMoveTo(qreal x, qreal y)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
|
||||
animation->setStartValue(property("pos").toPointF());
|
||||
animation->setEndValue(QPointF(x, y));
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
Animations::moveTo(this, x, y);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "divetextitem.h"
|
||||
#include "animationfunctions.h"
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
DiveTextItem::DiveTextItem(QGraphicsItem* parent): QGraphicsSimpleTextItem(parent)
|
||||
|
@ -38,17 +39,10 @@ void DiveTextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opti
|
|||
|
||||
void DiveTextItem::animatedHide()
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "opacity");
|
||||
connect(animation, SIGNAL(finished()), SLOT(deleteLater()));
|
||||
animation->setStartValue(1);
|
||||
animation->setEndValue(0);
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
Animations::hide(this);
|
||||
}
|
||||
|
||||
void DiveTextItem::animateMoveTo(qreal x, qreal y)
|
||||
{
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
|
||||
animation->setStartValue(property("pos").toPointF());
|
||||
animation->setEndValue(QPointF(x, y));
|
||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
Animations::moveTo(this, x, y);
|
||||
}
|
|
@ -67,7 +67,8 @@ HEADERS = \
|
|||
qt-ui/profile/diverectitem.h \
|
||||
qt-ui/profile/divepixmapitem.h \
|
||||
qt-ui/profile/divelineitem.h \
|
||||
qt-ui/profile/divetextitem.h
|
||||
qt-ui/profile/divetextitem.h \
|
||||
qt-ui/profile/animationfunctions.h
|
||||
|
||||
SOURCES = \
|
||||
deco.c \
|
||||
|
@ -122,7 +123,8 @@ SOURCES = \
|
|||
qt-ui/profile/diverectitem.cpp \
|
||||
qt-ui/profile/divepixmapitem.cpp \
|
||||
qt-ui/profile/divelineitem.cpp \
|
||||
qt-ui/profile/divetextitem.cpp
|
||||
qt-ui/profile/divetextitem.cpp \
|
||||
qt-ui/profile/animationfunctions.cpp
|
||||
|
||||
linux*: SOURCES += linux.c
|
||||
mac: SOURCES += macos.c
|
||||
|
|
Loading…
Add table
Reference in a new issue