Skip to content

Commit

Permalink
Fix translation of dock titles
Browse files Browse the repository at this point in the history
Docks are created from tabs and no longer managed by mainwindow.ui. Perform
retranslation when necessary.
  • Loading branch information
Vogtinator committed Dec 30, 2022
1 parent 880ccf7 commit 26585bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ MainWindow::MainWindow(QWidget *parent) :

//Load settings
convertTabsToDocks();
retranslateDocks();
setExtLCD(settings->value(QStringLiteral("extLCDVisible")).toBool());
lcd.restoreGeometry(settings->value(QStringLiteral("extLCDGeometry")).toByteArray());
restoreGeometry(settings->value(QStringLiteral("windowGeometry")).toByteArray());
Expand Down Expand Up @@ -271,6 +272,7 @@ void MainWindow::changeEvent(QEvent* event)
{
ui->retranslateUi(this);
updateWindowTitle();
retranslateDocks();
}
else if (eventType == QEvent::LocaleChange)
switchTranslator(QLocale::system());
Expand Down Expand Up @@ -532,7 +534,8 @@ void MainWindow::convertTabsToDocks()
DockWidget *dw = new DockWidget(ui->tabWidget->tabText(0), this);
dw->hideTitlebar(true); // Create with hidden titlebar to not resize the window on startup
dw->setWindowIcon(ui->tabWidget->tabIcon(0));
dw->setObjectName(dw->windowTitle());
// This is used for storing window state, so must not be translated at this point
dw->setObjectName(ui->tabWidget->tabText(0));

// Fill "Docks" menu
QAction *action = dw->toggleViewAction();
Expand All @@ -557,6 +560,23 @@ void MainWindow::convertTabsToDocks()
ui->tabWidget->setHidden(true);
}

void MainWindow::retranslateDocks()
{
// The docks are not handled by mainwindow.ui but got created by
// convertTabsToDocks() above, so translation needs to be done manually.
const auto dockChildren = findChildren<DockWidget*>();
for(DockWidget *dw : dockChildren) {
if(dw->widget() == ui->tab)
dw->setWindowTitle(tr("Keypad"));
else if(dw->widget() == ui->tabFiles)
dw->setWindowTitle(tr("File Transfer"));
else if(dw->widget() == ui->tabSerial)
dw->setWindowTitle(tr("Serial Monitor"));
else if(dw->widget() == ui->tabDebugger)
dw->setWindowTitle(tr("Debugger"));
}
}

void MainWindow::showSpeed(double value)
{
ui->buttonSpeed->setText(tr("Speed: %1 %").arg(value * 100, 1, 'f', 0));
Expand Down
1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public slots:
bool resumeFromPath(QString path);

void convertTabsToDocks();
void retranslateDocks();

void updateUIActionState(bool emulation_running);
void raiseDebugger();
Expand Down

0 comments on commit 26585bf

Please sign in to comment.