Qt: implement EnhanceRadioButton

This commit is contained in:
Megamouse 2020-04-06 20:08:02 +02:00
parent 078c31c1da
commit 96086d57fa
4 changed files with 89 additions and 92 deletions

View File

@ -366,7 +366,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, SettingsType type, bool
}
else
{
QStringList settings = GetSettingOptions(type);
const QStringList settings = GetSettingOptions(type);
for (const QString& setting : settings)
{
@ -580,6 +580,41 @@ void emu_settings::EnhanceEdit(QLineEdit* edit, SettingsType type)
});
}
void emu_settings::EnhanceRadioButton(QButtonGroup* button_group, SettingsType type)
{
if (!button_group)
{
cfg_log.fatal("EnhanceRadioButton '%s' was used with an invalid object", GetSettingName(type));
return;
}
const QString selected = qstr(GetSetting(type));
const QStringList options = GetSettingOptions(type);
if (button_group->buttons().count() < options.size())
{
cfg_log.fatal("EnhanceRadioButton '%s': wrong button count", GetSettingName(type));
return;
}
for (int i = 0; i < options.count(); i++)
{
const QString localized_setting = GetLocalizedSetting(options[i], type, i);
button_group->button(i)->setText(localized_setting);
if (options[i] == selected)
{
button_group->button(i)->setChecked(true);
}
connect(button_group->button(i), &QAbstractButton::clicked, [=, this]()
{
SetSetting(type, sstr(options[i]));
});
}
}
std::vector<std::string> emu_settings::GetLoadedLibraries()
{
return m_currentSettings["Core"]["Load libraries"].as<std::vector<std::string>, std::initializer_list<std::string>>({});
@ -795,6 +830,33 @@ QString emu_settings::GetLocalizedSetting(const QString& original, SettingsType
case screen_quadrant::bottom_right: return tr("Bottom Right");
}
break;
case emu_settings::LibLoadOptions:
switch (static_cast<lib_loading_type>(index))
{
case lib_loading_type::manual: return tr("Manually load selected libraries");
case lib_loading_type::hybrid: return tr("Load automatic and manual selection");
case lib_loading_type::liblv2only: return tr("Load liblv2.sprx only");
case lib_loading_type::liblv2both: return tr("Load liblv2.sprx and manual selection");
case lib_loading_type::liblv2list: return tr("Load liblv2.sprx and strict selection");
}
break;
case emu_settings::PPUDecoder:
switch (static_cast<ppu_decoder_type>(index))
{
case ppu_decoder_type::precise: return tr("Interpreter (precise)");
case ppu_decoder_type::fast: return tr("Interpreter (fast)");
case ppu_decoder_type::llvm: return tr("Recompiler (LLVM)");
}
break;
case emu_settings::SPUDecoder:
switch (static_cast<spu_decoder_type>(index))
{
case spu_decoder_type::precise: return tr("Interpreter (precise)");
case spu_decoder_type::fast: return tr("Interpreter (fast)");
case spu_decoder_type::asmjit: return tr("Recompiler (ASMJIT)");
case spu_decoder_type::llvm: return tr("Recompiler (LLVM)");
}
break;
default:
break;
}

View File

@ -4,6 +4,7 @@
#include "stdafx.h"
#include <QButtonGroup>
#include <QCheckBox>
#include <QStringList>
#include <QMap>
@ -236,6 +237,9 @@ public:
/** Connects a line edit with the target settings type*/
void EnhanceEdit(QLineEdit* edit, SettingsType type);
/** Connects a button group with the target settings type*/
void EnhanceRadioButton(QButtonGroup* button_group, SettingsType type);
std::vector<std::string> GetLoadedLibraries();
void SaveSelectedLibraries(const std::vector<std::string>& libs);
@ -266,13 +270,13 @@ public:
/** Fixes all registered invalid settings after asking the user for permission.*/
void OpenCorrectionDialog(QWidget* parent = Q_NULLPTR);
/** Get a localized and therefore freely adjustable version of the string used in config.yml.*/
QString GetLocalizedSetting(const QString& original, SettingsType type, int index) const;
public Q_SLOTS:
/** Writes the unsaved settings to file. Used in settings dialog on accept.*/
void SaveSettings();
private:
/** Get a localized and therefore freely adjustable version of the string used in config.yml.*/
QString GetLocalizedSetting(const QString& original, SettingsType type, int index) const;
/** A helper map that keeps track of where a given setting type is located*/
const QMap<SettingsType, cfg_location> m_settings_location =
{

View File

@ -241,23 +241,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
ppu_bg->addButton(ui->ppu_fast, static_cast<int>(ppu_decoder_type::fast));
ppu_bg->addButton(ui->ppu_llvm, static_cast<int>(ppu_decoder_type::llvm));
{ // PPU Stuff
const QString selected_ppu = qstr(m_emu_settings->GetSetting(emu_settings::PPUDecoder));
QStringList ppu_list = m_emu_settings->GetSettingOptions(emu_settings::PPUDecoder);
for (int i = 0; i < ppu_list.count(); i++)
{
if (ppu_list[i] == selected_ppu)
{
ppu_bg->button(i)->setChecked(true);
}
connect(ppu_bg->button(i), &QAbstractButton::clicked, [=, this]()
{
m_emu_settings->SetSetting(emu_settings::PPUDecoder, sstr(ppu_list[i]));
});
}
}
m_emu_settings->EnhanceRadioButton(ppu_bg, emu_settings::PPUDecoder);
// SPU tool tips
SubscribeTooltip(ui->spu_precise, tooltips.settings.spu_precise);
@ -271,23 +255,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
spu_bg->addButton(ui->spu_asmjit, static_cast<int>(spu_decoder_type::asmjit));
spu_bg->addButton(ui->spu_llvm, static_cast<int>(spu_decoder_type::llvm));
{ // Spu stuff
const QString selected_spu = qstr(m_emu_settings->GetSetting(emu_settings::SPUDecoder));
QStringList spu_list = m_emu_settings->GetSettingOptions(emu_settings::SPUDecoder);
for (int i = 0; i < spu_list.count(); i++)
{
if (spu_list[i] == selected_spu)
{
spu_bg->button(i)->setChecked(true);
}
connect(spu_bg->button(i), &QAbstractButton::clicked, [=, this]()
{
m_emu_settings->SetSetting(emu_settings::SPUDecoder, sstr(spu_list[i]));
});
}
}
m_emu_settings->EnhanceRadioButton(spu_bg, emu_settings::SPUDecoder);
connect(ui->spu_llvm, &QAbstractButton::toggled, [this](bool checked)
{
@ -863,32 +831,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
// Radio Buttons
SubscribeTooltip(ui->gb_enterButtonAssignment, tooltips.settings.enter_button_assignment);
// creating this in ui file keeps scrambling the order...
QButtonGroup *enter_button_assignment_bg = new QButtonGroup(this);
enter_button_assignment_bg->addButton(ui->enterButtonAssignCircle, 0);
enter_button_assignment_bg->addButton(ui->enterButtonAssignCross, 1);
{ // EnterButtonAssignment options
const QString assigned_button = qstr(m_emu_settings->GetSetting(emu_settings::EnterButtonAssignment));
QStringList assignable_buttons = m_emu_settings->GetSettingOptions(emu_settings::EnterButtonAssignment);
for (int i = 0; i < assignable_buttons.count(); i++)
{
enter_button_assignment_bg->button(i)->setText(assignable_buttons[i]);
if (assignable_buttons[i] == assigned_button)
{
enter_button_assignment_bg->button(i)->setChecked(true);
}
connect(enter_button_assignment_bg->button(i), &QAbstractButton::clicked, [=, this]()
{
m_emu_settings->SetSetting(emu_settings::EnterButtonAssignment, sstr(assignable_buttons[i]));
});
}
}
m_emu_settings->EnhanceRadioButton(enter_button_assignment_bg, emu_settings::EnterButtonAssignment);
SubscribeTooltip(ui->gb_enterButtonAssignment, tooltips.settings.enter_button_assignment);
// _ _ _ _ _______ _
// | \ | | | | | | |__ __| | |
@ -1051,25 +1000,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
lib_mode_bg->addButton(ui->lib_lv2b, static_cast<int>(lib_loading_type::liblv2both));
lib_mode_bg->addButton(ui->lib_lv2l, static_cast<int>(lib_loading_type::liblv2list));
{// Handle lib loading options
const QString selected_lib = qstr(m_emu_settings->GetSetting(emu_settings::LibLoadOptions));
QStringList libmode_list = m_emu_settings->GetSettingOptions(emu_settings::LibLoadOptions);
for (int i = 0; i < libmode_list.count(); i++)
{
lib_mode_bg->button(i)->setText(libmode_list[i]);
if (libmode_list[i] == selected_lib)
{
lib_mode_bg->button(i)->setChecked(true);
}
connect(lib_mode_bg->button(i), &QAbstractButton::clicked, [=, this]()
{
m_emu_settings->SetSetting(emu_settings::LibLoadOptions, sstr(libmode_list[i]));
});
}
}
m_emu_settings->EnhanceRadioButton(lib_mode_bg, emu_settings::LibLoadOptions);
// Sort string vector alphabetically
static const auto sort_string_vector = [](std::vector<std::string>& vec)

View File

@ -56,21 +56,21 @@
<item>
<widget class="QRadioButton" name="ppu_precise">
<property name="text">
<string>Interpreter (precise)</string>
<string notr="true">Interpreter (precise)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="ppu_fast">
<property name="text">
<string>Interpreter (fast)</string>
<string notr="true">Interpreter (fast)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="ppu_llvm">
<property name="text">
<string>LLVM Recompiler (fastest)</string>
<string notr="true">LLVM Recompiler (fastest)</string>
</property>
</widget>
</item>
@ -86,28 +86,28 @@
<item>
<widget class="QRadioButton" name="spu_precise">
<property name="text">
<string>Interpreter (precise)</string>
<string notr="true">Interpreter (precise)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="spu_fast">
<property name="text">
<string>Interpreter (fast)</string>
<string notr="true">Interpreter (fast)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="spu_asmjit">
<property name="text">
<string>ASMJIT Recompiler (faster)</string>
<string notr="true">ASMJIT Recompiler (faster)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="spu_llvm">
<property name="text">
<string>LLVM Recompiler (fastest)</string>
<string notr="true">LLVM Recompiler (fastest)</string>
</property>
</widget>
</item>
@ -1378,14 +1378,14 @@
<item>
<widget class="QRadioButton" name="enterButtonAssignCircle">
<property name="text">
<string>Enter with circle</string>
<string notr="true">Enter with circle</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="enterButtonAssignCross">
<property name="text">
<string>Enter with cross</string>
<string notr="true">Enter with cross</string>
</property>
</widget>
</item>
@ -1791,7 +1791,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Manually load selected libraries</string>
<string notr="true">Manually load selected libraries</string>
</property>
</widget>
</item>
@ -1804,7 +1804,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Load automatic and manual selection</string>
<string notr="true">Load automatic and manual selection</string>
</property>
</widget>
</item>
@ -1817,7 +1817,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Load liblv2.sprx only</string>
<string notr="true">Load liblv2.sprx only</string>
</property>
</widget>
</item>
@ -1830,7 +1830,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Load liblv2.sprx and manual selection</string>
<string notr="true">Load liblv2.sprx and manual selection</string>
</property>
</widget>
</item>
@ -1843,7 +1843,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Load liblv2.sprx and strict selection</string>
<string notr="true">Load liblv2.sprx and strict selection</string>
</property>
</widget>
</item>