diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-04 00:33:50 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-04 00:33:50 +0200 |
| commit | 79415b76442ac6f8307ec0e10accec32383fabb9 (patch) | |
| tree | b393ba96a348bec7eb2ef9887a039366f500fc09 /mainwindow.cpp | |
| parent | b60bb2ed272972847cb533be2e86bd2d7e565918 (diff) | |
| download | GUI_SS2015-79415b76442ac6f8307ec0e10accec32383fabb9.tar.gz GUI_SS2015-79415b76442ac6f8307ec0e10accec32383fabb9.zip | |
Add translations that are changeable during runtime
Diffstat (limited to 'mainwindow.cpp')
| -rw-r--r-- | mainwindow.cpp | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 5a548db..8bc0a22 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -26,17 +26,17 @@ void MainWindow::on_actionPreferences_triggered() tmp->setHeight(size().height()); tmp->setWidth(size().width()); - if(tmp->exec()) + if (tmp->exec()) { qDebug() << "DlgPreferences okay clicked."; int width = tmp->Width(); int height = tmp->Height(); - if(width >= 100 && width <= 800 && height >= 100 && height <= 800) + if (width >= 100 && width <= 800 && height >= 100 && height <= 800) { qDebug() << "Resizing QMainWindow."; - resize(width,height); + resize(width, height); } } @@ -44,7 +44,62 @@ void MainWindow::on_actionPreferences_triggered() } +void MainWindow::on_actionLanguage_triggered() +{ + LanguageDialog *tmp = new LanguageDialog(this); + + if (QLocale::system().language() == QLocale::German) + { + tmp->setLanguage(1); + } + else + { + tmp->setLanguage(0); + } + + if (tmp->exec()) + { + switch (tmp->language()) + { + case 0: + qDebug() << "English"; + loadLanguage(":/english.qm"); + + break; + + case 1: + qDebug() << "German"; + loadLanguage(":/german.qm"); + + break; + } + } +} + + void MainWindow::mouseMoveEvent(QMouseEvent *mouseEvent) { qDebug() << "MainWindow:" << mouseEvent->pos(); } + +void MainWindow::loadLanguage(const QString& rLanguageFile) +{ + // remove the old translator + qApp->removeTranslator(&m_translator); + + // load the new translator + if (m_translator.load(rLanguageFile)) + { + qApp->installTranslator(&m_translator); + } +} + +void MainWindow::changeEvent(QEvent *event) +{ + if (event != 0 && event->type() == QEvent::LanguageChange) + { + ui->retranslateUi(this); + } + + QMainWindow::changeEvent(event); +} |
