Skip to content
Permalink
Browse files

Merge pull request #7690 from NarryG/dragload-savestate

Reimplement savestate loading via drag and drop (resubmission of #7425)
  • Loading branch information...
leoetlino committed Jan 16, 2019
2 parents a8bc6f9 + d69740c commit 3892c3ac481cdde5c9631ba0c8845660c7a95586
Showing with 40 additions and 0 deletions.
  1. +38 −0 Source/Core/DolphinQt/RenderWidget.cpp
  2. +2 −0 Source/Core/DolphinQt/RenderWidget.h
@@ -4,16 +4,22 @@

#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>
#include <QTimer>

#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);
@@ -36,6 +36,8 @@ class RenderWidget final : public QWidget
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;

0 comments on commit 3892c3a

Please sign in to comment.
You can’t perform that action at this time.