From eb4c41d6fc8ab1ed16e9812e4f54a1de93d6cc3c Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 25 Jan 2015 04:53:24 -0800 Subject: [PATCH] Qt: Drag and drop game loading (fixes #146) --- CHANGES | 1 + src/platform/qt/Window.cpp | 24 ++++++++++++++++++++++++ src/platform/qt/Window.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/CHANGES b/CHANGES index 6c53e7a39..57d817b20 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ Features: - Support BPS patches - Configurable game overrides - Support loading 7-Zip files + - Drag and drop game loading Bugfixes: - ARM7: Extend prefetch by one stage - GBA Audio: Support 16-bit writes to FIFO audio diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index a252150c3..4b48c530a 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "ConfigController.h" @@ -54,6 +55,7 @@ Window::Window(ConfigController* config, QWidget* parent) { setWindowTitle(PROJECT_NAME); setFocusPolicy(Qt::StrongFocus); + setAcceptDrops(true); m_controller = new GameController(this); m_controller->setInputController(&m_inputController); m_controller->setOverrides(m_config->overrides()); @@ -326,6 +328,28 @@ void Window::focusOutEvent(QFocusEvent*) { m_controller->clearKeys(); } +void Window::dragEnterEvent(QDragEnterEvent* event) { + if (event->mimeData()->hasFormat("text/uri-list")) { + event->acceptProposedAction(); + } +} + +void Window::dropEvent(QDropEvent* event) { + QString uris = event->mimeData()->data("text/uri-list"); + uris = uris.trimmed(); + if (uris.contains("\n")) { + // Only one file please + return; + } + QUrl url(uris); + if (!url.isLocalFile()) { + // No remote loading + return; + } + event->accept(); + m_controller->loadGame(url.path()); +} + void Window::toggleFullScreen() { if (isFullScreen()) { showNormal(); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index c70741d8a..be4effa89 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -91,6 +91,8 @@ protected: virtual void resizeEvent(QResizeEvent*) override; virtual void closeEvent(QCloseEvent*) override; virtual void focusOutEvent(QFocusEvent*) override; + virtual void dragEnterEvent(QDragEnterEvent*) override; + virtual void dropEvent(QDropEvent*) override; private slots: void gameStarted(GBAThread*);