diff options
author | noah the goodra <peterpan0413@live.com> | 2017-02-15 21:23:30 -0600 |
---|---|---|
committer | noah the goodra <peterpan0413@live.com> | 2017-02-16 14:43:18 -0600 |
commit | 6bcd5ce047bd6914e83bd1eed959adf6c0df2be0 (patch) | |
tree | 45622934bd7a7bef6cbadf016bec1752b04be52f /src/citra_qt/main.cpp | |
parent | 5472528202e644b4c9c4438a4e083607cded2757 (diff) |
added drag n drop feature
Diffstat (limited to 'src/citra_qt/main.cpp')
-rw-r--r-- | src/citra_qt/main.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 3c2e19344e..3c1ae8848e 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -54,7 +54,7 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { Pica::g_debug_context = Pica::DebugContext::Construct(); - + setAcceptDrops(true); ui.setupUi(this); statusBar()->hide(); @@ -625,6 +625,40 @@ void GMainWindow::closeEvent(QCloseEvent* event) { QWidget::closeEvent(event); } +bool IsSingleFileDropEvent(QDropEvent* event) { + const QMimeData* mimeData = event->mimeData(); + return mimeData->hasUrls() && mimeData->urls().length() == 1; +} + +void GMainWindow::dropEvent(QDropEvent* event) { + if (IsSingleFileDropEvent(event) && ConfirmChangeGame()) { + const QMimeData* mimeData = event->mimeData(); + QString filename = mimeData->urls().at(0).toLocalFile(); + BootGame(filename.toStdString()); + } +} + +void GMainWindow::dragEnterEvent(QDragEnterEvent* event) { + if (IsSingleFileDropEvent(event)) { + event->acceptProposedAction(); + } +} + +void GMainWindow::dragMoveEvent(QDragMoveEvent* event) { + event->acceptProposedAction(); +} + +bool GMainWindow::ConfirmChangeGame() { + if (emu_thread == nullptr) + return true; + + auto answer = QMessageBox::question( + this, tr("Citra"), + tr("Are you sure you want to stop the emulation? Any unsaved progress will be lost."), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + return answer != QMessageBox::No; +} + #ifdef main #undef main #endif |