DolphinQt: Refactor, add ConfigControl class

This reduces code duplication in the different ConfigControls. This is
helpful for the next commit, which will modify the now deduplicated
code.
This commit is contained in:
TryTwo
2024-09-17 23:29:13 -07:00
committed by JosJuice
parent 0a84d93a8e
commit 08df9a66e0
15 changed files with 189 additions and 147 deletions

View File

@ -3,33 +3,20 @@
#include "DolphinQt/Config/ConfigControls/ConfigRadio.h"
#include <QSignalBlocker>
#include "Common/Config/Config.h"
#include "DolphinQt/Settings.h"
ConfigRadioInt::ConfigRadioInt(const QString& label, const Config::Info<int>& setting, int value)
: ToolTipRadioButton(label), m_setting(setting), m_value(value)
: ConfigControl(label, setting.GetLocation()), m_setting(setting), m_value(value)
{
setChecked(Config::Get(m_setting) == m_value);
setChecked(ReadValue(setting) == value);
connect(this, &QRadioButton::toggled, this, &ConfigRadioInt::Update);
connect(&Settings::Instance(), &Settings::ConfigChanged, this, [this] {
QFont bf = font();
bf.setBold(Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base);
setFont(bf);
const QSignalBlocker blocker(this);
setChecked(Config::Get(m_setting) == m_value);
});
}
void ConfigRadioInt::Update()
{
if (isChecked())
{
Config::SetBaseOrCurrent(m_setting, m_value);
SaveValue(m_setting, m_value);
emit OnSelected(m_value);
}
else
@ -37,3 +24,8 @@ void ConfigRadioInt::Update()
emit OnDeselected(m_value);
}
}
void ConfigRadioInt::OnConfigChanged()
{
setChecked(ReadValue(m_setting) == m_value);
}