]> Creatis software - clitk.git/commitdiff
Merge branch 'm-pilia-drop_files'
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 4 Oct 2018 12:33:18 +0000 (14:33 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 4 Oct 2018 12:33:18 +0000 (14:33 +0200)
vv/vvMainWindow.cxx
vv/vvMainWindow.h

index 6a81732949e5857d50b2acb260925c5a0a2f7b7f..30f7da57693088207b345d4420971b291daf6858 100644 (file)
@@ -18,6 +18,7 @@ It is distributed under dual licence
 
 #include <algorithm>
 #include <QMessageBox>
+#include <QMimeData>
 #include <QInputDialog>
 #include <QTimer>
 #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<std::string> images;
+  for (auto const & url : mimeData->urls()) {
+    images.push_back(url.toLocalFile().toStdString());
+  }
+  LoadImages(images, vvImageReader::IMAGE);
+}
+//------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
index 2be7e7584caaf78ad91daf261642d5b343eb7449..07f38e5f9f415613c68410f8eb35445a504203b8 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <iostream>
 #include <vector>
+#include <QDropEvent>
 #include "vtkVersion.h"
 #if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9
 #include "ui_vvMainWindow.h"
@@ -197,6 +198,10 @@ protected:
   void createRecentlyOpenedFilesMenu();
   void updateRecentlyOpenedFilesMenu(const std::list<std::string> &files);
   
+  // Drag and drop event handlers
+  virtual void dragEnterEvent(QDragEnterEvent *event);
+  virtual void dropEvent(QDropEvent *event);
+
 private:
 
   //variables