From 3a2567c97cc7dc03d662a7609c979aef9e0a80ae Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 12 Sep 2018 01:06:50 -0400 Subject: yuzu/configure_gamelist: Move combo box initializtion to their own functions Keeps the individual initialization of the combo boxes logically separate. We also shouldn't be dumping this sort of thing in the constructor directly. --- src/yuzu/configuration/configure_gamelist.cpp | 51 +++++++++++++++------------ src/yuzu/configuration/configure_gamelist.h | 4 ++- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/yuzu/configuration/configure_gamelist.cpp b/src/yuzu/configuration/configure_gamelist.cpp index 1ae3423cf..1238356a8 100644 --- a/src/yuzu/configuration/configure_gamelist.cpp +++ b/src/yuzu/configuration/configure_gamelist.cpp @@ -12,6 +12,33 @@ ConfigureGameList::ConfigureGameList(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureGameList) { ui->setupUi(this); + InitializeIconSizeComboBox(); + InitializeRowComboBoxes(); + + this->setConfiguration(); +} + +ConfigureGameList::~ConfigureGameList() = default; + +void ConfigureGameList::applyConfiguration() { + UISettings::values.show_unknown = ui->show_unknown->isChecked(); + UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); + UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); + UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); + Settings::Apply(); +} + +void ConfigureGameList::setConfiguration() { + ui->show_unknown->setChecked(UISettings::values.show_unknown); + ui->icon_size_combobox->setCurrentIndex( + ui->icon_size_combobox->findData(UISettings::values.icon_size)); + ui->row_1_text_combobox->setCurrentIndex( + ui->row_1_text_combobox->findData(UISettings::values.row_1_text_id)); + ui->row_2_text_combobox->setCurrentIndex( + ui->row_2_text_combobox->findData(UISettings::values.row_2_text_id)); +} + +void ConfigureGameList::InitializeIconSizeComboBox() { static const std::vector> default_icon_sizes{ std::make_pair(0, "None"), std::make_pair(32, "Small"), std::make_pair(64, "Standard"), std::make_pair(128, "Large"), @@ -24,7 +51,9 @@ ConfigureGameList::ConfigureGameList(QWidget* parent) std::to_string(size.first) + ")"), size.first); } +} +void ConfigureGameList::InitializeRowComboBoxes() { static const std::vector row_text_names{ "Filename", "Filetype", @@ -38,26 +67,4 @@ ConfigureGameList::ConfigureGameList(QWidget* parent) ui->row_2_text_combobox->addItem(QString::fromStdString(row_text_names[i]), QVariant::fromValue(i)); } - - this->setConfiguration(); -} - -ConfigureGameList::~ConfigureGameList() {} - -void ConfigureGameList::setConfiguration() { - ui->show_unknown->setChecked(UISettings::values.show_unknown); - ui->icon_size_combobox->setCurrentIndex( - ui->icon_size_combobox->findData(UISettings::values.icon_size)); - ui->row_1_text_combobox->setCurrentIndex( - ui->row_1_text_combobox->findData(UISettings::values.row_1_text_id)); - ui->row_2_text_combobox->setCurrentIndex( - ui->row_2_text_combobox->findData(UISettings::values.row_2_text_id)); -} - -void ConfigureGameList::applyConfiguration() { - UISettings::values.show_unknown = ui->show_unknown->isChecked(); - UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); - UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); - UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); - Settings::Apply(); } diff --git a/src/yuzu/configuration/configure_gamelist.h b/src/yuzu/configuration/configure_gamelist.h index 94fba6373..71fd67e99 100644 --- a/src/yuzu/configuration/configure_gamelist.h +++ b/src/yuzu/configuration/configure_gamelist.h @@ -23,6 +23,8 @@ public: private: void setConfiguration(); -private: + void InitializeIconSizeComboBox(); + void InitializeRowComboBoxes(); + std::unique_ptr ui; }; -- cgit v1.2.3 From a9b953e6d41e7fd0c5d4c9de7c353d7a0204a784 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 12 Sep 2018 01:09:25 -0400 Subject: yuzu/configure_gamelist: Use std::array instead of std::vector for translatable strings We don't need to use an allocating container for these, given we know the fixed amount of strings being used. This is just a waste of memory. --- src/yuzu/configuration/configure_gamelist.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/yuzu/configuration/configure_gamelist.cpp b/src/yuzu/configuration/configure_gamelist.cpp index 1238356a8..20090ed29 100644 --- a/src/yuzu/configuration/configure_gamelist.cpp +++ b/src/yuzu/configuration/configure_gamelist.cpp @@ -2,11 +2,14 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "core/core.h" +#include +#include + +#include "common/common_types.h" #include "core/settings.h" #include "ui_configure_gamelist.h" -#include "ui_settings.h" #include "yuzu/configuration/configure_gamelist.h" +#include "yuzu/ui_settings.h" ConfigureGameList::ConfigureGameList(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureGameList) { @@ -39,11 +42,11 @@ void ConfigureGameList::setConfiguration() { } void ConfigureGameList::InitializeIconSizeComboBox() { - static const std::vector> default_icon_sizes{ + static const std::array, 5> default_icon_sizes{{ std::make_pair(0, "None"), std::make_pair(32, "Small"), std::make_pair(64, "Standard"), std::make_pair(128, "Large"), std::make_pair(256, "Full Size"), - }; + }}; for (const auto& size : default_icon_sizes) { ui->icon_size_combobox->addItem(QString::fromStdString(size.second + " (" + @@ -54,12 +57,12 @@ void ConfigureGameList::InitializeIconSizeComboBox() { } void ConfigureGameList::InitializeRowComboBoxes() { - static const std::vector row_text_names{ + static const std::array row_text_names{{ "Filename", "Filetype", "Title ID", "Title Name", - }; + }}; for (size_t i = 0; i < row_text_names.size(); ++i) { ui->row_1_text_combobox->addItem(QString::fromStdString(row_text_names[i]), -- cgit v1.2.3 From e89c22c1471d02e5e9c3fe3f5fd4e6cb7800f6cc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 12 Sep 2018 01:11:25 -0400 Subject: yuzu/configure_gamelist: Make combo box strings translatable Given these are shown to the user, they should be translatable. While we're at it, also set up the dialog to automatically retranslate the dialog along with the combo boxes if it receives a LanguageChange event. --- src/yuzu/configuration/configure_gamelist.cpp | 65 ++++++++++++++++++--------- src/yuzu/configuration/configure_gamelist.h | 3 ++ 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/yuzu/configuration/configure_gamelist.cpp b/src/yuzu/configuration/configure_gamelist.cpp index 20090ed29..0be030434 100644 --- a/src/yuzu/configuration/configure_gamelist.cpp +++ b/src/yuzu/configuration/configure_gamelist.cpp @@ -11,6 +11,23 @@ #include "yuzu/configuration/configure_gamelist.h" #include "yuzu/ui_settings.h" +namespace { +constexpr std::array, 5> default_icon_sizes{{ + std::make_pair(0, QT_TR_NOOP("None")), + std::make_pair(32, QT_TR_NOOP("Small (32x32)")), + std::make_pair(64, QT_TR_NOOP("Standard (64x64)")), + std::make_pair(128, QT_TR_NOOP("Large (128x128)")), + std::make_pair(256, QT_TR_NOOP("Full Size (256x256)")), +}}; + +constexpr std::array row_text_names{{ + QT_TR_NOOP("Filename"), + QT_TR_NOOP("Filetype"), + QT_TR_NOOP("Title ID"), + QT_TR_NOOP("Title Name"), +}}; +} // Anonymous namespace + ConfigureGameList::ConfigureGameList(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureGameList) { ui->setupUi(this); @@ -41,33 +58,39 @@ void ConfigureGameList::setConfiguration() { ui->row_2_text_combobox->findData(UISettings::values.row_2_text_id)); } -void ConfigureGameList::InitializeIconSizeComboBox() { - static const std::array, 5> default_icon_sizes{{ - std::make_pair(0, "None"), std::make_pair(32, "Small"), - std::make_pair(64, "Standard"), std::make_pair(128, "Large"), - std::make_pair(256, "Full Size"), - }}; +void ConfigureGameList::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + return; + } + QWidget::changeEvent(event); +} + +void ConfigureGameList::RetranslateUI() { + ui->retranslateUi(this); + + for (int i = 0; i < ui->icon_size_combobox->count(); i++) { + ui->icon_size_combobox->setItemText(i, tr(default_icon_sizes[i].second)); + } + + for (int i = 0; i < ui->row_1_text_combobox->count(); i++) { + const QString name = tr(row_text_names[i]); + + ui->row_1_text_combobox->setItemText(i, name); + ui->row_2_text_combobox->setItemText(i, name); + } +} + +void ConfigureGameList::InitializeIconSizeComboBox() { for (const auto& size : default_icon_sizes) { - ui->icon_size_combobox->addItem(QString::fromStdString(size.second + " (" + - std::to_string(size.first) + "x" + - std::to_string(size.first) + ")"), - size.first); + ui->icon_size_combobox->addItem(size.second, size.first); } } void ConfigureGameList::InitializeRowComboBoxes() { - static const std::array row_text_names{{ - "Filename", - "Filetype", - "Title ID", - "Title Name", - }}; - for (size_t i = 0; i < row_text_names.size(); ++i) { - ui->row_1_text_combobox->addItem(QString::fromStdString(row_text_names[i]), - QVariant::fromValue(i)); - ui->row_2_text_combobox->addItem(QString::fromStdString(row_text_names[i]), - QVariant::fromValue(i)); + ui->row_1_text_combobox->addItem(row_text_names[i], QVariant::fromValue(i)); + ui->row_2_text_combobox->addItem(row_text_names[i], QVariant::fromValue(i)); } } diff --git a/src/yuzu/configuration/configure_gamelist.h b/src/yuzu/configuration/configure_gamelist.h index 71fd67e99..ff7406c60 100644 --- a/src/yuzu/configuration/configure_gamelist.h +++ b/src/yuzu/configuration/configure_gamelist.h @@ -23,6 +23,9 @@ public: private: void setConfiguration(); + void changeEvent(QEvent*) override; + void RetranslateUI(); + void InitializeIconSizeComboBox(); void InitializeRowComboBoxes(); -- cgit v1.2.3