Update settings_dialog.cpp

This commit is contained in:
UltraDaCat 2025-07-13 18:29:39 +02:00 committed by GitHub
parent c012352968
commit 628d72fe24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,6 +68,7 @@ QMap<QString, QString> chooseHomeTabMap;
int backgroundImageOpacitySlider_backup; int backgroundImageOpacitySlider_backup;
int bgm_volume_backup; int bgm_volume_backup;
int volume_slider_backup;
static std::vector<QString> m_physical_devices; static std::vector<QString> m_physical_devices;
@ -149,9 +150,11 @@ SettingsDialog::SettingsDialog(std::shared_ptr<gui_settings> gui_settings,
} else if (button == ui->buttonBox->button(QDialogButtonBox::Close)) { } else if (button == ui->buttonBox->button(QDialogButtonBox::Close)) {
ui->backgroundImageOpacitySlider->setValue(backgroundImageOpacitySlider_backup); ui->backgroundImageOpacitySlider->setValue(backgroundImageOpacitySlider_backup);
emit BackgroundOpacityChanged(backgroundImageOpacitySlider_backup); emit BackgroundOpacityChanged(backgroundImageOpacitySlider_backup);
ui->horizontalVolumeSlider->setValue(volume_slider_backup);
Config::setVolumeSlider(volume_slider_backup);
ui->BGMVolumeSlider->setValue(bgm_volume_backup); ui->BGMVolumeSlider->setValue(bgm_volume_backup);
BackgroundMusicPlayer::getInstance().setVolume(bgm_volume_backup); BackgroundMusicPlayer::getInstance().setVolume(bgm_volume_backup);
ResetInstallFolders(); SyncRealTimeWidgetstoConfig();
} }
if (Common::Log::IsActive()) { if (Common::Log::IsActive()) {
Common::Log::Filter filter; Common::Log::Filter filter;
@ -170,6 +173,9 @@ SettingsDialog::SettingsDialog(std::shared_ptr<gui_settings> gui_settings,
// GENERAL TAB // GENERAL TAB
{ {
connect(ui->horizontalVolumeSlider, &QSlider::valueChanged, this,
[this](int value) { VolumeSliderChange(value); });
#ifdef ENABLE_UPDATER #ifdef ENABLE_UPDATER
#if (QT_VERSION < QT_VERSION_CHECK(6, 7, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 7, 0))
connect(ui->updateCheckBox, &QCheckBox::stateChanged, this, [this](int state) { connect(ui->updateCheckBox, &QCheckBox::stateChanged, this, [this](int state) {
@ -398,6 +404,8 @@ void SettingsDialog::closeEvent(QCloseEvent* event) {
if (!is_saving) { if (!is_saving) {
ui->backgroundImageOpacitySlider->setValue(backgroundImageOpacitySlider_backup); ui->backgroundImageOpacitySlider->setValue(backgroundImageOpacitySlider_backup);
emit BackgroundOpacityChanged(backgroundImageOpacitySlider_backup); emit BackgroundOpacityChanged(backgroundImageOpacitySlider_backup);
ui->horizontalVolumeSlider->setValue(volume_slider_backup);
Config::setVolumeSlider(volume_slider_backup);
ui->BGMVolumeSlider->setValue(bgm_volume_backup); ui->BGMVolumeSlider->setValue(bgm_volume_backup);
BackgroundMusicPlayer::getInstance().setVolume(bgm_volume_backup); BackgroundMusicPlayer::getInstance().setVolume(bgm_volume_backup);
} }
@ -463,6 +471,8 @@ void SettingsDialog::LoadValuesFromConfig() {
ui->radioButton_Bottom->setChecked(side == "bottom"); ui->radioButton_Bottom->setChecked(side == "bottom");
ui->BGMVolumeSlider->setValue(m_gui_settings->GetValue(gui::gl_backgroundMusicVolume).toInt()); ui->BGMVolumeSlider->setValue(m_gui_settings->GetValue(gui::gl_backgroundMusicVolume).toInt());
ui->horizontalVolumeSlider->setValue(m_gui_settings->GetValue(gui::gl_VolumeSlider).toInt());
ui->volumeText->setText(QString::number(ui->horizontalVolumeSlider->sliderPosition()) + "%");
ui->discordRPCCheckbox->setChecked( ui->discordRPCCheckbox->setChecked(
toml::find_or<bool>(data, "General", "enableDiscordRPC", true)); toml::find_or<bool>(data, "General", "enableDiscordRPC", true));
QString translatedText_FullscreenMode = QString translatedText_FullscreenMode =
@ -532,7 +542,7 @@ void SettingsDialog::LoadValuesFromConfig() {
toml::find_or<bool>(data, "Input", "isMotionControlsEnabled", true)); toml::find_or<bool>(data, "Input", "isMotionControlsEnabled", true));
ui->removeFolderButton->setEnabled(!ui->gameFoldersListWidget->selectedItems().isEmpty()); ui->removeFolderButton->setEnabled(!ui->gameFoldersListWidget->selectedItems().isEmpty());
ResetInstallFolders(); SyncRealTimeWidgetstoConfig();
ui->backgroundImageOpacitySlider->setValue( ui->backgroundImageOpacitySlider->setValue(
m_gui_settings->GetValue(gui::gl_backgroundImageOpacity).toInt()); m_gui_settings->GetValue(gui::gl_backgroundImageOpacity).toInt());
ui->showBackgroundImageCheckBox->setChecked( ui->showBackgroundImageCheckBox->setChecked(
@ -541,6 +551,7 @@ void SettingsDialog::LoadValuesFromConfig() {
backgroundImageOpacitySlider_backup = backgroundImageOpacitySlider_backup =
m_gui_settings->GetValue(gui::gl_backgroundImageOpacity).toInt(); m_gui_settings->GetValue(gui::gl_backgroundImageOpacity).toInt();
bgm_volume_backup = m_gui_settings->GetValue(gui::gl_backgroundMusicVolume).toInt(); bgm_volume_backup = m_gui_settings->GetValue(gui::gl_backgroundMusicVolume).toInt();
volume_slider_backup = m_gui_settings->GetValue(gui::gl_VolumeSlider).toInt();
} }
void SettingsDialog::InitializeEmulatorLanguages() { void SettingsDialog::InitializeEmulatorLanguages() {
@ -599,6 +610,10 @@ void SettingsDialog::OnCursorStateChanged(s16 index) {
} }
} }
void SettingsDialog::VolumeSliderChange(int value) {
ui->volumeText->setText(QString::number(ui->horizontalVolumeSlider->sliderPosition()) + "%");
}
int SettingsDialog::exec() { int SettingsDialog::exec() {
return QDialog::exec(); return QDialog::exec();
} }
@ -719,7 +734,6 @@ bool SettingsDialog::eventFilter(QObject* obj, QEvent* event) {
if (qobject_cast<QWidget*>(obj)) { if (qobject_cast<QWidget*>(obj)) {
bool hovered = (event->type() == QEvent::Enter); bool hovered = (event->type() == QEvent::Enter);
QString elementName = obj->objectName(); QString elementName = obj->objectName();
if (hovered) { if (hovered) {
updateNoteTextEdit(elementName); updateNoteTextEdit(elementName);
} else { } else {
@ -759,6 +773,7 @@ void SettingsDialog::UpdateSettings() {
Config::setCursorState(ui->hideCursorComboBox->currentIndex()); Config::setCursorState(ui->hideCursorComboBox->currentIndex());
Config::setCursorHideTimeout(ui->idleTimeoutSpinBox->value()); Config::setCursorHideTimeout(ui->idleTimeoutSpinBox->value());
Config::setGpuId(ui->graphicsAdapterBox->currentIndex() - 1); Config::setGpuId(ui->graphicsAdapterBox->currentIndex() - 1);
m_gui_settings->SetValue(gui::gl_VolumeSlider, ui->horizontalVolumeSlider->value());
m_gui_settings->SetValue(gui::gl_backgroundMusicVolume, ui->BGMVolumeSlider->value()); m_gui_settings->SetValue(gui::gl_backgroundMusicVolume, ui->BGMVolumeSlider->value());
Config::setLanguage(languageIndexes[ui->consoleLanguageComboBox->currentIndex()]); Config::setLanguage(languageIndexes[ui->consoleLanguageComboBox->currentIndex()]);
Config::setEnableDiscordRPC(ui->discordRPCCheckbox->isChecked()); Config::setEnableDiscordRPC(ui->discordRPCCheckbox->isChecked());
@ -815,9 +830,10 @@ void SettingsDialog::UpdateSettings() {
#endif #endif
BackgroundMusicPlayer::getInstance().setVolume(ui->BGMVolumeSlider->value()); BackgroundMusicPlayer::getInstance().setVolume(ui->BGMVolumeSlider->value());
Config::setVolumeSlider(ui->horizontalVolumeSlider->value());
} }
void SettingsDialog::ResetInstallFolders() { void SettingsDialog::SyncRealTimeWidgetstoConfig() {
ui->gameFoldersListWidget->clear(); ui->gameFoldersListWidget->clear();
std::filesystem::path userdir = Common::FS::GetUserPath(Common::FS::PathType::UserDir); std::filesystem::path userdir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
@ -865,6 +881,7 @@ void SettingsDialog::setDefaultValues() {
m_gui_settings->SetValue(gui::gl_backgroundImageOpacity, 50); m_gui_settings->SetValue(gui::gl_backgroundImageOpacity, 50);
m_gui_settings->SetValue(gui::gl_playBackgroundMusic, false); m_gui_settings->SetValue(gui::gl_playBackgroundMusic, false);
m_gui_settings->SetValue(gui::gl_backgroundMusicVolume, 50); m_gui_settings->SetValue(gui::gl_backgroundMusicVolume, 50);
m_gui_settings->SetValue(gui::gl_VolumeSlider, 100);
m_gui_settings->SetValue(gui::gen_checkForUpdates, false); m_gui_settings->SetValue(gui::gen_checkForUpdates, false);
m_gui_settings->SetValue(gui::gen_showChangeLog, false); m_gui_settings->SetValue(gui::gen_showChangeLog, false);
if (Common::g_is_release) { if (Common::g_is_release) {
@ -873,4 +890,4 @@ void SettingsDialog::setDefaultValues() {
m_gui_settings->SetValue(gui::gen_updateChannel, "Nightly"); m_gui_settings->SetValue(gui::gen_updateChannel, "Nightly");
} }
m_gui_settings->SetValue(gui::gen_guiLanguage, "en_US"); m_gui_settings->SetValue(gui::gen_guiLanguage, "en_US");
} }