From 7e7e562d4529e8c059ee8f45a4eb88acd4375f7d Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 15 Oct 2016 12:13:31 -0700 Subject: [PATCH] Open files when they are dropped on the main window. --- common/lc_mainwindow.cpp | 17 ++++++++++++++++- common/lc_mainwindow.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 7bf4b80c..7679b1cc 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -60,7 +60,8 @@ lcMainWindow::~lcMainWindow() void lcMainWindow::CreateWidgets() { - setWindowIcon(QIcon(":/resources/leocad.png")); + setAcceptDrops(true); + setWindowIcon(QIcon(":/resources/icon64.png")); setWindowFilePath(QString()); CreateActions(); @@ -687,6 +688,20 @@ void lcMainWindow::closeEvent(QCloseEvent *event) event->ignore(); } +void lcMainWindow::dragEnterEvent(QDragEnterEvent* Event) +{ + if (Event->mimeData()->hasUrls()) + Event->acceptProposedAction(); +} + +void lcMainWindow::dropEvent(QDropEvent* Event) +{ + const QMimeData* MimeData = Event->mimeData(); + foreach (const QUrl &Url, MimeData->urls()) + if (OpenProject(Url.toLocalFile())) + break; +} + QMenu* lcMainWindow::createPopupMenu() { QMenu* Menu = new QMenu(this); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 6d42e420..bead1aa3 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -275,6 +275,8 @@ protected slots: protected: void closeEvent(QCloseEvent *event); + void dragEnterEvent(QDragEnterEvent* Event); + void dropEvent(QDropEvent* Event); QMenu* createPopupMenu(); void CreateActions();