diff options
author | Arisotura <thetotalworm@gmail.com> | 2021-03-29 01:08:22 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2021-03-29 01:08:22 +0200 |
commit | d5dbef2c22f755ad82ec59e04948111797bc270a (patch) | |
tree | a4e8591ae28b1d7a8f6e4bb2d9f6e8c26303b052 /src/frontend/qt_sdl | |
parent | 284a9b73b055b6d450825efe0a5dcf7881438c00 (diff) |
make path inputs support drag/dropping files onto them to add the path quickly. fixes #1033
Diffstat (limited to 'src/frontend/qt_sdl')
-rw-r--r-- | src/frontend/qt_sdl/AudioSettingsDialog.ui | 9 | ||||
-rw-r--r-- | src/frontend/qt_sdl/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/frontend/qt_sdl/EmuSettingsDialog.ui | 25 | ||||
-rw-r--r-- | src/frontend/qt_sdl/QPathInput.h | 66 |
4 files changed, 91 insertions, 10 deletions
diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.ui b/src/frontend/qt_sdl/AudioSettingsDialog.ui index bcaf937..e57b6c5 100644 --- a/src/frontend/qt_sdl/AudioSettingsDialog.ui +++ b/src/frontend/qt_sdl/AudioSettingsDialog.ui @@ -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> diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 5ccab7d..d47005c 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -18,6 +18,7 @@ SET(SOURCES_QT_SDL font.h Platform.cpp PlatformConfig.cpp + QPathInput.h ArchiveUtil.h ArchiveUtil.cpp diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui index ac5506f..4291539 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.ui +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -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><html><head/><body><p>DS-mode ARM7 BIOS</p><p>Size should be 16 KB</p></body></html></string> </property> </widget> </item> <item row="2" column="1"> - <widget class="QLineEdit" name="txtFirmwarePath"> + <widget class="QPathInput" name="txtFirmwarePath"> <property name="whatsThis"> <string><html><head/><body><p>DS-mode firmware</p><p><br/></p><p>Possible firmwares:</p><p>* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.</p><p>* 256 KB: regular DS firmware.</p><p>* 512 KB: iQue DS firmware.</p></body></html></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><html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html></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><html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html></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><html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html></string> </property> </widget> </item> <item row="5" column="1"> - <widget class="QLineEdit" name="txtDSiSDPath"> + <widget class="QPathInput" name="txtDSiSDPath"> <property name="whatsThis"> <string><html><head/><body><p>SD image file for emulating the DSi's SD card</p></body></html></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> diff --git a/src/frontend/qt_sdl/QPathInput.h b/src/frontend/qt_sdl/QPathInput.h new file mode 100644 index 0000000..1cb1f7c --- /dev/null +++ b/src/frontend/qt_sdl/QPathInput.h @@ -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 |