Qt: Drag and drop game loading (fixes #146)
Jeffrey Pfau jeffrey@endrift.com
Sun, 25 Jan 2015 04:53:24 -0800
3 files changed,
27 insertions(+),
0 deletions(-)
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -11,6 +11,7 @@ #include <QKeyEvent>
#include <QKeySequence> #include <QMenuBar> #include <QMessageBox> +#include <QMimeData> #include <QStackedLayout> #include "ConfigController.h"@@ -54,6 +55,7 @@ , m_shortcutController(new ShortcutController(this))
{ setWindowTitle(PROJECT_NAME); setFocusPolicy(Qt::StrongFocus); + setAcceptDrops(true); m_controller = new GameController(this); m_controller->setInputController(&m_inputController); m_controller->setOverrides(m_config->overrides());@@ -324,6 +326,28 @@
void Window::focusOutEvent(QFocusEvent*) { m_controller->setTurbo(false, false); 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() {
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -91,6 +91,8 @@ virtual void keyReleaseEvent(QKeyEvent* event) override;
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*);