Qt: Drag and drop game loading (fixes #146)

This commit is contained in:
Jeffrey Pfau 2015-01-25 04:53:24 -08:00
parent 0367a9db06
commit eb4c41d6fc
3 changed files with 27 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Features:
- Support BPS patches - Support BPS patches
- Configurable game overrides - Configurable game overrides
- Support loading 7-Zip files - Support loading 7-Zip files
- Drag and drop game loading
Bugfixes: Bugfixes:
- ARM7: Extend prefetch by one stage - ARM7: Extend prefetch by one stage
- GBA Audio: Support 16-bit writes to FIFO audio - GBA Audio: Support 16-bit writes to FIFO audio

View File

@ -11,6 +11,7 @@
#include <QKeySequence> #include <QKeySequence>
#include <QMenuBar> #include <QMenuBar>
#include <QMessageBox> #include <QMessageBox>
#include <QMimeData>
#include <QStackedLayout> #include <QStackedLayout>
#include "ConfigController.h" #include "ConfigController.h"
@ -54,6 +55,7 @@ Window::Window(ConfigController* config, QWidget* parent)
{ {
setWindowTitle(PROJECT_NAME); setWindowTitle(PROJECT_NAME);
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
setAcceptDrops(true);
m_controller = new GameController(this); m_controller = new GameController(this);
m_controller->setInputController(&m_inputController); m_controller->setInputController(&m_inputController);
m_controller->setOverrides(m_config->overrides()); m_controller->setOverrides(m_config->overrides());
@ -326,6 +328,28 @@ void Window::focusOutEvent(QFocusEvent*) {
m_controller->clearKeys(); 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() { void Window::toggleFullScreen() {
if (isFullScreen()) { if (isFullScreen()) {
showNormal(); showNormal();

View File

@ -91,6 +91,8 @@ protected:
virtual void resizeEvent(QResizeEvent*) override; virtual void resizeEvent(QResizeEvent*) override;
virtual void closeEvent(QCloseEvent*) override; virtual void closeEvent(QCloseEvent*) override;
virtual void focusOutEvent(QFocusEvent*) override; virtual void focusOutEvent(QFocusEvent*) override;
virtual void dragEnterEvent(QDragEnterEvent*) override;
virtual void dropEvent(QDropEvent*) override;
private slots: private slots:
void gameStarted(GBAThread*); void gameStarted(GBAThread*);