From ff522eff274adb15595bb95eb50fd5048d364b53 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 27 Nov 2021 12:19:04 -0500 Subject: [PATCH] Retranslate the settings modal when language changes --- src/mainwindow.cpp | 30 +++++++----------------------- src/mainwindow.h | 13 +++---------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f63d038..c771c92 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,9 +22,6 @@ #include "requestdialog.h" #include "websockets.h" -SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { -} - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -195,6 +192,10 @@ void MainWindow::slotLanguageChanged(QString lang) if(lang != "") { // load the language loadLanguage(lang); + + QDialog settingsDialog(this); + qDebug() << __func__ << ": retranslating settingsDialog"; + settings.retranslateUi(&settingsDialog); } } @@ -342,27 +343,11 @@ void MainWindow::setupStatusBar() { ui->statusBar->addPermanentWidget(statusIcon); } -// something like this is needed for QDialogs to listen to changeEvent -// so the Settings modal gets retranslated -// https://stackoverflow.com/questions/68665394/how-to-use-retranslateui-recursively-on-all-ui-in-qmainwindow -void SettingsDialog::changeEvent(QEvent* event) { - Ui_Settings settings; - qDebug() << __func__ << ":changeEvent type=" << event->type(); - if (event->type() == QEvent::LanguageChange) { - SettingsDialog settingsDialog(this); - settings.retranslateUi(&settingsDialog); - } - - QWidget::changeEvent(event); -} - void MainWindow::setupSettingsModal() { // Set up File -> Settings action QObject::connect(ui->actionSettings, &QAction::triggered, [=]() { - // this coredumps at run-time - //SettingsDialog settingsDialog(this); QDialog settingsDialog(this); - Ui_Settings settings; + //Ui_Settings settings; settings.setupUi(&settingsDialog); Settings::saveRestore(&settingsDialog); @@ -397,7 +382,7 @@ void MainWindow::setupSettingsModal() { QObject::connect(settings.comboBoxTheme, &QComboBox::currentTextChanged, [=] (QString theme_name) { this->slot_change_theme(theme_name); - QMessageBox::information(this, tr("Theme Change"), tr("This change can take a few seconds."), QMessageBox::Ok); + // QMessageBox::information(this, tr("Theme Change"), tr("This change can take a few seconds."), QMessageBox::Ok); }); @@ -408,7 +393,7 @@ void MainWindow::setupSettingsModal() { QObject::connect(settings.comboBoxCurrency, &QComboBox::currentTextChanged, [=] (QString ticker) { this->slot_change_currency(ticker); rpc->refresh(true); - QMessageBox::information(this, tr("Currency Change"), tr("This change can take a few seconds."), QMessageBox::Ok); + // QMessageBox::information(this, tr("Currency Change"), tr("This change can take a few seconds."), QMessageBox::Ok); }); // Save sent transactions @@ -441,7 +426,6 @@ void MainWindow::setupSettingsModal() { } //Use Consolidation - bool isUsingConsolidation = false; int size = 0; qDebug() << __func__ << ": hushDir=" << rpc->getConnection()->config->hushDir; diff --git a/src/mainwindow.h b/src/mainwindow.h index a811665..0b75c6c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -6,6 +6,7 @@ #include "precompiled.h" #include "logger.h" #include +#include "ui_settings.h" // Forward declare to break circular dependency. class RPC; @@ -32,15 +33,6 @@ namespace Ui { class MainWindow; } -class SettingsDialog : public QDialog -{ - Q_OBJECT -public: - explicit SettingsDialog(QWidget *parent = nullptr); - // this event is called, when a new translator is loaded or the system language is changed - void changeEvent(QEvent* event); -}; - class MainWindow : public QMainWindow { Q_OBJECT @@ -73,6 +65,7 @@ public: void updateFromCombo(); Ui::MainWindow* ui; + Ui_Settings settings; QLabel* statusLabel; QLabel* statusIcon; @@ -81,11 +74,11 @@ public: Logger* logger; void doClose(); + protected: // this event is called, when a new translator is loaded or the system language is changed void changeEvent(QEvent* event); - //void slotLanguageChanged(QAction* action); protected slots: // this slot is called by the language menu actions void slotLanguageChanged(QString lang);