summaryrefslogtreecommitdiffstats
path: root/qt-gui.cpp
diff options
context:
space:
mode:
authorGravatar Alberto Mardegan <mardy@users.sourceforge.net>2013-04-01 13:57:51 +0300
committerGravatar Alberto Mardegan <mardy@users.sourceforge.net>2013-04-01 16:03:59 +0300
commit7ea22811802cda1df227e7fb4b76720fc15b2dcd (patch)
treeadc3b1144ef9abdbbfe53f50dff116f9ee581c4a /qt-gui.cpp
parent578d633d0148a13397f330aa91af1470843d73c1 (diff)
downloadsubsurface-7ea22811802cda1df227e7fb4b76720fc15b2dcd.tar.gz
Introduce QApplication
Instantiate a QApplication and let Qt handle the event loop. Add a QTranslator subclass to translate the UI via gettext. Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r--qt-gui.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 54aa582b4..3285d8e27 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -27,11 +27,36 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixdata.h>
+#include <QApplication>
+#include <QTranslator>
#if HAVE_OSM_GPS_MAP
#include <osm-gps-map-source.h>
#endif
+class Translator: public QTranslator
+{
+ Q_OBJECT
+
+public:
+ Translator(QObject *parent = 0);
+ ~Translator() {}
+
+ virtual QString translate(const char *context, const char *sourceText,
+ const char *disambiguation = NULL) const;
+};
+
+Translator::Translator(QObject *parent):
+ QTranslator(parent)
+{
+}
+
+QString Translator::translate(const char *context, const char *sourceText,
+ const char *disambiguation) const
+{
+ return QString::fromUtf8(gettext(sourceText));
+}
+
static const GdkPixdata subsurface_icon_pixbuf = {};
GtkWidget *main_window;
@@ -40,6 +65,7 @@ GtkWidget *error_info_bar;
GtkWidget *error_label;
GtkWidget *vpane, *hpane;
GtkWidget *notebook;
+static QApplication *application = NULL;
int error_count;
const char *existing_filename;
@@ -1719,6 +1745,9 @@ void init_ui(int *argcp, char ***argvp)
GtkSettings *settings;
GtkUIManager *ui_manager;
+ application = new QApplication(*argcp, *argvp);
+ application->installTranslator(new Translator(application));
+
gtk_init(argcp, argvp);
settings = gtk_settings_get_default();
gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", 10, "subsurface setting");
@@ -1832,11 +1861,12 @@ void init_ui(int *argcp, char ***argvp)
void run_ui(void)
{
- gtk_main();
+ application->exec();
}
void exit_ui(void)
{
+ delete application;
subsurface_close_conf();
if (existing_filename)
free((void *)existing_filename);
@@ -2363,3 +2393,5 @@ gdouble get_screen_dpi(void)
gdouble dpi_h = floor((h / h_mm) * mm_per_inch);
return dpi_h;
}
+
+#include "qt-gui.moc.cpp"