diff view/Pane.cpp @ 312:6de6f78b13a1

* Make it possible to drop audio files, layer files, session files and images onto SV panes. Need to do a bit more work on where we expect the dropped file to go, particularly in the case of audio files -- at the moment they're always opened in new panes, but it may be better to by default replace whatever is in the target pane.
author Chris Cannam
date Wed, 10 Oct 2007 15:18:02 +0000
parents 5636eeacc467
children c0b9eec70639
line wrap: on
line diff
--- a/view/Pane.cpp	Wed Oct 10 10:22:34 2007 +0000
+++ b/view/Pane.cpp	Wed Oct 10 15:18:02 2007 +0000
@@ -27,6 +27,8 @@
 #include <QPaintEvent>
 #include <QPainter>
 #include <QBitmap>
+#include <QDragEnterEvent>
+#include <QDropEvent>
 #include <QCursor>
 #include <iostream>
 #include <cmath>
@@ -67,6 +69,7 @@
 {
     setObjectName("Pane");
     setMouseTracking(true);
+    setAcceptDrops(true);
     
     updateHeadsUpDisplay();
 }
@@ -1893,6 +1896,55 @@
     }
 }
 
+void
+Pane::dragEnterEvent(QDragEnterEvent *e)
+{
+    QStringList formats(e->mimeData()->formats());
+    std::cerr << "dragEnterEvent: format: "
+              << formats.join(",").toStdString()
+              << ", possibleActions: " << e->possibleActions()
+              << ", proposedAction: " << e->proposedAction() << std::endl;
+    
+    if (e->provides("text/uri-list") || e->provides("text/plain")) {
+
+        if (e->proposedAction() & Qt::CopyAction) {
+            e->acceptProposedAction();
+        } else {
+            e->setDropAction(Qt::CopyAction);
+            e->accept();
+        }
+    }
+}
+
+void
+Pane::dropEvent(QDropEvent *e)
+{
+    std::cerr << "dropEvent: text: \"" << e->mimeData()->text().toStdString()
+              << "\"" << std::endl;
+
+    if (e->provides("text/uri-list") || e->provides("text/plain")) {
+
+        if (e->proposedAction() & Qt::CopyAction) {
+            e->acceptProposedAction();
+        } else {
+            e->setDropAction(Qt::CopyAction);
+            e->accept();
+        }
+
+        if (e->provides("text/uri-list")) {
+
+            std::cerr << "accepting... data is \"" << e->encodedData("text/uri-list").data() << "\"" << std::endl;
+            emit dropAccepted(QString::fromLocal8Bit
+                              (e->encodedData("text/uri-list").data())
+                              .split(QRegExp("[\\r\\n]+"), 
+                                     QString::SkipEmptyParts));
+        } else {
+            emit dropAccepted(QString::fromLocal8Bit
+                              (e->encodedData("text/plain").data()));
+        }
+    }
+}
+
 bool
 Pane::editSelectionStart(QMouseEvent *e)
 {