Patches to add Context Menu to Images
Guido Lerch
guido.lerch at gmail.com
Tue Nov 3 08:21:03 PST 2015
Hi All,
Re-submitting.
This set of patches enables users to use the mouse and a context menu to:
1. Add images from files/web
2. Delete selected images
3. Delete all images
If there is no objection, I am going to work on a local file based
management
of images again that can be selected via the preferences, so people that
don't
want that don't have to.
--
Best regards,
Guido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20151103/87e145e1/attachment-0001.html>
-------------- next part --------------
From 65241f94f08ebcd5165d488067b32ba64c0620dc Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 21:02:41 +0200
Subject: [PATCH 1/6] Adding context menu to Images
Allowing to delete selected or all photos from the
dive images
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
desktop-widgets/maintab.cpp | 9 +++++++++
desktop-widgets/maintab.h | 1 +
2 files changed, 10 insertions(+)
diff --git a/desktop-widgets/maintab.cpp b/desktop-widgets/maintab.cpp
index 0afb7b4..a1f0438 100644
--- a/desktop-widgets/maintab.cpp
+++ b/desktop-widgets/maintab.cpp
@@ -1610,3 +1610,12 @@ void MainTab::showAndTriggerEditSelective(struct dive_components what)
weightModel->changed = true;
}
}
+
+void MainTab::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu popup(this);
+ popup.addAction(tr("Delete selected images"), this, SLOT(removeSelectedPhotos()));
+ popup.addAction(tr("Delete all images"), this, SLOT(removeAllPhotos()));
+ QAction *actionTaken = popup.exec(event->globalPos());
+ event->accept();
+}
diff --git a/desktop-widgets/maintab.h b/desktop-widgets/maintab.h
index 20b4da6..7b2bb86 100644
--- a/desktop-widgets/maintab.h
+++ b/desktop-widgets/maintab.h
@@ -54,6 +54,7 @@ public:
void refreshDisplayedDiveSite();
void nextInputField(QKeyEvent *event);
void showAndTriggerEditSelective(struct dive_components what);
+ void contextMenuEvent(QContextMenuEvent *event);
signals:
void addDiveFinished();
--
2.3.8 (Apple Git-58)
-------------- next part --------------
From a62e8f94408dded8cff07d8bec3c8cefb50200ff Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 21:07:43 +0200
Subject: [PATCH 3/6] Context menu support for images
removing obsolete code
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
desktop-widgets/maintab.cpp | 7 -------
1 file changed, 7 deletions(-)
diff --git a/desktop-widgets/maintab.cpp b/desktop-widgets/maintab.cpp
index a1f0438..595e9da 100644
--- a/desktop-widgets/maintab.cpp
+++ b/desktop-widgets/maintab.cpp
@@ -177,13 +177,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.cylinders->view()->horizontalHeader()->addAction(action);
}
- QAction *deletePhoto = new QAction(this);
- deletePhoto->setShortcut(Qt::Key_Delete);
- deletePhoto->setShortcutContext(Qt::WidgetShortcut);
- ui.photosView->addAction(deletePhoto);
- ui.photosView->setSelectionMode(QAbstractItemView::SingleSelection);
- connect(deletePhoto, SIGNAL(triggered(bool)), this, SLOT(removeSelectedPhotos()));
-
ui.waitingSpinner->setRoundness(70.0);
ui.waitingSpinner->setMinimumTrailOpacity(15.0);
ui.waitingSpinner->setTrailFadePercentage(70.0);
--
2.3.8 (Apple Git-58)
-------------- next part --------------
From f7f3e711262989f2ae095fc49af173b3c1909167 Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 21:08:59 +0200
Subject: [PATCH 4/6] Context menu support for images
Adding modified code to support deletion of selected images as
well as deleting of all images (with warning messagebox)
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
desktop-widgets/maintab.cpp | 25 ++++++++++++++++++++++---
desktop-widgets/maintab.h | 1 +
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/desktop-widgets/maintab.cpp b/desktop-widgets/maintab.cpp
index 595e9da..88f7903 100644
--- a/desktop-widgets/maintab.cpp
+++ b/desktop-widgets/maintab.cpp
@@ -1556,12 +1556,31 @@ void MainTab::photoDoubleClicked(const QString filePath)
void MainTab::removeSelectedPhotos()
{
+ bool last = false;
if (!ui.photosView->selectionModel()->hasSelection())
return;
+ QModelIndexList indexes = ui.photosView->selectionModel()->selectedRows();
+ if (indexes.count() == 0)
+ indexes = ui.photosView->selectionModel()->selectedIndexes();
+ QModelIndex photo = indexes.first();
+ do {
+ photo = indexes.first();
+ last = indexes.count() == 1;
+ if (photo.isValid()) {
+ QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString();
+ if (fileUrl.length() > 0)
+ DivePictureModel::instance()->removePicture(fileUrl, last);
+ }
+ indexes.removeFirst();
+ } while(!indexes.isEmpty());
+}
- QModelIndex photoIndex = ui.photosView->selectionModel()->selectedIndexes().first();
- QString fileUrl = photoIndex.data(Qt::DisplayPropertyRole).toString();
- DivePictureModel::instance()->removePicture(fileUrl);
+void MainTab::removeAllPhotos()
+{
+ if (QMessageBox::warning(this, tr("Deleting Images"), tr("Are you sure you want to delete all images?"), QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Cancel ) {
+ ui.photosView->selectAll();
+ removeSelectedPhotos();
+ }
}
#define SHOW_SELECTIVE(_component) \
diff --git a/desktop-widgets/maintab.h b/desktop-widgets/maintab.h
index 7b2bb86..c3f6649 100644
--- a/desktop-widgets/maintab.h
+++ b/desktop-widgets/maintab.h
@@ -97,6 +97,7 @@ slots:
void escDetected(void);
void photoDoubleClicked(const QString filePath);
void removeSelectedPhotos();
+ void removeAllPhotos();
void showLocation();
void enableGeoLookupEdition();
void disableGeoLookupEdition();
--
2.3.8 (Apple Git-58)
-------------- next part --------------
From 16905ded34691e42655de562147a4e6e456cf4c4 Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 21:10:44 +0200
Subject: [PATCH 5/6] Context menu support for images
Required change within DivePictureItem, adding update
parameter defaulted to true in this case.
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
profile-widget/divepixmapitem.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/profile-widget/divepixmapitem.cpp b/profile-widget/divepixmapitem.cpp
index 581f6f9..2be21ae 100644
--- a/profile-widget/divepixmapitem.cpp
+++ b/profile-widget/divepixmapitem.cpp
@@ -126,5 +126,5 @@ void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
void DivePictureItem::removePicture()
{
- DivePictureModel::instance()->removePicture(fileUrl);
+ DivePictureModel::instance()->removePicture(fileUrl, true);
}
--
2.3.8 (Apple Git-58)
-------------- next part --------------
From 8e48d93bf256e74ce2b483d2a11f71b8734fe12c Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 22:04:40 +0200
Subject: [PATCH 6/6] Context menu suport for images
Enabling multi selection
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
desktop-widgets/maintab.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/desktop-widgets/maintab.cpp b/desktop-widgets/maintab.cpp
index 88f7903..57e9a36 100644
--- a/desktop-widgets/maintab.cpp
+++ b/desktop-widgets/maintab.cpp
@@ -198,6 +198,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
acceptingEdit = false;
ui.diveTripLocation->hide();
+ ui.photosView->setSelectionMode(QAbstractItemView::MultiSelection);
}
MainTab::~MainTab()
--
2.3.8 (Apple Git-58)
-------------- next part --------------
From f7594fbbd54197abb7a20b65cc8d394afc8f07e8 Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 22:36:59 +0200
Subject: [PATCH 7/7] Context menu support for images
Adding loading from file and loading from web.
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
desktop-widgets/maintab.cpp | 13 +++++++++++++
desktop-widgets/maintab.h | 2 ++
2 files changed, 15 insertions(+)
diff --git a/desktop-widgets/maintab.cpp b/desktop-widgets/maintab.cpp
index 57e9a36..8a9f2c7 100644
--- a/desktop-widgets/maintab.cpp
+++ b/desktop-widgets/maintab.cpp
@@ -1584,6 +1584,16 @@ void MainTab::removeAllPhotos()
}
}
+void MainTab::addPhotosFromFile()
+{
+ MainWindow::instance()->dive_list()->loadImages();
+}
+
+void MainTab::addPhotosFromURL()
+{
+ MainWindow::instance()->dive_list()->loadWebImages();
+}
+
#define SHOW_SELECTIVE(_component) \
if (what._component) \
ui._component->setText(displayed_dive._component);
@@ -1627,6 +1637,9 @@ void MainTab::showAndTriggerEditSelective(struct dive_components what)
void MainTab::contextMenuEvent(QContextMenuEvent *event)
{
QMenu popup(this);
+ popup.addAction(tr("Load image(s) from file(s)"), this, SLOT(addPhotosFromFile()));
+ popup.addAction(tr("Load image(s) from web"), this, SLOT(addPhotosFromURL()));
+ popup.addSeparator();
popup.addAction(tr("Delete selected images"), this, SLOT(removeSelectedPhotos()));
popup.addAction(tr("Delete all images"), this, SLOT(removeAllPhotos()));
QAction *actionTaken = popup.exec(event->globalPos());
diff --git a/desktop-widgets/maintab.h b/desktop-widgets/maintab.h
index c3f6649..d4f7aaa 100644
--- a/desktop-widgets/maintab.h
+++ b/desktop-widgets/maintab.h
@@ -98,6 +98,8 @@ slots:
void photoDoubleClicked(const QString filePath);
void removeSelectedPhotos();
void removeAllPhotos();
+ void addPhotosFromFile();
+ void addPhotosFromURL();
void showLocation();
void enableGeoLookupEdition();
void disableGeoLookupEdition();
--
2.3.8 (Apple Git-58)
-------------- next part --------------
From bf989a642f9bb50cf6cf6f266fb0f8407f3916c9 Mon Sep 17 00:00:00 2001
From: Guido Lerch <guido.lerch at gmail.com>
Date: Tue, 20 Oct 2015 21:03:53 +0200
Subject: [PATCH 2/6] Context menu support for images
Altering DivePicture model to allow deleting images
from the QListView without immediate updating of the
list. Updating is determined by an additioanl parameter
Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
---
qt-models/divepicturemodel.cpp | 10 ++++++----
qt-models/divepicturemodel.h | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp
index 1f37423..bb5db33 100644
--- a/qt-models/divepicturemodel.cpp
+++ b/qt-models/divepicturemodel.cpp
@@ -111,12 +111,14 @@ QVariant DivePictureModel::data(const QModelIndex &index, int role) const
return ret;
}
-void DivePictureModel::removePicture(const QString &fileUrl)
+void DivePictureModel::removePicture(const QString &fileUrl, bool last)
{
dive_remove_picture(fileUrl.toUtf8().data());
- copy_dive(current_dive, &displayed_dive);
- updateDivePictures();
- mark_divelist_changed(true);
+ if (last) {
+ copy_dive(current_dive, &displayed_dive);
+ updateDivePictures();
+ mark_divelist_changed(true);
+ }
}
int DivePictureModel::rowCount(const QModelIndex &parent) const
diff --git a/qt-models/divepicturemodel.h b/qt-models/divepicturemodel.h
index d6393e4..7390fc5 100644
--- a/qt-models/divepicturemodel.h
+++ b/qt-models/divepicturemodel.h
@@ -33,7 +33,7 @@ public:
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual void updateDivePictures();
void updateDivePicturesWhenDone(QList<QFuture<void> >);
- void removePicture(const QString& fileUrl);
+ void removePicture(const QString& fileUrl, bool last);
protected:
DivePictureModel();
--
2.3.8 (Apple Git-58)
More information about the subsurface
mailing list