port InterfaceSettings to the new config system.

This commit is contained in:
Arisotura 2024-05-24 22:52:43 +02:00
parent 28e4d39363
commit 5855e93f43
9 changed files with 57 additions and 47 deletions

View File

@ -82,12 +82,6 @@ std::string SaveFilePath;
std::string SavestatePath; std::string SavestatePath;
std::string CheatFilePath; std::string CheatFilePath;
bool MouseHide;
int MouseHideSeconds;
bool PauseLostFocus;
std::string UITheme;
int64_t RTCOffset; int64_t RTCOffset;
bool DSBatteryLevelOkay; bool DSBatteryLevelOkay;

View File

@ -196,11 +196,6 @@ extern std::string SaveFilePath;
extern std::string SavestatePath; extern std::string SavestatePath;
extern std::string CheatFilePath; extern std::string CheatFilePath;
extern bool MouseHide;
extern int MouseHideSeconds;
extern bool PauseLostFocus;
extern std::string UITheme;
extern int64_t RTCOffset; extern int64_t RTCOffset;
extern bool DSBatteryLevelOkay; extern bool DSBatteryLevelOkay;

View File

@ -35,21 +35,22 @@ InterfaceSettingsDialog::InterfaceSettingsDialog(QWidget* parent) : QDialog(pare
auto& cfg = emuInstance->getGlobalConfig(); auto& cfg = emuInstance->getGlobalConfig();
ui->cbMouseHide->setChecked(Config::MouseHide != 0); ui->cbMouseHide->setChecked(cfg.GetBool("MouseHide"));
ui->spinMouseHideSeconds->setEnabled(Config::MouseHide != 0); ui->spinMouseHideSeconds->setEnabled(ui->cbMouseHide->isChecked());
ui->spinMouseHideSeconds->setValue(Config::MouseHideSeconds); ui->spinMouseHideSeconds->setValue(cfg.GetInt("MouseHideSeconds"));
ui->cbPauseLostFocus->setChecked(Config::PauseLostFocus != 0); ui->cbPauseLostFocus->setChecked(cfg.GetBool("PauseLostFocus"));
ui->spinMaxFPS->setValue(cfg.GetInt("MaxFPS")); ui->spinMaxFPS->setValue(cfg.GetInt("MaxFPS"));
const QList<QString> themeKeys = QStyleFactory::keys(); const QList<QString> themeKeys = QStyleFactory::keys();
const QString currentTheme = qApp->style()->objectName(); const QString currentTheme = qApp->style()->objectName();
QString cfgTheme = cfg.GetQString("UITheme");
ui->cbxUITheme->addItem("System default", ""); ui->cbxUITheme->addItem("System default", "");
for (int i = 0; i < themeKeys.length(); i++) for (int i = 0; i < themeKeys.length(); i++)
{ {
ui->cbxUITheme->addItem(themeKeys[i], themeKeys[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); ui->cbxUITheme->setCurrentIndex(i + 1);
} }
} }
@ -61,39 +62,31 @@ InterfaceSettingsDialog::~InterfaceSettingsDialog()
void InterfaceSettingsDialog::on_cbMouseHide_clicked() void InterfaceSettingsDialog::on_cbMouseHide_clicked()
{ {
if (ui->spinMouseHideSeconds->isEnabled()) ui->spinMouseHideSeconds->setEnabled(ui->cbMouseHide->isChecked());
{
ui->spinMouseHideSeconds->setEnabled(false);
}
else
{
ui->spinMouseHideSeconds->setEnabled(true);
}
} }
void InterfaceSettingsDialog::done(int r) void InterfaceSettingsDialog::done(int r)
{ {
if (r == QDialog::Accepted) if (r == QDialog::Accepted)
{ {
Config::MouseHide = ui->cbMouseHide->isChecked() ? 1:0; auto& cfg = emuInstance->getGlobalConfig();
Config::MouseHideSeconds = ui->spinMouseHideSeconds->value();
Config::PauseLostFocus = ui->cbPauseLostFocus->isChecked() ? 1:0; cfg.SetBool("MouseHide", ui->cbMouseHide->isChecked());
emuInstance->maxFPS = ui->spinMaxFPS->value(); cfg.SetInt("MouseHideSeconds", ui->spinMouseHideSeconds->value());
cfg.SetBool("PauseLostFocus", ui->cbPauseLostFocus->isChecked());
cfg.SetInt("MaxFPS", ui->spinMaxFPS->value());
QString themeName = ui->cbxUITheme->currentData().toString(); QString themeName = ui->cbxUITheme->currentData().toString();
Config::UITheme = themeName.toStdString(); cfg.SetQString("UITheme", themeName);
auto& cfg = emuInstance->getGlobalConfig();
cfg.SetInt("MaxFPS", emuInstance->maxFPS);
Config::Save(); Config::Save();
if (!Config::UITheme.empty()) if (!themeName.isEmpty())
qApp->setStyle(themeName); qApp->setStyle(themeName);
else else
qApp->setStyle(*systemThemeName); qApp->setStyle(*systemThemeName);
emit updateMouseTimer(); emit updateInterfaceSettings();
} }
QDialog::done(r); QDialog::done(r);

View File

@ -53,7 +53,7 @@ public:
} }
signals: signals:
void updateMouseTimer(); void updateInterfaceSettings();
private slots: private slots:
void done(int r); void done(int r);

View File

@ -82,9 +82,12 @@ ScreenPanel::ScreenPanel(QWidget* parent) : QWidget(parent)
} }
emuInstance = mainWindow->getEmuInstance(); emuInstance = mainWindow->getEmuInstance();
mouseHide = false;
mouseHideDelay = 0;
QTimer* mouseTimer = setupMouseTimer(); QTimer* mouseTimer = setupMouseTimer();
connect(mouseTimer, &QTimer::timeout, [=] { if (Config::MouseHide) setCursor(Qt::BlankCursor);}); connect(mouseTimer, &QTimer::timeout, [=] { if (mouseHide) setCursor(Qt::BlankCursor);});
osdEnabled = false; osdEnabled = false;
osdID = 1; osdID = 1;
@ -96,6 +99,14 @@ ScreenPanel::~ScreenPanel()
delete mouseTimer; delete mouseTimer;
} }
void ScreenPanel::setMouseHide(bool enable, int delay)
{
mouseHide = enable;
mouseHideDelay = delay;
mouseTimer->setInterval(mouseHideDelay);
}
void ScreenPanel::setupScreenLayout() void ScreenPanel::setupScreenLayout()
{ {
int w = width(); int w = width();
@ -329,7 +340,7 @@ QTimer* ScreenPanel::setupMouseTimer()
{ {
mouseTimer = new QTimer(); mouseTimer = new QTimer();
mouseTimer->setSingleShot(true); mouseTimer->setSingleShot(true);
mouseTimer->setInterval(Config::MouseHideSeconds*1000); mouseTimer->setInterval(mouseHideDelay);
mouseTimer->start(); mouseTimer->start();
return mouseTimer; return mouseTimer;

View File

@ -58,6 +58,8 @@ public:
explicit ScreenPanel(QWidget* parent); explicit ScreenPanel(QWidget* parent);
virtual ~ScreenPanel(); virtual ~ScreenPanel();
void setMouseHide(bool enable, int delay);
QTimer* setupMouseTimer(); QTimer* setupMouseTimer();
void updateMouseTimer(); void updateMouseTimer();
QTimer* mouseTimer; QTimer* mouseTimer;
@ -73,6 +75,9 @@ protected:
MainWindow* mainWindow; MainWindow* mainWindow;
EmuInstance* emuInstance; EmuInstance* emuInstance;
bool mouseHide;
int mouseHideDelay;
struct OSDItem struct OSDItem
{ {
unsigned int id; unsigned int id;

View File

@ -696,6 +696,9 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actPreferences->setEnabled(false); actPreferences->setEnabled(false);
#endif // __APPLE__ #endif // __APPLE__
} }
QObject::connect(qApp, &QApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged);
onUpdateInterfaceSettings();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -953,12 +956,12 @@ void MainWindow::onAppStateChanged(Qt::ApplicationState state)
if (state == Qt::ApplicationInactive) if (state == Qt::ApplicationInactive)
{ {
emuInstance->keyReleaseAll(); emuInstance->keyReleaseAll();
if (Config::PauseLostFocus && emuThread->emuIsRunning()) if (pauseOnLostFocus && emuThread->emuIsRunning())
emuThread->emuPause(); emuThread->emuPause();
} }
else if (state == Qt::ApplicationActive) else if (state == Qt::ApplicationActive)
{ {
if (Config::PauseLostFocus && !pausedManually) if (pauseOnLostFocus && !pausedManually)
emuThread->emuUnpause(); emuThread->emuUnpause();
} }
} }
@ -1870,12 +1873,16 @@ void MainWindow::onOpenInterfaceSettings()
emuThread->emuPause(); emuThread->emuPause();
InterfaceSettingsDialog* dlg = InterfaceSettingsDialog::openDlg(this); InterfaceSettingsDialog* dlg = InterfaceSettingsDialog::openDlg(this);
connect(dlg, &InterfaceSettingsDialog::finished, this, &MainWindow::onInterfaceSettingsFinished); 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) void MainWindow::onInterfaceSettingsFinished(int res)

View File

@ -193,7 +193,7 @@ private slots:
void onPathSettingsFinished(int res); void onPathSettingsFinished(int res);
void onOpenInterfaceSettings(); void onOpenInterfaceSettings();
void onInterfaceSettingsFinished(int res); void onInterfaceSettingsFinished(int res);
void onUpdateMouseTimer(); void onUpdateInterfaceSettings();
void onChangeSavestateSRAMReloc(bool checked); void onChangeSavestateSRAMReloc(bool checked);
void onChangeScreenSize(); void onChangeScreenSize();
void onChangeScreenRotation(QAction* act); void onChangeScreenRotation(QAction* act);
@ -238,7 +238,8 @@ private:
bool hasOGL; bool hasOGL;
bool pausedManually = false; bool pauseOnLostFocus;
bool pausedManually;
int oldW, oldH; int oldW, oldH;
bool oldMax; bool oldMax;

View File

@ -335,9 +335,13 @@ int main(int argc, char** argv)
systemThemeName = new QString(QApplication::style()->objectName()); 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(); /* mainWindow = new MainWindow();