As requested by Trac tickets #496 and #548:

double click on photo will launch external viewer by the means of
QDesktopServices::openURL().
What I personally dislike is launching external process from MainTab (while
MainWindow is a proper place). Unfortunately I have no idea how to connect
signal from DivePictureWidget to MainWindow.

Tested both on Linux and Windows platforms.

Sergey
From b7d254fab67adbbc3e6e804c51c729d8c7ad9790 Mon Sep 17 00:00:00 2001
From: Sergey Starosek <[email protected]>
Date: Fri, 27 Jun 2014 16:16:55 +0400
Subject: [PATCH 1/2] Emit signal on photo double-click
To: [email protected]

Signed-off-by: Sergey Starosek <[email protected]>
---
 qt-ui/divepicturewidget.cpp | 10 ++++++++++
 qt-ui/divepicturewidget.h   |  7 ++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index 6849146..6742fc2 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -77,6 +77,9 @@ QVariant DivePictureModel::data(const QModelIndex &index, int role) const
 			break;
 		case Qt::DisplayRole:
 			ret = QFileInfo(key).fileName();
+			break;
+		case Qt::DisplayPropertyRole:
+			ret = QFileInfo(key).filePath();
 		}
 	} else if (index.column() == 1) {
 		switch (role) {
@@ -94,4 +97,11 @@ int DivePictureModel::rowCount(const QModelIndex &parent) const
 
 DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent)
 {
+	connect(this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(doubleClicked(const QModelIndex &)));
+}
+
+void DivePictureWidget::doubleClicked(const QModelIndex &index)
+{
+	QString filePath = model()->data(index, Qt::DisplayPropertyRole).toString();
+	emit photoDoubleClicked(filePath);
 }
diff --git a/qt-ui/divepicturewidget.h b/qt-ui/divepicturewidget.h
index fde7c5a..f0ddebe 100644
--- a/qt-ui/divepicturewidget.h
+++ b/qt-ui/divepicturewidget.h
@@ -33,9 +33,14 @@ class DivePictureWidget : public QListView {
 	Q_OBJECT
 public:
 	DivePictureWidget(QWidget *parent);
+signals:
+	void photoDoubleClicked(const QString filePath);
+private
+slots:
+	void doubleClicked(const QModelIndex &index);
 };
 
 class DivePictureThumbnailThread : public QThread {
 };
 
-#endif
\ No newline at end of file
+#endif
-- 
1.8.5.5

From 17fef200e013148da1735059fb0c0cd710380d64 Mon Sep 17 00:00:00 2001
From: Sergey Starosek <[email protected]>
Date: Fri, 27 Jun 2014 16:17:33 +0400
Subject: [PATCH 2/2] Start external viewer on photo double-click
To: [email protected]

Signed-off-by: Sergey Starosek <[email protected]>
---
 qt-ui/maintab.cpp | 7 +++++++
 qt-ui/maintab.h   | 1 +
 2 files changed, 8 insertions(+)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 3df1e8a..6f9be07 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -27,6 +27,7 @@
 #include <QScrollBar>
 #include <QShortcut>
 #include <QMessageBox>
+#include <QDesktopServices>
 
 MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	weightModel(new WeightModel(this)),
@@ -41,6 +42,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	ui.cylinders->setModel(cylindersModel);
 	ui.weights->setModel(weightModel);
 	ui.photosView->setModel(divePictureModel);
+	connect(ui.photosView, SIGNAL(photoDoubleClicked(QString)), this, SLOT(photoDoubleClicked(QString)));
 	closeMessage();
 
 	QAction *action = new QAction(tr("Save"), this);
@@ -1119,3 +1121,8 @@ void MainTab::escDetected()
 	if (editMode != NONE)
 		rejectChanges();
 }
+
+void MainTab::photoDoubleClicked(const QString filePath)
+{
+	QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
+}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index f20af84..3d51f72 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -85,6 +85,7 @@ slots:
 	void updateTextLabels(bool showUnits = true);
 	QString trHemisphere(const char *orig);
 	void escDetected(void);
+	void photoDoubleClicked(const QString filePath);
 
 private:
 	Ui::MainTab ui;
-- 
1.8.5.5

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

Reply via email to