make path inputs support drag/dropping files onto them to add the path quickly. fixes #1033

This commit is contained in:
Arisotura 2021-03-29 01:08:22 +02:00
parent 284a9b73b0
commit d5dbef2c22
4 changed files with 91 additions and 10 deletions

View File

@ -62,7 +62,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QLineEdit" name="txtMicWavPath">
<widget class="QPathInput" name="txtMicWavPath">
<property name="minimumSize">
<size>
<width>290</width>
@ -136,6 +136,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QPathInput</class>
<extends>QLineEdit</extends>
<header>QPathInput.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>

View File

@ -18,6 +18,7 @@ SET(SOURCES_QT_SDL
font.h
Platform.cpp
PlatformConfig.cpp
QPathInput.h
ArchiveUtil.h
ArchiveUtil.cpp

View File

@ -90,14 +90,14 @@
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QLineEdit" name="txtBIOS7Path">
<widget class="QPathInput" name="txtBIOS7Path">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DS-mode ARM7 BIOS&lt;/p&gt;&lt;p&gt;Size should be 16 KB&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtFirmwarePath">
<widget class="QPathInput" name="txtFirmwarePath">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DS-mode firmware&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Possible firmwares:&lt;/p&gt;&lt;p&gt;* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.&lt;/p&gt;&lt;p&gt;* 256 KB: regular DS firmware.&lt;/p&gt;&lt;p&gt;* 512 KB: iQue DS firmware.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -155,7 +155,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtBIOS9Path">
<widget class="QPathInput" name="txtBIOS9Path">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -197,7 +197,7 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QLineEdit" name="txtDSiBIOS7Path">
<widget class="QPathInput" name="txtDSiBIOS7Path">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DSi-mode ARM7 BIOS&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Size should be 64 KB&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -239,7 +239,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtDSiNANDPath">
<widget class="QPathInput" name="txtDSiNANDPath">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DSi NAND dump&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Should have 'nocash footer' at the end&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -260,7 +260,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtDSiBIOS9Path">
<widget class="QPathInput" name="txtDSiBIOS9Path">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -287,14 +287,14 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtDSiFirmwarePath">
<widget class="QPathInput" name="txtDSiFirmwarePath">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DSi-mode firmware (used for DS-mode backwards compatibility)&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Size should be 128 KB&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="txtDSiSDPath">
<widget class="QPathInput" name="txtDSiSDPath">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;SD image file for emulating the DSi's SD card&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -410,7 +410,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtDLDISDPath"/>
<widget class="QPathInput" name="txtDLDISDPath"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
@ -448,6 +448,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QPathInput</class>
<extends>QLineEdit</extends>
<header>QPathInput.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cbxConsoleType</tabstop>
<tabstop>chkDirectBoot</tabstop>

View File

@ -0,0 +1,66 @@
/*
Copyright 2016-2021 Arisotura
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#ifndef QPATHINPUT_H
#define QPATHINPUT_H
#include <QLineEdit>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
class QPathInput : public QLineEdit
{
Q_OBJECT
public:
QPathInput(QWidget* parent = nullptr) : QLineEdit(parent)
{
setAcceptDrops(true);
}
~QPathInput()
{
}
protected:
void dragEnterEvent(QDragEnterEvent* event) override
{
if (!event->mimeData()->hasUrls()) return QLineEdit::dragEnterEvent(event);
QList<QUrl> urls = event->mimeData()->urls();
if (urls.count() > 1) return QLineEdit::dragEnterEvent(event);
QString filename = urls.at(0).toLocalFile();
event->acceptProposedAction();
}
void dropEvent(QDropEvent* event) override
{
if (!event->mimeData()->hasUrls()) return QLineEdit::dropEvent(event);
QList<QUrl> urls = event->mimeData()->urls();
if (urls.count() > 1) return QLineEdit::dropEvent(event);
QString filename = urls.at(0).toLocalFile();
setText(filename);
}
};
#endif // QPATHINPUT_H