Edit configure_ui.cpp

This commit is contained in:
collecting
2025-10-04 00:37:07 +00:00
parent 4fabdfd9a9
commit a5d3efa8da

View File

@@ -12,6 +12,7 @@
#include <utility> #include <utility>
#include <QCheckBox> #include <QCheckBox>
#include <QColorDialog>
#include <QComboBox> #include <QComboBox>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDirIterator> #include <QDirIterator>
@@ -121,26 +122,31 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
SetConfiguration(); SetConfiguration();
connect(ui->accentColorButton, &QPushButton::clicked, this, &ConfigureUi::OnAccentColorButtonPressed);
connect(ui->rainbowModeCheckBox, &QCheckBox::checkStateChanged, this, [this](int state) {
emit themeChanged();
});
// Force game list reload if any of the relevant settings are changed. // Force game list reload if any of the relevant settings are changed.
connect(ui->show_add_ons, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); connect(ui->show_add_ons, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_compat, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); connect(ui->show_compat, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_size, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); connect(ui->show_size, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_types, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); connect(ui->show_types, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_play_time, &QCheckBox::stateChanged, this, connect(ui->show_play_time, &QCheckBox::checkStateChanged, this,
&ConfigureUi::RequestGameListUpdate); &ConfigureUi::RequestGameListUpdate);
connect(ui->game_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->game_icon_size_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::RequestGameListUpdate); &ConfigureUi::RequestGameListUpdate);
connect(ui->folder_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(ui->folder_icon_size_combobox, &QComboBox::currentIndexChanged,
this, &ConfigureUi::RequestGameListUpdate); this, &ConfigureUi::RequestGameListUpdate);
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->row_1_text_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::RequestGameListUpdate); &ConfigureUi::RequestGameListUpdate);
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->row_2_text_combobox, &QComboBox::currentIndexChanged, this,
&ConfigureUi::RequestGameListUpdate); &ConfigureUi::RequestGameListUpdate);
// Update text ComboBoxes after user interaction. // Update text ComboBoxes after user interaction.
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::activated), connect(ui->row_1_text_combobox, &QComboBox::activated,
[this] { ConfigureUi::UpdateSecondRowComboBox(); }); [this] { ConfigureUi::UpdateSecondRowComboBox(); });
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated), connect(ui->row_2_text_combobox, &QComboBox::activated,
[this] { ConfigureUi::UpdateFirstRowComboBox(); }); [this] { ConfigureUi::UpdateFirstRowComboBox(); });
// Set screenshot path to user specification. // Set screenshot path to user specification.
@@ -168,6 +174,7 @@ ConfigureUi::~ConfigureUi() = default;
void ConfigureUi::ApplyConfiguration() { void ConfigureUi::ApplyConfiguration() {
UISettings::values.theme = UISettings::values.theme =
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString().toStdString(); ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString().toStdString();
UISettings::values.enable_rainbow_mode = ui->rainbowModeCheckBox->isChecked();
UISettings::values.show_add_ons = ui->show_add_ons->isChecked(); UISettings::values.show_add_ons = ui->show_add_ons->isChecked();
UISettings::values.show_compat = ui->show_compat->isChecked(); UISettings::values.show_compat = ui->show_compat->isChecked();
UISettings::values.show_size = ui->show_size->isChecked(); UISettings::values.show_size = ui->show_size->isChecked();
@@ -198,6 +205,7 @@ void ConfigureUi::SetConfiguration() {
ui->theme_combobox->findData(QString::fromStdString(UISettings::values.theme))); ui->theme_combobox->findData(QString::fromStdString(UISettings::values.theme)));
ui->language_combobox->setCurrentIndex(ui->language_combobox->findData( ui->language_combobox->setCurrentIndex(ui->language_combobox->findData(
QString::fromStdString(UISettings::values.language.GetValue()))); QString::fromStdString(UISettings::values.language.GetValue())));
ui->rainbowModeCheckBox->setChecked(UISettings::values.enable_rainbow_mode.GetValue());
ui->show_add_ons->setChecked(UISettings::values.show_add_ons.GetValue()); ui->show_add_ons->setChecked(UISettings::values.show_add_ons.GetValue());
ui->show_compat->setChecked(UISettings::values.show_compat.GetValue()); ui->show_compat->setChecked(UISettings::values.show_compat.GetValue());
ui->show_size->setChecked(UISettings::values.show_size.GetValue()); ui->show_size->setChecked(UISettings::values.show_size.GetValue());
@@ -221,6 +229,18 @@ void ConfigureUi::SetConfiguration() {
} }
} }
void ConfigureUi::OnAccentColorButtonPressed() {
const QColor current_color(QString::fromStdString(UISettings::values.accent_color.GetValue()));
QColorDialog dialog(current_color, this);
if (dialog.exec() == QDialog::Accepted) {
const QColor color = dialog.selectedColor();
if (color.isValid()) {
UISettings::values.accent_color.SetValue(color.name().toStdString());
emit themeChanged();
}
}
}
void ConfigureUi::changeEvent(QEvent* event) { void ConfigureUi::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) { if (event->type() == QEvent::LanguageChange) {
RetranslateUI(); RetranslateUI();
@@ -263,10 +283,7 @@ void ConfigureUi::InitializeLanguageComboBox() {
ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, country), locale); ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, country), locale);
} }
// Unlike other configuration changes, interface language changes need to be reflected on the connect(ui->language_combobox, &QComboBox::currentIndexChanged, this,
// interface immediately. This is done by passing a signal to the main window, and then
// retranslating when passing back.
connect(ui->language_combobox, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfigureUi::OnLanguageChanged); &ConfigureUi::OnLanguageChanged);
} }