Reimplement savestate loading via drag and drop

This commit is contained in:
Dan B 2018-09-21 22:26:26 -04:00 committed by Léo Lam
parent b2de98cad1
commit d69740c8b4
2 changed files with 40 additions and 0 deletions

View File

@ -4,9 +4,14 @@
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QFileInfo>
#include <QGuiApplication> #include <QGuiApplication>
#include <QIcon> #include <QIcon>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMessageBox>
#include <QMimeData>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPalette> #include <QPalette>
#include <QScreen> #include <QScreen>
@ -14,6 +19,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/State.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/RenderWidget.h" #include "DolphinQt/RenderWidget.h"
@ -27,6 +33,7 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
{ {
setWindowTitle(QStringLiteral("Dolphin")); setWindowTitle(QStringLiteral("Dolphin"));
setWindowIcon(Resources::GetAppIcon()); setWindowIcon(Resources::GetAppIcon());
setAcceptDrops(true);
QPalette p; QPalette p;
p.setColor(QPalette::Background, Qt::black); p.setColor(QPalette::Background, Qt::black);
@ -81,6 +88,37 @@ void RenderWidget::SetFillBackground(bool fill)
setAutoFillBackground(fill); setAutoFillBackground(fill);
} }
void RenderWidget::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1)
event->acceptProposedAction();
}
void RenderWidget::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())
{
return;
}
State::LoadAs(path.toStdString());
}
void RenderWidget::OnHideCursorChanged() void RenderWidget::OnHideCursorChanged()
{ {
setCursor(Settings::Instance().GetHideCursor() ? Qt::BlankCursor : Qt::ArrowCursor); setCursor(Settings::Instance().GetHideCursor() ? Qt::BlankCursor : Qt::ArrowCursor);

View File

@ -36,6 +36,8 @@ private:
void OnKeepOnTopChanged(bool top); void OnKeepOnTopChanged(bool top);
void SetFillBackground(bool fill); void SetFillBackground(bool fill);
void OnFreeLookMouseMove(QMouseEvent* event); void OnFreeLookMouseMove(QMouseEvent* event);
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
static constexpr int MOUSE_HIDE_DELAY = 3000; static constexpr int MOUSE_HIDE_DELAY = 3000;
QTimer* m_mouse_timer; QTimer* m_mouse_timer;