mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-23 17:45:35 +00:00
shared_widget: Internalize component restoring
This commit is contained in:
parent
21723879e7
commit
d1de1c3bed
|
@ -52,20 +52,6 @@ ConfigureSystem::ConfigureSystem(
|
||||||
|
|
||||||
Setup(builder);
|
Setup(builder);
|
||||||
|
|
||||||
connect(rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
|
|
||||||
rng_seed_edit->setEnabled(state == Qt::Checked);
|
|
||||||
if (state != Qt::Checked) {
|
|
||||||
rng_seed_edit->setText(QStringLiteral("00000000"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
|
|
||||||
custom_rtc_edit->setEnabled(state == Qt::Checked);
|
|
||||||
if (state != Qt::Checked) {
|
|
||||||
custom_rtc_edit->setDateTime(QDateTime::currentDateTime());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto locale_check = [this]() {
|
const auto locale_check = [this]() {
|
||||||
const auto region_index = combo_region->currentIndex();
|
const auto region_index = combo_region->currentIndex();
|
||||||
const auto language_index = combo_language->currentIndex();
|
const auto language_index = combo_language->currentIndex();
|
||||||
|
@ -149,19 +135,7 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting->Id() == Settings::values.rng_seed.Id()) {
|
if (setting->Id() == Settings::values.region_index.Id()) {
|
||||||
// Keep track of rng_seed's widgets to reset it with the checkbox state
|
|
||||||
rng_seed_checkbox = widget->checkbox;
|
|
||||||
rng_seed_edit = widget->line_edit;
|
|
||||||
|
|
||||||
rng_seed_edit->setEnabled(Settings::values.rng_seed_enabled.GetValue());
|
|
||||||
} else if (setting->Id() == Settings::values.custom_rtc.Id()) {
|
|
||||||
// Keep track of custom_rtc's widgets to reset it with the checkbox state
|
|
||||||
custom_rtc_checkbox = widget->checkbox;
|
|
||||||
custom_rtc_edit = widget->date_time_edit;
|
|
||||||
|
|
||||||
custom_rtc_edit->setEnabled(Settings::values.custom_rtc_enabled.GetValue());
|
|
||||||
} else if (setting->Id() == Settings::values.region_index.Id()) {
|
|
||||||
// Keep track of the region_index (and langauge_index) combobox to validate the selected
|
// Keep track of the region_index (and langauge_index) combobox to validate the selected
|
||||||
// settings
|
// settings
|
||||||
combo_region = widget->combobox;
|
combo_region = widget->combobox;
|
||||||
|
|
|
@ -50,10 +50,6 @@ private:
|
||||||
|
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
|
|
||||||
QCheckBox* rng_seed_checkbox;
|
|
||||||
QLineEdit* rng_seed_edit;
|
|
||||||
QCheckBox* custom_rtc_checkbox;
|
|
||||||
QDateTimeEdit* custom_rtc_edit;
|
|
||||||
QComboBox* combo_region;
|
QComboBox* combo_region;
|
||||||
QComboBox* combo_language;
|
QComboBox* combo_language;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,6 +46,10 @@ namespace ConfigurationShared {
|
||||||
|
|
||||||
static int restore_button_count = 0;
|
static int restore_button_count = 0;
|
||||||
|
|
||||||
|
static std::string RelevantDefault(const Settings::BasicSetting& setting) {
|
||||||
|
return Settings::IsConfiguringGlobal() ? setting.DefaultToString() : setting.ToStringGlobal();
|
||||||
|
}
|
||||||
|
|
||||||
QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) {
|
QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) {
|
||||||
restore_button_count++;
|
restore_button_count++;
|
||||||
|
|
||||||
|
@ -92,12 +96,12 @@ QWidget* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const QStr
|
||||||
return checkbox->checkState() == Qt::CheckState::Checked ? "true" : "false";
|
return checkbox->checkState() == Qt::CheckState::Checked ? "true" : "false";
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
restore_func = [this, bool_setting]() {
|
||||||
restore_func = [this, bool_setting]() {
|
checkbox->setCheckState(RelevantDefault(*bool_setting) == "true" ? Qt::Checked
|
||||||
checkbox->setCheckState(bool_setting->ToStringGlobal() == "true" ? Qt::Checked
|
: Qt::Unchecked);
|
||||||
: Qt::Unchecked);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
QObject::connect(checkbox, &QCheckBox::clicked, [touch]() { touch(); });
|
QObject::connect(checkbox, &QCheckBox::clicked, [touch]() { touch(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,12 +143,12 @@ QWidget* Widget::CreateCombobox(std::function<std::string()>& serializer,
|
||||||
return std::to_string(enumeration->at(current).first);
|
return std::to_string(enumeration->at(current).first);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
restore_func = [this, find_index]() {
|
||||||
restore_func = [this, find_index]() {
|
const u32 global_value = std::stoi(RelevantDefault(setting));
|
||||||
const u32 global_value = std::stoi(setting.ToStringGlobal());
|
combobox->setCurrentIndex(find_index(global_value));
|
||||||
combobox->setCurrentIndex(find_index(global_value));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated),
|
QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated),
|
||||||
[touch]() { touch(); });
|
[touch]() { touch(); });
|
||||||
}
|
}
|
||||||
|
@ -165,11 +169,11 @@ QWidget* Widget::CreateLineEdit(std::function<std::string()>& serializer,
|
||||||
return line_edit;
|
return line_edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
restore_func = [this]() {
|
||||||
restore_func = [this]() {
|
line_edit->setText(QString::fromStdString(RelevantDefault(setting)));
|
||||||
line_edit->setText(QString::fromStdString(setting.ToStringGlobal()));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
|
QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +219,9 @@ QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& fo
|
||||||
slider->setInvertedAppearance(reversed);
|
slider->setInvertedAppearance(reversed);
|
||||||
|
|
||||||
serializer = [this]() { return std::to_string(slider->value()); };
|
serializer = [this]() { return std::to_string(slider->value()); };
|
||||||
|
restore_func = [this]() { slider->setValue(std::stoi(RelevantDefault(setting))); };
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
restore_func = [this]() { slider->setValue(std::stoi(setting.ToStringGlobal())); };
|
|
||||||
|
|
||||||
QObject::connect(slider, &QAbstractSlider::actionTriggered, [touch]() { touch(); });
|
QObject::connect(slider, &QAbstractSlider::actionTriggered, [touch]() { touch(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,9 +245,12 @@ QWidget* Widget::CreateSpinBox(const QString& suffix, std::function<std::string(
|
||||||
|
|
||||||
serializer = [this]() { return std::to_string(spinbox->value()); };
|
serializer = [this]() { return std::to_string(spinbox->value()); };
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
restore_func = [this]() {
|
||||||
restore_func = [this]() { spinbox->setValue(std::stoi(setting.ToStringGlobal())); };
|
auto value{std::stol(RelevantDefault(setting))};
|
||||||
|
spinbox->setValue(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this, touch]() {
|
QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this, touch]() {
|
||||||
if (spinbox->value() != std::stoi(setting.ToStringGlobal())) {
|
if (spinbox->value() != std::stoi(setting.ToStringGlobal())) {
|
||||||
touch();
|
touch();
|
||||||
|
@ -264,7 +270,7 @@ QWidget* Widget::CreateHexEdit(std::function<std::string()>& serializer,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto to_hex = [=](const std::string& input) {
|
auto to_hex = [=](const std::string& input) {
|
||||||
return QString::fromStdString(fmt::format("{:08x}", std::stoi(input)));
|
return QString::fromStdString(fmt::format("{:08x}", std::stoul(input)));
|
||||||
};
|
};
|
||||||
|
|
||||||
QRegExpValidator* regex =
|
QRegExpValidator* regex =
|
||||||
|
@ -282,8 +288,9 @@ QWidget* Widget::CreateHexEdit(std::function<std::string()>& serializer,
|
||||||
|
|
||||||
serializer = [hex_to_dec]() { return hex_to_dec(); };
|
serializer = [hex_to_dec]() { return hex_to_dec(); };
|
||||||
|
|
||||||
|
restore_func = [this, to_hex]() { line_edit->setText(to_hex(RelevantDefault(setting))); };
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
restore_func = [this, to_hex]() { line_edit->setText(to_hex(setting.ToStringGlobal())); };
|
|
||||||
|
|
||||||
QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
|
QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
|
||||||
}
|
}
|
||||||
|
@ -306,18 +313,18 @@ QWidget* Widget::CreateDateTimeEdit(bool disabled, bool restrict,
|
||||||
|
|
||||||
serializer = [this]() { return std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()); };
|
serializer = [this]() { return std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()); };
|
||||||
|
|
||||||
|
auto get_clear_val = [this, restrict, current_time]() {
|
||||||
|
return QDateTime::fromSecsSinceEpoch([this, restrict, current_time]() {
|
||||||
|
if (restrict && checkbox->checkState() == Qt::Checked) {
|
||||||
|
return std::stoll(RelevantDefault(setting));
|
||||||
|
}
|
||||||
|
return current_time;
|
||||||
|
}());
|
||||||
|
};
|
||||||
|
|
||||||
|
restore_func = [this, get_clear_val]() { date_time_edit->setDateTime(get_clear_val()); };
|
||||||
|
|
||||||
if (!Settings::IsConfiguringGlobal()) {
|
if (!Settings::IsConfiguringGlobal()) {
|
||||||
auto get_clear_val = [this, restrict, current_time]() {
|
|
||||||
return QDateTime::fromSecsSinceEpoch([this, restrict, current_time]() {
|
|
||||||
if (restrict && checkbox->checkState() == Qt::Checked) {
|
|
||||||
return std::stoll(setting.ToStringGlobal());
|
|
||||||
}
|
|
||||||
return current_time;
|
|
||||||
}());
|
|
||||||
};
|
|
||||||
|
|
||||||
restore_func = [this, get_clear_val]() { date_time_edit->setDateTime(get_clear_val()); };
|
|
||||||
|
|
||||||
QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished,
|
QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished,
|
||||||
[this, get_clear_val, touch]() {
|
[this, get_clear_val, touch]() {
|
||||||
if (date_time_edit->dateTime() != get_clear_val()) {
|
if (date_time_edit->dateTime() != get_clear_val()) {
|
||||||
|
@ -493,6 +500,17 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (other_setting != nullptr) {
|
||||||
|
const auto reset = [restore_func, data_component](int state) {
|
||||||
|
data_component->setEnabled(state == Qt::Checked);
|
||||||
|
if (state != Qt::Checked) {
|
||||||
|
restore_func();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
connect(checkbox, &QCheckBox::stateChanged, reset);
|
||||||
|
reset(checkbox->checkState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::Valid() const {
|
bool Widget::Valid() const {
|
||||||
|
|
Loading…
Reference in a new issue