Qt: Implement memory card remove button

This commit is contained in:
Connor McLaughlin 2020-04-09 00:13:44 +10:00
parent 3272b37853
commit 1f40d5f77d
2 changed files with 18 additions and 5 deletions

View File

@ -5,6 +5,7 @@
#include "qthostinterface.h"
#include "qtutils.h"
#include "settingwidgetbinder.h"
#include <QtCore/QSignalBlocker>
#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
#include <QtWidgets/QFileDialog>
@ -45,10 +46,14 @@ void PortSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* ui)
QStringLiteral("MemoryCards/Card%1Path").arg(index + 1));
memory_card_layout->addWidget(ui->memory_card_path);
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);
QPushButton* memory_card_path_browse = new QPushButton(tr("Browse..."), ui->widget);
connect(memory_card_path_browse, &QPushButton::clicked, [this, index]() { onBrowseMemoryCardPathClicked(index); });
memory_card_layout->addWidget(memory_card_path_browse);
QPushButton* memory_card_remove = new QPushButton(tr("Remove"), ui->widget);
connect(memory_card_remove, &QPushButton::clicked, [this, index]() { onEjectMemoryCardClicked(index); });
memory_card_layout->addWidget(memory_card_remove);
ui->layout->addWidget(new QLabel(tr("Memory Card Path:"), ui->widget));
ui->layout->addLayout(memory_card_layout);
@ -247,3 +252,11 @@ void PortSettingsWidget::onBrowseMemoryCardPathClicked(int index)
m_port_ui[index].memory_card_path->setText(path);
}
void PortSettingsWidget::onEjectMemoryCardClicked(int index)
{
QSignalBlocker blocker(m_port_ui[index].memory_card_path);
m_port_ui[index].memory_card_path->setText(QString());
m_host_interface->removeSettingValue(QStringLiteral("MemoryCards/Card%1Path").arg(index + 1));
m_host_interface->applySettings();
}

View File

@ -34,7 +34,6 @@ private:
QVBoxLayout* layout;
QComboBox* controller_type;
QLineEdit* memory_card_path;
QPushButton* memory_card_path_browse;
QWidget* button_binding_container;
};
@ -43,6 +42,7 @@ private:
void createPortBindingSettingsUi(int index, PortSettingsUI* ui, ControllerType ctype);
void onControllerTypeChanged(int index);
void onBrowseMemoryCardPathClicked(int index);
void onEjectMemoryCardClicked(int index);
std::array<PortSettingsUI, 2> m_port_ui = {};
};