commit 5a38a2db976cf17640808317694c2aaa7091fe35 parent d9301bbba097438546344405bd8899b0311cdc85 Author: Matt Keeter <matt.j.keeter@gmail.com> Date: Wed, 26 Mar 2014 21:51:58 -0400 Allow dropping of files onto window Diffstat:
M | src/window.cpp | | | 16 | ++++++++++++++++ |
M | src/window.h | | | 4 | ++++ |
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git 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 @@ -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();