port InterfaceSettings to the new config system.
This commit is contained in:
parent
28e4d39363
commit
5855e93f43
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<QString> 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);
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
}
|
||||
|
||||
signals:
|
||||
void updateMouseTimer();
|
||||
void updateInterfaceSettings();
|
||||
|
||||
private slots:
|
||||
void done(int r);
|
||||
|
|
|
@ -83,8 +83,11 @@ 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue