Qt: Implement browse button for memory card paths

This commit is contained in:
Connor McLaughlin 2020-04-09 00:09:16 +10:00
parent 9915d977e4
commit 3272b37853
2 changed files with 16 additions and 0 deletions

View File

@ -7,8 +7,11 @@
#include "settingwidgetbinder.h" #include "settingwidgetbinder.h"
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox> #include <QtWidgets/QMessageBox>
static constexpr char MEMORY_CARD_IMAGE_FILTER[] = "All Memory Card Types (*.mcd *.mc)";
PortSettingsWidget::PortSettingsWidget(QtHostInterface* host_interface, QWidget* parent /* = nullptr */) PortSettingsWidget::PortSettingsWidget(QtHostInterface* host_interface, QWidget* parent /* = nullptr */)
: QWidget(parent), m_host_interface(host_interface) : QWidget(parent), m_host_interface(host_interface)
{ {
@ -43,6 +46,8 @@ void PortSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* ui)
memory_card_layout->addWidget(ui->memory_card_path); memory_card_layout->addWidget(ui->memory_card_path);
ui->memory_card_path_browse = new QPushButton(tr("Browse..."), ui->widget); ui->memory_card_path_browse = new QPushButton(tr("Browse..."), ui->widget);
connect(ui->memory_card_path_browse, &QPushButton::clicked,
[this, index]() { onBrowseMemoryCardPathClicked(index); });
memory_card_layout->addWidget(ui->memory_card_path_browse); memory_card_layout->addWidget(ui->memory_card_path_browse);
ui->layout->addWidget(new QLabel(tr("Memory Card Path:"), ui->widget)); ui->layout->addWidget(new QLabel(tr("Memory Card Path:"), ui->widget));
ui->layout->addLayout(memory_card_layout); ui->layout->addLayout(memory_card_layout);
@ -232,3 +237,13 @@ void PortSettingsWidget::onControllerTypeChanged(int index)
m_host_interface->applySettings(); m_host_interface->applySettings();
createPortBindingSettingsUi(index, &m_port_ui[index], static_cast<ControllerType>(type_index)); createPortBindingSettingsUi(index, &m_port_ui[index], static_cast<ControllerType>(type_index));
} }
void PortSettingsWidget::onBrowseMemoryCardPathClicked(int index)
{
QString path =
QFileDialog::getOpenFileName(this, tr("Select path to memory card image"), QString(), tr(MEMORY_CARD_IMAGE_FILTER));
if (path.isEmpty())
return;
m_port_ui[index].memory_card_path->setText(path);
}

View File

@ -42,6 +42,7 @@ private:
void createPortSettingsUi(int index, PortSettingsUI* ui); void createPortSettingsUi(int index, PortSettingsUI* ui);
void createPortBindingSettingsUi(int index, PortSettingsUI* ui, ControllerType ctype); void createPortBindingSettingsUi(int index, PortSettingsUI* ui, ControllerType ctype);
void onControllerTypeChanged(int index); void onControllerTypeChanged(int index);
void onBrowseMemoryCardPathClicked(int index);
std::array<PortSettingsUI, 2> m_port_ui = {}; std::array<PortSettingsUI, 2> m_port_ui = {};
}; };