diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index c06305f7d..b5288a5b6 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -1084,6 +1084,7 @@ void MainWindow::connectSignals() connect(m_ui.actionGridViewRefreshCovers, &QAction::triggered, m_game_list_widget, &GameListWidget::refreshGridCovers); + connect(m_host_interface, &QtHostInterface::settingsResetToDefault, this, &MainWindow::onSettingsResetToDefault); connect(m_host_interface, &QtHostInterface::errorReported, this, &MainWindow::reportError, Qt::BlockingQueuedConnection); connect(m_host_interface, &QtHostInterface::messageReported, this, &MainWindow::reportMessage); @@ -1297,6 +1298,28 @@ void MainWindow::updateTheme() } } +void MainWindow::onSettingsResetToDefault() +{ + if (m_settings_dialog) + { + const bool shown = m_settings_dialog->isVisible(); + + m_settings_dialog->hide(); + m_settings_dialog->deleteLater(); + m_settings_dialog = new SettingsDialog(m_host_interface, this); + if (shown) + { + m_settings_dialog->setModal(false); + m_settings_dialog->show(); + } + } + + updateDebugMenuCPUExecutionMode(); + updateDebugMenuGPURenderer(); + updateDebugMenuCropMode(); + updateDebugMenuVisibility(); +} + void MainWindow::saveStateToConfig() { { diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 0ee78e0ff..87a2bd5ed 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -65,6 +65,7 @@ private Q_SLOTS: void setTheme(const QString& theme); void updateTheme(); + void onSettingsResetToDefault(); void onEmulationStarting(); void onEmulationStarted(); void onEmulationStopped(); diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 8e2eccee7..fab04debb 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -290,18 +290,15 @@ void QtHostInterface::setDefaultSettings() return; } - Settings old_settings(std::move(g_settings)); - { - std::lock_guard guard(m_settings_mutex); - SetDefaultSettings(*m_settings_interface.get()); - m_settings_interface->Save(); + SetDefaultSettings(); +} - CommonHostInterface::LoadSettings(*m_settings_interface.get()); - CommonHostInterface::ApplyGameSettings(false); - CommonHostInterface::FixIncompatibleSettings(false); - } - - CheckForSettingsChanges(old_settings); +void QtHostInterface::SetDefaultSettings() +{ + CommonHostInterface::SetDefaultSettings(); + checkRenderToMainState(); + queueSettingsSave(); + emit settingsResetToDefault(); } void QtHostInterface::applySettings(bool display_osd_messages /* = false */) @@ -318,7 +315,11 @@ void QtHostInterface::applySettings(bool display_osd_messages /* = false */) void QtHostInterface::ApplySettings(bool display_osd_messages) { CommonHostInterface::ApplySettings(display_osd_messages); + checkRenderToMainState(); +} +void QtHostInterface::checkRenderToMainState() +{ // detect when render-to-main flag changes if (!System::IsShutdown()) { diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 7dd65c63b..df989ba67 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -127,6 +127,7 @@ Q_SIGNALS: void messageReported(const QString& message); void debuggerMessageReported(const QString& message); bool messageConfirmed(const QString& message); + void settingsResetToDefault(); void emulationStarting(); void emulationStarted(); void emulationStopped(); @@ -213,6 +214,7 @@ protected: const std::string& game_title) override; void SetDefaultSettings(SettingsInterface& si) override; + void SetDefaultSettings() override; void ApplySettings(bool display_osd_messages) override; void SetMouseMode(bool relative, bool hide_cursor) override; @@ -267,6 +269,7 @@ private: void installTranslator(); void renderDisplay(); void connectDisplaySignals(QtDisplayWidget* widget); + void checkRenderToMainState(); void updateDisplayState(); void queueSettingsSave(); void wakeThread(); diff --git a/src/duckstation-qt/settingsdialog.cpp b/src/duckstation-qt/settingsdialog.cpp index 4ca6774ce..80380e5bb 100644 --- a/src/duckstation-qt/settingsdialog.cpp +++ b/src/duckstation-qt/settingsdialog.cpp @@ -14,6 +14,7 @@ #include "postprocessingsettingswidget.h" #include "qthostinterface.h" #include +#include #ifdef WITH_CHEEVOS #include "achievementsettingswidget.h" @@ -76,6 +77,7 @@ SettingsDialog::SettingsDialog(QtHostInterface* host_interface, QWidget* parent m_ui.helpText->setText(m_category_help_text[0]); connect(m_ui.settingsCategory, &QListWidget::currentRowChanged, this, &SettingsDialog::onCategoryCurrentRowChanged); connect(m_ui.closeButton, &QPushButton::clicked, this, &SettingsDialog::accept); + connect(m_ui.restoreDefaultsButton, &QPushButton::clicked, this, &SettingsDialog::onRestoreDefaultsClicked); connect(m_console_settings, &ConsoleSettingsWidget::multitapModeChanged, m_controller_settings, &ControllerSettingsWidget::updateMultitapControllerTitles); @@ -143,6 +145,16 @@ void SettingsDialog::onCategoryCurrentRowChanged(int row) m_ui.helpText->setText(m_category_help_text[row]); } +void SettingsDialog::onRestoreDefaultsClicked() +{ + if (!QMessageBox::question(this, tr("Confirm Restore Defaults"), tr("Are you sure you want to restore the default settings? Any preferences will be lost."))) + { + return; + } + + m_host_interface->setDefaultSettings(); +} + void SettingsDialog::registerWidgetHelp(QObject* object, QString title, QString recommended_value, QString text) { // construct rich text with formatted description diff --git a/src/duckstation-qt/settingsdialog.h b/src/duckstation-qt/settingsdialog.h index fc5294185..36927c842 100644 --- a/src/duckstation-qt/settingsdialog.h +++ b/src/duckstation-qt/settingsdialog.h @@ -67,11 +67,15 @@ public: void registerWidgetHelp(QObject* object, QString title, QString recommended_value, QString text); bool eventFilter(QObject* object, QEvent* event) override; +Q_SIGNALS: + void settingsResetToDefaults(); + public Q_SLOTS: void setCategory(Category category); private Q_SLOTS: void onCategoryCurrentRowChanged(int row); + void onRestoreDefaultsClicked(); private: void setCategoryHelpTexts(); diff --git a/src/duckstation-qt/settingsdialog.ui b/src/duckstation-qt/settingsdialog.ui index 86ae0532c..c08594059 100644 --- a/src/duckstation-qt/settingsdialog.ui +++ b/src/duckstation-qt/settingsdialog.ui @@ -217,6 +217,13 @@ + + + + Restore Defaults + + + diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 2ca9e88eb..d0e40914d 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -3104,6 +3104,21 @@ void CommonHostInterface::ApplySettings(bool display_osd_messages) CheckForSettingsChanges(old_settings); } +void CommonHostInterface::SetDefaultSettings() +{ + Settings old_settings(std::move(g_settings)); + { + std::lock_guard guard(m_settings_mutex); + SetDefaultSettings(*m_settings_interface.get()); + + LoadSettings(*m_settings_interface.get()); + ApplyGameSettings(true); + FixIncompatibleSettings(true); + } + + CheckForSettingsChanges(old_settings); +} + void CommonHostInterface::UpdateInputMap() { std::lock_guard lock(m_settings_mutex); diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 73a44d15d..328310826 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -426,6 +426,9 @@ protected: /// Restores all settings to defaults. virtual void SetDefaultSettings(SettingsInterface& si) override; + /// Resets known settings to default. + virtual void SetDefaultSettings(); + /// Loads settings to m_settings and any frontend-specific parameters. virtual void LoadSettings(SettingsInterface& si) override;