Qt: Change settings dialogs to widgets/windows

Stops them breaking in Qt 6.6.
This commit is contained in:
Stenzek
2023-11-06 23:01:38 +10:00
parent 3ab27e7220
commit ac825855f7
50 changed files with 442 additions and 322 deletions

View File

@ -16,7 +16,7 @@
#include "memorycardeditordialog.h"
#include "qthost.h"
#include "qtutils.h"
#include "settingsdialog.h"
#include "settingswindow.h"
#include "settingwidgetbinder.h"
#include "core/achievements.h"
@ -130,6 +130,7 @@ MainWindow::~MainWindow()
Assert(!m_display_widget);
Assert(!m_debugger_window);
cancelGameListRefresh();
destroySubWindows();
// we compare here, since recreate destroys the window later
if (g_main_window == this)
@ -730,6 +731,30 @@ void MainWindow::recreate()
g_emu_thread->reloadInputSources();
}
void MainWindow::destroySubWindows()
{
if (m_debugger_window)
{
m_debugger_window->close();
m_debugger_window->deleteLater();
m_debugger_window = nullptr;
}
if (m_controller_settings_window)
{
m_controller_settings_window->close();
m_controller_settings_window->deleteLater();
m_controller_settings_window = nullptr;
}
if (m_settings_window)
{
m_settings_window->close();
m_settings_window->deleteLater();
m_settings_window = nullptr;
}
}
void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidget* parent_window, QMenu* menu)
{
QAction* resume_action = menu->addAction(tr("Resume"));
@ -1269,7 +1294,7 @@ void MainWindow::onViewGamePropertiesActionTriggered()
if (path.empty() || serial.empty())
return;
SettingsDialog::openGamePropertiesDialog(path, serial, System::GetDiscRegion());
SettingsWindow::openGamePropertiesDialog(path, serial, System::GetDiscRegion());
}
void MainWindow::onGitHubRepositoryActionTriggered()
@ -1368,7 +1393,7 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
{
QAction* action = menu.addAction(tr("Properties..."));
connect(action, &QAction::triggered,
[entry]() { SettingsDialog::openGamePropertiesDialog(entry->path, entry->serial, entry->region); });
[entry]() { SettingsWindow::openGamePropertiesDialog(entry->path, entry->serial, entry->region); });
connect(menu.addAction(tr("Open Containing Directory...")), &QAction::triggered, [this, entry]() {
const QFileInfo fi(QString::fromStdString(entry->path));
@ -1951,9 +1976,9 @@ void MainWindow::connectSignals()
connect(m_ui.actionEmulationSettings, &QAction::triggered, [this]() { doSettings("Emulation"); });
connect(m_ui.actionGameListSettings, &QAction::triggered, [this]() { doSettings("Game List"); });
connect(m_ui.actionHotkeySettings, &QAction::triggered,
[this]() { doControllerSettings(ControllerSettingsDialog::Category::HotkeySettings); });
[this]() { doControllerSettings(ControllerSettingsWindow::Category::HotkeySettings); });
connect(m_ui.actionControllerSettings, &QAction::triggered,
[this]() { doControllerSettings(ControllerSettingsDialog::Category::GlobalSettings); });
[this]() { doControllerSettings(ControllerSettingsWindow::Category::GlobalSettings); });
connect(m_ui.actionMemoryCardSettings, &QAction::triggered, [this]() { doSettings("Memory Cards"); });
connect(m_ui.actionDisplaySettings, &QAction::triggered, [this]() { doSettings("Display"); });
connect(m_ui.actionEnhancementSettings, &QAction::triggered, [this]() { doSettings("Enhancements"); });
@ -1972,7 +1997,8 @@ void MainWindow::connectSignals()
connect(m_ui.actionGitHubRepository, &QAction::triggered, this, &MainWindow::onGitHubRepositoryActionTriggered);
connect(m_ui.actionIssueTracker, &QAction::triggered, this, &MainWindow::onIssueTrackerActionTriggered);
connect(m_ui.actionDiscordServer, &QAction::triggered, this, &MainWindow::onDiscordServerActionTriggered);
connect(m_ui.actionViewThirdPartyNotices, &QAction::triggered, this, [this]() { AboutDialog::showThirdPartyNotices(this); });
connect(m_ui.actionViewThirdPartyNotices, &QAction::triggered, this,
[this]() { AboutDialog::showThirdPartyNotices(this); });
connect(m_ui.actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
connect(m_ui.actionAbout, &QAction::triggered, this, &MainWindow::onAboutActionTriggered);
connect(m_ui.actionCheckForUpdates, &QAction::triggered, this, &MainWindow::onCheckForUpdatesActionTriggered);
@ -2219,20 +2245,28 @@ void MainWindow::setIconThemeFromSettings()
QIcon::setThemeName(dark ? QStringLiteral("white") : QStringLiteral("black"));
}
void MainWindow::onSettingsResetToDefault()
void MainWindow::onSettingsResetToDefault(bool system, bool controller)
{
if (m_settings_dialog)
if (system && m_settings_window)
{
const bool shown = m_settings_dialog->isVisible();
const bool had_settings_window = m_settings_window->isVisible();
m_settings_window->close();
m_settings_window->deleteLater();
m_settings_window = nullptr;
m_settings_dialog->hide();
m_settings_dialog->deleteLater();
m_settings_dialog = new SettingsDialog(this);
if (shown)
{
m_settings_dialog->setModal(false);
m_settings_dialog->show();
}
if (had_settings_window)
doSettings();
}
if (controller && m_controller_settings_window)
{
const bool had_controller_settings_window = m_controller_settings_window->isVisible();
m_controller_settings_window->close();
m_controller_settings_window->deleteLater();
m_controller_settings_window = nullptr;
if (had_controller_settings_window)
doControllerSettings(ControllerSettingsWindow::Category::GlobalSettings);
}
updateDebugMenuCPUExecutionMode();
@ -2285,55 +2319,49 @@ void MainWindow::restoreDisplayWindowGeometryFromConfig()
container->resize(640, 480);
}
SettingsDialog* MainWindow::getSettingsDialog()
SettingsWindow* MainWindow::getSettingsDialog()
{
if (!m_settings_dialog)
m_settings_dialog = new SettingsDialog(this);
if (!m_settings_window)
m_settings_window = new SettingsWindow();
return m_settings_dialog;
return m_settings_window;
}
void MainWindow::doSettings(const char* category /* = nullptr */)
{
SettingsDialog* dlg = getSettingsDialog();
SettingsWindow* dlg = getSettingsDialog();
if (!dlg->isVisible())
{
dlg->setModal(false);
dlg->show();
}
else
{
dlg->raise();
dlg->setFocus();
}
if (category)
dlg->setCategory(category);
}
ControllerSettingsDialog* MainWindow::getControllerSettingsDialog()
{
if (!m_controller_settings_dialog)
m_controller_settings_dialog = new ControllerSettingsDialog(this);
return m_controller_settings_dialog;
}
void MainWindow::doControllerSettings(
ControllerSettingsDialog::Category category /*= ControllerSettingsDialog::Category::Count*/)
ControllerSettingsWindow::Category category /*= ControllerSettingsDialog::Category::Count*/)
{
ControllerSettingsDialog* dlg = getControllerSettingsDialog();
if (!dlg->isVisible())
if (!m_controller_settings_window)
m_controller_settings_window = new ControllerSettingsWindow();
if (!m_controller_settings_window->isVisible())
{
dlg->setModal(false);
dlg->show();
m_controller_settings_window->show();
}
else
{
dlg->raise();
m_controller_settings_window->raise();
m_controller_settings_window->setFocus();
}
if (category != ControllerSettingsDialog::Category::Count)
dlg->setCategory(category);
if (category != ControllerSettingsWindow::Category::Count)
m_controller_settings_window->setCategory(category);
}
void MainWindow::updateDebugMenuCPUExecutionMode()
@ -2426,6 +2454,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
{
saveGeometryToConfig();
g_emu_thread->stopFullscreenUI();
destroySubWindows();
QMainWindow::closeEvent(event);
return;
}