]> git.sur5r.net Git - fstl/commitdiff
Allow dropping of files onto window upstream-master v0.9.2
authorMatt Keeter <matt.j.keeter@gmail.com>
Thu, 27 Mar 2014 01:51:58 +0000 (21:51 -0400)
committerMatt Keeter <matt.j.keeter@gmail.com>
Thu, 27 Mar 2014 01:51:58 +0000 (21:51 -0400)
src/window.cpp
src/window.h

index 2d809bfb0610c8a3924213148528d9693c377c22..3002ecc83daa6008dd3c42c420b933c24605008e 100644 (file)
@@ -14,6 +14,7 @@ Window::Window(QWidget *parent) :
 
 {
     setWindowTitle("fstl");
+    setAcceptDrops(true);
 
     QFile styleFile(":/qt/style.qss");
     styleFile.open( QFile::ReadOnly );
@@ -128,3 +129,18 @@ bool Window::load_stl(const QString& filename)
     loader->start();
     return true;
 }
+
+void Window::dragEnterEvent(QDragEnterEvent *event)
+{
+    if (event->mimeData()->hasUrls())
+    {
+        auto urls = event->mimeData()->urls();
+        if (urls.size() == 1 && urls.front().path().endsWith(".stl"))
+            event->acceptProposedAction();
+    }
+}
+
+void Window::dropEvent(QDropEvent *event)
+{
+    load_stl(event->mimeData()->urls().front().toLocalFile());
+}
index 3ac5e9567401ed2cd534079a81c77b1389060b73..cb92ebb4708d2d68c52b3a1af82915c2b31c3940 100644 (file)
@@ -12,6 +12,10 @@ public:
     explicit Window(QWidget* parent=0);
     bool load_stl(const QString& filename);
 
+protected:
+    void dragEnterEvent(QDragEnterEvent* event);
+    void dropEvent(QDropEvent* event);
+
 public slots:
     void on_open();
     void on_about();