From 9d90b97ba31c47ae093650601f4643737d4768a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 4 Oct 2016 10:16:46 +0200 Subject: [PATCH] Added support for drag&drop --- src/gui.cpp | 23 +++++++++++++++++++++++ src/gui.h | 2 ++ src/pathview.cpp | 1 + 3 files changed, 26 insertions(+) diff --git a/src/gui.cpp b/src/gui.cpp index fa3ad6ec..fb724696 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "config.h" #include "icons.h" @@ -1173,6 +1174,28 @@ void GUI::closeEvent(QCloseEvent *event) event->accept(); } +void GUI::dragEnterEvent(QDragEnterEvent *event) +{ + if (!event->mimeData()->hasUrls()) + return; + if (event->proposedAction() != Qt::CopyAction) + return; + + QList urls = event->mimeData()->urls(); + for (int i = 0; i < urls.size(); i++) + if (!urls.at(i).isLocalFile()) + return; + + event->acceptProposedAction(); +} + +void GUI::dropEvent(QDropEvent *event) +{ + QList urls = event->mimeData()->urls(); + for (int i = 0; i < urls.size(); i++) + openFile(urls.at(i).toLocalFile()); +} + void GUI::writeSettings() { QSettings settings(APP_NAME, APP_NAME); diff --git a/src/gui.h b/src/gui.h index 745c3aaf..673930d8 100644 --- a/src/gui.h +++ b/src/gui.h @@ -110,6 +110,8 @@ private: void keyPressEvent(QKeyEvent *event); void closeEvent(QCloseEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); QToolBar *_fileToolBar; QToolBar *_showToolBar; diff --git a/src/pathview.cpp b/src/pathview.cpp index e34d0ee8..c2f34af2 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -26,6 +26,7 @@ PathView::PathView(QWidget *parent) setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setRenderHints(QPainter::Antialiasing); + setAcceptDrops(false); _mapScale = new ScaleItem(); _mapScale->setZValue(2.0);