this should make the picture handling a bit nicer.
From af8d131381ab3bf427b6cd92e001743164f36cc5 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 27 Jun 2014 18:00:42 -0300
Subject: [PATCH 1/3] Open picture manager when clicking on the picture at the
 profile

This patch makes the click on pic == open picture browser works
also on the profile instead of only on the list view..

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divepixmapitem.cpp | 13 ++++++++++++-
 qt-ui/profile/divepixmapitem.h   |  5 ++++-
 qt-ui/profile/profilewidget2.cpp |  7 +++----
 qt-ui/simplewidgets.cpp          |  1 -
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp
index 263a802..026bf23 100644
--- a/qt-ui/profile/divepixmapitem.cpp
+++ b/qt-ui/profile/divepixmapitem.cpp
@@ -1,21 +1,25 @@
 #include "divepixmapitem.h"
 #include "animationfunctions.h"
+#include <divepicturewidget.h>
 
 #include <QPen>
 #include <QBrush>
 #include <QGraphicsDropShadowEffect>
+#include <QDesktopServices>
+#include <QUrl>
 
 DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem()
 {
 }
 
-DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent)
+DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(parent)
 {
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 	setAcceptsHoverEvents(true);
 #else
 	setAcceptHoverEvents(true);
 #endif
+	rowOnModel = row;
 	setScale(0.2);
 }
 
@@ -56,3 +60,10 @@ void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
 	Animations::scaleTo(this, 0.2);
 	this->setZValue(0);
 }
+
+void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+	QString filePath = DivePictureModel::instance()->index(rowOnModel,0).data(Qt::ToolTipRole).toString();
+	QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
+}
+
diff --git a/qt-ui/profile/divepixmapitem.h b/qt-ui/profile/divepixmapitem.h
index a0f542e..26aeeaf 100644
--- a/qt-ui/profile/divepixmapitem.h
+++ b/qt-ui/profile/divepixmapitem.h
@@ -18,11 +18,14 @@ class DivePictureItem : public DivePixmapItem {
 	Q_OBJECT
 	Q_PROPERTY(qreal scale WRITE setScale READ scale)
 public:
-	DivePictureItem(QObject *parent = 0);
+	DivePictureItem(int row, QObject *parent = 0);
 	void setPixmap(const QPixmap& pix);
 protected:
 	void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
 	void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+	void mousePressEvent(QGraphicsSceneMouseEvent *event);
+private:
+	int rowOnModel;
 };
 
 #endif // DIVEPIXMAPITEM_H
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 66d7872..d8764c4 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -1325,16 +1325,15 @@ void ProfileWidget2::plotPictures()
 		// information area.
 		if (!pic->offset.seconds)
 			continue;
-		DivePictureItem *item = new DivePictureItem();
+		DivePictureItem *item = new DivePictureItem(i);
 		item->setPixmap(m->index(i,0).data(Qt::DecorationRole).value<QPixmap>());
 		// let's put the picture at the correct time, but at a fixed "depth" on the profile
 		// not sure this is ideal, but it seems to look right.
 		x = timeAxis->posAtValue(pic->offset.seconds);
 		if (i == 0)
 			y = 10;
-		else
-			if (fabs(x - lastX) < 4)
-				y = lastY + 3;
+		else if (fabs(x - lastX) < 4)
+			y = lastY + 3;
 		lastX = x;
 		lastY = y;
 		item->setPos(x, y);
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
index 035e278..643efd4 100644
--- a/qt-ui/simplewidgets.cpp
+++ b/qt-ui/simplewidgets.cpp
@@ -337,7 +337,6 @@ void DateWidget::paintEvent(QPaintEvent *event)
 	QString year = mDate.toString("yyyy");
 	QString day = mDate.toString("dd");
 
-
 	QFont font = QFont("monospace", 10);
 	QFontMetrics metrics = QFontMetrics(font);
 	painter.setFont(font);
-- 
2.0.0

From 13f206e04f22fe350b5e24a953ab65ea3d597393 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 27 Jun 2014 18:03:18 -0300
Subject: [PATCH 2/3] This is unecessary when calling methods.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divepixmapitem.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp
index 026bf23..1ec937b 100644
--- a/qt-ui/profile/divepixmapitem.cpp
+++ b/qt-ui/profile/divepixmapitem.cpp
@@ -52,13 +52,13 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
 void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
 	Animations::scaleTo(this, 1.0);
-	this->setZValue(5);
+	setZValue(5);
 }
 
 void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
 {
 	Animations::scaleTo(this, 0.2);
-	this->setZValue(0);
+	setZValue(0);
 }
 
 void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
-- 
2.0.0

From c2ee38b40a23dc16c5b991e7a9e8188d5efc9f3c Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 27 Jun 2014 18:13:33 -0300
Subject: [PATCH 3/3] Fix dive picture position

I was messing with the origin point, making the dive picture
be a tiny bit to the right. This removes the rotation, but
that was also not very good.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divepixmapitem.cpp | 9 +--------
 qt-ui/profile/profilewidget2.cpp | 1 -
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp
index 1ec937b..7d6c335 100644
--- a/qt-ui/profile/divepixmapitem.cpp
+++ b/qt-ui/profile/divepixmapitem.cpp
@@ -14,6 +14,7 @@ DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixm
 
 DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(parent)
 {
+	setFlag(ItemIgnoresTransformations);
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 	setAcceptsHoverEvents(true);
 #else
@@ -39,14 +40,6 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
 	shadow->setBrush(QColor(Qt::lightGray));
 	shadow->setFlag(ItemStacksBehindParent);
 	shadow->setZValue(-2);
-
-	setTransformOriginPoint(boundingRect().width()/2, boundingRect().height()/2);
-
-	qreal angle = qrand() % 5;
-	if (rand() % 2)
-		angle *= -1;
-
-	setRotation(angle);
 }
 
 void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index d8764c4..299cc29 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -1337,7 +1337,6 @@ void ProfileWidget2::plotPictures()
 		lastX = x;
 		lastY = y;
 		item->setPos(x, y);
-		item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
 		scene()->addItem(item);
 		pictures.push_back(item);
 	}
-- 
2.0.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to