all repos — mgba @ d44a26d96227b025031cc323bd8efe2aca7e7b30

mGBA Game Boy Advance Emulator

Qt: Pay down some technical debt in the shader selector
Vicki Pfau vi@endrift.com
Thu, 03 Dec 2020 23:55:46 -0800
commit

d44a26d96227b025031cc323bd8efe2aca7e7b30

parent

a8a73720830e4f7681f320b913ef72941b1e358e

3 files changed, 13 insertions(+), 15 deletions(-)

jump to
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -184,12 +184,12 @@ }

return filename; } -QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title) { +QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title, const QString& path) { QList<Window*> paused; pauseAll(&paused); - QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController->getOption("lastDirectory")); + QString filename = QFileDialog::getExistingDirectory(owner, title, !path.isNull() ? path : m_configController->getOption("lastDirectory")); continueAll(paused); - if (!filename.isEmpty()) { + if (path.isNull() && !filename.isEmpty()) { m_configController->setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath()); } return filename;
M src/platform/qt/GBAApp.hsrc/platform/qt/GBAApp.h

@@ -58,10 +58,10 @@ static QString dataDir();

Window* newWindow(); - QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString()); - QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = QString()); - QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString()); - QString getOpenDirectoryName(QWidget* owner, const QString& title); + QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = {}); + QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = {}); + QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = {}); + QString getOpenDirectoryName(QWidget* owner, const QString& title, const QString& path = {}); const NoIntroDB* gameDB() const { return m_db; } bool reloadGameDB();
M src/platform/qt/ShaderSelector.cppsrc/platform/qt/ShaderSelector.cpp

@@ -11,6 +11,7 @@ #include "Display.h"

#include "VFileDevice.h" #include <QCheckBox> +#include <QDir> #include <QDoubleSpinBox> #include <QFileDialog> #include <QFormLayout>

@@ -60,14 +61,11 @@ }

} void ShaderSelector::selectShader() { - QString path(GBAApp::dataDir()); - path += QLatin1String("/shaders"); - QFileDialog dialog(nullptr, tr("Load shader"), path); - dialog.setFileMode(QFileDialog::Directory); - dialog.exec(); - QStringList names = dialog.selectedFiles(); - if (names.count() == 1) { - loadShader(names[0]); + QDir path(GBAApp::dataDir()); + path.cd(QLatin1String("shaders")); + QString name = GBAApp::app()->getOpenDirectoryName(this, tr("Load shader"), path.absolutePath()); + if (!name.isNull()) { + loadShader(name); refreshShaders(); } }