diff options
| author | spycrab <spycrab@users.noreply.github.com> | 2017-06-26 23:22:40 +0200 |
|---|---|---|
| committer | spycrab <spycrab@users.noreply.github.com> | 2017-06-27 10:18:15 +0200 |
| commit | 2a1d18444f8c941364abff338e4ab18c5a44385f (patch) | |
| tree | cb2b99f5fffec9966a980fb0d07573e3fb7b794e /Source/Core/DolphinQt2/MainWindow.cpp | |
| parent | aa020040f6a1e47950d81d567a91101a42647901 (diff) | |
Qt: Implement gamelist drag and drop
Diffstat (limited to 'Source/Core/DolphinQt2/MainWindow.cpp')
| -rw-r--r-- | Source/Core/DolphinQt2/MainWindow.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 92a7ec0020..2da631a34c 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -4,9 +4,13 @@ #include <QCloseEvent> #include <QDir> +#include <QDragEnterEvent> +#include <QDropEvent> #include <QFileDialog> +#include <QFileInfo> #include <QIcon> #include <QMessageBox> +#include <QMimeData> #include "Common/Common.h" @@ -45,6 +49,7 @@ MainWindow::MainWindow() : QMainWindow(nullptr) setWindowTitle(QString::fromStdString(scm_rev_str)); setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL))); setUnifiedTitleAndToolBarOnMac(true); + setAcceptDrops(true); CreateComponents(); @@ -530,3 +535,46 @@ bool MainWindow::eventFilter(QObject* object, QEvent* event) return false; } + +void MainWindow::dragEnterEvent(QDragEnterEvent* event) +{ + if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) + event->acceptProposedAction(); +} + +void MainWindow::dropEvent(QDropEvent* event) +{ + const auto& urls = event->mimeData()->urls(); + if (urls.empty()) + return; + + const auto& url = urls[0]; + QFileInfo file_info(url.toLocalFile()); + + auto path = file_info.filePath(); + + if (!file_info.exists() || !file_info.isReadable()) + { + QMessageBox::critical(this, tr("Error"), tr("Failed to open '%1'").arg(path)); + return; + } + + if (file_info.isFile()) + { + StartGame(path); + } + else + { + auto& settings = Settings::Instance(); + + if (settings.GetPaths().size() != 0) + { + if (QMessageBox::question( + this, tr("Confirm"), + tr("Do you want to add \"%1\" to the list of Game Paths?").arg(path)) != + QMessageBox::Yes) + return; + } + settings.AddPath(path); + } +} |
