Skip to content

Commit b46ab64

Browse files
committed
Fix translation of FBAboutDialog
It needs to react to language change events to behave properly, also to get the initial language correct.
1 parent 26585bf commit b46ab64

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

fbaboutdialog.cpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <QJsonDocument>
66
#include <QJsonObject>
77

8+
#include <QEvent>
89
#include <QIcon>
910
#include <QDialogButtonBox>
1011
#include <QVBoxLayout>
@@ -17,41 +18,28 @@
1718
FBAboutDialog::FBAboutDialog(QWidget *parent)
1819
: QDialog(parent)
1920
{
21+
retranslateUi();
22+
2023
QIcon icon{QStringLiteral(":/icons/resources/org.firebird-emus.firebird-emu.png")};
2124
iconLabel.setPixmap(icon.pixmap(icon.actualSize(QSize{64, 64})));
2225

23-
setWindowTitle(tr("About Firebird"));
24-
header.setText(tr("<h3>Firebird %1</h3>"
25-
"<a href='https://github.com/nspire-emus/firebird'>On GitHub</a>").arg(QStringLiteral(STRINGIFY(FB_VERSION))));
2626
header.setTextInteractionFlags(Qt::TextBrowserInteraction);
2727
header.setOpenExternalLinks(true);
2828

29-
update.setText(tr("Checking for update"));
3029
update.setTextInteractionFlags(Qt::TextBrowserInteraction);
3130
update.setOpenExternalLinks(true);
3231

33-
authors.setText(tr( "Authors:<br>"
34-
"Fabian Vogt (<a href='https://github.com/Vogtinator'>Vogtinator</a>)<br>"
35-
"Adrien Bertrand (<a href='https://github.com/adriweb'>Adriweb</a>)<br>"
36-
"Antonio Vasquez (<a href='https://github.com/antoniovazquezblanco'>antoniovazquezblanco</a>)<br>"
37-
"Lionel Debroux (<a href='https://github.com/debrouxl'>debrouxl</a>)<br>"
38-
"Denis Avashurov (<a href='https://github.com/denisps'>denisps</a>)<br>"
39-
"Based on nspire_emu v0.70 by Goplat<br><br>"
40-
"This work is licensed under the GPLv3.<br>"
41-
"To view a copy of this license, visit <a href='https://www.gnu.org/licenses/gpl-3.0.html'>https://www.gnu.org/licenses/gpl-3.0.html</a>"));
4232
authors.setTextInteractionFlags(Qt::TextBrowserInteraction);
4333
authors.setOpenExternalLinks(true);
4434

45-
auto *okButton = new QPushButton(tr("Ok"));
46-
connect(okButton, SIGNAL(clicked(bool)), this, SLOT(close()));
47-
okButton->setDefault(true);
35+
connect(&okButton, SIGNAL(clicked(bool)), this, SLOT(close()));
36+
okButton.setDefault(true);
4837

49-
updateButton.setText(tr("Check for Update"));
5038
updateButton.setAutoDefault(false);
5139
connect(&updateButton, SIGNAL(clicked(bool)), this, SLOT(checkForUpdate()));
5240

5341
auto *buttonBox = new QDialogButtonBox(Qt::Horizontal);
54-
buttonBox->addButton(okButton, QDialogButtonBox::AcceptRole);
42+
buttonBox->addButton(&okButton, QDialogButtonBox::AcceptRole);
5543
buttonBox->addButton(&updateButton, QDialogButtonBox::ActionRole);
5644

5745
auto *layout = new QVBoxLayout;
@@ -65,6 +53,40 @@ FBAboutDialog::FBAboutDialog(QWidget *parent)
6553
hlayout->addLayout(layout);
6654
}
6755

56+
void FBAboutDialog::changeEvent(QEvent* event)
57+
{
58+
if (event->type() == QEvent::LanguageChange)
59+
retranslateUi();
60+
61+
QDialog::changeEvent(event);
62+
}
63+
64+
void FBAboutDialog::retranslateUi()
65+
{
66+
setWindowTitle(tr("About Firebird"));
67+
header.setText(tr("<h3>Firebird %1</h3>"
68+
"<a href='https://github.com/nspire-emus/firebird'>On GitHub</a>").arg(QStringLiteral(STRINGIFY(FB_VERSION))));
69+
70+
authors.setText(tr( "Authors:<br>"
71+
"Fabian Vogt (<a href='https://github.com/Vogtinator'>Vogtinator</a>)<br>"
72+
"Adrien Bertrand (<a href='https://github.com/adriweb'>Adriweb</a>)<br>"
73+
"Antonio Vasquez (<a href='https://github.com/antoniovazquezblanco'>antoniovazquezblanco</a>)<br>"
74+
"Lionel Debroux (<a href='https://github.com/debrouxl'>debrouxl</a>)<br>"
75+
"Denis Avashurov (<a href='https://github.com/denisps'>denisps</a>)<br>"
76+
"Based on nspire_emu v0.70 by Goplat<br><br>"
77+
"This work is licensed under the GPLv3.<br>"
78+
"To view a copy of this license, visit <a href='https://www.gnu.org/licenses/gpl-3.0.html'>https://www.gnu.org/licenses/gpl-3.0.html</a>"));
79+
80+
update.setText(tr("Checking for update"));
81+
82+
okButton.setText(tr("Ok"));
83+
updateButton.setText(tr("Check for Update"));
84+
85+
// If necessary, refresh the status text. Easiest way is to just check again.
86+
if(isVisible() || checkSuccessful)
87+
QTimer::singleShot(0, this, SLOT(checkForUpdate()));
88+
}
89+
6890
void FBAboutDialog::checkForUpdate()
6991
{
7092
updateButton.setDisabled(true);

fbaboutdialog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ public slots:
1919

2020
void setVisible(bool v) override;
2121

22+
protected:
23+
void changeEvent(QEvent* event) override;
24+
2225
private:
26+
void retranslateUi();
27+
2328
bool checkSuccessful = false;
2429

2530
QLabel iconLabel, header, update, authors;
26-
QPushButton updateButton;
31+
QPushButton okButton, updateButton;
2732
QNetworkReply *reply;
2833
QNetworkAccessManager nam;
2934
};

0 commit comments

Comments
 (0)