From 5a38a2db976cf17640808317694c2aaa7091fe35 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Wed, 26 Mar 2014 21:51:58 -0400 Subject: [PATCH] Allow dropping of files onto window --- src/window.cpp | 16 ++++++++++++++++ src/window.h | 4 ++++ 2 files changed, 20 insertions(+) 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(); -- 2.39.5