From 0e51b8dde15bfe59437d6f351c516f4137faf631 Mon Sep 17 00:00:00 2001 From: Martino Pilia Date: Tue, 11 Sep 2018 20:47:09 +0200 Subject: [PATCH] Open files by dropping them inside the window Set the window to allow drag events entering it, and add an handler to open files dropped within the window. --- vv/vvMainWindow.cxx | 22 ++++++++++++++++++++++ vv/vvMainWindow.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 4e3ba21..153b461 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -18,6 +18,7 @@ It is distributed under dual licence #include #include +#include #include #include #include "QTreePushButton.h" @@ -132,6 +133,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() { setupUi(this); // this sets up the GUI + setAcceptDrops(true); // enable to drop into the window + setDicomClient(); //Qt::WindowFlags flags = windowFlags(); @@ -816,6 +819,25 @@ void vvMainWindow::OpenRecentImage() LoadImages(images, vvImageReader::IMAGE); } //------------------------------------------------------------------------------ +void vvMainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } +} +//------------------------------------------------------------------------------ +void vvMainWindow::dropEvent(QDropEvent *event) +{ + const QMimeData * mimeData = event->mimeData(); + if (!mimeData->hasUrls()) + return; + std::vector images; + for (auto const & url : mimeData->urls()) { + images.push_back(url.toLocalFile().toStdString()); + } + LoadImages(images, vvImageReader::IMAGE); +} +//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index 8908b24..2d6a21d 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -21,6 +21,7 @@ #include #include +#include #include "ui_vvMainWindow.h" #include "vvMainWindowBase.h" #include "vvToolManager.h" @@ -192,6 +193,10 @@ protected: void createRecentlyOpenedFilesMenu(); void updateRecentlyOpenedFilesMenu(const std::list &files); + // Drag and drop event handlers + virtual void dragEnterEvent(QDragEnterEvent *event); + virtual void dropEvent(QDropEvent *event); + private: //variables -- 2.45.0