Qt: Populate controller tabs based on multitap mode

This commit is contained in:
Connor McLaughlin 2021-03-03 21:33:24 +10:00
parent a8a1a9efd5
commit 1d00f96f89
5 changed files with 96 additions and 4 deletions

View file

@ -79,6 +79,8 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW
connect(m_ui.cpuClockSpeed, &QSlider::valueChanged, this, &ConsoleSettingsWidget::onCPUClockSpeedValueChanged);
connect(m_ui.cdromReadSpeedup, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ConsoleSettingsWidget::onCDROMReadSpeedupValueChanged);
connect(m_ui.multitapMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
[this](int index) { emit multitapModeChanged(); });
calculateCPUClockValue();
}

View file

@ -15,6 +15,9 @@ public:
explicit ConsoleSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog);
~ConsoleSettingsWidget();
Q_SIGNALS:
void multitapModeChanged();
private Q_SLOTS:
void onEnableCPUClockSpeedControlChecked(int state);
void onCPUClockSpeedValueChanged(int value);

View file

@ -28,20 +28,95 @@ ControllerSettingsWidget::ControllerSettingsWidget(QtHostInterface* host_interfa
ControllerSettingsWidget::~ControllerSettingsWidget() = default;
MultitapMode ControllerSettingsWidget::getMultitapMode()
{
return Settings::ParseMultitapModeName(
QtHostInterface::GetInstance()
->GetStringSettingValue("ControllerPorts", "MultitapMode",
Settings::GetMultitapModeName(Settings::DEFAULT_MULTITAP_MODE))
.c_str())
.value_or(Settings::DEFAULT_MULTITAP_MODE);
}
QString ControllerSettingsWidget::getTabTitleForPort(u32 index, MultitapMode mode) const
{
constexpr u32 NUM_PORTS_PER_MULTITAP = 4;
u32 port_number, subport_number;
switch (mode)
{
case MultitapMode::Port1Only:
{
if (index == NUM_PORTS_PER_MULTITAP)
return tr("Port %1").arg((index / NUM_PORTS_PER_MULTITAP) + 1);
else if (index > NUM_PORTS_PER_MULTITAP)
return QString();
port_number = 0;
subport_number = index;
}
break;
case MultitapMode::Port2Only:
{
if (index == 0)
return tr("Port %1").arg(index + 1);
else if (index > NUM_PORTS_PER_MULTITAP)
return QString();
port_number = 1;
subport_number = (index - 1);
}
break;
case MultitapMode::BothPorts:
{
port_number = index / NUM_PORTS_PER_MULTITAP;
subport_number = (index % NUM_PORTS_PER_MULTITAP);
}
break;
case MultitapMode::Disabled:
default:
{
if (index >= (NUM_CONTROLLER_AND_CARD_PORTS / NUM_PORTS_PER_MULTITAP))
return QString();
return tr("Port %1").arg(index + 1);
}
}
return tr("Port %1%2").arg(port_number + 1).arg(QChar::fromLatin1('A' + subport_number));
}
void ControllerSettingsWidget::createUi()
{
QGridLayout* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
const MultitapMode multitap_mode = getMultitapMode();
m_tab_widget = new QTabWidget(this);
for (int i = 0; i < static_cast<int>(m_port_ui.size()); i++)
createPortSettingsUi(i, &m_port_ui[i]);
createPortSettingsUi(i, &m_port_ui[i], multitap_mode);
layout->addWidget(m_tab_widget, 0, 0, 1, 1);
setLayout(layout);
}
void ControllerSettingsWidget::updateMultitapControllerTitles()
{
const MultitapMode mode = getMultitapMode();
for (int i = 0; i < static_cast<int>(m_port_ui.size()); i++)
{
const QString tab_title(getTabTitleForPort(i, mode));
m_tab_widget->setTabVisible(i, !tab_title.isEmpty());
m_tab_widget->setTabText(i, tab_title);
}
}
void ControllerSettingsWidget::onProfileLoaded()
{
for (int i = 0; i < static_cast<int>(m_port_ui.size()); i++)
@ -74,7 +149,7 @@ void ControllerSettingsWidget::reloadBindingButtons()
}
}
void ControllerSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* ui)
void ControllerSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* ui, MultitapMode multitap_mode)
{
ui->widget = new QWidget(m_tab_widget);
ui->layout = new QVBoxLayout(ui->widget);
@ -165,7 +240,9 @@ void ControllerSettingsWidget::createPortSettingsUi(int index, PortSettingsUI* u
ui->widget->setLayout(ui->layout);
m_tab_widget->addTab(ui->widget, tr("Port %1").arg(index + 1));
const QString tab_title(getTabTitleForPort(index, multitap_mode));
m_tab_widget->addTab(ui->widget, tab_title);
m_tab_widget->setTabVisible(index, !tab_title.isEmpty());
}
void ControllerSettingsWidget::createPortBindingSettingsUi(int index, PortSettingsUI* ui, ControllerType ctype)

View file

@ -24,6 +24,9 @@ public:
ControllerSettingsWidget(QtHostInterface* host_interface, QWidget* parent = nullptr);
~ControllerSettingsWidget();
public Q_SLOTS:
void updateMultitapControllerTitles();
private Q_SLOTS:
void onProfileLoaded();
@ -42,9 +45,13 @@ private:
InputBindingWidget* first_button;
};
static MultitapMode getMultitapMode();
QString getTabTitleForPort(u32 index, MultitapMode mode) const;
void createUi();
void reloadBindingButtons();
void createPortSettingsUi(int index, PortSettingsUI* ui);
void createPortSettingsUi(int index, PortSettingsUI* ui, MultitapMode multitap_mode);
void createPortBindingSettingsUi(int index, PortSettingsUI* ui, ControllerType ctype);
void onControllerTypeChanged(int index);
void onLoadProfileClicked();

View file

@ -76,6 +76,9 @@ SettingsDialog::SettingsDialog(QtHostInterface* host_interface, QWidget* parent
m_ui.helpText->setText(m_category_help_text[0]);
connect(m_ui.settingsCategory, &QListWidget::currentRowChanged, this, &SettingsDialog::onCategoryCurrentRowChanged);
connect(m_ui.closeButton, &QPushButton::clicked, this, &SettingsDialog::accept);
connect(m_console_settings, &ConsoleSettingsWidget::multitapModeChanged, m_controller_settings,
&ControllerSettingsWidget::updateMultitapControllerTitles);
}
SettingsDialog::~SettingsDialog() = default;