summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-14 15:23:57 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-16 10:12:29 +0700
commit408b7dd5e568519360701e01bc87888a5d8be931 (patch)
treecc73353ea73d49c4ae10d70265be391a51ea461f
parentd47456b4e858fa75dadcff4a1c6525ad0137d965 (diff)
downloadsubsurface-408b7dd5e568519360701e01bc87888a5d8be931.tar.gz
Add a class based on QGraphicsSimpleTextItem that handles animations.
This commit adds a class based on QGraphicsSimpleTextItem that handls animations via animatedHide() animatedMoveTo() and a few other QPropertyes. This is to be used in conjunction with the DiveLineItem added in the past commit on the Coordinate Axis. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/profile/divetextitem.cpp54
-rw-r--r--qt-ui/profile/divetextitem.h22
-rw-r--r--subsurface.pro6
3 files changed, 80 insertions, 2 deletions
diff --git a/qt-ui/profile/divetextitem.cpp b/qt-ui/profile/divetextitem.cpp
new file mode 100644
index 000000000..417f537c2
--- /dev/null
+++ b/qt-ui/profile/divetextitem.cpp
@@ -0,0 +1,54 @@
+#include "divetextitem.h"
+#include <QPropertyAnimation>
+
+DiveTextItem::DiveTextItem(QGraphicsItem* parent): QGraphicsSimpleTextItem(parent)
+{
+ setFlag(ItemIgnoresTransformations);
+}
+
+void DiveTextItem::setAlignment(int alignFlags)
+{
+ internalAlignFlags = alignFlags;
+ update();
+}
+
+void DiveTextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+{
+ /* This block of code corrects paints the Text on the
+ * alignment choosed, but it created artifacts on the screen,
+ * so I'm leaving this disabled for the time being.
+ */
+// QRectF rect = boundingRect();
+// if (internalAlignFlags & Qt::AlignTop)
+// painter->translate(0, -rect.height());
+// // else if (internalAlignFlags & Qt::AlignBottom)
+// // painter->translate(0, rect.height()); this is the default, uneeded.
+// else if (internalAlignFlags & Qt::AlignVCenter)
+// painter->translate(0, -rect.height() / 2);
+//
+// // if (internalAlignFlags & Qt::AlignLeft )
+// // painter->translate(); // This is the default, uneeded.
+// if(internalAlignFlags & Qt::AlignHCenter)
+// painter->translate(-rect.width()/2, 0);
+// else if(internalAlignFlags & Qt::AlignRight)
+// painter->translate(-rect.width(), 0);
+
+ QGraphicsSimpleTextItem::paint(painter, option, widget);
+}
+
+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);
+}
+
+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);
+} \ No newline at end of file
diff --git a/qt-ui/profile/divetextitem.h b/qt-ui/profile/divetextitem.h
new file mode 100644
index 000000000..b2e3fb61e
--- /dev/null
+++ b/qt-ui/profile/divetextitem.h
@@ -0,0 +1,22 @@
+#ifndef DIVETEXTITEM_H
+#define DIVETEXTITEM_H
+
+#include <QObject>
+#include <QGraphicsSimpleTextItem>
+
+/* A Line Item that has animated-properties. */
+class DiveTextItem :public QObject, public QGraphicsSimpleTextItem{
+ Q_OBJECT
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+ Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
+public:
+ DiveTextItem(QGraphicsItem* parent = 0);
+ virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
+ void setAlignment(int alignFlags);
+ void animatedHide();
+ void animateMoveTo(qreal x, qreal y);
+private:
+ int internalAlignFlags;
+};
+
+#endif
diff --git a/subsurface.pro b/subsurface.pro
index 1ba852d81..1fcabe2bd 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -66,7 +66,8 @@ HEADERS = \
qt-ui/profile/profilewidget2.h \
qt-ui/profile/diverectitem.h \
qt-ui/profile/divepixmapitem.h \
- qt-ui/profile/divelineitem.h
+ qt-ui/profile/divelineitem.h \
+ qt-ui/profile/divetextitem.h
SOURCES = \
deco.c \
@@ -120,7 +121,8 @@ SOURCES = \
qt-ui/profile/profilewidget2.cpp \
qt-ui/profile/diverectitem.cpp \
qt-ui/profile/divepixmapitem.cpp \
- qt-ui/profile/divelineitem.cpp
+ qt-ui/profile/divelineitem.cpp \
+ qt-ui/profile/divetextitem.cpp
linux*: SOURCES += linux.c
mac: SOURCES += macos.c