settings_dialog: Add Restore Defaults button

Only works for config.yml for now (not gui settings)
This commit is contained in:
Megamouse 2020-09-30 00:04:23 +02:00
parent 42de2a3e0b
commit 019fa390f2
7 changed files with 269 additions and 157 deletions

View File

@ -257,6 +257,12 @@ bool emu_settings::ValidateSettings(bool cleanup)
return is_clean;
}
void emu_settings::RestoreDefaults()
{
m_current_settings = YAML::Clone(m_default_settings);
Q_EMIT RestoreDefaultsSignal();
}
void emu_settings::SaveSettings()
{
YAML::Emitter out;
@ -334,8 +340,13 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
}
// Since the QComboBox has localised strings, we can't just findText / findData, so we need to manually iterate through it to find our index
const auto find_index = [&](const QString& value)
const auto find_index = [](QComboBox* combobox, const QString& value)
{
if (!combobox)
{
return -1;
}
for (int i = 0; i < combobox->count(); i++)
{
const QVariantList var_list = combobox->itemData(i).toList();
@ -349,6 +360,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
return -1;
};
const std::string def = GetSettingDefault(type);
const std::string selected = GetSetting(type);
const QString selected_q = qstr(selected);
int index;
@ -359,12 +371,11 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
}
else
{
index = find_index(selected_q);
index = find_index(combobox, selected_q);
}
if (index == -1)
{
const std::string def = GetSettingDefault(type);
cfg_log.error("EnhanceComboBox '%s' tried to set an invalid value: %s. Setting to default: %s", cfg_adapter::get_setting_name(type), selected, def);
if (is_ranged)
@ -373,7 +384,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
}
else
{
index = find_index(qstr(def));
index = find_index(combobox, qstr(def));
}
m_broken_types.insert(type);
@ -394,6 +405,18 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
SetSetting(type, sstr(var_list[0]));
}
});
connect(this, &emu_settings::RestoreDefaultsSignal, combobox, [def, combobox, is_ranged, find_index]()
{
if (is_ranged)
{
combobox->setCurrentIndex(combobox->findData(qstr(def)));
}
else
{
combobox->setCurrentIndex(find_index(combobox, qstr(def)));
}
});
}
void emu_settings::EnhanceCheckBox(QCheckBox* checkbox, emu_settings_type type)
@ -427,11 +450,16 @@ void emu_settings::EnhanceCheckBox(QCheckBox* checkbox, emu_settings_type type)
m_broken_types.insert(type);
}
connect(checkbox, &QCheckBox::stateChanged, [type, this](int val)
connect(checkbox, &QCheckBox::stateChanged, this, [type, this](int val)
{
const std::string str = val != 0 ? "true" : "false";
SetSetting(type, str);
});
connect(this, &emu_settings::RestoreDefaultsSignal, checkbox, [def, checkbox]()
{
checkbox->setChecked(def == "true");
});
}
void emu_settings::EnhanceDateTimeEdit(QDateTimeEdit* date_time_edit, emu_settings_type type, const QString& format, bool use_calendar, bool as_offset_from_now, int offset_update_time)
@ -485,11 +513,11 @@ void emu_settings::EnhanceDateTimeEdit(QDateTimeEdit* date_time_edit, emu_settin
if (offset_update_time > 0)
{
QTimer* console_time_update = new QTimer(date_time_edit);
connect(console_time_update, &QTimer::timeout, [this, date_time_edit, min, max]()
connect(console_time_update, &QTimer::timeout, date_time_edit, [this, date_time_edit, min, max]()
{
if (!date_time_edit->hasFocus() && (!date_time_edit->calendarPopup() || !date_time_edit->calendarWidget()->hasFocus()))
{
const auto now = QDateTime::currentDateTime();
const QDateTime now = QDateTime::currentDateTime();
const s64 offset = qstr(GetSetting(emu_settings_type::ConsoleTimeOffset)).toLongLong();
date_time_edit->setDateTime(now.addSecs(offset));
date_time_edit->setDateTimeRange(now.addSecs(min), now.addSecs(max));
@ -498,14 +526,19 @@ void emu_settings::EnhanceDateTimeEdit(QDateTimeEdit* date_time_edit, emu_settin
console_time_update->start(offset_update_time);
}
connect(this, &emu_settings::RestoreDefaultsSignal, date_time_edit, [def, date_time_edit]()
{
date_time_edit->setDateTime(QDateTime::currentDateTime().addSecs(def));
});
}
else
{
auto str = qstr(GetSettingDefault(type));
QString str = qstr(GetSettingDefault(type));
const QStringList range = GetSettingOptions(type);
const auto def = QDateTime::fromString(str, Qt::ISODate);
const auto min = QDateTime::fromString(range.first(), Qt::ISODate);
const auto max = QDateTime::fromString(range.last(), Qt::ISODate);
const QDateTime def = QDateTime::fromString(str, Qt::ISODate);
const QDateTime min = QDateTime::fromString(range.first(), Qt::ISODate);
const QDateTime max = QDateTime::fromString(range.last(), Qt::ISODate);
if (!def.isValid() || !min.isValid() || !max.isValid())
{
cfg_log.fatal("EnhanceDateTimeEdit '%s' was used with an invalid emu_settings_type", cfg_adapter::get_setting_name(type));
@ -513,7 +546,7 @@ void emu_settings::EnhanceDateTimeEdit(QDateTimeEdit* date_time_edit, emu_settin
}
str = qstr(GetSetting(type));
auto val = QDateTime::fromString(str, Qt::ISODate);
QDateTime val = QDateTime::fromString(str, Qt::ISODate);
if (!val.isValid() || val < min || val > max)
{
cfg_log.error("EnhanceDateTimeEdit '%s' tried to set an invalid value: %s. Setting to default: %s Allowed range: [%s, %s]",
@ -529,9 +562,14 @@ void emu_settings::EnhanceDateTimeEdit(QDateTimeEdit* date_time_edit, emu_settin
// set the date_time value to the control
date_time_edit->setDateTime(val);
connect(this, &emu_settings::RestoreDefaultsSignal, date_time_edit, [def, date_time_edit]()
{
date_time_edit->setDateTime(def);
});
}
connect(date_time_edit, &QDateTimeEdit::dateTimeChanged, [date_time_edit, type, as_offset_from_now, this](const QDateTime& datetime)
connect(date_time_edit, &QDateTimeEdit::dateTimeChanged, this, [date_time_edit, type, as_offset_from_now, this](const QDateTime& datetime)
{
if (as_offset_from_now)
{
@ -541,7 +579,10 @@ void emu_settings::EnhanceDateTimeEdit(QDateTimeEdit* date_time_edit, emu_settin
// HACK: We are only looking at whether the control has focus to prevent the time from updating dynamically, so we
// clear the focus, so that this dynamic updating isn't suppressed.
date_time_edit->clearFocus();
if (date_time_edit)
{
date_time_edit->clearFocus();
}
}
else
{
@ -585,10 +626,15 @@ void emu_settings::EnhanceSlider(QSlider* slider, emu_settings_type type)
slider->setRange(min, max);
slider->setValue(val);
connect(slider, &QSlider::valueChanged, [type, this](int value)
connect(slider, &QSlider::valueChanged, this, [type, this](int value)
{
SetSetting(type, sstr(value));
});
connect(this, &emu_settings::RestoreDefaultsSignal, slider, [def, slider]()
{
slider->setValue(def);
});
}
void emu_settings::EnhanceSpinBox(QSpinBox* spinbox, emu_settings_type type, const QString& prefix, const QString& suffix)
@ -627,10 +673,16 @@ void emu_settings::EnhanceSpinBox(QSpinBox* spinbox, emu_settings_type type, con
spinbox->setRange(min, max);
spinbox->setValue(val);
connect(spinbox, &QSpinBox::textChanged, [=, this](const QString&/* text*/)
connect(spinbox, &QSpinBox::textChanged, this, [type, spinbox, this](const QString& /* text*/)
{
if (!spinbox) return;
SetSetting(type, sstr(spinbox->cleanText()));
});
connect(this, &emu_settings::RestoreDefaultsSignal, spinbox, [def, spinbox]()
{
spinbox->setValue(def);
});
}
void emu_settings::EnhanceDoubleSpinBox(QDoubleSpinBox* spinbox, emu_settings_type type, const QString& prefix, const QString& suffix)
@ -669,10 +721,16 @@ void emu_settings::EnhanceDoubleSpinBox(QDoubleSpinBox* spinbox, emu_settings_ty
spinbox->setRange(min, max);
spinbox->setValue(val);
connect(spinbox, &QDoubleSpinBox::textChanged, [=, this](const QString&/* text*/)
connect(spinbox, &QDoubleSpinBox::textChanged, this, [type, spinbox, this](const QString& /* text*/)
{
if (!spinbox) return;
SetSetting(type, sstr(spinbox->cleanText()));
});
connect(this, &emu_settings::RestoreDefaultsSignal, spinbox, [def, spinbox]()
{
spinbox->setValue(def);
});
}
void emu_settings::EnhanceLineEdit(QLineEdit* edit, emu_settings_type type)
@ -686,10 +744,15 @@ void emu_settings::EnhanceLineEdit(QLineEdit* edit, emu_settings_type type)
const std::string set_text = GetSetting(type);
edit->setText(qstr(set_text));
connect(edit, &QLineEdit::textChanged, [type, this](const QString &text)
connect(edit, &QLineEdit::textChanged, this, [type, this](const QString &text)
{
SetSetting(type, sstr(text));
});
connect(this, &emu_settings::RestoreDefaultsSignal, edit, [this, edit, type]()
{
edit->setText(qstr(GetSettingDefault(type)));
});
}
void emu_settings::EnhanceRadioButton(QButtonGroup* button_group, emu_settings_type type)
@ -715,23 +778,29 @@ void emu_settings::EnhanceRadioButton(QButtonGroup* button_group, emu_settings_t
for (int i = 0; i < options.count(); i++)
{
const QString localized_setting = GetLocalizedSetting(options[i], type, i);
const QString& option = options[i];
const QString localized_setting = GetLocalizedSetting(option, type, i);
button_group->button(i)->setText(localized_setting);
QAbstractButton* button = button_group->button(i);
button->setText(localized_setting);
if (!found && options[i] == selected)
if (!found && option == selected)
{
found = true;
button_group->button(i)->setChecked(true);
button->setChecked(true);
}
else if (def_pos == -1 && options[i] == def)
if (def_pos == -1 && option == def)
{
def_pos = i;
}
connect(button_group->button(i), &QAbstractButton::clicked, [=, this]()
connect(button, &QAbstractButton::toggled, this, [this, type, val = sstr(option)](bool checked)
{
SetSetting(type, sstr(options[i]));
if (checked)
{
SetSetting(type, val);
}
});
}
@ -745,6 +814,14 @@ void emu_settings::EnhanceRadioButton(QButtonGroup* button_group, emu_settings_t
// Select the default option on invalid setting string
button_group->button(def_pos)->setChecked(true);
}
connect(this, &emu_settings::RestoreDefaultsSignal, button_group, [button_group, def_pos]()
{
if (button_group && button_group->button(def_pos))
{
button_group->button(def_pos)->setChecked(true);
}
});
}
std::vector<std::string> emu_settings::GetLibrariesControl()

View File

@ -92,9 +92,16 @@ public:
/** Validates the settings and logs unused entries or cleans up the yaml*/
bool ValidateSettings(bool cleanup);
/** Resets the current settings to the global default. This includes all connected widgets. */
void RestoreDefaults();
Q_SIGNALS:
void RestoreDefaultsSignal();
public Q_SLOTS:
/** Writes the unsaved settings to file. Used in settings dialog on accept.*/
void SaveSettings();
private:
YAML::Node m_default_settings; // The default settings as a YAML node.
YAML::Node m_current_settings; // The current settings as a YAML node.

View File

@ -578,7 +578,7 @@ void main_window::InstallPackages(QStringList file_paths)
if (!info.is_valid)
{
QMessageBox::warning(this, QObject::tr("Invalid package!"), QObject::tr("The selected package is invalid!\n\nPath:\n%0").arg(file_path));
QMessageBox::warning(this, tr("Invalid package!"), tr("The selected package is invalid!\n\nPath:\n%0").arg(file_path));
return;
}

View File

@ -57,10 +57,12 @@ std::array<std::string, 4> microphone_creator::get_selection_list() const
std::string microphone_creator::set_device(u32 num, const QString& text)
{
ensure(num < m_sel_list.size());
if (text == get_none())
m_sel_list[num - 1] = "";
m_sel_list[num].clear();
else
m_sel_list[num - 1] = text.toStdString();
m_sel_list[num] = text.toStdString();
return m_sel_list[0] + "@@@" + m_sel_list[1] + "@@@" + m_sel_list[2] + "@@@" + m_sel_list[3] + "@@@";
}

View File

@ -177,6 +177,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
{
apply_configs(false);
}
else if (button == ui->buttonBox->button(QDialogButtonBox::RestoreDefaults))
{
m_emu_settings->RestoreDefaults();
// Handle special restrictions after the settings were restored
Q_EMIT signal_restore_dependant_defaults();
}
});
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
@ -223,7 +230,9 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
).arg(min_thread_count));
}
else
{
SubscribeTooltip(ui->gb_threadsched, tooltips.settings.enable_thread_scheduler);
}
m_emu_settings->EnhanceComboBox(ui->preferredSPUThreads, emu_settings_type::PreferredSPUThreads, true);
SubscribeTooltip(ui->gb_spu_threads, tooltips.settings.preferred_spu_threads);
@ -264,6 +273,10 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
SubscribeTooltip(ui->enableTSX, tr("Unfortunately, your CPU model does not support this instruction set.", "Enable TSX"));
m_emu_settings->SetSetting(emu_settings_type::EnableTSX, fmt::format("%s", tsx_usage::disabled));
connect(this, &settings_dialog::signal_restore_dependant_defaults, [this]()
{
m_emu_settings->SetSetting(emu_settings_type::EnableTSX, fmt::format("%s", tsx_usage::disabled));
});
}
// PPU tool tips
@ -427,6 +440,50 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceComboBox(ui->shaderCompilerThreads, emu_settings_type::ShaderCompilerNumThreads, true);
SubscribeTooltip(ui->gb_shader_compiler_threads, tooltips.settings.shader_compiler_threads);
ui->shaderCompilerThreads->setItemText(ui->shaderCompilerThreads->findData(0), tr("Auto", "Number of Shader Compiler Threads"));
// Custom control that simplifies operation of two independent variables. Can probably be done better but this works.
ui->zcullPrecisionMode->addItem(tr("Precise (Default)"), static_cast<int>(zcull_precision_level::precise));
ui->zcullPrecisionMode->addItem(tr("Approximate (Fast)"), static_cast<int>(zcull_precision_level::approximate));
ui->zcullPrecisionMode->addItem(tr("Relaxed (Fastest)"), static_cast<int>(zcull_precision_level::relaxed));
const auto reset_zcull_options = [this]()
{
if (m_emu_settings->GetSetting(emu_settings_type::RelaxedZCULL) == "true")
{
ui->zcullPrecisionMode->setCurrentIndex(ui->zcullPrecisionMode->findData(static_cast<int>(zcull_precision_level::relaxed)));
}
else if (m_emu_settings->GetSetting(emu_settings_type::PreciseZCULL) == "true")
{
ui->zcullPrecisionMode->setCurrentIndex(ui->zcullPrecisionMode->findData(static_cast<int>(zcull_precision_level::precise)));
}
else
{
ui->zcullPrecisionMode->setCurrentIndex(ui->zcullPrecisionMode->findData(static_cast<int>(zcull_precision_level::approximate)));
}
};
reset_zcull_options();
connect(this, &settings_dialog::signal_restore_dependant_defaults, this, reset_zcull_options);
connect(ui->zcullPrecisionMode, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index)
{
bool relaxed = false, precise = false;
switch (static_cast<zcull_precision_level>(ui->zcullPrecisionMode->itemData(index).toInt()))
{
case zcull_precision_level::precise:
precise = true; break;
case zcull_precision_level::approximate:
break;
case zcull_precision_level::relaxed:
relaxed = true; break;
default:
fmt::throw_exception("Unexpected selection");
}
m_emu_settings->SetSetting(emu_settings_type::RelaxedZCULL, relaxed ? "true" : "false");
m_emu_settings->SetSetting(emu_settings_type::PreciseZCULL, precise ? "true" : "false");
});
SubscribeTooltip(ui->gbZCULL, tooltips.settings.zcull_operation_mode);
// Checkboxes: main options
m_emu_settings->EnhanceCheckBox(ui->dumpColor, emu_settings_type::WriteColorBuffers);
@ -443,7 +500,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->multithreadedRSX, emu_settings_type::MultithreadedRSX);
SubscribeTooltip(ui->multithreadedRSX, tooltips.settings.multithreaded_rsx);
connect(ui->multithreadedRSX, &QCheckBox::clicked, [this](bool checked)
connect(ui->multithreadedRSX, &QCheckBox::toggled, [this](bool checked)
{
ui->disableVertexCache->setEnabled(!checked);
});
@ -451,14 +508,14 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->strictModeRendering, emu_settings_type::StrictRenderingMode);
SubscribeTooltip(ui->strictModeRendering, tooltips.settings.strict_rendering_mode);
const auto onStrictRenderingMode = [this](bool checked)
const auto on_strict_rendering_mode = [this](bool checked)
{
ui->gb_resolutionScale->setEnabled(!checked);
ui->gb_minimumScalableDimension->setEnabled(!checked);
ui->gb_anisotropicFilter->setEnabled(!checked);
ui->vulkansched->setEnabled(!checked);
};
connect(ui->strictModeRendering, &QCheckBox::clicked, this, onStrictRenderingMode);
connect(ui->strictModeRendering, &QCheckBox::toggled, this, on_strict_rendering_mode);
m_emu_settings->EnhanceCheckBox(ui->asyncTextureStreaming, emu_settings_type::VulkanAsyncTextureUploads);
SubscribeTooltip(ui->asyncTextureStreaming, tooltips.settings.async_texture_streaming);
@ -487,7 +544,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
SubscribeTooltip(ui->gb_resolutionScale, tooltips.settings.resolution_scale);
// rename label texts to fit current state of Resolution Scale
const int resolution_scale_def = stoi(m_emu_settings->GetSettingDefault(emu_settings_type::ResolutionScale));
auto scaled_resolution = [resolution_scale_def](int percentage)
const auto scaled_resolution = [resolution_scale_def](int percentage)
{
if (percentage == resolution_scale_def)
{
@ -515,7 +572,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
SubscribeTooltip(ui->gb_minimumScalableDimension, tooltips.settings.minimum_scalable_dimension);
// rename label texts to fit current state of Minimum Scalable Dimension
const int minimum_scalable_dimension_def = stoi(m_emu_settings->GetSettingDefault(emu_settings_type::MinimumScalableDimension));
auto min_scalable_dimension = [minimum_scalable_dimension_def](int dim)
const auto min_scalable_dimension = [minimum_scalable_dimension_def](int dim)
{
if (dim == minimum_scalable_dimension_def)
{
@ -539,7 +596,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
});
const int fsr_sharpening_strength_def = stoi(m_emu_settings->GetSettingDefault(emu_settings_type::FsrSharpeningStrength));
auto fmt_fsr_sharpening_strength = [fsr_sharpening_strength_def](int value)
const auto fmt_fsr_sharpening_strength = [fsr_sharpening_strength_def](int value)
{
if (value == fsr_sharpening_strength_def)
{
@ -683,7 +740,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
connect(ui->graphicsAdapterBox, &QComboBox::currentTextChanged, set_adapter);
connect(ui->renderBox, &QComboBox::currentTextChanged, set_renderer);
auto apply_renderer_specific_options = [=, this](const QString& text)
const auto apply_renderer_specific_options = [=, this](const QString& text)
{
// Vulkan-only
const bool is_vulkan = (text == r_creator->Vulkan.name);
@ -695,7 +752,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
};
// Handle connects to disable specific checkboxes that depend on GUI state.
onStrictRenderingMode(ui->strictModeRendering->isChecked());
on_strict_rendering_mode(ui->strictModeRendering->isChecked());
apply_renderer_specific_options(ui->renderBox->currentText()); // Init
connect(ui->renderBox, &QComboBox::currentTextChanged, apply_renderer_specific_options);
@ -706,13 +763,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
// / ____ \ |_| | (_| | | (_) | | | (_| | |_) |
// /_/ \_\__,_|\__,_|_|\___/ |_|\__,_|_.__/
auto enable_time_stretching_options = [this](bool enabled)
const auto enable_time_stretching_options = [this](bool enabled)
{
ui->timeStretchingThresholdLabel->setEnabled(enabled);
ui->timeStretchingThreshold->setEnabled(enabled);
};
auto enable_buffering_options = [this, enable_time_stretching_options](bool enabled)
const auto enable_buffering_options = [this, enable_time_stretching_options](bool enabled)
{
ui->audioBufferDuration->setEnabled(enabled);
ui->audioBufferDurationLabel->setEnabled(enabled);
@ -720,7 +777,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
enable_time_stretching_options(enabled && ui->enableTimeStretching->isChecked());
};
auto enable_buffering = [this, enable_buffering_options](int index)
const auto enable_buffering = [this, enable_buffering_options](int index)
{
const QVariantList var_list = ui->audioOutBox->itemData(index).toList();
ensure(var_list.size() == 2 && var_list[0].canConvert<QString>());
@ -732,7 +789,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
const QString mic_none = m_emu_settings->m_microphone_creator.get_none();
auto change_microphone_type = [mic_none, this](int index)
const auto change_microphone_type = [mic_none, this](int index)
{
if (index < 0)
{
@ -766,13 +823,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
ui->microphone4Box->setEnabled(ui->microphone3Box->isEnabled() && ui->microphone3Box->currentText() != mic_none);
};
auto propagate_used_devices = [mic_none, change_microphone_type, this]()
const auto propagate_used_devices = [mic_none, change_microphone_type, this]()
{
for (u32 index = 0; index < 4; index++)
for (u32 index = 0; index < m_mics_combo.size(); index++)
{
const QString cur_item = m_mics_combo[index]->currentText();
QStringList cur_list = m_emu_settings->m_microphone_creator.get_microphone_list();
for (u32 subindex = 0; subindex < 4; subindex++)
for (u32 subindex = 0; subindex < m_mics_combo.size(); subindex++)
{
if (subindex != index && m_mics_combo[subindex]->currentText() != mic_none)
cur_list.removeOne(m_mics_combo[subindex]->currentText());
@ -786,10 +843,10 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
change_microphone_type(ui->microphoneBox->currentIndex());
};
const auto change_microphone_device = [mic_none, propagate_used_devices, this](u32 next_index, const QString& text)
const auto change_microphone_device = [mic_none, propagate_used_devices, this](u32 index, const QString& text)
{
m_emu_settings->SetSetting(emu_settings_type::MicrophoneDevices, m_emu_settings->m_microphone_creator.set_device(next_index, text));
if (next_index < 4 && text == mic_none)
m_emu_settings->SetSetting(emu_settings_type::MicrophoneDevices, m_emu_settings->m_microphone_creator.set_device(index, text));
if (const u32 next_index = index + 1; next_index < 4 && text == mic_none)
m_mics_combo[next_index]->setCurrentText(mic_none);
propagate_used_devices();
};
@ -814,26 +871,28 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_mics_combo[1] = ui->microphone2Box;
m_mics_combo[2] = ui->microphone3Box;
m_mics_combo[3] = ui->microphone4Box;
connect(m_mics_combo[0], &QComboBox::currentTextChanged, [=, this](const QString& text) { change_microphone_device(1, text); });
connect(m_mics_combo[1], &QComboBox::currentTextChanged, [=, this](const QString& text) { change_microphone_device(2, text); });
connect(m_mics_combo[2], &QComboBox::currentTextChanged, [=, this](const QString& text) { change_microphone_device(3, text); });
connect(m_mics_combo[3], &QComboBox::currentTextChanged, [=, this](const QString& text) { change_microphone_device(4, text); });
for (u32 i = 0; i < m_mics_combo.size(); i++)
{
connect(m_mics_combo[i], &QComboBox::currentTextChanged, [change_microphone_device, i](const QString& text) { change_microphone_device(i, text); });
connect(m_emu_settings.get(), &emu_settings::RestoreDefaultsSignal, [change_microphone_device, i, mic_none]() { change_microphone_device(i, mic_none); });
}
m_emu_settings->m_microphone_creator.refresh_list();
propagate_used_devices(); // Fills comboboxes list
m_emu_settings->m_microphone_creator.parse_devices(m_emu_settings->GetSetting(emu_settings_type::MicrophoneDevices));
const auto mic_sel_list = m_emu_settings->m_microphone_creator.get_selection_list();
const std::array<std::string, 4> mic_sel_list = m_emu_settings->m_microphone_creator.get_selection_list();
for (s32 index = 3; index >= 0; index--)
{
const auto mic = mic_sel_list[index];
const auto qmic = qstr(mic);
const QString qmic = qstr(mic_sel_list[index]);
if (mic.empty() || m_mics_combo[index]->findText(qmic) == -1)
if (qmic.isEmpty() || m_mics_combo[index]->findText(qmic) == -1)
{
m_mics_combo[index]->setCurrentText(mic_none);
change_microphone_device(index+1, mic_none); // Ensures the value is set in config
change_microphone_device(index, mic_none); // Ensures the value is set in config
}
else
{
@ -856,11 +915,11 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->enableBuffering, emu_settings_type::EnableBuffering);
SubscribeTooltip(ui->enableBuffering, tooltips.settings.enable_buffering);
connect(ui->enableBuffering, &QCheckBox::clicked, enable_buffering_options);
connect(ui->enableBuffering, &QCheckBox::toggled, enable_buffering_options);
m_emu_settings->EnhanceCheckBox(ui->enableTimeStretching, emu_settings_type::EnableTimeStretching);
SubscribeTooltip(ui->enableTimeStretching, tooltips.settings.enable_time_stretching);
connect(ui->enableTimeStretching, &QCheckBox::clicked, enable_time_stretching_options);
connect(ui->enableTimeStretching, &QCheckBox::toggled, enable_time_stretching_options);
enable_buffering(ui->audioOutBox->currentIndex());
@ -1041,47 +1100,6 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceComboBox(ui->vulkansched, emu_settings_type::VulkanAsyncSchedulerDriver);
SubscribeTooltip(ui->gb_vulkansched, tooltips.settings.vulkan_async_scheduler);
// Custom control that simplifies operation of two independent variables. Can probably be done better but this works.
ui->zcullPrecisionMode->addItem(tr("Precise (Default)"), static_cast<int>(zcull_precision_level::precise));
ui->zcullPrecisionMode->addItem(tr("Approximate (Fast)"), static_cast<int>(zcull_precision_level::approximate));
ui->zcullPrecisionMode->addItem(tr("Relaxed (Fastest)"), static_cast<int>(zcull_precision_level::relaxed));
if (m_emu_settings->GetSetting(emu_settings_type::RelaxedZCULL) == "true")
{
ui->zcullPrecisionMode->setCurrentIndex(
ui->zcullPrecisionMode->findData(static_cast<int>(zcull_precision_level::relaxed)));
}
else if (m_emu_settings->GetSetting(emu_settings_type::PreciseZCULL) == "true")
{
ui->zcullPrecisionMode->setCurrentIndex(
ui->zcullPrecisionMode->findData(static_cast<int>(zcull_precision_level::precise)));
}
else
{
ui->zcullPrecisionMode->setCurrentIndex(
ui->zcullPrecisionMode->findData(static_cast<int>(zcull_precision_level::approximate)));
}
connect(ui->zcullPrecisionMode, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index)
{
bool relaxed = false, precise = false;
switch (static_cast<zcull_precision_level>(ui->zcullPrecisionMode->itemData(index).toInt()))
{
case zcull_precision_level::precise:
precise = true; break;
case zcull_precision_level::approximate:
break;
case zcull_precision_level::relaxed:
relaxed = true; break;
default:
fmt::throw_exception("Unexpected selection");
}
m_emu_settings->SetSetting(emu_settings_type::RelaxedZCULL, relaxed ? "true" : "false");
m_emu_settings->SetSetting(emu_settings_type::PreciseZCULL, precise ? "true" : "false");
});
SubscribeTooltip(ui->gbZCULL, tooltips.settings.zcull_operation_mode);
// Sliders
EnhanceSlider(emu_settings_type::DriverWakeUpDelay, ui->wakeupDelay, ui->wakeupText, tr(reinterpret_cast<const char*>(u8"%0 µs"), "Driver wake up delay"));
@ -1203,12 +1221,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
}
};
// Sort libs
on_lib_state_changed({});
// Events
connect(ui->searchBox, &QLineEdit::textChanged, on_lib_state_changed);
connect(ui->resetLleList, &QAbstractButton::clicked, [this, on_lib_state_changed]()
const auto reset_library_lists = [this, on_lib_state_changed]()
{
for (int i = 0; i < ui->lleList->count(); i++)
{
@ -1221,7 +1234,14 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
}
on_lib_state_changed(ui->searchBox->text());
});
};
// Sort libs
on_lib_state_changed({});
// Events
connect(ui->searchBox, &QLineEdit::textChanged, on_lib_state_changed);
connect(ui->resetLleList, &QAbstractButton::clicked, reset_library_lists);
// enable multiselection (there must be a better way)
connect(ui->lleList, &QListWidget::itemChanged, [this](QListWidgetItem* item)
@ -1240,6 +1260,8 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
}
});
connect(m_emu_settings.get(), &emu_settings::RestoreDefaultsSignal, reset_library_lists);
// ______ _ _ _______ _
// | ____| | | | | |__ __| | |
// | |__ _ __ ___ _ _| | __ _| |_ ___ _ __ | | __ _| |__
@ -1285,7 +1307,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->perfOverlayCenterX, emu_settings_type::PerfOverlayCenterX);
SubscribeTooltip(ui->perfOverlayCenterX, tooltips.settings.perf_overlay_center_x);
connect(ui->perfOverlayCenterX, &QCheckBox::clicked, [this](bool checked)
connect(ui->perfOverlayCenterX, &QCheckBox::toggled, [this](bool checked)
{
ui->perfOverlayMarginX->setEnabled(!checked);
});
@ -1293,7 +1315,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->perfOverlayCenterY, emu_settings_type::PerfOverlayCenterY);
SubscribeTooltip(ui->perfOverlayCenterY, tooltips.settings.perf_overlay_center_y);
connect(ui->perfOverlayCenterY, &QCheckBox::clicked, [this](bool checked)
connect(ui->perfOverlayCenterY, &QCheckBox::toggled, [this](bool checked)
{
ui->perfOverlayMarginY->setEnabled(!checked);
});
@ -1307,7 +1329,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->perfOverlayEnabled, emu_settings_type::PerfOverlayEnabled);
SubscribeTooltip(ui->perfOverlayEnabled, tooltips.settings.perf_overlay_enabled);
auto enable_perf_overlay_options = [this](bool enabled)
const auto enable_perf_overlay_options = [this](bool enabled)
{
ui->label_detail_level->setEnabled(enabled);
ui->label_update_interval->setEnabled(enabled);
@ -1331,11 +1353,11 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
ui->perf_overlay_frametime_datapoints->setEnabled(enabled);
};
enable_perf_overlay_options(ui->perfOverlayEnabled->isChecked());
connect(ui->perfOverlayEnabled, &QCheckBox::clicked, enable_perf_overlay_options);
connect(ui->perfOverlayEnabled, &QCheckBox::toggled, enable_perf_overlay_options);
m_emu_settings->EnhanceCheckBox(ui->shaderLoadBgEnabled, emu_settings_type::ShaderLoadBgEnabled);
SubscribeTooltip(ui->shaderLoadBgEnabled, tooltips.settings.shader_load_bg_enabled);
auto enable_shader_loader_options = [this](bool enabled)
const auto enable_shader_loader_options = [this](bool enabled)
{
ui->label_shaderLoadBgDarkening->setEnabled(enabled);
ui->label_shaderLoadBgBlur->setEnabled(enabled);
@ -1343,7 +1365,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
ui->shaderLoadBgBlur->setEnabled(enabled);
};
enable_shader_loader_options(ui->shaderLoadBgEnabled->isChecked());
connect(ui->shaderLoadBgEnabled, &QCheckBox::clicked, enable_shader_loader_options);
connect(ui->shaderLoadBgEnabled, &QCheckBox::toggled, enable_shader_loader_options);
// Sliders
@ -1387,31 +1409,31 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
SubscribeTooltip(ui->gs_hideMouseOnIdle_widget, tooltips.settings.hide_mouse_on_idle);
ui->gs_disableMouse->setChecked(m_gui_settings->GetValue(gui::gs_disableMouse).toBool());
connect(ui->gs_disableMouse, &QCheckBox::clicked, [this](bool val)
connect(ui->gs_disableMouse, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::gs_disableMouse, val);
m_gui_settings->SetValue(gui::gs_disableMouse, checked);
});
ui->gs_disableKbHotkeys->setChecked(m_gui_settings->GetValue(gui::gs_disableKbHotkeys).toBool());
connect(ui->gs_disableKbHotkeys, &QCheckBox::clicked, [this](bool val)
connect(ui->gs_disableKbHotkeys, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::gs_disableKbHotkeys, val);
m_gui_settings->SetValue(gui::gs_disableKbHotkeys, checked);
});
ui->gs_showMouseInFullscreen->setChecked(m_gui_settings->GetValue(gui::gs_showMouseFs).toBool());
connect(ui->gs_showMouseInFullscreen, &QCheckBox::clicked, [this](bool val)
connect(ui->gs_showMouseInFullscreen, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::gs_showMouseFs, val);
m_gui_settings->SetValue(gui::gs_showMouseFs, checked);
});
ui->gs_lockMouseInFullscreen->setChecked(m_gui_settings->GetValue(gui::gs_lockMouseFs).toBool());
connect(ui->gs_lockMouseInFullscreen, &QCheckBox::clicked, [this](bool val)
connect(ui->gs_lockMouseInFullscreen, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::gs_lockMouseFs, val);
m_gui_settings->SetValue(gui::gs_lockMouseFs, checked);
});
ui->gs_hideMouseOnIdle->setChecked(m_gui_settings->GetValue(gui::gs_hideMouseIdle).toBool());
connect(ui->gs_hideMouseOnIdle, &QCheckBox::clicked, [this](bool checked)
connect(ui->gs_hideMouseOnIdle, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::gs_hideMouseIdle, checked);
ui->gs_hideMouseOnIdleTime->setEnabled(checked);
@ -1434,18 +1456,18 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
ui->gs_width->setValue(std::min(width, screen.width()));
ui->gs_height->setValue(std::min(height, screen.height()));
connect(ui->gs_resizeOnBoot, &QCheckBox::clicked, [=, this](bool val)
connect(ui->gs_resizeOnBoot, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::gs_resize, val);
ui->gs_width->setEnabled(val);
ui->gs_height->setEnabled(val);
m_gui_settings->SetValue(gui::gs_resize, checked);
ui->gs_width->setEnabled(checked);
ui->gs_height->setEnabled(checked);
});
connect(ui->gs_width, &QSpinBox::editingFinished, [=, this]()
connect(ui->gs_width, &QSpinBox::editingFinished, [this]()
{
ui->gs_width->setValue(std::min(ui->gs_width->value(), QGuiApplication::primaryScreen()->size().width()));
m_gui_settings->SetValue(gui::gs_width, ui->gs_width->value());
});
connect(ui->gs_height, &QSpinBox::editingFinished, [=, this]()
connect(ui->gs_height, &QSpinBox::editingFinished, [this]()
{
ui->gs_height->setValue(std::min(ui->gs_height->value(), QGuiApplication::primaryScreen()->size().height()));
m_gui_settings->SetValue(gui::gs_height, ui->gs_height->value());
@ -1490,12 +1512,12 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
const auto set_game_window_title = [get_game_window_title, this](const std::string& format)
{
const auto game_window_title_format = qstr(format);
const auto game_window_title = get_game_window_title(game_window_title_format);
const auto width = ui->label_game_window_title_format->sizeHint().width();
const auto metrics = ui->label_game_window_title_format->fontMetrics();
const auto elided_text = metrics.elidedText(game_window_title_format, Qt::ElideRight, width);
const auto tooltip = game_window_title_format + QStringLiteral("\n\n") + game_window_title;
const QString game_window_title_format = qstr(format);
const QString game_window_title = get_game_window_title(game_window_title_format);
const int width = ui->label_game_window_title_format->sizeHint().width();
const QFontMetrics metrics = ui->label_game_window_title_format->fontMetrics();
const QString elided_text = metrics.elidedText(game_window_title_format, Qt::ElideRight, width);
const QString tooltip = game_window_title_format + QStringLiteral("\n\n") + game_window_title;
ui->label_game_window_title_format->setText(elided_text);
ui->label_game_window_title_format->setToolTip(tooltip);
@ -1550,12 +1572,14 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
}
});
connect(ui->reset_button_game_window_title_format, &QAbstractButton::clicked, [set_game_window_title, this]()
const auto reset_game_window_title_format = [set_game_window_title, this]()
{
const std::string default_game_title_format = m_emu_settings->GetSettingDefault(emu_settings_type::WindowTitleFormat);
m_emu_settings->SetSetting(emu_settings_type::WindowTitleFormat, default_game_title_format);
set_game_window_title(default_game_title_format);
});
};
connect(ui->reset_button_game_window_title_format, &QAbstractButton::clicked, this, reset_game_window_title_format);
connect(this, &settings_dialog::signal_restore_dependant_defaults, this, reset_game_window_title_format);
// Load and apply the configured game window title format
set_game_window_title(m_emu_settings->GetSetting(emu_settings_type::WindowTitleFormat));
@ -1590,7 +1614,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
ui->discordState->setEnabled(m_use_discord);
ui->discordState->setText(m_discord_state);
connect(ui->useRichPresence, &QCheckBox::clicked, [this](bool checked)
connect(ui->useRichPresence, &QCheckBox::toggled, [this](bool checked)
{
ui->discordState->setEnabled(checked);
ui->label_discordState->setEnabled(checked);
@ -1673,44 +1697,45 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
connect(ui->pb_apply_stylesheet, &QAbstractButton::clicked, this, [this]() { ApplyStylesheet(false); });
connect(ui->cb_show_welcome, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_welcome, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_show_welcome, val);
m_gui_settings->SetValue(gui::ib_show_welcome, checked);
});
connect(ui->cb_show_exit_game, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_exit_game, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_confirm_exit, val);
m_gui_settings->SetValue(gui::ib_confirm_exit, checked);
});
connect(ui->cb_show_boot_game, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_boot_game, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_confirm_boot, val);
m_gui_settings->SetValue(gui::ib_confirm_boot, checked);
});
connect(ui->cb_show_pkg_install, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_pkg_install, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_pkg_success, val);
m_gui_settings->SetValue(gui::ib_pkg_success, checked);
});
connect(ui->cb_show_pup_install, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_pup_install, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_pup_success, val);
m_gui_settings->SetValue(gui::ib_pup_success, checked);
});
connect(ui->cb_show_obsolete_cfg_dialog, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_obsolete_cfg_dialog, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_obsolete_cfg, val);
m_gui_settings->SetValue(gui::ib_obsolete_cfg, checked);
});
connect(ui->cb_show_same_buttons_dialog, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_show_same_buttons_dialog, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::ib_same_buttons, val);
m_gui_settings->SetValue(gui::ib_same_buttons, checked);
});
connect(ui->cb_custom_colors, &QCheckBox::clicked, [this](bool val)
connect(ui->cb_custom_colors, &QCheckBox::toggled, [this](bool checked)
{
m_gui_settings->SetValue(gui::m_enableUIColors, val);
ui->pb_gl_icon_color->setEnabled(val);
ui->pb_sd_icon_color->setEnabled(val);
ui->pb_tr_icon_color->setEnabled(val);
m_gui_settings->SetValue(gui::m_enableUIColors, checked);
ui->pb_gl_icon_color->setEnabled(checked);
ui->pb_sd_icon_color->setEnabled(checked);
ui->pb_tr_icon_color->setEnabled(checked);
Q_EMIT GuiRepaintRequest();
});
auto color_dialog = [&](const gui_save& color, const QString& title, QPushButton *button)
const auto color_dialog = [&](const gui_save& color, const QString& title, QPushButton *button)
{
const QColor old_color = m_gui_settings->GetValue(color).value<QColor>();
QColorDialog dlg(old_color, this);

View File

@ -28,6 +28,7 @@ Q_SIGNALS:
void GuiStylesheetRequest();
void GuiRepaintRequest();
void EmuSettingsApplied();
void signal_restore_dependant_defaults();
private:
void EnhanceSlider(emu_settings_type settings_type, QSlider* slider, QLabel* label, const QString& label_text) const;
@ -43,7 +44,7 @@ private:
// Gpu tab
QString m_old_renderer;
// Audio tab
QComboBox *m_mics_combo[4];
std::array<QComboBox*, 4> m_mics_combo;
int m_tab_index;
Ui::settings_dialog *ui;

View File

@ -3852,7 +3852,7 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close|QDialogButtonBox::Save</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Save</set>
</property>
</widget>
</item>