From e14a15e61c6fa5529f33de410bfc6e0ad351a7af Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 8 Jun 2014 12:43:04 -0300 Subject: Subtle animation when the picture gets hovered with the mouse. This patch adds a subtle animation when the picture gets hovered with the mouse, and restored to it's original size when mouse exits the image area. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/divepixmapitem.cpp | 24 +++++++++++++++++++++++- qt-ui/profile/divepixmapitem.h | 11 +++++++++++ qt-ui/profile/profilewidget2.cpp | 2 +- qt-ui/profile/profilewidget2.h | 3 ++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp index d27d77cba..b1942344e 100644 --- a/qt-ui/profile/divepixmapitem.cpp +++ b/qt-ui/profile/divepixmapitem.cpp @@ -1,5 +1,27 @@ #include "divepixmapitem.h" - +#include "animationfunctions.h" DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem() { } + +DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent) +{ + setAcceptsHoverEvents(true); + setScale(0.2); +} + +void DivePictureItem::setPixmap(const QPixmap &pix) +{ + DivePixmapItem::setPixmap(pix); + setTransformOriginPoint(boundingRect().width()/2, boundingRect().height()/2); +} + +void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Animations::scaleTo(this, 1.0); +} + +void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Animations::scaleTo(this, 0.2); +} diff --git a/qt-ui/profile/divepixmapitem.h b/qt-ui/profile/divepixmapitem.h index aa2563877..a0f542ea0 100644 --- a/qt-ui/profile/divepixmapitem.h +++ b/qt-ui/profile/divepixmapitem.h @@ -14,4 +14,15 @@ public: DivePixmapItem(QObject *parent = 0); }; +class DivePictureItem : public DivePixmapItem { + Q_OBJECT + Q_PROPERTY(qreal scale WRITE setScale READ scale) +public: + DivePictureItem(QObject *parent = 0); + void setPixmap(const QPixmap& pix); +protected: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); +}; + #endif // DIVEPIXMAPITEM_H diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 92c368cb8..b2021fd8c 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -1309,7 +1309,7 @@ void ProfileWidget2::plotPictures() // information area. if (!pic->timestamp) continue; - DivePixmapItem *item = new DivePixmapItem(); + DivePictureItem *item = new DivePictureItem(); item->setPixmap(m->index(i,0).data(Qt::DecorationRole).value()); // TODO: put the item in the correct place. use the pic.timestamp to find where it belongs on the dive. item->setPos(10 ,10); diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index a1ba7a23a..7d55fe5d0 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -43,6 +43,7 @@ class AbstractProfilePolygonItem; class DiveHandler; class QGraphicsSimpleTextItem; class QModelIndex; +class DivePictureItem; class ProfileWidget2 : public QGraphicsView { Q_OBJECT @@ -160,7 +161,7 @@ private: //specifics for ADD and PLAN QList handles; QList gases; - QList pictures; + QList pictures; void repositionDiveHandlers(); int fixHandlerIndex(DiveHandler *activeHandler); friend class DiveHandler; -- cgit v1.2.3-70-g09d2