Qt: Implement gamelist drag and drop
This commit is contained in:
parent
aa020040f6
commit
2a1d18444f
|
@ -4,9 +4,13 @@
|
||||||
|
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
#include <QDropEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
|
|
||||||
|
@ -45,6 +49,7 @@ MainWindow::MainWindow() : QMainWindow(nullptr)
|
||||||
setWindowTitle(QString::fromStdString(scm_rev_str));
|
setWindowTitle(QString::fromStdString(scm_rev_str));
|
||||||
setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL)));
|
setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL)));
|
||||||
setUnifiedTitleAndToolBarOnMac(true);
|
setUnifiedTitleAndToolBarOnMac(true);
|
||||||
|
setAcceptDrops(true);
|
||||||
|
|
||||||
CreateComponents();
|
CreateComponents();
|
||||||
|
|
||||||
|
@ -530,3 +535,46 @@ bool MainWindow::eventFilter(QObject* object, QEvent* event)
|
||||||
|
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ class HotkeyScheduler;
|
||||||
class MappingWindow;
|
class MappingWindow;
|
||||||
class SettingsWindow;
|
class SettingsWindow;
|
||||||
class ControllersWindow;
|
class ControllersWindow;
|
||||||
|
class DragEnterEvent;
|
||||||
|
|
||||||
class MainWindow final : public QMainWindow
|
class MainWindow final : public QMainWindow
|
||||||
{
|
{
|
||||||
|
@ -82,6 +83,9 @@ private:
|
||||||
void ShowAboutDialog();
|
void ShowAboutDialog();
|
||||||
void ShowHotkeyDialog();
|
void ShowHotkeyDialog();
|
||||||
|
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
|
||||||
QStackedWidget* m_stack;
|
QStackedWidget* m_stack;
|
||||||
ToolBar* m_tool_bar;
|
ToolBar* m_tool_bar;
|
||||||
MenuBar* m_menu_bar;
|
MenuBar* m_menu_bar;
|
||||||
|
|
Loading…
Reference in New Issue