mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
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:
@ -3,31 +3,22 @@
|
||||
|
||||
#include "DolphinQt/Config/ConfigControls/ConfigBool.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QFont>
|
||||
#include <QSignalBlocker>
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
ConfigBool::ConfigBool(const QString& label, const Config::Info<bool>& setting, bool reverse)
|
||||
: ToolTipCheckBox(label), m_setting(setting), m_reverse(reverse)
|
||||
: ConfigControl(label, setting.GetLocation()), m_setting(setting), m_reverse(reverse)
|
||||
{
|
||||
setChecked(ReadValue(setting) ^ reverse);
|
||||
|
||||
connect(this, &QCheckBox::toggled, this, &ConfigBool::Update);
|
||||
setChecked(Config::Get(m_setting) ^ reverse);
|
||||
|
||||
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_reverse);
|
||||
});
|
||||
}
|
||||
|
||||
void ConfigBool::Update()
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, static_cast<bool>(isChecked() ^ m_reverse));
|
||||
const bool value = static_cast<bool>(isChecked() ^ m_reverse);
|
||||
|
||||
SaveValue(m_setting, value);
|
||||
}
|
||||
|
||||
void ConfigBool::OnConfigChanged()
|
||||
{
|
||||
setChecked(ReadValue(m_setting) ^ m_reverse);
|
||||
}
|
||||
|
Reference in New Issue
Block a user