summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-14 16:01:17 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-16 10:12:29 +0700
commitca07f45561aecf788dfbbbda9e36135f6fae69d2 (patch)
tree000717f1fea8c0608179f8dfd494f39dce890981
parent408b7dd5e568519360701e01bc87888a5d8be931 (diff)
downloadsubsurface-ca07f45561aecf788dfbbbda9e36135f6fae69d2.tar.gz
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>
-rw-r--r--qt-ui/profile/animationfunctions.cpp24
-rw-r--r--qt-ui/profile/animationfunctions.h12
-rw-r--r--qt-ui/profile/divelineitem.cpp12
-rw-r--r--qt-ui/profile/divetextitem.cpp12
-rw-r--r--subsurface.pro6
5 files changed, 46 insertions, 20 deletions
diff --git a/qt-ui/profile/animationfunctions.cpp b/qt-ui/profile/animationfunctions.cpp
new file mode 100644
index 000000000..1e307db87
--- /dev/null
+++ b/qt-ui/profile/animationfunctions.cpp
@@ -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);
+}
+
+}
diff --git a/qt-ui/profile/animationfunctions.h b/qt-ui/profile/animationfunctions.h
new file mode 100644
index 000000000..e1a0d4dee
--- /dev/null
+++ b/qt-ui/profile/animationfunctions.h
@@ -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 \ No newline at end of file
diff --git a/qt-ui/profile/divelineitem.cpp b/qt-ui/profile/divelineitem.cpp
index 9ceea1e70..834c1b8e3 100644
--- a/qt-ui/profile/divelineitem.cpp
+++ b/qt-ui/profile/divelineitem.cpp
@@ -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);
}
diff --git a/qt-ui/profile/divetextitem.cpp b/qt-ui/profile/divetextitem.cpp
index 417f537c2..7f9adf181 100644
--- a/qt-ui/profile/divetextitem.cpp
+++ b/qt-ui/profile/divetextitem.cpp
@@ -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);
} \ No newline at end of file
diff --git a/subsurface.pro b/subsurface.pro
index 1fcabe2bd..2753e3374 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -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