From c09ff382a41cfc631efa9392bdb3143bd4c713a5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 5 Jun 2019 18:39:46 -0400 Subject: 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. --- .../configuration/configure_profile_manager.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/yuzu/configuration/configure_profile_manager.cpp') diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp index 7c1597488..c90f4cdd8 100644 --- a/src/yuzu/configuration/configure_profile_manager.cpp +++ b/src/yuzu/configuration/configure_profile_manager.cpp @@ -80,11 +80,10 @@ ConfigureProfileManager ::ConfigureProfileManager(QWidget* parent) profile_manager(std::make_unique()) { ui->setupUi(this); - layout = new QVBoxLayout; tree_view = new QTreeView; item_model = new QStandardItemModel(tree_view); + item_model->insertColumns(0, 1); tree_view->setModel(item_model); - tree_view->setAlternatingRowColors(true); tree_view->setSelectionMode(QHeaderView::SingleSelection); tree_view->setSelectionBehavior(QHeaderView::SelectRows); @@ -96,13 +95,11 @@ ConfigureProfileManager ::ConfigureProfileManager(QWidget* parent) tree_view->setIconSize({64, 64}); tree_view->setContextMenuPolicy(Qt::NoContextMenu); - item_model->insertColumns(0, 1); - item_model->setHeaderData(0, Qt::Horizontal, tr("Users")); - // We must register all custom types with the Qt Automoc system so that we are able to use it // with signals/slots. In this case, QList falls under the umbrells of custom types. qRegisterMetaType>("QList"); + layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); layout->addWidget(tree_view); @@ -120,10 +117,24 @@ ConfigureProfileManager ::ConfigureProfileManager(QWidget* parent) ui->current_user_icon->setScene(scene); SetConfiguration(); + RetranslateUI(); } ConfigureProfileManager::~ConfigureProfileManager() = default; +void ConfigureProfileManager::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QWidget::changeEvent(event); +} + +void ConfigureProfileManager::RetranslateUI() { + ui->retranslateUi(this); + item_model->setHeaderData(0, Qt::Horizontal, tr("Users")); +} + void ConfigureProfileManager::SetConfiguration() { enabled = !Core::System::GetInstance().IsPoweredOn(); item_model->removeRows(0, item_model->rowCount()); -- cgit v1.2.3