add drag-drop support

This commit is contained in:
Arisotura 2020-05-20 02:36:48 +02:00
parent 4dae6d8928
commit 5ed87a634a
2 changed files with 65 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include <QPaintEvent>
#include <QPainter>
#include <QKeyEvent>
#include <QMimeData>
#include <SDL2/SDL.h>
@ -503,6 +504,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
{
setWindowTitle("melonDS " MELONDS_VERSION);
setAttribute(Qt::WA_DeleteOnClose);
setAcceptDrops(true);
QMenuBar* menubar = new QMenuBar();
{
@ -612,6 +614,66 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event)
}
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
{
if (!event->mimeData()->hasUrls()) return;
QList<QUrl> urls = event->mimeData()->urls();
if (urls.count() > 1) return; // not handling more than one file at once
QString filename = urls.at(0).toLocalFile();
QString ext = filename.right(3);
if (ext == "nds" || ext == "srl" || (ext == "gba" && RunningSomething))
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent* event)
{
if (!event->mimeData()->hasUrls()) return;
QList<QUrl> urls = event->mimeData()->urls();
if (urls.count() > 1) return; // not handling more than one file at once
emuThread->emuPause(true);
QString filename = urls.at(0).toLocalFile();
QString ext = filename.right(3);
char _filename[1024];
strncpy(_filename, filename.toStdString().c_str(), 1023); _filename[1023] = '\0';
int slot; int res;
if (ext == "gba")
{
slot = 1;
res = Frontend::LoadROM(_filename, Frontend::ROMSlot_GBA);
}
else
{
slot = 0;
res = Frontend::LoadROM(_filename, Frontend::ROMSlot_NDS);
}
if (res != Frontend::Load_OK)
{
QMessageBox::critical(this,
"melonDS",
loadErrorStr(res));
emuThread->emuUnpause();
}
else if (slot == 1)
{
// checkme
emuThread->emuUnpause();
}
else
{
emuThread->emuRun();
}
}
QString MainWindow::loadErrorStr(int error)
{
switch (error)

View File

@ -92,6 +92,9 @@ protected:
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
private slots:
void onOpenFile();
void onBootFirmware();