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 <QDesktopWidget>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QFileInfo>
#include <QGuiApplication>
#include <QIcon>
#include <QKeyEvent>
#include <QMessageBox>
#include <QMimeData>
#include <QMouseEvent>
#include <QPalette>
#include <QScreen>
@ -14,6 +19,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/State.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/RenderWidget.h"
@ -27,6 +33,7 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
{
setWindowTitle(QStringLiteral("Dolphin"));
setWindowIcon(Resources::GetAppIcon());
setAcceptDrops(true);
QPalette p;
p.setColor(QPalette::Background, Qt::black);
@ -81,6 +88,37 @@ void RenderWidget::SetFillBackground(bool 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()
{
setCursor(Settings::Instance().GetHideCursor() ? Qt::BlankCursor : Qt::ArrowCursor);

View File

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