From b59b226da8b5bdc29585bc1970163c1bf02b2c5a Mon Sep 17 00:00:00 2001 From: spacy51 Date: Sun, 10 Feb 2008 00:08:37 +0000 Subject: [PATCH] Qt: ADDED dynamic translation file loading ADDED File->Exit menu entry SIMPLIFIED menu construction git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@362 a31d4220-a93d-0410-bf67-fe4944624d44 --- lang/german.ts | 121 ++++++++++++++++++++++++++++++++++++++------- src/qt/MainWnd.cpp | 84 +++++++++++++++++++++++++------ src/qt/MainWnd.h | 13 ++++- src/qt/main.cpp | 7 +-- 4 files changed, 184 insertions(+), 41 deletions(-) diff --git a/lang/german.ts b/lang/german.ts index ee90434a..f38c17bb 100644 --- a/lang/german.ts +++ b/lang/german.ts @@ -1,102 +1,185 @@ + + @default + + + About VBA-M + Über VBA-M + + + + This program is licensed under terms of the GNU General Public License. + Dieses Programm ist unter den Bedingungen der GNU General Public License lizenziert. + + + + OpenGL version 2.1 is present. + OpenGL Version 2.1 ist verfügbar. + + + + OpenGL version 2.0 is present. + OpenGL Version 2.0 ist verfügbar. + + + + OpenGL version 1.5 is present. + OpenGL Version 1.5 ist verfügbar. + + + + OpenGL version 1.4 is present. + OpenGL Version 1.4 ist verfügbar. + + + + OpenGL version 1.3 is present. + OpenGL Version 1.3 ist verfügbar. + + + + OpenGL version 1.2 is present. + OpenGL Version 1.2 ist verfügbar. + + + + OpenGL version 1.1 is present. + OpenGL Version 1.1 ist verfügbar. + + + + OpenGL is NOT available! + OpenGL ist NICHT verfügbar! + + + + About OpenGL + Über OpenGL + + MainWnd - + VBA-M - + &File &Datei - + &Settings &Einstellungen - + &Tools &Werkzeuge - + &Help &Hilfe - + About &OpenGL... Über &OpenGL... - + About &VBA-M... Über &VBA-M... - + About &Qt... Über &Qt... - + This program is licensed under terms of the GNU General Public License. Dieses Programm ist unter den Bedingungen der GNU General Public License lizenziert. - + OpenGL version 2.1 is present. OpenGL Version 2.1 ist verfügbar. - + OpenGL version 2.0 is present. OpenGL Version 2.0 ist verfügbar. - + OpenGL version 1.5 is present. OpenGL Version 1.5 ist verfügbar. - + OpenGL version 1.4 is present. OpenGL Version 1.4 ist verfügbar. - + OpenGL version 1.3 is present. OpenGL Version 1.3 ist verfügbar. - + OpenGL version 1.2 is present. OpenGL Version 1.2 ist verfügbar. - + OpenGL version 1.1 is present. OpenGL Version 1.1 ist verfügbar. - + OpenGL is NOT available! OpenGL ist NICHT verfügbar! - + About VBA-M Über VBA-M - + About OpenGL Über OpenGL + + + Select translation... + Übersetzung auswählen... + + + + Select translation + Übersetzung auswählen + + + + Translation files (*.qm) + Übersetzungsdateien (*.qm) + + + + .qm + + + + + Exit + Beenden + diff --git a/src/qt/MainWnd.cpp b/src/qt/MainWnd.cpp index 79f05dd3..9ccf6ee5 100644 --- a/src/qt/MainWnd.cpp +++ b/src/qt/MainWnd.cpp @@ -20,8 +20,14 @@ #include "glwidget.h" -MainWnd::MainWnd( QWidget *parent ) - : QMainWindow( parent ) +MainWnd::MainWnd( QWidget *parent, QApplication *app, QTranslator **trans ) + : QMainWindow( parent ), + theApp( app ), + translator( trans ), + fileMenu( 0 ), + settingsMenu( 0 ), + toolsMenu( 0 ), + helpMenu( 0 ) { createDisplay(); @@ -37,22 +43,43 @@ MainWnd::~MainWnd() void MainWnd::createMenus() { - QMenu *fileMenu = menuBar()->addMenu( tr( "&File" ) ); - QMenu *settingsMenu = menuBar()->addMenu( tr( "&Settings" ) ); - QMenu *toolsMenu = menuBar()->addMenu( tr( "&Tools" ) ); - QMenu *helpMenu = menuBar()->addMenu( tr( "&Help" ) ); + if( fileMenu ) { + delete fileMenu; + fileMenu = 0; + } - QAction *showAboutOpenGLAct = new QAction( tr( "About &OpenGL..." ), this ); - connect( showAboutOpenGLAct, SIGNAL( triggered() ), this, SLOT( showAboutOpenGL() ) ); - helpMenu->addAction( showAboutOpenGLAct ); + if( settingsMenu ) { + delete settingsMenu; + settingsMenu = 0; + } - QAction *showAboutAct = new QAction( tr( "About &VBA-M..." ), this ); - connect( showAboutAct, SIGNAL( triggered() ), this, SLOT( showAbout() ) ); - helpMenu->addAction( showAboutAct ); + if( toolsMenu ) { + delete toolsMenu; + toolsMenu = 0; + } - QAction *showAboutQtAct = new QAction( tr( "About &Qt..." ), this ); - connect( showAboutQtAct, SIGNAL( triggered() ), this, SLOT( showAboutQt() ) ); - helpMenu->addAction( showAboutQtAct ); + if( helpMenu ) { + delete helpMenu; + helpMenu = 0; + } + + // File menu + fileMenu = menuBar()->addMenu( tr( "&File" ) ); + fileMenu->addAction( tr( "Exit" ), this, SLOT( close() ) ); + + // Settings menu + settingsMenu = menuBar()->addMenu( tr( "&Settings" ) ); + settingsMenu->addAction( tr( "Select translation..." ), this, SLOT( selectTranslation() ) ); + + // Tools menu + toolsMenu = menuBar()->addMenu( tr( "&Tools" ) ); + + // Help menu + helpMenu = menuBar()->addMenu( tr( "&Help" ) ); + + helpMenu->addAction( tr( "About &VBA-M..." ), this, SLOT( showAbout() ) ); + helpMenu->addAction( tr( "About &OpenGL..." ), this, SLOT( showAboutOpenGL() ) ); + helpMenu->addAction( tr( "About &Qt..." ), this, SLOT( showAboutQt() ) ); } bool MainWnd::createDisplay() @@ -68,6 +95,33 @@ bool MainWnd::createDisplay() return false; } +void MainWnd::selectTranslation() +{ + QString file = QFileDialog::getOpenFileName( + this, + tr( "Select translation" ), + "lang", + tr( "Translation files (*.qm)" ) ); + + if( file.isNull() ) return; + if( !file.endsWith( tr( ".qm" ), Qt::CaseInsensitive ) ) return; + + // load translation + if( *translator != 0 ) { + theApp->removeTranslator( *translator ); + delete *translator; + *translator = 0; + } + file.chop( 3 ); // remove file extension ".qm" + *translator = new QTranslator(); + (*translator)->load( file ); + theApp->installTranslator( *translator ); + + // apply translation + createMenus(); + // the user might have to restart the application to apply changes completely +} + void MainWnd::showAbout() { QMessageBox::about( this, tr( "About VBA-M" ), diff --git a/src/qt/MainWnd.h b/src/qt/MainWnd.h index cbbd102f..1117e58d 100644 --- a/src/qt/MainWnd.h +++ b/src/qt/MainWnd.h @@ -26,7 +26,7 @@ class MainWnd : public QMainWindow Q_OBJECT public: - MainWnd::MainWnd( QWidget *parent = 0 ); + MainWnd::MainWnd( QWidget *parent = 0, QApplication *app = 0, QTranslator **trans = 0 ); MainWnd::~MainWnd(); private: @@ -34,9 +34,18 @@ private: bool createDisplay(); private slots: + void selectTranslation(); void showAbout(); - void showAboutQt(); void showAboutOpenGL(); + void showAboutQt(); + +private: + QApplication *theApp; + QTranslator **translator; + QMenu *fileMenu; + QMenu *settingsMenu; + QMenu *toolsMenu; + QMenu *helpMenu; }; #endif // #ifndef MAINWND_H diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 678c58d5..c3f2d03f 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -23,12 +23,9 @@ int main( int argc, char *argv[] ) { QApplication theApp( argc, argv ); + QTranslator *translator = 0; - QTranslator translator; - translator.load( "lang/german" ); - theApp.installTranslator( &translator ); - - MainWnd *mainWnd = new MainWnd(); + MainWnd *mainWnd = new MainWnd( 0, &theApp, &translator ); mainWnd->show(); return theApp.exec();