add drag-drop support
This commit is contained in:
parent
4dae6d8928
commit
5ed87a634a
|
@ -28,6 +28,7 @@
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
@ -503,6 +504,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
{
|
{
|
||||||
setWindowTitle("melonDS " MELONDS_VERSION);
|
setWindowTitle("melonDS " MELONDS_VERSION);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
setAcceptDrops(true);
|
||||||
|
|
||||||
QMenuBar* menubar = new QMenuBar();
|
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)
|
QString MainWindow::loadErrorStr(int error)
|
||||||
{
|
{
|
||||||
switch (error)
|
switch (error)
|
||||||
|
|
|
@ -92,6 +92,9 @@ protected:
|
||||||
void keyPressEvent(QKeyEvent* event) override;
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
void keyReleaseEvent(QKeyEvent* event) override;
|
void keyReleaseEvent(QKeyEvent* event) override;
|
||||||
|
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onOpenFile();
|
void onOpenFile();
|
||||||
void onBootFirmware();
|
void onBootFirmware();
|
||||||
|
|
Loading…
Reference in New Issue