From 5855e93f43240e3af4b6abfeb4168b2922b558bf Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 24 May 2024 22:52:43 +0200 Subject: [PATCH] port InterfaceSettings to the new config system. --- src/frontend/qt_sdl/Config.cpp | 6 --- src/frontend/qt_sdl/Config.h | 5 --- .../qt_sdl/InterfaceSettingsDialog.cpp | 39 ++++++++----------- src/frontend/qt_sdl/InterfaceSettingsDialog.h | 2 +- src/frontend/qt_sdl/Screen.cpp | 17 ++++++-- src/frontend/qt_sdl/Screen.h | 5 +++ src/frontend/qt_sdl/Window.cpp | 17 +++++--- src/frontend/qt_sdl/Window.h | 5 ++- src/frontend/qt_sdl/main.cpp | 8 +++- 9 files changed, 57 insertions(+), 47 deletions(-) diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index 482a9347..4fefea7f 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -82,12 +82,6 @@ std::string SaveFilePath; std::string SavestatePath; std::string CheatFilePath; -bool MouseHide; -int MouseHideSeconds; - -bool PauseLostFocus; -std::string UITheme; - int64_t RTCOffset; bool DSBatteryLevelOkay; diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h index 5c4825be..5c0c01fb 100644 --- a/src/frontend/qt_sdl/Config.h +++ b/src/frontend/qt_sdl/Config.h @@ -196,11 +196,6 @@ extern std::string SaveFilePath; extern std::string SavestatePath; extern std::string CheatFilePath; -extern bool MouseHide; -extern int MouseHideSeconds; -extern bool PauseLostFocus; -extern std::string UITheme; - extern int64_t RTCOffset; extern bool DSBatteryLevelOkay; diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp b/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp index 51d523e2..ecc3231f 100644 --- a/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp +++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.cpp @@ -35,21 +35,22 @@ InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(pare auto& cfg = emuInstance->getGlobalConfig(); - ui->cbMouseHide->setChecked(Config::MouseHide != 0); - ui->spinMouseHideSeconds->setEnabled(Config::MouseHide != 0); - ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds); - ui->cbPauseLostFocus->setChecked(Config::PauseLostFocus != 0); + ui->cbMouseHide->setChecked(cfg.GetBool("MouseHide")); + ui->spinMouseHideSeconds->setEnabled(ui->cbMouseHide->isChecked()); + ui->spinMouseHideSeconds->setValue(cfg.GetInt("MouseHideSeconds")); + ui->cbPauseLostFocus->setChecked(cfg.GetBool("PauseLostFocus")); ui->spinMaxFPS->setValue(cfg.GetInt("MaxFPS")); const QList themeKeys = QStyleFactory::keys(); const QString currentTheme = qApp->style()->objectName(); + QString cfgTheme = cfg.GetQString("UITheme"); ui->cbxUITheme->addItem("System default", ""); for (int i = 0; i < themeKeys.length(); i++) { ui->cbxUITheme->addItem(themeKeys[i], themeKeys[i]); - if (!Config::UITheme.empty() && themeKeys[i].compare(currentTheme, Qt::CaseInsensitive) == 0) + if (!cfgTheme.isEmpty() && themeKeys[i].compare(currentTheme, Qt::CaseInsensitive) == 0) ui->cbxUITheme->setCurrentIndex(i + 1); } } @@ -61,39 +62,31 @@ InterfaceSettingsDialog::~InterfaceSettingsDialog() void InterfaceSettingsDialog::on_cbMouseHide_clicked() { - if (ui->spinMouseHideSeconds->isEnabled()) - { - ui->spinMouseHideSeconds->setEnabled(false); - } - else - { - ui->spinMouseHideSeconds->setEnabled(true); - } + ui->spinMouseHideSeconds->setEnabled(ui->cbMouseHide->isChecked()); } void InterfaceSettingsDialog::done(int r) { if (r == QDialog::Accepted) { - Config::MouseHide = ui->cbMouseHide->isChecked() ? 1:0; - Config::MouseHideSeconds = ui->spinMouseHideSeconds->value(); - Config::PauseLostFocus = ui->cbPauseLostFocus->isChecked() ? 1:0; - emuInstance->maxFPS = ui->spinMaxFPS->value(); + auto& cfg = emuInstance->getGlobalConfig(); + + cfg.SetBool("MouseHide", ui->cbMouseHide->isChecked()); + cfg.SetInt("MouseHideSeconds", ui->spinMouseHideSeconds->value()); + cfg.SetBool("PauseLostFocus", ui->cbPauseLostFocus->isChecked()); + cfg.SetInt("MaxFPS", ui->spinMaxFPS->value()); QString themeName = ui->cbxUITheme->currentData().toString(); - Config::UITheme = themeName.toStdString(); - - auto& cfg = emuInstance->getGlobalConfig(); - cfg.SetInt("MaxFPS", emuInstance->maxFPS); + cfg.SetQString("UITheme", themeName); Config::Save(); - if (!Config::UITheme.empty()) + if (!themeName.isEmpty()) qApp->setStyle(themeName); else qApp->setStyle(*systemThemeName); - emit updateMouseTimer(); + emit updateInterfaceSettings(); } QDialog::done(r); diff --git a/src/frontend/qt_sdl/InterfaceSettingsDialog.h b/src/frontend/qt_sdl/InterfaceSettingsDialog.h index 07e9f73c..97d18f22 100644 --- a/src/frontend/qt_sdl/InterfaceSettingsDialog.h +++ b/src/frontend/qt_sdl/InterfaceSettingsDialog.h @@ -53,7 +53,7 @@ public: } signals: - void updateMouseTimer(); + void updateInterfaceSettings(); private slots: void done(int r); diff --git a/src/frontend/qt_sdl/Screen.cpp b/src/frontend/qt_sdl/Screen.cpp index bb1fffe4..f7564a8f 100644 --- a/src/frontend/qt_sdl/Screen.cpp +++ b/src/frontend/qt_sdl/Screen.cpp @@ -82,9 +82,12 @@ ScreenPanel::ScreenPanel(QWidget* parent) : QWidget(parent) } emuInstance = mainWindow->getEmuInstance(); - + + mouseHide = false; + mouseHideDelay = 0; + QTimer* mouseTimer = setupMouseTimer(); - connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) setCursor(Qt::BlankCursor);}); + connect(mouseTimer, &QTimer::timeout, [=] { if (mouseHide) setCursor(Qt::BlankCursor);}); osdEnabled = false; osdID = 1; @@ -96,6 +99,14 @@ ScreenPanel::~ScreenPanel() delete mouseTimer; } +void ScreenPanel::setMouseHide(bool enable, int delay) +{ + mouseHide = enable; + mouseHideDelay = delay; + + mouseTimer->setInterval(mouseHideDelay); +} + void ScreenPanel::setupScreenLayout() { int w = width(); @@ -329,7 +340,7 @@ QTimer* ScreenPanel::setupMouseTimer() { mouseTimer = new QTimer(); mouseTimer->setSingleShot(true); - mouseTimer->setInterval(Config::MouseHideSeconds*1000); + mouseTimer->setInterval(mouseHideDelay); mouseTimer->start(); return mouseTimer; diff --git a/src/frontend/qt_sdl/Screen.h b/src/frontend/qt_sdl/Screen.h index a8be962b..53b55341 100644 --- a/src/frontend/qt_sdl/Screen.h +++ b/src/frontend/qt_sdl/Screen.h @@ -58,6 +58,8 @@ public: explicit ScreenPanel(QWidget* parent); virtual ~ScreenPanel(); + void setMouseHide(bool enable, int delay); + QTimer* setupMouseTimer(); void updateMouseTimer(); QTimer* mouseTimer; @@ -73,6 +75,9 @@ protected: MainWindow* mainWindow; EmuInstance* emuInstance; + bool mouseHide; + int mouseHideDelay; + struct OSDItem { unsigned int id; diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index fd82677e..c52b7a3b 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -696,6 +696,9 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : actPreferences->setEnabled(false); #endif // __APPLE__ } + + QObject::connect(qApp, &QApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged); + onUpdateInterfaceSettings(); } MainWindow::~MainWindow() @@ -953,12 +956,12 @@ void MainWindow::onAppStateChanged(Qt::ApplicationState state) if (state == Qt::ApplicationInactive) { emuInstance->keyReleaseAll(); - if (Config::PauseLostFocus && emuThread->emuIsRunning()) + if (pauseOnLostFocus && emuThread->emuIsRunning()) emuThread->emuPause(); } else if (state == Qt::ApplicationActive) { - if (Config::PauseLostFocus && !pausedManually) + if (pauseOnLostFocus && !pausedManually) emuThread->emuUnpause(); } } @@ -1870,12 +1873,16 @@ void MainWindow::onOpenInterfaceSettings() emuThread->emuPause(); InterfaceSettingsDialog* dlg = InterfaceSettingsDialog::openDlg(this); connect(dlg, &InterfaceSettingsDialog::finished, this, &MainWindow::onInterfaceSettingsFinished); - connect(dlg, &InterfaceSettingsDialog::updateMouseTimer, this, &MainWindow::onUpdateMouseTimer); + connect(dlg, &InterfaceSettingsDialog::updateInterfaceSettings, this, &MainWindow::onUpdateInterfaceSettings); } -void MainWindow::onUpdateMouseTimer() +void MainWindow::onUpdateInterfaceSettings() { - panel->mouseTimer->setInterval(Config::MouseHideSeconds*1000); + pauseOnLostFocus = globalCfg.GetBool("PauseLostFocus"); + emuInstance->maxFPS = globalCfg.GetInt("MaxFPS"); + + panel->setMouseHide(globalCfg.GetBool("MouseHide"), + globalCfg.GetInt("MouseHideSeconds")*1000); } void MainWindow::onInterfaceSettingsFinished(int res) diff --git a/src/frontend/qt_sdl/Window.h b/src/frontend/qt_sdl/Window.h index c965209f..58bef361 100644 --- a/src/frontend/qt_sdl/Window.h +++ b/src/frontend/qt_sdl/Window.h @@ -193,7 +193,7 @@ private slots: void onPathSettingsFinished(int res); void onOpenInterfaceSettings(); void onInterfaceSettingsFinished(int res); - void onUpdateMouseTimer(); + void onUpdateInterfaceSettings(); void onChangeSavestateSRAMReloc(bool checked); void onChangeScreenSize(); void onChangeScreenRotation(QAction* act); @@ -238,7 +238,8 @@ private: bool hasOGL; - bool pausedManually = false; + bool pauseOnLostFocus; + bool pausedManually; int oldW, oldH; bool oldMax; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index db678cce..a077c554 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -335,9 +335,13 @@ int main(int argc, char** argv) systemThemeName = new QString(QApplication::style()->objectName()); - if (!Config::UITheme.empty()) { - QApplication::setStyle(QString::fromStdString(Config::UITheme)); + Config::Table cfg = Config::GetGlobalTable(); + QString uitheme = cfg.GetQString("UITheme"); + if (!uitheme.isEmpty()) + { + QApplication::setStyle(uitheme); + } } /* mainWindow = new MainWindow();