From b46ab646dc7cd156ff20b3167a40218e5a06cb6f Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Sat, 31 Dec 2022 21:52:53 +0100 Subject: [PATCH] Fix translation of FBAboutDialog It needs to react to language change events to behave properly, also to get the initial language correct. --- fbaboutdialog.cpp | 58 ++++++++++++++++++++++++++++++++--------------- fbaboutdialog.h | 7 +++++- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/fbaboutdialog.cpp b/fbaboutdialog.cpp index afc56052..eaa70d4c 100644 --- a/fbaboutdialog.cpp +++ b/fbaboutdialog.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -17,41 +18,28 @@ FBAboutDialog::FBAboutDialog(QWidget *parent) : QDialog(parent) { + retranslateUi(); + QIcon icon{QStringLiteral(":/icons/resources/org.firebird-emus.firebird-emu.png")}; iconLabel.setPixmap(icon.pixmap(icon.actualSize(QSize{64, 64}))); - setWindowTitle(tr("About Firebird")); - header.setText(tr("

Firebird %1

" - "On GitHub").arg(QStringLiteral(STRINGIFY(FB_VERSION)))); header.setTextInteractionFlags(Qt::TextBrowserInteraction); header.setOpenExternalLinks(true); - update.setText(tr("Checking for update")); update.setTextInteractionFlags(Qt::TextBrowserInteraction); update.setOpenExternalLinks(true); - authors.setText(tr( "Authors:
" - "Fabian Vogt (Vogtinator)
" - "Adrien Bertrand (Adriweb)
" - "Antonio Vasquez (antoniovazquezblanco)
" - "Lionel Debroux (debrouxl)
" - "Denis Avashurov (denisps)
" - "Based on nspire_emu v0.70 by Goplat

" - "This work is licensed under the GPLv3.
" - "To view a copy of this license, visit https://www.gnu.org/licenses/gpl-3.0.html")); authors.setTextInteractionFlags(Qt::TextBrowserInteraction); authors.setOpenExternalLinks(true); - auto *okButton = new QPushButton(tr("Ok")); - connect(okButton, SIGNAL(clicked(bool)), this, SLOT(close())); - okButton->setDefault(true); + connect(&okButton, SIGNAL(clicked(bool)), this, SLOT(close())); + okButton.setDefault(true); - updateButton.setText(tr("Check for Update")); updateButton.setAutoDefault(false); connect(&updateButton, SIGNAL(clicked(bool)), this, SLOT(checkForUpdate())); auto *buttonBox = new QDialogButtonBox(Qt::Horizontal); - buttonBox->addButton(okButton, QDialogButtonBox::AcceptRole); + buttonBox->addButton(&okButton, QDialogButtonBox::AcceptRole); buttonBox->addButton(&updateButton, QDialogButtonBox::ActionRole); auto *layout = new QVBoxLayout; @@ -65,6 +53,40 @@ FBAboutDialog::FBAboutDialog(QWidget *parent) hlayout->addLayout(layout); } +void FBAboutDialog::changeEvent(QEvent* event) +{ + if (event->type() == QEvent::LanguageChange) + retranslateUi(); + + QDialog::changeEvent(event); +} + +void FBAboutDialog::retranslateUi() +{ + setWindowTitle(tr("About Firebird")); + header.setText(tr("

Firebird %1

" + "On GitHub").arg(QStringLiteral(STRINGIFY(FB_VERSION)))); + + authors.setText(tr( "Authors:
" + "Fabian Vogt (Vogtinator)
" + "Adrien Bertrand (Adriweb)
" + "Antonio Vasquez (antoniovazquezblanco)
" + "Lionel Debroux (debrouxl)
" + "Denis Avashurov (denisps)
" + "Based on nspire_emu v0.70 by Goplat

" + "This work is licensed under the GPLv3.
" + "To view a copy of this license, visit https://www.gnu.org/licenses/gpl-3.0.html")); + + update.setText(tr("Checking for update")); + + okButton.setText(tr("Ok")); + updateButton.setText(tr("Check for Update")); + + // If necessary, refresh the status text. Easiest way is to just check again. + if(isVisible() || checkSuccessful) + QTimer::singleShot(0, this, SLOT(checkForUpdate())); +} + void FBAboutDialog::checkForUpdate() { updateButton.setDisabled(true); diff --git a/fbaboutdialog.h b/fbaboutdialog.h index ccffc09e..eeddc2e3 100644 --- a/fbaboutdialog.h +++ b/fbaboutdialog.h @@ -19,11 +19,16 @@ public slots: void setVisible(bool v) override; +protected: + void changeEvent(QEvent* event) override; + private: + void retranslateUi(); + bool checkSuccessful = false; QLabel iconLabel, header, update, authors; - QPushButton updateButton; + QPushButton okButton, updateButton; QNetworkReply *reply; QNetworkAccessManager nam; };