]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Convert Drag/Drop opening file function to c++ < c++11
[clitk.git] / vv / vvMainWindow.cxx
index 6a81732949e5857d50b2acb260925c5a0a2f7b7f..1bf54692df4a6de78ae15e312f2d3786f9098249 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 (int i=0; i<mimeData->urls().size(); ++i) {
+    images.push_back(mimeData->urls()[i].toLocalFile().toStdString());
+  }
+  LoadImages(images, vvImageReader::IMAGE);
+}
+//------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------