mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
EnhancementsWidget:: Move to using ConfigControls and add new control for ComboBoxes that set two settings at once.
This commit is contained in:
@ -71,3 +71,102 @@ void ConfigStringChoice::OnConfigChanged()
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
ConfigComplexChoice::ConfigComplexChoice(const InfoVariant setting1, const InfoVariant setting2,
|
||||
Config::Layer* layer)
|
||||
: m_setting1(setting1), m_setting2(setting2), m_layer(layer)
|
||||
{
|
||||
connect(&Settings::Instance(), &Settings::ConfigChanged, this, &ConfigComplexChoice::Refresh);
|
||||
connect(this, &QComboBox::currentIndexChanged, this, &ConfigComplexChoice::SaveValue);
|
||||
}
|
||||
|
||||
void ConfigComplexChoice::Refresh()
|
||||
{
|
||||
auto& location = GetLocation();
|
||||
|
||||
QFont bf = font();
|
||||
if (m_layer != nullptr)
|
||||
{
|
||||
bf.setBold(m_layer->Exists(location.first) || m_layer->Exists(location.second));
|
||||
}
|
||||
else
|
||||
{
|
||||
bf.setBold(Config::GetActiveLayerForConfig(location.first) != Config::LayerType::Base ||
|
||||
Config::GetActiveLayerForConfig(location.second) != Config::LayerType::Base);
|
||||
}
|
||||
|
||||
setFont(bf);
|
||||
UpdateComboIndex();
|
||||
}
|
||||
|
||||
void ConfigComplexChoice::Add(const QString& name, const OptionVariant option1,
|
||||
const OptionVariant option2)
|
||||
{
|
||||
const QSignalBlocker blocker(this);
|
||||
addItem(name);
|
||||
m_options.push_back(std::make_pair(option1, option2));
|
||||
}
|
||||
|
||||
void ConfigComplexChoice::Reset()
|
||||
{
|
||||
clear();
|
||||
m_options.clear();
|
||||
}
|
||||
|
||||
void ConfigComplexChoice::SaveValue(int choice)
|
||||
{
|
||||
auto Set = [this, choice](auto& setting, auto& value) {
|
||||
if (m_layer != nullptr)
|
||||
{
|
||||
m_layer->Set(setting.GetLocation(), value);
|
||||
Config::OnConfigChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Config::SetBaseOrCurrent(setting, value);
|
||||
};
|
||||
|
||||
std::visit(Set, m_setting1, m_options[choice].first);
|
||||
std::visit(Set, m_setting2, m_options[choice].second);
|
||||
}
|
||||
|
||||
void ConfigComplexChoice::UpdateComboIndex()
|
||||
{
|
||||
auto Get = [this](auto& setting) {
|
||||
if (m_layer != nullptr)
|
||||
return static_cast<OptionVariant>(m_layer->Get(setting));
|
||||
|
||||
return static_cast<OptionVariant>(Config::Get(setting));
|
||||
};
|
||||
|
||||
std::pair<OptionVariant, OptionVariant> values =
|
||||
std::make_pair(std::visit(Get, m_setting1), std::visit(Get, m_setting2));
|
||||
|
||||
auto it = std::find(m_options.begin(), m_options.end(), values);
|
||||
int index = static_cast<int>(std::distance(m_options.begin(), it));
|
||||
|
||||
const QSignalBlocker blocker(this);
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
|
||||
const std::pair<Config::Location, Config::Location> ConfigComplexChoice::GetLocation() const
|
||||
{
|
||||
auto visit = [](auto& v) { return v.GetLocation(); };
|
||||
|
||||
return {std::visit(visit, m_setting1), std::visit(visit, m_setting2)};
|
||||
}
|
||||
|
||||
void ConfigComplexChoice::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton && m_layer != nullptr)
|
||||
{
|
||||
auto& location = GetLocation();
|
||||
m_layer->DeleteKey(location.first);
|
||||
m_layer->DeleteKey(location.second);
|
||||
Config::OnConfigChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
QComboBox::mousePressEvent(event);
|
||||
}
|
||||
};
|
||||
|
@ -51,3 +51,30 @@ private:
|
||||
const Config::Info<std::string>& m_setting;
|
||||
bool m_text_is_data = false;
|
||||
};
|
||||
|
||||
class ConfigComplexChoice final : public ToolTipComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
using InfoVariant = std::variant<Config::Info<u32>, Config::Info<int>, Config::Info<bool>>;
|
||||
using OptionVariant = std::variant<u32, int, bool>;
|
||||
|
||||
public:
|
||||
ConfigComplexChoice(const InfoVariant setting1, const InfoVariant setting2,
|
||||
Config::Layer* layer = nullptr);
|
||||
|
||||
void Add(const QString& name, const OptionVariant option1, const OptionVariant option2);
|
||||
void Refresh();
|
||||
void Reset();
|
||||
const std::pair<Config::Location, Config::Location> GetLocation() const;
|
||||
|
||||
private:
|
||||
void SaveValue(int choice);
|
||||
void UpdateComboIndex();
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
Config::Layer* m_layer;
|
||||
const InfoVariant m_setting1;
|
||||
const InfoVariant m_setting2;
|
||||
std::vector<std::pair<OptionVariant, OptionVariant>> m_options;
|
||||
};
|
||||
|
Reference in New Issue
Block a user