From: Martino Pilia Date: Tue, 11 Sep 2018 18:47:09 +0000 (+0200) Subject: Open files by dropping them inside the window X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=clitk.git;a=commitdiff_plain;h=0e51b8dde15bfe59437d6f351c516f4137faf631 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. --- 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