From: Matt Keeter Date: Thu, 27 Mar 2014 01:51:58 +0000 (-0400) Subject: Allow dropping of files onto window X-Git-Tag: v0.9.2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fheads%2Fupstream-master;p=fstl Allow dropping of files onto window --- diff --git a/src/window.cpp b/src/window.cpp index 2d809bf..3002ecc 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -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()); +} diff --git a/src/window.h b/src/window.h index 3ac5e95..cb92ebb 100644 --- a/src/window.h +++ b/src/window.h @@ -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();