mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-21 03:23:34 +00:00
Edit configure_ui.cpp
This commit is contained in:
@@ -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>
|
||||||
@@ -33,42 +34,42 @@
|
|||||||
#include "citron/uisettings.h"
|
#include "citron/uisettings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr std::array default_game_icon_sizes{
|
constexpr std::array default_game_icon_sizes{
|
||||||
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
|
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
|
||||||
std::make_pair(32, QT_TRANSLATE_NOOP("ConfigureUI", "Small (32x32)")),
|
std::make_pair(32, QT_TRANSLATE_NOOP("ConfigureUI", "Small (32x32)")),
|
||||||
std::make_pair(64, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (64x64)")),
|
std::make_pair(64, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (64x64)")),
|
||||||
std::make_pair(128, QT_TRANSLATE_NOOP("ConfigureUI", "Large (128x128)")),
|
std::make_pair(128, QT_TRANSLATE_NOOP("ConfigureUI", "Large (128x128)")),
|
||||||
std::make_pair(256, QT_TRANSLATE_NOOP("ConfigureUI", "Full Size (256x256)")),
|
std::make_pair(256, QT_TRANSLATE_NOOP("ConfigureUI", "Full Size (256x256)")),
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::array default_folder_icon_sizes{
|
constexpr std::array default_folder_icon_sizes{
|
||||||
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
|
std::make_pair(0, QT_TRANSLATE_NOOP("ConfigureUI", "None")),
|
||||||
std::make_pair(24, QT_TRANSLATE_NOOP("ConfigureUI", "Small (24x24)")),
|
std::make_pair(24, QT_TRANSLATE_NOOP("ConfigureUI", "Small (24x24)")),
|
||||||
std::make_pair(48, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (48x48)")),
|
std::make_pair(48, QT_TRANSLATE_NOOP("ConfigureUI", "Standard (48x48)")),
|
||||||
std::make_pair(72, QT_TRANSLATE_NOOP("ConfigureUI", "Large (72x72)")),
|
std::make_pair(72, QT_TRANSLATE_NOOP("ConfigureUI", "Large (72x72)")),
|
||||||
};
|
};
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
constexpr std::array row_text_names{
|
constexpr std::array row_text_names{
|
||||||
QT_TRANSLATE_NOOP("ConfigureUI", "Filename"),
|
QT_TRANSLATE_NOOP("ConfigureUI", "Filename"),
|
||||||
QT_TRANSLATE_NOOP("ConfigureUI", "Filetype"),
|
QT_TRANSLATE_NOOP("ConfigureUI", "Filetype"),
|
||||||
QT_TRANSLATE_NOOP("ConfigureUI", "Title ID"),
|
QT_TRANSLATE_NOOP("ConfigureUI", "Title ID"),
|
||||||
QT_TRANSLATE_NOOP("ConfigureUI", "Title Name"),
|
QT_TRANSLATE_NOOP("ConfigureUI", "Title Name"),
|
||||||
QT_TRANSLATE_NOOP("ConfigureUI", "None"),
|
QT_TRANSLATE_NOOP("ConfigureUI", "None"),
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
QString GetTranslatedGameIconSize(size_t index) {
|
QString GetTranslatedGameIconSize(size_t index) {
|
||||||
return QCoreApplication::translate("ConfigureUI", default_game_icon_sizes[index].second);
|
return QCoreApplication::translate("ConfigureUI", default_game_icon_sizes[index].second);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetTranslatedFolderIconSize(size_t index) {
|
QString GetTranslatedFolderIconSize(size_t index) {
|
||||||
return QCoreApplication::translate("ConfigureUI", default_folder_icon_sizes[index].second);
|
return QCoreApplication::translate("ConfigureUI", default_folder_icon_sizes[index].second);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetTranslatedRowTextName(size_t index) {
|
QString GetTranslatedRowTextName(size_t index) {
|
||||||
return QCoreApplication::translate("ConfigureUI", row_text_names[index]);
|
return QCoreApplication::translate("ConfigureUI", row_text_names[index]);
|
||||||
}
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
static float GetUpFactor(Settings::ResolutionSetup res_setup) {
|
static float GetUpFactor(Settings::ResolutionSetup res_setup) {
|
||||||
@@ -81,7 +82,7 @@ static void PopulateResolutionComboBox(QComboBox* screenshot_height, QWidget* pa
|
|||||||
screenshot_height->clear();
|
screenshot_height->clear();
|
||||||
|
|
||||||
const auto& enumeration =
|
const auto& enumeration =
|
||||||
Settings::EnumMetadata<Settings::ResolutionSetup>::Canonicalizations();
|
Settings::EnumMetadata<Settings::ResolutionSetup>::Canonicalizations();
|
||||||
std::set<u32> resolutions{};
|
std::set<u32> resolutions{};
|
||||||
for (const auto& [name, value] : enumeration) {
|
for (const auto& [name, value] : enumeration) {
|
||||||
const float up_factor = GetUpFactor(value);
|
const float up_factor = GetUpFactor(value);
|
||||||
@@ -102,9 +103,9 @@ static u32 ScreenshotDimensionToInt(const QString& height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
|
ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
|
||||||
: QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()},
|
: QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()},
|
||||||
ratio{Settings::values.aspect_ratio.GetValue()},
|
ratio{Settings::values.aspect_ratio.GetValue()},
|
||||||
resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} {
|
resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
InitializeLanguageComboBox();
|
InitializeLanguageComboBox();
|
||||||
@@ -121,34 +122,39 @@ 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.
|
||||||
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
|
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
|
||||||
auto dir =
|
auto dir =
|
||||||
QFileDialog::getExistingDirectory(this, tr("Select Screenshots Path..."),
|
QFileDialog::getExistingDirectory(this, tr("Select Screenshots Path..."),
|
||||||
QString::fromStdString(Common::FS::GetCitronPathString(
|
QString::fromStdString(Common::FS::GetCitronPathString(
|
||||||
Common::FS::CitronPath::ScreenshotsDir)));
|
Common::FS::CitronPath::ScreenshotsDir)));
|
||||||
if (!dir.isEmpty()) {
|
if (!dir.isEmpty()) {
|
||||||
if (dir.back() != QChar::fromLatin1('/')) {
|
if (dir.back() != QChar::fromLatin1('/')) {
|
||||||
dir.append(QChar::fromLatin1('/'));
|
dir.append(QChar::fromLatin1('/'));
|
||||||
@@ -167,7 +173,8 @@ 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();
|
||||||
@@ -180,7 +187,7 @@ void ConfigureUi::ApplyConfiguration() {
|
|||||||
|
|
||||||
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
|
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
|
||||||
Common::FS::SetCitronPath(Common::FS::CitronPath::ScreenshotsDir,
|
Common::FS::SetCitronPath(Common::FS::CitronPath::ScreenshotsDir,
|
||||||
ui->screenshot_path_edit->text().toStdString());
|
ui->screenshot_path_edit->text().toStdString());
|
||||||
|
|
||||||
const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText());
|
const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText());
|
||||||
UISettings::values.screenshot_height.SetValue(height);
|
UISettings::values.screenshot_height.SetValue(height);
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,8 +305,8 @@ void ConfigureUi::InitializeRowComboBoxes() {
|
|||||||
|
|
||||||
void ConfigureUi::UpdateFirstRowComboBox(bool init) {
|
void ConfigureUi::UpdateFirstRowComboBox(bool init) {
|
||||||
const int currentIndex =
|
const int currentIndex =
|
||||||
init ? UISettings::values.row_1_text_id.GetValue()
|
init ? UISettings::values.row_1_text_id.GetValue()
|
||||||
: ui->row_1_text_combobox->findData(ui->row_1_text_combobox->currentData());
|
: ui->row_1_text_combobox->findData(ui->row_1_text_combobox->currentData());
|
||||||
|
|
||||||
ui->row_1_text_combobox->clear();
|
ui->row_1_text_combobox->clear();
|
||||||
|
|
||||||
@@ -307,8 +324,8 @@ void ConfigureUi::UpdateFirstRowComboBox(bool init) {
|
|||||||
|
|
||||||
void ConfigureUi::UpdateSecondRowComboBox(bool init) {
|
void ConfigureUi::UpdateSecondRowComboBox(bool init) {
|
||||||
const int currentIndex =
|
const int currentIndex =
|
||||||
init ? UISettings::values.row_2_text_id.GetValue()
|
init ? UISettings::values.row_2_text_id.GetValue()
|
||||||
: ui->row_2_text_combobox->findData(ui->row_2_text_combobox->currentData());
|
: ui->row_2_text_combobox->findData(ui->row_2_text_combobox->currentData());
|
||||||
|
|
||||||
ui->row_2_text_combobox->clear();
|
ui->row_2_text_combobox->clear();
|
||||||
|
|
||||||
@@ -340,10 +357,10 @@ void ConfigureUi::UpdateWidthText() {
|
|||||||
const u32 height_undocked = Layout::ScreenUndocked::Height * up_factor;
|
const u32 height_undocked = Layout::ScreenUndocked::Height * up_factor;
|
||||||
const u32 width_undocked = UISettings::CalculateWidth(height_undocked, ratio);
|
const u32 width_undocked = UISettings::CalculateWidth(height_undocked, ratio);
|
||||||
ui->screenshot_width->setText(tr("Auto (%1 x %2, %3 x %4)", "Screenshot width value")
|
ui->screenshot_width->setText(tr("Auto (%1 x %2, %3 x %4)", "Screenshot width value")
|
||||||
.arg(width_undocked)
|
.arg(width_undocked)
|
||||||
.arg(height_undocked)
|
.arg(height_undocked)
|
||||||
.arg(width_docked)
|
.arg(width_docked)
|
||||||
.arg(height_docked));
|
.arg(height_docked));
|
||||||
} else {
|
} else {
|
||||||
ui->screenshot_width->setText(QStringLiteral("%1 x").arg(width));
|
ui->screenshot_width->setText(QStringLiteral("%1 x").arg(width));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user