Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: Change settings windows from QDialog to QWidget #10107

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pcsx2-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ target_sources(pcsx2-qt PRIVATE
Settings/ControllerMacroEditWidget.ui
Settings/ControllerMacroWidget.ui
Settings/ControllerMouseSettingsDialog.ui
Settings/ControllerSettingsDialog.cpp
Settings/ControllerSettingsDialog.h
Settings/ControllerSettingsDialog.ui
Settings/ControllerSettingsWindow.cpp
Settings/ControllerSettingsWindow.h
Settings/ControllerSettingsWindow.ui
Settings/ControllerSettingWidgetBinder.h
Settings/DebugSettingsWidget.cpp
Settings/DebugSettingsWidget.h
Expand Down Expand Up @@ -137,9 +137,9 @@ target_sources(pcsx2-qt PRIVATE
Settings/HddCreateQt.cpp
Settings/HddCreateQt.h
Settings/PatchDetailsWidget.ui
Settings/SettingsDialog.cpp
Settings/SettingsDialog.h
Settings/SettingsDialog.ui
Settings/SettingsWindow.cpp
Settings/SettingsWindow.h
Settings/SettingsWindow.ui
Settings/USBBindingWidget_DrivingForce.ui
Settings/USBBindingWidget_GTForce.ui
Settings/USBBindingWidget_GunCon2.ui
Expand Down
113 changes: 60 additions & 53 deletions pcsx2-qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "Settings/AchievementLoginDialog.h"
#include "Settings/ControllerSettingsDialog.h"
#include "Settings/ControllerSettingsWindow.h"
#include "Settings/GameListSettingsWidget.h"
#include "Settings/InterfaceSettingsWidget.h"
#include "Tools/InputRecording/InputRecordingViewer.h"
Expand Down Expand Up @@ -117,13 +117,7 @@ MainWindow::~MainWindow()
{
// make sure the game list isn't refreshing, because it's on a separate thread
cancelGameListRefresh();

if (m_debugger_window)
{
m_debugger_window->close();
m_debugger_window->deleteLater();
m_debugger_window = nullptr;
}
destroySubWindows();

// we compare here, since recreate destroys the window later
if (g_main_window == this)
Expand Down Expand Up @@ -320,7 +314,7 @@ void MainWindow::connectSignals()
connect(m_ui.actionToolbarSaveState, &QAction::triggered, this, [this]() { m_ui.menuSaveState->exec(QCursor::pos()); });
connect(m_ui.actionToolbarSettings, &QAction::triggered, this, &MainWindow::onSettingsTriggeredFromToolbar);
connect(m_ui.actionToolbarControllerSettings, &QAction::triggered,
[this]() { doControllerSettings(ControllerSettingsDialog::Category::GlobalSettings); });
[this]() { doControllerSettings(ControllerSettingsWindow::Category::GlobalSettings); });
connect(m_ui.actionToolbarScreenshot, &QAction::triggered, this, &MainWindow::onScreenshotActionTriggered);
connect(m_ui.actionExit, &QAction::triggered, this, &MainWindow::close);
connect(m_ui.actionScreenshot, &QAction::triggered, this, &MainWindow::onScreenshotActionTriggered);
Expand All @@ -338,11 +332,11 @@ void MainWindow::connectSignals()
connect(m_ui.actionFolderSettings, &QAction::triggered, [this]() { doSettings("Folders"); });
connect(m_ui.actionAchievementSettings, &QAction::triggered, [this]() { doSettings("Achievements"); });
connect(m_ui.actionControllerSettings, &QAction::triggered,
[this]() { doControllerSettings(ControllerSettingsDialog::Category::GlobalSettings); });
[this]() { doControllerSettings(ControllerSettingsWindow::Category::GlobalSettings); });
connect(m_ui.actionHotkeySettings, &QAction::triggered,
[this]() { doControllerSettings(ControllerSettingsDialog::Category::HotkeySettings); });
[this]() { doControllerSettings(ControllerSettingsWindow::Category::HotkeySettings); });
connect(m_ui.actionAddGameDirectory, &QAction::triggered,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });
[this]() { getSettingsWindow()->getGameListSettingsWidget()->addSearchDirectory(this); });
connect(m_ui.actionScanForNewGames, &QAction::triggered, [this]() { refreshGameList(false); });
connect(m_ui.actionRescanAllGames, &QAction::triggered, [this]() { refreshGameList(true); });
connect(m_ui.actionViewToolbar, &QAction::toggled, this, &MainWindow::onViewToolbarActionToggled);
Expand Down Expand Up @@ -415,7 +409,7 @@ void MainWindow::connectSignals()
connect(m_game_list_widget, &GameListWidget::entryContextMenuRequested, this, &MainWindow::onGameListEntryContextMenuRequested,
Qt::QueuedConnection);
connect(m_game_list_widget, &GameListWidget::addGameDirectoryRequested, this,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });
[this]() { getSettingsWindow()->getGameListSettingsWidget()->addSearchDirectory(this); });
}

void MainWindow::connectVMThreadSignals(EmuThread* thread)
Expand Down Expand Up @@ -485,14 +479,14 @@ void MainWindow::recreate()
void MainWindow::recreateSettings()
{
QString current_category;
if (m_settings_dialog)
if (m_setings_window)
{
const bool was_visible = m_settings_dialog->isVisible();
const bool was_visible = m_setings_window->isVisible();

current_category = m_settings_dialog->getCategory();
m_settings_dialog->hide();
m_settings_dialog->deleteLater();
m_settings_dialog = nullptr;
current_category = m_setings_window->getCategory();
m_setings_window->hide();
m_setings_window->deleteLater();
m_setings_window = nullptr;

if (!was_visible)
return;
Expand All @@ -518,7 +512,29 @@ void MainWindow::resetSettings(bool ui)
g_main_window->recreateSettings();
}

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_setings_window)
{
m_setings_window->close();
m_setings_window->deleteLater();
m_setings_window = nullptr;
}
}

void MainWindow::onScreenshotActionTriggered()
{
Expand Down Expand Up @@ -594,7 +610,7 @@ void MainWindow::onShowAdvancedSettingsToggled(bool checked)
m_ui.menuDebug->menuAction()->setVisible(checked);

// just recreate the entire settings window, it's easier.
if (m_settings_dialog)
if (m_setings_window)
recreateSettings();
}

Expand Down Expand Up @@ -1174,7 +1190,7 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
if (action->isEnabled())
{
connect(action, &QAction::triggered, [entry]() {
SettingsDialog::openGamePropertiesDialog(entry, entry->title,
SettingsWindow::openGamePropertiesDialog(entry, entry->title,
(entry->type != GameList::EntryType::ELF) ? entry->serial : std::string(),
entry->crc);
});
Expand All @@ -1191,7 +1207,7 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
connect(action, &QAction::triggered, [this, entry]() { setGameListEntryCoverImage(entry); });

connect(menu.addAction(tr("Exclude From List")), &QAction::triggered,
[this, entry]() { getSettingsDialog()->getGameListSettingsWidget()->addExcludedPath(entry->path); });
[this, entry]() { getSettingsWindow()->getGameListSettingsWidget()->addExcludedPath(entry->path); });

connect(menu.addAction(tr("Reset Play Time")), &QAction::triggered, [this, entry]() { clearGameListEntryPlayTime(entry); });

Expand Down Expand Up @@ -1239,7 +1255,7 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
}

connect(menu.addAction(tr("Add Search Directory...")), &QAction::triggered,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });
[this]() { getSettingsWindow()->getGameListSettingsWidget()->addSearchDirectory(this); });

menu.exec(point);
}
Expand Down Expand Up @@ -1387,7 +1403,7 @@ void MainWindow::onViewGamePropertiesActionTriggered()
const GameList::Entry* entry = GameList::GetEntryForPath(path.toUtf8().constData());
if (entry)
{
SettingsDialog::openGamePropertiesDialog(
SettingsWindow::openGamePropertiesDialog(
entry, entry->title, m_current_elf_override.isEmpty() ? entry->serial : std::string(), entry->crc);
return;
}
Expand All @@ -1403,12 +1419,12 @@ void MainWindow::onViewGamePropertiesActionTriggered()
// can't use serial for ELFs, because they might have a disc set
if (m_current_elf_override.isEmpty())
{
SettingsDialog::openGamePropertiesDialog(
SettingsWindow::openGamePropertiesDialog(
nullptr, m_current_title.toStdString(), m_current_disc_serial.toStdString(), m_current_disc_crc);
}
else
{
SettingsDialog::openGamePropertiesDialog(
SettingsWindow::openGamePropertiesDialog(
nullptr, m_current_title.toStdString(), std::string(), m_current_disc_crc);
}
}
Expand Down Expand Up @@ -1812,6 +1828,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
saveStateToConfig();
if (m_display_widget)
g_emu_thread->stopFullscreenUI();
destroySubWindows();
QMainWindow::closeEvent(event);
return;
}
Expand Down Expand Up @@ -2267,13 +2284,13 @@ void MainWindow::restoreDisplayWindowGeometryFromConfig()
}
}

SettingsDialog* MainWindow::getSettingsDialog()
SettingsWindow* MainWindow::getSettingsWindow()
{
if (!m_settings_dialog)
if (!m_setings_window)
{
m_settings_dialog = new SettingsDialog(this);
connect(m_settings_dialog->getInterfaceSettingsWidget(), &InterfaceSettingsWidget::themeChanged, this, &MainWindow::updateTheme);
connect(m_settings_dialog->getInterfaceSettingsWidget(), &InterfaceSettingsWidget::languageChanged, this, [this]() {
m_setings_window = new SettingsWindow();
connect(m_setings_window->getInterfaceSettingsWidget(), &InterfaceSettingsWidget::themeChanged, this, &MainWindow::updateTheme);
connect(m_setings_window->getInterfaceSettingsWidget(), &InterfaceSettingsWidget::languageChanged, this, [this]() {
// reopen settings dialog after it applies
updateLanguage();
// If you doSettings now, on macOS, the window will somehow end up underneath the main window that was created above
Expand All @@ -2284,21 +2301,16 @@ SettingsDialog* MainWindow::getSettingsDialog()
});
}

return m_settings_dialog;
return m_setings_window;
}

void MainWindow::doSettings(const char* category /* = nullptr */)
{
SettingsDialog* dlg = getSettingsDialog();
SettingsWindow* dlg = getSettingsWindow();
if (dlg->isVisible())
{
dlg->raise();
}
else
{
dlg->setModal(false);
dlg->show();
}

if (category)
dlg->setCategory(category);
Expand All @@ -2319,25 +2331,20 @@ void MainWindow::openDebugger()
dwnd->isVisible() ? dwnd->hide() : dwnd->show();
}

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)
void MainWindow::doControllerSettings(ControllerSettingsWindow::Category category)
{
ControllerSettingsDialog* dlg = getControllerSettingsDialog();
if (!dlg->isVisible())
if (m_controller_settings_window)
{
dlg->setModal(false);
dlg->show();
m_controller_settings_window->raise();
}
else
{
m_controller_settings_window = new ControllerSettingsWindow();
m_controller_settings_window->show();
}

if (category != ControllerSettingsDialog::Category::Count)
dlg->setCategory(category);
if (category != ControllerSettingsWindow::Category::Count)
m_controller_settings_window->setCategory(category);
}

QString MainWindow::getDiscDevicePath(const QString& title)
Expand Down
16 changes: 8 additions & 8 deletions pcsx2-qt/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <optional>

#include "Tools/InputRecording/InputRecordingViewer.h"
#include "Settings/ControllerSettingsDialog.h"
#include "Settings/SettingsDialog.h"
#include "Settings/ControllerSettingsWindow.h"
#include "Settings/SettingsWindow.h"
#include "Debugger/DebuggerWindow.h"
#include "ui_MainWindow.h"

Expand All @@ -35,7 +35,7 @@ class AutoUpdaterDialog;
class DisplayWidget;
class DisplayContainer;
class GameListWidget;
class ControllerSettingsDialog;
class ControllerSettingsWindow;

class EmuThread;

Expand Down Expand Up @@ -218,6 +218,7 @@ private Q_SLOTS:
void connectSignals();
void recreate();
void recreateSettings();
void destroySubWindows();

void registerForDeviceNotifications();
void unregisterForDeviceNotifications();
Expand Down Expand Up @@ -250,16 +251,15 @@ private Q_SLOTS:
void destroyDisplayWidget(bool show_game_list);
void updateDisplayWidgetCursor();

SettingsDialog* getSettingsDialog();
SettingsWindow* getSettingsWindow();
void doSettings(const char* category = nullptr);

InputRecordingViewer* getInputRecordingViewer();
void updateInputRecordingActions(bool started);

DebuggerWindow* getDebuggerWindow();

ControllerSettingsDialog* getControllerSettingsDialog();
void doControllerSettings(ControllerSettingsDialog::Category category = ControllerSettingsDialog::Category::Count);
void doControllerSettings(ControllerSettingsWindow::Category category = ControllerSettingsWindow::Category::Count);

QString getDiscDevicePath(const QString& title);

Expand All @@ -282,9 +282,9 @@ private Q_SLOTS:
DisplayWidget* m_display_widget = nullptr;
DisplayContainer* m_display_container = nullptr;

SettingsDialog* m_settings_dialog = nullptr;
SettingsWindow* m_setings_window = nullptr;
ControllerSettingsWindow* m_controller_settings_window = nullptr;
InputRecordingViewer* m_input_recording_viewer = nullptr;
ControllerSettingsDialog* m_controller_settings_dialog = nullptr;
AutoUpdaterDialog* m_auto_updater_dialog = nullptr;

DebuggerWindow* m_debugger_window = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion pcsx2-qt/SettingWidgetBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include "QtHost.h"
#include "QtUtils.h"
#include "Settings/SettingsDialog.h"
#include "Settings/SettingsWindow.h"

namespace SettingWidgetBinder
{
Expand Down
4 changes: 2 additions & 2 deletions pcsx2-qt/Settings/AchievementSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "AchievementSettingsWidget.h"
#include "AchievementLoginDialog.h"
#include "MainWindow.h"
#include "SettingsDialog.h"
#include "SettingsWindow.h"
#include "SettingWidgetBinder.h"
#include "QtUtils.h"

Expand All @@ -30,7 +30,7 @@
#include <QtCore/QDateTime>
#include <QtWidgets/QMessageBox>

AchievementSettingsWidget::AchievementSettingsWidget(SettingsDialog* dialog, QWidget* parent)
AchievementSettingsWidget::AchievementSettingsWidget(SettingsWindow* dialog, QWidget* parent)
: QWidget(parent)
, m_dialog(dialog)
{
Expand Down
6 changes: 3 additions & 3 deletions pcsx2-qt/Settings/AchievementSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#include <QtWidgets/QWidget>
#include "ui_AchievementSettingsWidget.h"

class SettingsDialog;
class SettingsWindow;

class AchievementSettingsWidget : public QWidget
{
Q_OBJECT

public:
explicit AchievementSettingsWidget(SettingsDialog* dialog, QWidget* parent);
explicit AchievementSettingsWidget(SettingsWindow* dialog, QWidget* parent);
~AchievementSettingsWidget();

private Q_SLOTS:
Expand All @@ -41,5 +41,5 @@ private Q_SLOTS:

Ui::AchievementSettingsWidget m_ui;

SettingsDialog* m_dialog;
SettingsWindow* m_dialog;
};
Loading