diff options
author | Lioncash <mathew1800@gmail.com> | 2019-06-05 18:39:46 -0400 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-06-05 21:57:21 -0400 |
commit | c09ff382a41cfc631efa9392bdb3143bd4c713a5 (patch) | |
tree | a1755331546012b9c1e5711d78372bc4dda1bce7 /src/yuzu/configuration/configure_input.cpp | |
parent | 8d7a012297ea884f0309ed2207eeb5e6c8d6a495 (diff) |
yuzu/configuration: Make all widgets and dialogs aware of language changes
To prepare for translation support, this makes all of the widgets
cognizant of the language change event that occurs whenever
installTranslator() is called and automatically retranslates their text
where necessary.
This is important as calling the backing UI's retranslateUi() is often
not enough, particularly in cases where we add our own strings that
aren't controlled by it. In that case we need to manually refresh the
strings ourselves.
Diffstat (limited to 'src/yuzu/configuration/configure_input.cpp')
-rw-r--r-- | src/yuzu/configuration/configure_input.cpp | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index fb1210bcb..4dd775aab 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp @@ -5,6 +5,7 @@ #include <algorithm> #include <memory> +#include <QSignalBlocker> #include <QTimer> #include "configuration/configure_touchscreen_advanced.h" @@ -74,11 +75,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) ui->player5_configure, ui->player6_configure, ui->player7_configure, ui->player8_configure, }; - for (auto* controller_box : players_controller) { - controller_box->addItems({tr("None"), tr("Pro Controller"), tr("Dual Joycons"), - tr("Single Right Joycon"), tr("Single Left Joycon")}); - } - + RetranslateUI(); LoadConfiguration(); UpdateUIEnabled(); @@ -144,6 +141,31 @@ void ConfigureInput::ApplyConfiguration() { Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked(); } +void ConfigureInput::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QDialog::changeEvent(event); +} + +void ConfigureInput::RetranslateUI() { + ui->retranslateUi(this); + RetranslateControllerComboBoxes(); +} + +void ConfigureInput::RetranslateControllerComboBoxes() { + for (auto* controller_box : players_controller) { + [[maybe_unused]] const QSignalBlocker blocker(controller_box); + + controller_box->clear(); + controller_box->addItems({tr("None"), tr("Pro Controller"), tr("Dual Joycons"), + tr("Single Right Joycon"), tr("Single Left Joycon")}); + } + + LoadPlayerControllerIndices(); +} + void ConfigureInput::UpdateUIEnabled() { bool hit_disabled = false; for (auto* player : players_controller) { @@ -175,11 +197,7 @@ void ConfigureInput::LoadConfiguration() { Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD), [](const auto& player) { return player.connected; }); - for (std::size_t i = 0; i < players_controller.size(); ++i) { - const auto connected = Settings::values.players[i].connected; - players_controller[i]->setCurrentIndex( - connected ? static_cast<u8>(Settings::values.players[i].type) + 1 : 0); - } + LoadPlayerControllerIndices(); ui->use_docked_mode->setChecked(Settings::values.use_docked_mode); ui->handheld_connected->setChecked( @@ -194,6 +212,14 @@ void ConfigureInput::LoadConfiguration() { UpdateUIEnabled(); } +void ConfigureInput::LoadPlayerControllerIndices() { + for (std::size_t i = 0; i < players_controller.size(); ++i) { + const auto connected = Settings::values.players[i].connected; + players_controller[i]->setCurrentIndex( + connected ? static_cast<u8>(Settings::values.players[i].type) + 1 : 0); + } +} + void ConfigureInput::RestoreDefaults() { players_controller[0]->setCurrentIndex(2); |