summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-05-04 00:33:50 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-05-04 00:33:50 +0200
commit79415b76442ac6f8307ec0e10accec32383fabb9 (patch)
treeb393ba96a348bec7eb2ef9887a039366f500fc09
parentb60bb2ed272972847cb533be2e86bd2d7e565918 (diff)
downloadGUI_SS2015-79415b76442ac6f8307ec0e10accec32383fabb9.tar.gz
GUI_SS2015-79415b76442ac6f8307ec0e10accec32383fabb9.zip
Add translations that are changeable during runtime
-rw-r--r--GUI_SS2015.pro15
-rw-r--r--german.qmbin0 -> 801 bytes
-rw-r--r--languagedialog.cpp52
-rw-r--r--languagedialog.h38
-rw-r--r--languagedialog.ui87
-rw-r--r--main.cpp7
-rw-r--r--mainwindow.cpp61
-rw-r--r--mainwindow.h13
-rw-r--r--mainwindow.ui6
-rw-r--r--translations.qrc5
10 files changed, 275 insertions, 9 deletions
diff --git a/GUI_SS2015.pro b/GUI_SS2015.pro
index f6527fc..263d369 100644
--- a/GUI_SS2015.pro
+++ b/GUI_SS2015.pro
@@ -15,11 +15,20 @@ TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
dlgpreferences.cpp \
- interactioncanvas.cpp
+ interactioncanvas.cpp \
+ languagedialog.cpp
HEADERS += mainwindow.h \
dlgpreferences.h \
- interactioncanvas.h
+ interactioncanvas.h \
+ languagedialog.h
FORMS += mainwindow.ui \
- dlgpreferences.ui
+ dlgpreferences.ui \
+ languagedialog.ui
+
+TRANSLATIONS += \
+ german.ts
+
+RESOURCES += \
+ translations.qrc
diff --git a/german.qm b/german.qm
new file mode 100644
index 0000000..ed7e949
--- /dev/null
+++ b/german.qm
Binary files differ
diff --git a/languagedialog.cpp b/languagedialog.cpp
new file mode 100644
index 0000000..c470a30
--- /dev/null
+++ b/languagedialog.cpp
@@ -0,0 +1,52 @@
+#include "languagedialog.h"
+#include "ui_languagedialog.h"
+
+LanguageDialog::LanguageDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::LanguageDialog)
+{
+ ui->setupUi(this);
+}
+
+LanguageDialog::~LanguageDialog()
+{
+ delete ui;
+}
+
+int LanguageDialog::language() const
+{
+ return m_language;
+}
+
+void LanguageDialog::setLanguage(int arg)
+{
+ if (m_language == arg)
+ {
+ return;
+ }
+
+ switch (arg)
+ {
+ case 0:
+ ui->radioButtonEnglish->setChecked(true);
+ break;
+
+ case 1:
+ ui->radioButtonGerman->setChecked(true);
+ break;
+ }
+
+ m_language = arg;
+ emit languageChanged(arg);
+}
+
+void LanguageDialog::on_radioButtonEnglish_clicked()
+{
+ m_language = 0;
+}
+
+
+void LanguageDialog::on_radioButtonGerman_clicked()
+{
+ m_language = 1;
+}
diff --git a/languagedialog.h b/languagedialog.h
new file mode 100644
index 0000000..4dd0c61
--- /dev/null
+++ b/languagedialog.h
@@ -0,0 +1,38 @@
+#ifndef LANGUAGEDIALOG_H
+#define LANGUAGEDIALOG_H
+
+#include <QDialog>
+#include <QTranslator>
+
+namespace Ui {
+class LanguageDialog;
+}
+
+class LanguageDialog : public QDialog
+{
+ Q_OBJECT
+ Q_PROPERTY(int language READ language WRITE setLanguage NOTIFY languageChanged)
+
+public:
+ explicit LanguageDialog(QWidget *parent = 0);
+ ~LanguageDialog();
+
+ int language() const;
+
+public slots:
+ void setLanguage(int arg);
+
+signals:
+ void languageChanged(int arg);
+
+private slots:
+ void on_radioButtonEnglish_clicked();
+
+ void on_radioButtonGerman_clicked();
+
+private:
+ Ui::LanguageDialog *ui;
+ int m_language;
+};
+
+#endif // LANGUAGEDIALOG_H
diff --git a/languagedialog.ui b/languagedialog.ui
new file mode 100644
index 0000000..366541b
--- /dev/null
+++ b/languagedialog.ui
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LanguageDialog</class>
+ <widget class="QDialog" name="LanguageDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Language</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="radioButtonEnglish">
+ <property name="text">
+ <string>Eng&amp;lish</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonGerman">
+ <property name="text">
+ <string>Deuts&amp;ch</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>LanguageDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>LanguageDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/main.cpp b/main.cpp
index b48f94e..0649a69 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,9 +1,16 @@
#include "mainwindow.h"
#include <QApplication>
+#include <QLocale>
+#include <QTranslator>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
+
+// QTranslator translator;
+// translator.load(":/translations.pm");
+// a.installTranslator(&translator);
+
MainWindow w;
w.show();
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);
+}
diff --git a/mainwindow.h b/mainwindow.h
index 410878f..10976c4 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -6,6 +6,7 @@
#include <QMouseEvent>
#include "dlgpreferences.h"
#include "interactioncanvas.h"
+#include "languagedialog.h"
namespace Ui {
class MainWindow;
@@ -22,14 +23,20 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
+ void loadLanguage(const QString &rLanguageFile);
+
+protected:
+ void mouseMoveEvent(QMouseEvent *mouseEvent);
+
private slots:
void on_actionPreferences_triggered();
+ void on_actionLanguage_triggered();
+
+ void changeEvent(QEvent *event);
private:
Ui::MainWindow *ui;
+ QTranslator m_translator; // contains the translations for this application
- // QWidget interface
-protected:
- void mouseMoveEvent(QMouseEvent *mouseEvent);
};
#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
index 8e92663..209a4b9 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -37,6 +37,7 @@
<string>Edi&amp;t</string>
</property>
<addaction name="actionPreferences"/>
+ <addaction name="actionLanguage"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
@@ -66,6 +67,11 @@
<string>&amp;About</string>
</property>
</action>
+ <action name="actionLanguage">
+ <property name="text">
+ <string>&amp;Language</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
diff --git a/translations.qrc b/translations.qrc
new file mode 100644
index 0000000..dabca70
--- /dev/null
+++ b/translations.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>german.qm</file>
+ </qresource>
+</RCC>