Add:gui:Added boilerplate for qml based gui
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 10 Mar 2010 20:25:13 +0000 (20:25 +0000)
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 10 Mar 2010 20:25:13 +0000 (20:25 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2993 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/configure.in
navit/navit/attr_def.h
navit/navit/gui/Makefile.am
navit/navit/gui/qml/Makefile.am [new file with mode: 0644]
navit/navit/gui/qml/gui_qml.cpp [new file with mode: 0644]

index 803e5da..552e4d1 100644 (file)
@@ -43,6 +43,7 @@ fontconfig=yes; fontconfig_reason=default
 gui_gtk=no; gui_gtk_reason=default
 gui_win32=no; gui_win32_reason=default
 gui_internal=yes; gui_internal_reason=default
+gui_qml=no; gui_qml_reason=default
 graphics=yes; graphics_reason=default
 graphics_gd=no; graphics_gd_reason=default
 graphics_gtk_drawing_area=no; graphics_gtk_drawing_area_reason=default
@@ -760,6 +761,29 @@ AM_CONDITIONAL(GUI_INTERNAL, test "x${gui_internal}" = "xyes")
 # win32
 AC_ARG_ENABLE(gui-win32, [  --disable-gui-win32                 disable gui type win32], gui_win32=$enableval;gui_win32_reason="configure parameter")
 AM_CONDITIONAL(GUI_WIN32, test "x${gui_win32}" = "xyes")
+# qml
+AC_ARG_ENABLE(gui-qml, [  --disable-gui-qml              disable gui type QML], gui_qml=$enableval;gui_qml_reason="configure parameter")
+if test "x${gui_qml}" = "xyes" -a "x${QT_GUI_CFLAGS}" = "x" -a "x${QT_GUI_LIBS}" = "x"; then
+       PKG_CHECK_MODULES(QT_GUI, [QtGui QtCore], ,gui_qml=no,gui_qml_reason="Packages QtGui and/or QtCore missing")
+fi
+if test "x${gui_qml}" = "xyes" -a "x${QT_DECLARATIVE_CFLAGS}" = "x" -a "x${QT_DECLARATIVE_LIBS}" = "x"; then
+       PKG_CHECK_MODULES(QT_DECLARATIVE, [QtDeclarative], ,gui_qml=no,gui_qml_reason="Packages QtDeclarative missing")
+fi
+if test "x${graphics_qt_qpainter}" = "xyes" ; then
+       AC_DEFINE(USE_GUI_QML, 1, [Build with gui qml])
+       MOC=`$PKG_CONFIG QtGui --variable=moc_location`
+       if test "x${MOC}" = "x"; then
+               AC_CHECK_PROG(MOC, moc, moc)
+       fi
+       AC_SUBST(MOC)
+fi
+AC_SUBST(QT_GUI_CFLAGS)
+AC_SUBST(QT_GUI_LIBS)
+AC_SUBST(QT_DECLARATIVE_CFLAGS)
+AC_SUBST(QT_DECLARATIVE_LIBS)
+AM_CONDITIONAL(GUI_QML, test "x${gui_qml}" = "xyes")
+
+AM_CONDITIONAL(GUI_QML, test "x${gui_qml}" = "xyes")
 
 ## plugins
 # pedestrian
@@ -897,6 +921,7 @@ navit/gui/Makefile
 navit/gui/gtk/Makefile
 navit/gui/internal/Makefile
 navit/gui/win32/Makefile
+navit/gui/qml/Makefile
 navit/osd/Makefile
 navit/osd/core/Makefile
 navit/plugin/Makefile
@@ -1006,6 +1031,7 @@ echo "GUI types:"
 echo "  gtk:               $gui_gtk ($gui_gtk_reason)"
 echo "  internal:          $gui_internal ($gui_internal_reason)"
 echo "  win32:             $gui_win32 ($gui_win32_reason)"
+echo "  qml:               $gui_qml ($gui_qml_reason)"
 
 echo "Bindings:"
 echo "  dbus:              $binding_dbus ($binding_dbus_reason)"
@@ -1033,7 +1059,7 @@ echo "  null:              $vehicle_null ($vehicle_null_reason)"
 echo "  wince:             $vehicle_wince ($vehicle_wince_reason)"
 echo "  iphone:            $vehicle_iphone ($vehicle_iphone_reason)"
 
-if  test "x${gtk2_pkgconfig}" != "xyes" -a "x${gui_win32}" != "xyes" -a "x${gui_internal}" != "xyes"
+if  test "x${gtk2_pkgconfig}" != "xyes" -a "x${gui_win32}" != "xyes" -a "x${gui_internal}" != "xyes" -a "x${gui_qml}" != "xyes"
 then
        echo ""
        echo "" 
index b3ccceb..648d78e 100644 (file)
@@ -77,6 +77,7 @@ ATTR(destination_distance)
 ATTR(check_version)
 ATTR(details)
 ATTR(width)
+ATTR(height)
 ATTR(offset)
 ATTR(directed)
 ATTR(radius)
index 320cd81..10086b5 100644 (file)
@@ -8,3 +8,6 @@ endif
 if GUI_WIN32
   SUBDIRS += win32
 endif
+if GUI_QML
+  SUBDIRS += qml
+endif
\ No newline at end of file
diff --git a/navit/navit/gui/qml/Makefile.am b/navit/navit/gui/qml/Makefile.am
new file mode 100644 (file)
index 0000000..20ac880
--- /dev/null
@@ -0,0 +1,10 @@
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = @QT_DECLARATIVE_CFLAGS@ @QT_GUI_CFLAGS@ @NAVIT_CFLAGS@ -I$(top_srcdir) -I$(top_srcdir)/navit -DMODULE=gui_qml
+modulegui_LTLIBRARIES = libgui_qml.la
+libgui_qml_la_SOURCES = gui_qml.moc gui_qml.cpp
+libgui_qml_la_LDFLAGS = @QT_DECLARATIVE_LIBS@ @QT_GUI_LIBS@ -module -avoid-version
+if GUI_QML
+BUILT_SOURCES = gui_qml.moc
+gui_qml.moc: gui_qml.cpp
+       @MOC@ $(srcdir)/gui_qml.cpp >gui_qml.moc
+endif
diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp
new file mode 100644 (file)
index 0000000..c08dbb4
--- /dev/null
@@ -0,0 +1,203 @@
+#include <glib.h>
+#include <QtCore>
+#include <QtGui>
+#include <QtDeclarative>
+#include "config.h"
+#include "plugin.h"
+#include "item.h"
+#include "attr.h"
+#include "gui.h"
+#include "callback.h"
+#include "debug.h"
+#include "navit.h"
+#include "point.h"
+#include "graphics.h"
+
+struct gui_priv {
+       struct navit *nav;
+       struct attr self;
+       
+       //configuration items
+       int fullscreen;
+       int w;
+       int h;
+       char *source;
+       char *skin;
+       
+       //Interface stuff
+       struct callback_list *cbl;
+       QCoreApplication *app;
+       struct window *win;
+       struct graphics *gra;
+       struct QMainWindow *mainWindow;
+       QWidget *graphicsWidget;
+       QWidget *guiWidget;
+       QStackedWidget *switcherWidget;
+       struct callback *button_cb;
+};
+
+static void gui_qml_button(void *data, int pressed, int button, struct point *p)
+{
+       struct gui_priv *this_=(struct gui_priv*)data;
+
+       dbg(1,"enter %d %d\n", pressed, button);
+       if (pressed == 0) {
+           if ( button == 1 ) {
+               if (this_->switcherWidget->currentWidget() == this_->graphicsWidget) {
+                   this_->switcherWidget->setCurrentWidget(this_->guiWidget);
+               } else {
+                   this_->switcherWidget->setCurrentWidget(this_->graphicsWidget);
+               }
+           }
+       }
+}
+
+
+static int argc=1;
+static char *argv[]={(char *)"navit",NULL};
+
+static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra)
+{
+       struct window *win;
+       struct transformation *trans=navit_get_trans(this_->nav);
+       struct QmlView *view;
+
+       this_->gra=gra;
+
+       //Check if we are already in Qt environment
+       if (QApplication::instance()==NULL) {
+           //Not yet
+           this_->app=new QApplication(argc,argv);
+       } else {
+           this_->app=QApplication::instance();
+       }
+       
+       //Create main window
+       this_->switcherWidget = new QStackedWidget(this_->mainWindow);
+       this_->mainWindow = new QMainWindow(NULL);
+       if ( this_->w && this_->h ) {
+           this_->mainWindow->setFixedSize(this_->w,this_->h);
+       }
+       if ( this_->fullscreen ) {
+           this_->mainWindow->showFullScreen();
+       }
+       this_->mainWindow->setCentralWidget(this_->switcherWidget);
+       
+       //Create gui widget
+       view = new QmlView(NULL);
+       this_->guiWidget = view;
+       
+       view->setUrl(QUrl::fromLocalFile(QString(this_->source)+"/"+this_->skin+"/main.qml"));
+       view->execute();
+       this_->switcherWidget->addWidget(this_->guiWidget);
+       
+       //Check, if we have compatible graphics
+       this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget");
+       if (this_->graphicsWidget == NULL ) {
+           this_->graphicsWidget = new QLabel(QString("Sorry, current graphics type is incompatible with this gui."));
+       }
+        this_->switcherWidget->addWidget(this_->graphicsWidget);
+       
+       //Switch to graphics
+       this_->switcherWidget->setCurrentWidget(this_->graphicsWidget);
+
+       //Link graphics events
+       this_->button_cb=callback_new_attr_1(callback_cast(gui_qml_button), attr_button, this_);
+       graphics_add_callback(gra, this_->button_cb);
+
+       this_->mainWindow->show();
+
+       return 0;
+}
+
+static void gui_qml_disable_suspend(struct gui_priv *this_)
+{
+/*     if (this->win->disable_suspend)
+               this->win->disable_suspend(this->win);*/
+}
+
+static int
+gui_qml_get_attr(struct gui_priv *this_, enum attr_type type, struct attr *attr)
+{
+       switch (type) {
+       case attr_fullscreen:
+               attr->u.num=this_->fullscreen;
+               break;
+       case attr_skin:
+               attr->u.str=this_->skin;
+       default:
+               return 0;
+       }
+       attr->type=type;
+       return 1;
+}
+
+static int
+gui_qml_set_attr(struct gui_priv *this_, struct attr *attr)
+{
+       switch (attr->type) {
+       case attr_fullscreen:
+               if (!(this_->fullscreen) && (attr->u.num)) {
+                       this_->mainWindow->showFullScreen();
+               }
+               if ((this_->fullscreen) && !(attr->u.num)) {
+                       this_->mainWindow->showNormal();
+               }
+               this_->fullscreen=attr->u.num;
+               return 1;
+       default:
+               dbg(0,"%s\n",attr_to_name(attr->type));
+               return 1;
+       }
+}
+
+struct gui_methods gui_qml_methods = {
+       NULL,
+       NULL,
+        gui_qml_set_graphics,
+       NULL,
+       NULL,
+       NULL,
+       gui_qml_disable_suspend,
+       gui_qml_get_attr,
+       NULL,
+       gui_qml_set_attr,
+};
+
+
+static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
+{
+       struct gui_priv *this_;
+       struct attr *attr;
+       *meth=gui_qml_methods;
+       this_=g_new0(struct gui_priv, 1);
+       this_->nav=nav;
+
+       this_->self.type=attr_gui;
+       this_->self.u.gui=gui;  
+
+       if( (attr=attr_search(attrs,NULL,attr_fullscreen)))
+             this_->fullscreen=attr->u.num;
+       if( (attr=attr_search(attrs,NULL,attr_width)))
+             this_->w=attr->u.num;
+       if( (attr=attr_search(attrs,NULL,attr_height)))
+             this_->h=attr->u.num;
+       if( (attr=attr_search(attrs,NULL,attr_source)))
+             this_->source=attr->u.str;
+       if( (attr=attr_search(attrs,NULL,attr_skin)))
+             this_->skin=attr->u.str;
+
+       if ( this_->source==NULL ) {
+           this_->source=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"),"/gui/qml/skins",NULL);
+       }
+
+       this_->cbl=callback_list_new();
+
+       plugin_init();
+
+       return this_;
+}
+
+void plugin_init(void) {
+    plugin_register_gui_type("qml",gui_qml_new);
+}