summaryrefslogtreecommitdiff
path: root/navit/graphics/qt5
diff options
context:
space:
mode:
authorStefan Wildemann <metalstrolch@users.noreply.github.com>2017-05-05 05:04:00 +0200
committerPierre GRANDIN <pgrandin@users.noreply.github.com>2017-05-04 20:04:00 -0700
commit585305d57ce8e1c5a3db978086102604f55cb006 (patch)
tree729b8e85769c9122f0a84e241d369373408e744a /navit/graphics/qt5
parenta5b607303d83e2b46950e2aef63eb5787f3098fb (diff)
downloadnavit-585305d57ce8e1c5a3db978086102604f55cb006.tar.gz
Add Qt5 qml gui skeleton (#236)R7461
* Initial parts of qt5 qml graphics based on graphics/qt5_qml * Qt5 QML gui: working handover The hand over of the QML engine between the graphics and the gui part is working now. The gui can load it's own QML component and embed the navit widget inside other QML code. * Remove unneeded moc include * Fix: Apply coding style * Fix:extern "C" the navit includes in graphics qt5 Seems the navit includes are not fully "c++" aware, so extern "C" them in the c++ parts.
Diffstat (limited to 'navit/graphics/qt5')
-rw-r--r--navit/graphics/qt5/QNavitQuick.cpp5
-rw-r--r--navit/graphics/qt5/QNavitWidget.cpp5
-rw-r--r--navit/graphics/qt5/event_qt5.cpp5
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp27
-rw-r--r--navit/graphics/qt5/graphics_qt5.h4
-rw-r--r--navit/graphics/qt5/graphics_qt5.qml17
-rw-r--r--navit/graphics/qt5/graphics_qt5.qrc1
-rw-r--r--navit/graphics/qt5/loader.qml20
8 files changed, 62 insertions, 22 deletions
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp
index d2664be27..798415f2c 100644
--- a/navit/graphics/qt5/QNavitQuick.cpp
+++ b/navit/graphics/qt5/QNavitQuick.cpp
@@ -18,10 +18,12 @@
*/
#include <glib.h>
-#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+extern"C" {
+#include "config.h"
+
#include "item.h"
#include "point.h"
#include "graphics.h"
@@ -32,6 +34,7 @@
#include "window.h"
#include "callback.h"
#include "keys.h"
+}
#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE)
#include <windows.h>
#endif
diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp
index d58f835a6..20b1d852f 100644
--- a/navit/graphics/qt5/QNavitWidget.cpp
+++ b/navit/graphics/qt5/QNavitWidget.cpp
@@ -18,10 +18,12 @@
*/
#include <glib.h>
-#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+extern "C" {
+#include "config.h"
+
#include "item.h"
#include "point.h"
#include "graphics.h"
@@ -32,6 +34,7 @@
#include "window.h"
#include "callback.h"
#include "keys.h"
+}
#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE)
#include <windows.h>
#endif
diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp
index 9cea3d921..729e3903b 100644
--- a/navit/graphics/qt5/event_qt5.cpp
+++ b/navit/graphics/qt5/event_qt5.cpp
@@ -20,7 +20,10 @@
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
+
+extern "C" {
#include "config.h"
+
#include "navit/point.h"
#include "navit/item.h"
#include "navit/graphics.h"
@@ -32,6 +35,8 @@
#include "navit/window.h"
#include "navit/keys.h"
#include "navit/navit.h"
+}
+
#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE)
#include <windows.h>
#endif
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index 37fda3d66..f03ad36e0 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -18,10 +18,12 @@
*/
#include <glib.h>
-#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+extern "C" {
+#include "config.h"
+
#include "item.h"
#include "point.h"
#include "graphics.h"
@@ -31,9 +33,8 @@
#include "debug.h"
#include "window.h"
#include "callback.h"
-#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE)
-#include <windows.h>
-#endif
+}
+
#include "graphics_qt5.h"
#include "event_qt5.h"
#include <QGuiApplication>
@@ -55,6 +56,9 @@
#include <QApplication>
#include "QNavitWidget.h"
#endif
+#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE)
+#include <windows.h>
+#endif
#if USE_QML
GraphicsPriv::GraphicsPriv(struct graphics_priv * gp)
@@ -665,6 +669,10 @@ get_data(struct graphics_priv *this_priv, char const *type)
resize_callback(this_priv, this_priv->pixmap->width(),this_priv->pixmap->height());
return win;
}
+ if (strcmp(type, "engine") == 0) {
+ dbg(lvl_debug, "Hand over QQmlApplicationEngine\n");
+ return(this_priv->engine);
+ }
return NULL;
}
@@ -893,6 +901,7 @@ graphics_qt5_new(struct navit *nav, struct graphics_methods *meth, struct attr *
graphics_priv->y = 0;
graphics_priv->disable = 0;
#if USE_QML
+ graphics_priv->engine = NULL;
graphics_priv->window = NULL;
graphics_priv->GPriv = NULL;
if(use_qml)
@@ -901,15 +910,15 @@ graphics_qt5_new(struct navit *nav, struct graphics_methods *meth, struct attr *
qmlRegisterType<QNavitQuick>("com.navit.graphics_qt5", 1, 0, "QNavitQuick");
/* get our qml application from embedded resources. May be replaced by the
* QtQuick gui component if enabled */
- QQmlApplicationEngine * engine = new QQmlApplicationEngine();
- if(engine != NULL)
+ graphics_priv->engine = new QQmlApplicationEngine();
+ if(graphics_priv->engine != NULL)
{
graphics_priv->GPriv = new GraphicsPriv(graphics_priv);
- QQmlContext *context = engine->rootContext();
+ QQmlContext *context = graphics_priv->engine->rootContext();
context->setContextProperty("graphics_qt5_context", graphics_priv->GPriv);
- engine->load(QUrl("qrc:///graphics_qt5.qml"));
+ graphics_priv->engine->load(QUrl("qrc:///loader.qml"));
/* Get the engine's root window (for resizing) */
- QObject *toplevel = engine->rootObjects().value(0);
+ QObject *toplevel = graphics_priv->engine->rootObjects().value(0);
graphics_priv->window = qobject_cast<QQuickWindow *> (toplevel);
}
}
diff --git a/navit/graphics/qt5/graphics_qt5.h b/navit/graphics/qt5/graphics_qt5.h
index 2e3f7b85e..fad818773 100644
--- a/navit/graphics/qt5/graphics_qt5.h
+++ b/navit/graphics/qt5/graphics_qt5.h
@@ -16,6 +16,7 @@
#include <QPen>
#include <QBrush>
#if USE_QML
+#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QObject>
#endif
@@ -57,7 +58,8 @@ signals:
struct graphics_priv {
#if USE_QML
- GraphicsPriv * GPriv;
+ QQmlApplicationEngine * engine;
+ GraphicsPriv * GPriv;
QQuickWindow * window;
#endif
#if USE_QWIDGET
diff --git a/navit/graphics/qt5/graphics_qt5.qml b/navit/graphics/qt5/graphics_qt5.qml
index a797c8eb9..5f6056b26 100644
--- a/navit/graphics/qt5/graphics_qt5.qml
+++ b/navit/graphics/qt5/graphics_qt5.qml
@@ -2,14 +2,11 @@ import com.navit.graphics_qt5 1.0
import QtQuick 2.2
import QtQuick.Window 2.0
-Window {
- width: 200; height: 200
- QNavitQuick {
- id: navit1
- anchors.fill: parent
- focus: true
- Component.onCompleted: {
- navit1.setGraphicContext(graphics_qt5_context)
- }
- }
+QNavitQuick {
+ id: navit1
+ anchors.fill: parent
+ focus: true
+ Component.onCompleted: {
+ navit1.setGraphicContext(graphics_qt5_context)
+ }
}
diff --git a/navit/graphics/qt5/graphics_qt5.qrc b/navit/graphics/qt5/graphics_qt5.qrc
index 4c82492ee..6a161f621 100644
--- a/navit/graphics/qt5/graphics_qt5.qrc
+++ b/navit/graphics/qt5/graphics_qt5.qrc
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
+ <file>loader.qml</file>
<file>graphics_qt5.qml</file>
</qresource>
</RCC>
diff --git a/navit/graphics/qt5/loader.qml b/navit/graphics/qt5/loader.qml
new file mode 100644
index 000000000..6901c2c6f
--- /dev/null
+++ b/navit/graphics/qt5/loader.qml
@@ -0,0 +1,20 @@
+import com.navit.graphics_qt5 1.0
+import QtQuick 2.2
+import QtQuick.Window 2.0
+
+Window {
+ width: 200; height: 200
+
+ Loader {
+ id: navit_loader
+ focus: true
+ source: "graphics_qt5.qml"
+ anchors.fill: parent
+ objectName: "navit_loader"
+ }
+
+ Item {
+ id: root_item
+ anchors.fill: parent
+ }
+}