Qt: add apply button to settings dialog

This commit is contained in:
Megamouse 2020-02-20 22:20:42 +01:00
parent e005581dda
commit 0ed87be47a
5 changed files with 29 additions and 8 deletions

View file

@ -1059,7 +1059,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
connect(configure, &QAction::triggered, [=, this]() connect(configure, &QAction::triggered, [=, this]()
{ {
settings_dialog dlg(m_gui_settings, m_emu_settings, 0, this, &currGame); settings_dialog dlg(m_gui_settings, m_emu_settings, 0, this, &currGame);
if (dlg.exec() == QDialog::Accepted) connect(&dlg, &settings_dialog::EmuSettingsApplied, [this, gameinfo]()
{ {
if (!gameinfo->hasCustomConfig) if (!gameinfo->hasCustomConfig)
{ {
@ -1067,7 +1067,8 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
ShowCustomConfigIcon(gameinfo); ShowCustomConfigIcon(gameinfo);
} }
Q_EMIT NotifyEmuSettingsChange(); Q_EMIT NotifyEmuSettingsChange();
} });
dlg.exec();
}); });
connect(pad_configure, &QAction::triggered, [=, this]() connect(pad_configure, &QAction::triggered, [=, this]()
{ {

View file

@ -1333,8 +1333,8 @@ void main_window::CreateConnects()
connect(&dlg, &settings_dialog::GuiSettingsSyncRequest, this, &main_window::ConfigureGuiFromSettings); connect(&dlg, &settings_dialog::GuiSettingsSyncRequest, this, &main_window::ConfigureGuiFromSettings);
connect(&dlg, &settings_dialog::GuiStylesheetRequest, this, &main_window::RequestGlobalStylesheetChange); connect(&dlg, &settings_dialog::GuiStylesheetRequest, this, &main_window::RequestGlobalStylesheetChange);
connect(&dlg, &settings_dialog::GuiRepaintRequest, this, &main_window::RepaintGui); connect(&dlg, &settings_dialog::GuiRepaintRequest, this, &main_window::RepaintGui);
connect(&dlg, &settings_dialog::accepted, this, &main_window::NotifyEmuSettingsChange); connect(&dlg, &settings_dialog::EmuSettingsApplied, this, &main_window::NotifyEmuSettingsChange);
connect(&dlg, &settings_dialog::accepted, m_logFrame, &log_frame::LoadSettings); connect(&dlg, &settings_dialog::EmuSettingsApplied, m_logFrame, &log_frame::LoadSettings);
dlg.exec(); dlg.exec();
}; };

View file

@ -92,7 +92,8 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
m_discord_state = xgui_settings->GetValue(gui::m_discordState).toString(); m_discord_state = xgui_settings->GetValue(gui::m_discordState).toString();
// Various connects // Various connects
connect(ui->buttonBox, &QDialogButtonBox::accepted, [this, use_discord_old = m_use_discord, discord_state_old = m_discord_state]
const auto apply_configs = [this, use_discord_old = m_use_discord, discord_state_old = m_discord_state](bool do_exit)
{ {
std::set<std::string> selectedlle; std::set<std::string> selectedlle;
for (int i = 0; i < ui->lleList->count(); ++i) for (int i = 0; i < ui->lleList->count(); ++i)
@ -106,7 +107,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
std::vector<std::string> selected_ls = std::vector<std::string>(selectedlle.begin(), selectedlle.end()); std::vector<std::string> selected_ls = std::vector<std::string>(selectedlle.begin(), selectedlle.end());
xemu_settings->SaveSelectedLibraries(selected_ls); xemu_settings->SaveSelectedLibraries(selected_ls);
xemu_settings->SaveSettings(); xemu_settings->SaveSettings();
if (do_exit)
{
accept(); accept();
}
Q_EMIT EmuSettingsApplied();
// Discord Settings can be saved regardless of WITH_DISCORD_RPC // Discord Settings can be saved regardless of WITH_DISCORD_RPC
xgui_settings->SetValue(gui::m_richPresence, m_use_discord); xgui_settings->SetValue(gui::m_richPresence, m_use_discord);
@ -130,6 +137,18 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
discord::update_presence(sstr(m_discord_state), "Idle", false); discord::update_presence(sstr(m_discord_state), "Idle", false);
} }
#endif #endif
};
connect(ui->buttonBox, &QDialogButtonBox::clicked, [=, this](QAbstractButton* button)
{
if (button == ui->buttonBox->button(QDialogButtonBox::Save))
{
apply_configs(true);
}
else if (button == ui->buttonBox->button(QDialogButtonBox::Apply))
{
apply_configs(false);
}
}); });
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);

View file

@ -29,6 +29,7 @@ Q_SIGNALS:
void GuiStylesheetRequest(const QString& path); void GuiStylesheetRequest(const QString& path);
void GuiSettingsSaveRequest(); void GuiSettingsSaveRequest();
void GuiRepaintRequest(); void GuiRepaintRequest();
void EmuSettingsApplied();
private Q_SLOTS: private Q_SLOTS:
void OnBackupCurrentConfig(); void OnBackupCurrentConfig();
void OnApplyConfig(); void OnApplyConfig();

View file

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