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
- 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

View File

@ -11,6 +11,7 @@
#include <QKeySequence>
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
#include <QStackedLayout>
#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();

View File

@ -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*);