mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
578d633d01
commit
7ea2281180
2 changed files with 35 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -317,6 +317,8 @@ MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $
|
||||||
@echo ' MOC' $<
|
@echo ' MOC' $<
|
||||||
@$(MOC) -i $(MOCFLAGS) $< -o $@
|
@$(MOC) -i $(MOCFLAGS) $< -o $@
|
||||||
|
|
||||||
|
qt-gui.o: qt-gui.moc.cpp
|
||||||
|
|
||||||
%.ui.h: ui/%.ui
|
%.ui.h: ui/%.ui
|
||||||
@echo ' UIC' $<
|
@echo ' UIC' $<
|
||||||
@$(UIC) $< -o $@
|
@$(UIC) $< -o $@
|
||||||
|
|
34
qt-gui.cpp
34
qt-gui.cpp
|
@ -27,11 +27,36 @@
|
||||||
|
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
#include <gdk-pixbuf/gdk-pixdata.h>
|
#include <gdk-pixbuf/gdk-pixdata.h>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
#if HAVE_OSM_GPS_MAP
|
#if HAVE_OSM_GPS_MAP
|
||||||
#include <osm-gps-map-source.h>
|
#include <osm-gps-map-source.h>
|
||||||
#endif
|
#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 = {};
|
static const GdkPixdata subsurface_icon_pixbuf = {};
|
||||||
|
|
||||||
GtkWidget *main_window;
|
GtkWidget *main_window;
|
||||||
|
@ -40,6 +65,7 @@ GtkWidget *error_info_bar;
|
||||||
GtkWidget *error_label;
|
GtkWidget *error_label;
|
||||||
GtkWidget *vpane, *hpane;
|
GtkWidget *vpane, *hpane;
|
||||||
GtkWidget *notebook;
|
GtkWidget *notebook;
|
||||||
|
static QApplication *application = NULL;
|
||||||
|
|
||||||
int error_count;
|
int error_count;
|
||||||
const char *existing_filename;
|
const char *existing_filename;
|
||||||
|
@ -1719,6 +1745,9 @@ void init_ui(int *argcp, char ***argvp)
|
||||||
GtkSettings *settings;
|
GtkSettings *settings;
|
||||||
GtkUIManager *ui_manager;
|
GtkUIManager *ui_manager;
|
||||||
|
|
||||||
|
application = new QApplication(*argcp, *argvp);
|
||||||
|
application->installTranslator(new Translator(application));
|
||||||
|
|
||||||
gtk_init(argcp, argvp);
|
gtk_init(argcp, argvp);
|
||||||
settings = gtk_settings_get_default();
|
settings = gtk_settings_get_default();
|
||||||
gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", 10, "subsurface setting");
|
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)
|
void run_ui(void)
|
||||||
{
|
{
|
||||||
gtk_main();
|
application->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_ui(void)
|
void exit_ui(void)
|
||||||
{
|
{
|
||||||
|
delete application;
|
||||||
subsurface_close_conf();
|
subsurface_close_conf();
|
||||||
if (existing_filename)
|
if (existing_filename)
|
||||||
free((void *)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);
|
gdouble dpi_h = floor((h / h_mm) * mm_per_inch);
|
||||||
return dpi_h;
|
return dpi_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "qt-gui.moc.cpp"
|
||||||
|
|
Loading…
Add table
Reference in a new issue