From 391f3300448c6c04e949514ef8a1c5a384c29745 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 26 Nov 2021 21:38:33 -0500 Subject: [PATCH] Render language list as a QComboBox --- src/mainwindow.cpp | 41 ++++++++++++++++++++++++++--------------- src/mainwindow.h | 4 ++-- src/settings.ui | 8 +++++++- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d6ef5ae..a17fc7a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -186,13 +186,13 @@ void MainWindow::doClose() { } // Called every time, when a menu entry of the language menu is called -void MainWindow::slotLanguageChanged(QAction* action) +void MainWindow::slotLanguageChanged(QString lang) { - qDebug() << __func__ << ": action=" << action->data().toString(); - if(0 != action) { - // load the language dependant on the action content - loadLanguage(action->data().toString()); - setWindowIcon(action->icon()); + qDebug() << __func__ << ": lang=" << lang; + if(lang != "") { + // load the language + loadLanguage(lang); + //setWindowIcon(action->icon()); } } @@ -210,9 +210,13 @@ void switchTranslator(QTranslator& translator, const QString& filename) { } } -void MainWindow::loadLanguage(const QString& rLanguage) { - qDebug() << "loadLanguage " << rLanguage; +void MainWindow::loadLanguage(QString& rLanguage) { + qDebug() << __func__ << ": currLang=" << m_currLang << " rLanguage=" << rLanguage; if(m_currLang != rLanguage) { + qDebug() << __func__ << ": changing language"; + if(rLanguage == "Russian") { + rLanguage = "ru"; + } m_currLang = rLanguage; QLocale locale = QLocale(m_currLang); QLocale::setDefault(locale); @@ -367,6 +371,11 @@ void MainWindow::setupSettingsModal() { QMessageBox::information(this, tr("Theme Change"), tr("This change can take a few seconds."), QMessageBox::Ok); }); + QObject::connect(settings.comboBoxLanguage, &QComboBox::currentTextChanged, [=] (QString lang) { + this->slotLanguageChanged(lang); + //QMessageBox::information(this, tr("Language Changed"), tr("This change can take a few seconds."), QMessageBox::Ok); + }); + // Set local currency QString ticker = Settings::getInstance()->get_currency_name(); int currency_index = settings.comboBoxCurrency->findText(ticker, Qt::MatchExactly); @@ -485,16 +494,19 @@ void MainWindow::setupSettingsModal() { settings.testnetAddressExplorerUrl->setText(explorer.testnetAddressExplorerUrl); /// create language drop down dynamically - QActionGroup* langGroup = new QActionGroup(settings.menuLanguage); + QActionGroup* langGroup = new QActionGroup(settings.comboBoxLanguage); langGroup->setExclusive(true); - qDebug() << __func__ << ": connecting langGroup to slotLanguageChanged"; - connect(langGroup, SIGNAL (triggered(QAction *)), this, SLOT (slotLanguageChanged(QAction *))); + //qDebug() << __func__ << ": connecting langGroup to slotLanguageChanged"; + //connect(langGroup, SIGNAL (triggered(QAction *)), this, SLOT (slotLanguageChanged(QAction *))); // format systems language QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" + //QString defaultLang = QLocale::languageToString(QLocale("en").language()); + settings.comboBoxLanguage->addItem("English"); + m_langPath = QApplication::applicationDirPath(); m_langPath.append("/res"); @@ -520,19 +532,18 @@ void MainWindow::setupSettingsModal() { action->setCheckable(true); action->setData(locale); - settings.menuLanguage->addAction(action); + //settings.comboBoxLanguage->addItem(action); + settings.comboBoxLanguage->addItem(lang); langGroup->addAction(action); qDebug() << __func__ << ": added language=" << locale; // set default translators and language checked if (defaultLocale == locale) { action->setChecked(true); + qDebug() << " set defaultLocale=" << locale << " to checked"; } } - - /// - // Connection tab by default settings.tabWidget->setCurrentIndex(0); diff --git a/src/mainwindow.h b/src/mainwindow.h index c5ef26d..a6a6c13 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -79,13 +79,13 @@ protected: //void slotLanguageChanged(QAction* action); protected slots: // this slot is called by the language menu actions - void slotLanguageChanged(QAction *action); + void slotLanguageChanged(QString lang); private: void closeEvent(QCloseEvent* event); // loads a language by the given language shortcode (e.g. de, en) - void loadLanguage(const QString& rLanguage); + void loadLanguage(QString& rLanguage); void setupSendTab(); void setupPeersTab(); diff --git a/src/settings.ui b/src/settings.ui index ce4887f..8ed308f 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -196,7 +196,13 @@ - + + + + 0 + 0 + +