From ab07d441933d24ffc7a6ce22d6e9bb64248b1f2d Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Fri, 2 Nov 2018 22:40:58 +0800 Subject: [PATCH] citra_qt/configuration: fix language configuration issues --- src/citra_qt/configuration/configure_audio.h | 2 +- src/citra_qt/configuration/configure_debug.h | 2 - .../configuration/configure_dialog.cpp | 52 +++++++++++++------ src/citra_qt/configuration/configure_dialog.h | 1 + .../configuration/configure_general.h | 3 +- .../configuration/configure_graphics.h | 2 - .../configuration/configure_input.cpp | 1 - src/citra_qt/configuration/configure_input.h | 5 +- .../configuration/configure_system.cpp | 1 - src/citra_qt/configuration/configure_ui.h | 3 +- src/citra_qt/configuration/configure_ui.ui | 10 ++++ src/citra_qt/configuration/configure_web.h | 3 +- 12 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/citra_qt/configuration/configure_audio.h b/src/citra_qt/configuration/configure_audio.h index 03f2c70c3e..9ba031070d 100644 --- a/src/citra_qt/configuration/configure_audio.h +++ b/src/citra_qt/configuration/configure_audio.h @@ -20,12 +20,12 @@ public: void applyConfiguration(); void retranslateUi(); + void setConfiguration(); public slots: void updateAudioDevices(int sink_index); private: - void setConfiguration(); void setOutputSinkFromSinkID(); void setAudioDeviceFromDeviceID(); void setVolumeIndicatorText(int percentage); diff --git a/src/citra_qt/configuration/configure_debug.h b/src/citra_qt/configuration/configure_debug.h index fc95c91ca9..e881842811 100644 --- a/src/citra_qt/configuration/configure_debug.h +++ b/src/citra_qt/configuration/configure_debug.h @@ -20,8 +20,6 @@ public: void applyConfiguration(); void retranslateUi(); - -private: void setConfiguration(); private: diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index ba2eda32d9..3f13401f16 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -14,7 +14,6 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry : QDialog(parent), ui(new Ui::ConfigureDialog) { ui->setupUi(this); ui->generalTab->PopulateHotkeyList(registry); - this->setConfiguration(); this->PopulateSelectionList(); connect(ui->uiTab, &ConfigureUi::languageChanged, this, &ConfigureDialog::onLanguageChanged); connect(ui->selectorList, &QListWidget::itemSelectionChanged, this, @@ -27,7 +26,17 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry ConfigureDialog::~ConfigureDialog() = default; -void ConfigureDialog::setConfiguration() {} +void ConfigureDialog::setConfiguration() { + ui->generalTab->setConfiguration(); + ui->systemTab->setConfiguration(); + ui->inputTab->loadConfiguration(); + ui->graphicsTab->setConfiguration(); + ui->audioTab->setConfiguration(); + ui->cameraTab->setConfiguration(); + ui->debugTab->setConfiguration(); + ui->webTab->setConfiguration(); + ui->uiTab->setConfiguration(); +} void ConfigureDialog::applyConfiguration() { ui->generalTab->applyConfiguration(); @@ -44,12 +53,14 @@ void ConfigureDialog::applyConfiguration() { } void ConfigureDialog::PopulateSelectionList() { + ui->selectorList->clear(); const std::array, 4> items{ - {{tr("General"), {tr("General"), tr("Web"), tr("Debug"), tr("UI")}}, - {tr("System"), {tr("System"), tr("Audio"), tr("Camera")}}, - {tr("Graphics"), {tr("Graphics")}}, - {tr("Controls"), {tr("Input")}}}}; + {{tr("General"), + {QT_TR_NOOP("General"), QT_TR_NOOP("Web"), QT_TR_NOOP("Debug"), QT_TR_NOOP("UI")}}, + {tr("System"), {QT_TR_NOOP("System"), QT_TR_NOOP("Audio"), QT_TR_NOOP("Camera")}}, + {tr("Graphics"), {QT_TR_NOOP("Graphics")}}, + {tr("Controls"), {QT_TR_NOOP("Input")}}}}; for (const auto& entry : items) { auto* item = new QListWidgetItem(entry.first); @@ -61,7 +72,21 @@ void ConfigureDialog::PopulateSelectionList() { void ConfigureDialog::onLanguageChanged(const QString& locale) { emit languageChanged(locale); + // first apply the configuration, and then restore the display + applyConfiguration(); + retranslateUi(); + setConfiguration(); +} + +void ConfigureDialog::retranslateUi() { + int old_row = ui->selectorList->currentRow(); + int old_index = ui->tabWidget->currentIndex(); ui->retranslateUi(this); + PopulateSelectionList(); + // restore selection after repopulating + ui->selectorList->setCurrentRow(old_row); + ui->tabWidget->setCurrentIndex(old_index); + ui->generalTab->retranslateUi(); ui->systemTab->retranslateUi(); ui->inputTab->retranslateUi(); @@ -78,20 +103,15 @@ void ConfigureDialog::UpdateVisibleTabs() { if (items.isEmpty()) return; - const QHash widgets = {{tr("General"), ui->generalTab}, - {tr("System"), ui->systemTab}, - {tr("Input"), ui->inputTab}, - {tr("Graphics"), ui->graphicsTab}, - {tr("Audio"), ui->audioTab}, - {tr("Camera"), ui->cameraTab}, - {tr("Debug"), ui->debugTab}, - {tr("Web"), ui->webTab}, - {tr("UI"), ui->uiTab}}; + const QHash widgets = { + {"General", ui->generalTab}, {"System", ui->systemTab}, {"Input", ui->inputTab}, + {"Graphics", ui->graphicsTab}, {"Audio", ui->audioTab}, {"Camera", ui->cameraTab}, + {"Debug", ui->debugTab}, {"Web", ui->webTab}, {"UI", ui->uiTab}}; ui->tabWidget->clear(); QStringList tabs = items[0]->data(Qt::UserRole).toStringList(); for (const auto& tab : tabs) - ui->tabWidget->addTab(widgets[tab], tab); + ui->tabWidget->addTab(widgets[tab], tr(qPrintable(tab))); } diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index f78c1fd20e..6c0d9ef773 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -32,6 +32,7 @@ signals: private: void setConfiguration(); + void retranslateUi(); private: std::unique_ptr ui; diff --git a/src/citra_qt/configuration/configure_general.h b/src/citra_qt/configuration/configure_general.h index ff99c95103..121fb508ae 100644 --- a/src/citra_qt/configuration/configure_general.h +++ b/src/citra_qt/configuration/configure_general.h @@ -24,9 +24,8 @@ public: void ResetDefaults(); void applyConfiguration(); void retranslateUi(); - -private: void setConfiguration(); +private: std::unique_ptr ui; }; diff --git a/src/citra_qt/configuration/configure_graphics.h b/src/citra_qt/configuration/configure_graphics.h index 44514faf8f..b78e570fcd 100644 --- a/src/citra_qt/configuration/configure_graphics.h +++ b/src/citra_qt/configuration/configure_graphics.h @@ -20,8 +20,6 @@ public: void applyConfiguration(); void retranslateUi(); - -private: void setConfiguration(); private: diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index a0312d827e..c0c9aaeb18 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -343,5 +343,4 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) { void ConfigureInput::retranslateUi() { ui->retranslateUi(this); - updateButtonLabels(); } diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index 3bd4899549..0f8ce7d1b0 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -35,6 +35,9 @@ public: void applyConfiguration(); void retranslateUi(); + /// Load configuration settings. + void loadConfiguration(); + private: std::unique_ptr ui; @@ -69,8 +72,6 @@ private: /// keyboard events are ignored. bool want_keyboard_keys = false; - /// Load configuration settings. - void loadConfiguration(); /// Restore all buttons to their default values. void restoreDefaults(); /// Clear all input configuration diff --git a/src/citra_qt/configuration/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index 4239aea762..d142fc844e 100644 --- a/src/citra_qt/configuration/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp @@ -422,5 +422,4 @@ void ConfigureSystem::RefreshConsoleID() { void ConfigureSystem::retranslateUi() { ui->retranslateUi(this); - ReadSystemSettings(); } diff --git a/src/citra_qt/configuration/configure_ui.h b/src/citra_qt/configuration/configure_ui.h index cb1b9790fd..feff6268de 100644 --- a/src/citra_qt/configuration/configure_ui.h +++ b/src/citra_qt/configuration/configure_ui.h @@ -20,6 +20,7 @@ public: void applyConfiguration(); void retranslateUi(); + void setConfiguration(); private slots: void onLanguageChanged(int index); @@ -28,7 +29,5 @@ signals: void languageChanged(const QString& locale); private: - void setConfiguration(); - std::unique_ptr ui; }; diff --git a/src/citra_qt/configuration/configure_ui.ui b/src/citra_qt/configuration/configure_ui.ui index 87eeb3e150..5b7d054afc 100644 --- a/src/citra_qt/configuration/configure_ui.ui +++ b/src/citra_qt/configuration/configure_ui.ui @@ -22,6 +22,16 @@ + + + + Note: Changing language will apply your configuration. + + + true + + + diff --git a/src/citra_qt/configuration/configure_web.h b/src/citra_qt/configuration/configure_web.h index 7741ab95d7..e2711ee446 100644 --- a/src/citra_qt/configuration/configure_web.h +++ b/src/citra_qt/configuration/configure_web.h @@ -21,6 +21,7 @@ public: void applyConfiguration(); void retranslateUi(); + void setConfiguration(); public slots: void RefreshTelemetryID(); @@ -29,8 +30,6 @@ public slots: void OnLoginVerified(); private: - void setConfiguration(); - bool user_verified = true; QFutureWatcher verify_watcher;