mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 19:45:20 +00:00
Qt: fix gui settings options
This commit is contained in:
parent
f8d396ac9e
commit
451d64407b
4 changed files with 108 additions and 41 deletions
|
@ -8,9 +8,17 @@
|
|||
|
||||
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
|
||||
|
||||
gui_settings::gui_settings(QObject* parent) : QObject(parent), m_settings(ComputeSettingsDir() + tr("CurrentSettings") + ".ini", QSettings::Format::IniFormat, parent),
|
||||
m_settingsDir(ComputeSettingsDir())
|
||||
gui_settings::gui_settings(QObject* parent) : QObject(parent)
|
||||
, m_current_name(gui::Settings)
|
||||
, m_settings(ComputeSettingsDir() + gui::Settings + ".ini", QSettings::Format::IniFormat, parent)
|
||||
, m_settingsDir(ComputeSettingsDir())
|
||||
{
|
||||
const QString settings_name = GetValue(gui::m_currentConfig).toString();
|
||||
|
||||
if (settings_name != m_current_name)
|
||||
{
|
||||
ChangeToConfig(settings_name);
|
||||
}
|
||||
}
|
||||
|
||||
gui_settings::~gui_settings()
|
||||
|
@ -45,19 +53,46 @@ QString gui_settings::ComputeSettingsDir()
|
|||
return QString::fromStdString(fs::get_config_dir()) + "/GuiConfigs/";
|
||||
}
|
||||
|
||||
void gui_settings::ChangeToConfig(const QString& name)
|
||||
bool gui_settings::ChangeToConfig(const QString& friendly_name)
|
||||
{
|
||||
if (name != tr("CurrentSettings"))
|
||||
{ // don't try to change to yourself.
|
||||
Reset(false);
|
||||
|
||||
QSettings other(m_settingsDir.absoluteFilePath(name + ".ini"), QSettings::IniFormat);
|
||||
for (const QString& key : other.allKeys())
|
||||
{
|
||||
m_settings.setValue(key, other.value(key));
|
||||
}
|
||||
m_settings.sync();
|
||||
if (m_current_name == friendly_name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (friendly_name != gui::Settings)
|
||||
{
|
||||
if (m_current_name == gui::Settings)
|
||||
{
|
||||
SetValue(gui::m_currentConfig, friendly_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSettings tmp(m_settingsDir.absoluteFilePath(gui::Settings + ".ini"), QSettings::Format::IniFormat, parent());
|
||||
tmp.beginGroup(gui::m_currentConfig.key);
|
||||
tmp.setValue(gui::m_currentConfig.name, friendly_name);
|
||||
tmp.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
m_settings.sync();
|
||||
|
||||
Reset(true);
|
||||
|
||||
QSettings other(m_settingsDir.absoluteFilePath(friendly_name + ".ini"), QSettings::IniFormat);
|
||||
|
||||
for (const QString& key : other.allKeys())
|
||||
{
|
||||
m_settings.setValue(key, other.value(key));
|
||||
}
|
||||
|
||||
SetValue(gui::m_currentConfig, friendly_name);
|
||||
|
||||
m_settings.sync();
|
||||
|
||||
m_current_name = friendly_name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_settings::Reset(bool removeMeta)
|
||||
|
@ -211,10 +246,26 @@ void gui_settings::SetCustomColor(int col, const QColor& val)
|
|||
SetValue(gui_save(gui::meta, "CustomColor" + QString::number(col), gui::gl_icon_color), val);
|
||||
}
|
||||
|
||||
void gui_settings::SaveCurrentConfig(const QString& friendlyName)
|
||||
void gui_settings::SaveCurrentConfig(const QString& friendly_name)
|
||||
{
|
||||
SetValue(gui::m_currentConfig, friendlyName);
|
||||
BackupSettingsToTarget(friendlyName);
|
||||
if (friendly_name != gui::Settings)
|
||||
{
|
||||
if (m_current_name == gui::Settings)
|
||||
{
|
||||
SetValue(gui::m_currentConfig, friendly_name);
|
||||
m_settings.sync();
|
||||
}
|
||||
else
|
||||
{
|
||||
QSettings tmp(m_settingsDir.absoluteFilePath(gui::Settings + ".ini"), QSettings::Format::IniFormat, parent());
|
||||
tmp.beginGroup(gui::m_currentConfig.key);
|
||||
tmp.setValue(gui::m_currentConfig.name, friendly_name);
|
||||
tmp.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
BackupSettingsToTarget(friendly_name);
|
||||
ChangeToConfig(friendly_name);
|
||||
}
|
||||
|
||||
logs::level gui_settings::GetLogLevel()
|
||||
|
@ -246,9 +297,10 @@ QStringList gui_settings::GetConfigEntries()
|
|||
return res;
|
||||
}
|
||||
|
||||
void gui_settings::BackupSettingsToTarget(const QString& friendlyName)
|
||||
void gui_settings::BackupSettingsToTarget(const QString& friendly_name)
|
||||
{
|
||||
QSettings target(ComputeSettingsDir() + friendlyName + ".ini", QSettings::Format::IniFormat);
|
||||
QSettings target(ComputeSettingsDir() + friendly_name + ".ini", QSettings::Format::IniFormat);
|
||||
|
||||
for (const QString& key : m_settings.allKeys())
|
||||
{
|
||||
if (!key.startsWith(gui::meta))
|
||||
|
@ -256,6 +308,7 @@ void gui_settings::BackupSettingsToTarget(const QString& friendlyName)
|
|||
target.setValue(key, m_settings.value(key));
|
||||
}
|
||||
}
|
||||
|
||||
target.sync();
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ namespace gui
|
|||
return q_string_pair(path, title.simplified()); // simplified() forces single line text
|
||||
}
|
||||
|
||||
const QString Settings = QObject::tr("CurrentSettings");
|
||||
const QString Default = QObject::tr("default");
|
||||
const QString main_window = "main_window";
|
||||
const QString game_list = "GameList";
|
||||
|
@ -189,7 +190,7 @@ namespace gui
|
|||
const gui_save rsx_geometry = gui_save(rsx, "geometry", QByteArray());
|
||||
const gui_save rsx_states = gui_save(rsx, "states", QVariantMap());
|
||||
|
||||
const gui_save m_currentConfig = gui_save(meta, "currentConfig", QObject::tr("CurrentSettings"));
|
||||
const gui_save m_currentConfig = gui_save(meta, "currentConfig", Settings);
|
||||
const gui_save m_currentStylesheet = gui_save(meta, "currentStylesheet", Default);
|
||||
const gui_save m_saveNotes = gui_save(meta, "saveNotes", QVariantMap());
|
||||
const gui_save m_showDebugTab = gui_save(meta, "showDebugTab", false);
|
||||
|
@ -236,7 +237,7 @@ public:
|
|||
QString GetSettingsDir();
|
||||
|
||||
/** Changes the settings file to the destination preset*/
|
||||
void ChangeToConfig(const QString& destination);
|
||||
bool ChangeToConfig(const QString& friendly_name);
|
||||
|
||||
bool GetCategoryVisibility(int cat);
|
||||
QVariant GetValue(const gui_save& entry);
|
||||
|
@ -268,15 +269,16 @@ public Q_SLOTS:
|
|||
|
||||
void SetCustomColor(int col, const QColor& val);
|
||||
|
||||
void SaveCurrentConfig(const QString& friendlyName);
|
||||
void SaveCurrentConfig(const QString& friendly_name);
|
||||
|
||||
static QSize SizeFromSlider(int pos);
|
||||
static gui_save GetGuiSaveForColumn(int col);
|
||||
|
||||
private:
|
||||
QString ComputeSettingsDir();
|
||||
void BackupSettingsToTarget(const QString& destination);
|
||||
void BackupSettingsToTarget(const QString& friendly_name);
|
||||
|
||||
QSettings m_settings;
|
||||
QDir m_settingsDir;
|
||||
QString m_current_name;
|
||||
};
|
||||
|
|
|
@ -78,9 +78,6 @@ void main_window::Init()
|
|||
|
||||
setAcceptDrops(true);
|
||||
|
||||
// hide utilities from the average user
|
||||
ui->menuUtilities->menuAction()->setVisible(guiSettings->GetValue(gui::m_showDebugTab).toBool());
|
||||
|
||||
// add toolbar widgets (crappy Qt designer is not able to)
|
||||
ui->toolBar->setObjectName("mw_toolbar");
|
||||
ui->sizeSlider->setRange(0, gui::gl_max_slider_pos);
|
||||
|
@ -1546,6 +1543,9 @@ void main_window::ConfigureGuiFromSettings(bool configure_all)
|
|||
}
|
||||
}
|
||||
|
||||
// hide utilities from the average user
|
||||
ui->menuUtilities->menuAction()->setVisible(guiSettings->GetValue(gui::m_showDebugTab).toBool());
|
||||
|
||||
ui->showLogAct->setChecked(guiSettings->GetValue(gui::mw_logger).toBool());
|
||||
ui->showGameListAct->setChecked(guiSettings->GetValue(gui::mw_gamelist).toBool());
|
||||
ui->showDebuggerAct->setChecked(guiSettings->GetValue(gui::mw_debugger).toBool());
|
||||
|
|
|
@ -972,7 +972,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
|
|||
ui->combo_stylesheets->setCurrentIndex(0);
|
||||
}
|
||||
// Only attempt to load a config if changes occurred.
|
||||
if (m_currentConfig != xgui_settings->GetValue(gui::m_currentConfig).toString())
|
||||
if (m_currentConfig != ui->combo_configs->currentText())
|
||||
{
|
||||
OnApplyConfig();
|
||||
}
|
||||
|
@ -1124,9 +1124,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
|
|||
xemu_settings->EnhanceCheckBox(ui->hookStFunc, emu_settings::HookStaticFuncs);
|
||||
SubscribeTooltip(ui->hookStFunc, json_debug["hookStFunc"].toString());
|
||||
|
||||
//
|
||||
// Layout fix for High Dpi
|
||||
//
|
||||
layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||
}
|
||||
|
||||
|
@ -1149,7 +1147,7 @@ void settings_dialog::AddConfigs()
|
|||
}
|
||||
}
|
||||
|
||||
m_currentConfig = tr("CurrentSettings");
|
||||
m_currentConfig = xgui_settings->GetValue(gui::m_currentConfig).toString();
|
||||
|
||||
int index = ui->combo_configs->findText(m_currentConfig);
|
||||
if (index != -1)
|
||||
|
@ -1158,7 +1156,7 @@ void settings_dialog::AddConfigs()
|
|||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING(GENERAL, "Trying to set an invalid config index ", index);
|
||||
LOG_WARNING(GENERAL, "Trying to set an invalid config index %d", index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1199,41 +1197,55 @@ void settings_dialog::OnBackupCurrentConfig()
|
|||
while (dialog->exec() != QDialog::Rejected)
|
||||
{
|
||||
dialog->resize(500, 100);
|
||||
QString friendlyName = dialog->textValue();
|
||||
if (friendlyName == "")
|
||||
QString friendly_name = dialog->textValue();
|
||||
if (friendly_name == "")
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error"), tr("Name cannot be empty"));
|
||||
continue;
|
||||
}
|
||||
if (friendlyName.contains("."))
|
||||
if (friendly_name.contains("."))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error"), tr("Must choose a name with no '.'"));
|
||||
continue;
|
||||
}
|
||||
if (ui->combo_configs->findText(friendlyName) != -1)
|
||||
if (ui->combo_configs->findText(friendly_name) != -1)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Error"), tr("Please choose a non-existing name"));
|
||||
continue;
|
||||
}
|
||||
Q_EMIT GuiSettingsSaveRequest();
|
||||
xgui_settings->SaveCurrentConfig(friendlyName);
|
||||
ui->combo_configs->addItem(friendlyName);
|
||||
ui->combo_configs->setCurrentIndex(ui->combo_configs->findText(friendlyName));
|
||||
xgui_settings->SaveCurrentConfig(friendly_name);
|
||||
ui->combo_configs->addItem(friendly_name);
|
||||
ui->combo_configs->setCurrentText(friendly_name);
|
||||
m_currentConfig = friendly_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void settings_dialog::OnApplyConfig()
|
||||
{
|
||||
m_currentConfig = ui->combo_configs->currentText();
|
||||
xgui_settings->SetValue(gui::m_currentConfig, m_currentConfig);
|
||||
xgui_settings->ChangeToConfig(m_currentConfig);
|
||||
const QString new_config = ui->combo_configs->currentText();
|
||||
|
||||
if (new_config == m_currentConfig)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!xgui_settings->ChangeToConfig(new_config))
|
||||
{
|
||||
const int new_config_idx = ui->combo_configs->currentIndex();
|
||||
ui->combo_configs->setCurrentText(m_currentConfig);
|
||||
ui->combo_configs->removeItem(new_config_idx);
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentConfig = new_config;
|
||||
Q_EMIT GuiSettingsSyncRequest(true);
|
||||
}
|
||||
|
||||
void settings_dialog::OnApplyStylesheet()
|
||||
{
|
||||
m_currentStylesheet = ui->combo_stylesheets->currentData().toString();
|
||||
m_currentStylesheet = ui->combo_stylesheets->currentText();
|
||||
xgui_settings->SetValue(gui::m_currentStylesheet, m_currentStylesheet);
|
||||
Q_EMIT GuiStylesheetRequest(xgui_settings->GetCurrentStylesheetPath());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue