From 0072003a14a0dc192df611c53a88e7aadb0343e4 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sun, 26 Jan 2020 00:37:48 +0100 Subject: [PATCH] configure_ui: Address some review comments from the previous PR --- src/yuzu/configuration/configure_ui.cpp | 36 ++++++++++++++----------- src/yuzu/configuration/configure_ui.h | 1 + 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 3058f2509..24b6c5b72 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -29,23 +29,8 @@ constexpr std::array row_text_names{ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureUi) { ui->setupUi(this); - ui->language_combobox->addItem(tr(""), QString{}); - ui->language_combobox->addItem(tr("English"), QStringLiteral("en")); - QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags); - while (it.hasNext()) { - QString locale = it.next(); - locale.truncate(locale.lastIndexOf(QLatin1Char{'.'})); - locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1); - QString lang = QLocale::languageToString(QLocale(locale).language()); - ui->language_combobox->addItem(lang, locale); - } - // Unlike other configuration changes, interface language changes need to be reflected on the - // interface immediately. This is done by passing a signal to the main window, and then - // retranslating when passing back. - connect(ui->language_combobox, - static_cast(&QComboBox::currentIndexChanged), this, - &ConfigureUi::OnLanguageChanged); + InitializeLanguageComboBox(); for (const auto& theme : UISettings::themes) { ui->theme_combobox->addItem(QString::fromUtf8(theme.first), @@ -120,6 +105,25 @@ void ConfigureUi::RetranslateUI() { } } +void ConfigureUi::InitializeLanguageComboBox() { + ui->language_combobox->addItem(tr(""), QString{}); + ui->language_combobox->addItem(tr("English"), QStringLiteral("en")); + QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags); + while (it.hasNext()) { + QString locale = it.next(); + locale.truncate(locale.lastIndexOf(QLatin1Char{'.'})); + locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1); + const QString lang = QLocale::languageToString(QLocale(locale).language()); + ui->language_combobox->addItem(lang, locale); + } + + // Unlike other configuration changes, interface language changes need to be reflected on the + // interface immediately. This is done by passing a signal to the main window, and then + // retranslating when passing back. + connect(ui->language_combobox, QOverload::of(&QComboBox::currentIndexChanged), this, + &ConfigureUi::OnLanguageChanged); +} + void ConfigureUi::InitializeIconSizeComboBox() { for (const auto& size : default_icon_sizes) { ui->icon_size_combobox->addItem(QString::fromUtf8(size.second), size.first); diff --git a/src/yuzu/configuration/configure_ui.h b/src/yuzu/configuration/configure_ui.h index 3ecbd07c4..c30bcf6ff 100644 --- a/src/yuzu/configuration/configure_ui.h +++ b/src/yuzu/configuration/configure_ui.h @@ -34,6 +34,7 @@ private: void changeEvent(QEvent*) override; void RetranslateUI(); + void InitializeLanguageComboBox(); void InitializeIconSizeComboBox(); void InitializeRowComboBoxes();