summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Grandin <grandinp@altern.org>2016-07-20 11:17:02 -0700
committerPierre Grandin <grandinp@altern.org>2016-07-20 11:17:02 -0700
commit8256261645d7267690022778fef42b9e4908333e (patch)
treef777f7c471bc5e20eb9d4e056ed2b9e2e1fa02e2
parentcdc4245f6a9f04236ad027a5630a1777e6398a8e (diff)
downloadnavit-8256261645d7267690022778fef42b9e4908333e.tar.gz
Working on qt5 graphics/qml2 UI
-rwxr-xr-xCMakeLists.txt26
-rw-r--r--navit/graphics/qt_qpainter/CMakeLists.txt4
-rw-r--r--navit/graphics/qt_qpainter/RenderArea.cpp354
-rw-r--r--navit/graphics/qt_qpainter/RenderArea.h3
-rw-r--r--navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp7
-rw-r--r--navit/gui/qml2/CMakeLists.txt4
-rw-r--r--navit/gui/qml2/gui_qml2.cpp270
7 files changed, 563 insertions, 105 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 38713bd33..cf942edf6 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -87,6 +87,7 @@ add_module(graphics/opengl "FreeType library not found" FALSE)
add_module(graphics/sdl "Required library not found" FALSE)
add_module(graphics/qt_qpainter "Qt libraries not found" FALSE)
add_module(gui/qml "Qt Declarative not found" FALSE)
+add_module(gui/qml2 "Qt Declarative not found" FALSE)
add_module(gui/gtk "GTK libs not found" FALSE)
add_module(vehicle/gpsd "gpsd lib not found" FALSE)
add_module(vehicle/gypsy "gypsy lib not found" FALSE)
@@ -148,6 +149,16 @@ find_package(DBusGLib)
find_package(PythonLibs)
find_package(OpenSSL)
find_package(Threads)
+
+# find_package(Qt5 COMPONENTS Widgets Declarative)
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Widgets REQUIRED)
+find_package(Qt5Quick REQUIRED)
+
+find_package(Qt5Gui REQUIRED)
+find_package(Qt5Xml REQUIRED)
+find_package(Qt5DBus REQUIRED)
+find_package(Qt5OpenGL REQUIRED)
libfind_pkg_check_modules(FONTCONFIG fontconfig)
#Qt detection
if (NOT DISABLE_QT)
@@ -286,7 +297,7 @@ if (QT_FOUND)
set_with_reason(graphics/qt_qpainter "Qt libraries found" TRUE ${QT_LIBRARIES})
if (QT_QTDECLARATIVE_FOUND AND QT_QTXML_FOUND)
- set_with_reason(gui/qml "Qt Declarative found" TRUE ${QT_LIBRARIES})
+ # set_with_reason(gui/qml "Qt Declarative found" TRUE ${QT_LIBRARIES})
endif()
if (QT_QTSVG_FOUND)
@@ -297,6 +308,19 @@ if (QT_FOUND)
endif()
endif(QT_FOUND)
+if (Qt5Core_FOUND)
+ include(${QT_USE_FILE})
+ if (Qt5Widgets_FOUND)
+ if (FREETYPE_FOUND)
+ set_with_reason(graphics/qt_qpainter "Qt libraries found" TRUE ${QT_LIBRARIES})
+ endif()
+
+ if (Qt5Quick_FOUND)
+ set_with_reason(gui/qml2 "Qt5 Declarative found" TRUE ${QT_LIBRARIES})
+ endif()
+ endif()
+endif(Qt5Core_FOUND)
+
if(GTK2_FOUND)
# Include gtk.h with "SYSTEM" to avoid GCC compiler warning for gtkitemfactory.h.
include_directories(SYSTEM ${GTK2_GTK_INCLUDE_DIR})
diff --git a/navit/graphics/qt_qpainter/CMakeLists.txt b/navit/graphics/qt_qpainter/CMakeLists.txt
index fa02132a0..e8ffcbfbb 100644
--- a/navit/graphics/qt_qpainter/CMakeLists.txt
+++ b/navit/graphics/qt_qpainter/CMakeLists.txt
@@ -1,4 +1,6 @@
module_add_library(graphics_qt_qpainter ${CMAKE_CURRENT_BINARY_DIR}/RenderArea.moc RenderArea.cpp graphics_qt_qpainter.cpp)
-QT4_GENERATE_MOC(RenderArea.h ${CMAKE_CURRENT_BINARY_DIR}/RenderArea.moc)
+# FIXME : qt5_use_modules is deprecated, we should use target_link_libraries
+qt5_use_modules(graphics_qt_qpainter Widgets OpenGL Gui)
+QT5_GENERATE_MOC(RenderArea.h ${CMAKE_CURRENT_BINARY_DIR}/RenderArea.moc)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
diff --git a/navit/graphics/qt_qpainter/RenderArea.cpp b/navit/graphics/qt_qpainter/RenderArea.cpp
index 1159082ed..e3c430cdf 100644
--- a/navit/graphics/qt_qpainter/RenderArea.cpp
+++ b/navit/graphics/qt_qpainter/RenderArea.cpp
@@ -21,6 +21,18 @@
#include "RenderArea.moc"
+#include <QtWidgets/QGestureEvent>
+
+bool touchStarted = false;
+bool zoomIn = false;
+bool gestureInProgress = false;
+int numberOfTaps =0;
+bool mouseTimerRunning = false;
+QPoint lastTouchEvent;
+QPoint touchPosition;
+QPoint firstTouchPosition;
+bool sentSignal = false;
+bool isTapAndHold =false;
#ifdef QT_QPAINTER_USE_EMBEDDING
EmbeddedWidget::EmbeddedWidget(struct graphics_priv *priv, QWidget* child, QWidget *parent)
: QX11EmbedWidget(parent) {
@@ -50,9 +62,12 @@ RenderArea::RenderArea(struct graphics_priv *priv, QT_QPAINTER_RENDERAREA_PARENT
#ifndef QT_QPAINTER_NO_WIDGET
if (!overlay) {
#if QT_VERSION >= 0x040700
- grabGesture(Qt::PinchGesture);
- grabGesture(Qt::SwipeGesture);
- grabGesture(Qt::PanGesture);
+ dbg(lvl_debug,"Registering gestures\n");
+ grabGesture(Qt::PinchGesture);
+ grabGesture(Qt::SwipeGesture);
+ grabGesture(Qt::PanGesture);
+ grabGesture(Qt::TapAndHoldGesture);
+ grabGesture(Qt::TapGesture);
#endif
setWindowTitle(priv->window_title);
}
@@ -65,6 +80,7 @@ RenderArea::RenderArea(struct graphics_priv *priv, QT_QPAINTER_RENDERAREA_PARENT
watches=g_hash_table_new(NULL, NULL);
#ifndef QT_QPAINTER_NO_WIDGET
setAttribute(Qt::WA_OpaquePaintEvent, true);
+ setAttribute(Qt::WA_AcceptTouchEvents, true);
#endif
#endif
}
@@ -84,13 +100,115 @@ void RenderArea::closeEvent(QCloseEvent* event)
bool RenderArea::event(QEvent *event)
{
-#if QT_VERSION >= 0x040700
- if (event->type() == QEvent::Gesture) {
- dbg(lvl_debug,"gesture\n");
- return true;
- }
-#endif
- return QWidget::event(event);
+ dbg(lvl_debug,"event\n");
+ if (event->type() == QEvent::Gesture) {
+ QGestureEvent* gest = static_cast<QGestureEvent*>(event);
+ if( QGesture* pinch = gest->gesture(Qt::PinchGesture) ) {
+ // pinch gesture
+ QPinchGesture *pinchEve = static_cast<QPinchGesture *>(pinch);
+ qDebug() << "Pinch " << pinchEve << pinchEve->state() << pinchEve->scaleFactor() << pinchEve->lastScaleFactor();
+ struct point p;
+ int button = 4;
+ if(pinchEve->state() == Qt::GestureStarted) {
+ gestureInProgress = true;
+ }
+ if (pinchEve->state() == Qt::GestureFinished ) {
+ gestureInProgress = false;
+ if (pinchEve->totalScaleFactor() > 1 ) {
+ button = 4;
+ } else {
+ button = 5;
+ }
+
+ p.x = pinchEve->lastCenterPoint().x();
+ p.y = pinchEve->lastCenterPoint().y();
+
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ }
+ } else if(QGesture* tap = gest->gesture(Qt::TapGesture) ) {
+ if (tap->state() == Qt::GestureFinished ) {
+ QTapGesture* gest = static_cast<QTapGesture*>(tap);
+ qDebug() << "tap tap" << tap->state();
+ lastTouchEvent = gest->position().toPoint();
+ numberOfTaps++;
+ if(!mouseTimerRunning) {
+ mouseTimerRunning = true;
+ QTimer::singleShot(500,this, SLOT(mouseTimer()));
+ }
+ }
+ } else if (QGesture* tapAndHold = gest->gesture(Qt::TapAndHoldGesture) ) {
+ if (tapAndHold->state() == Qt::GestureFinished) {
+ qDebug() << "Touch and hold";
+ QTapAndHoldGesture* gest = static_cast<QTapAndHoldGesture*>(tapAndHold);
+ if (gest) {
+ QPoint pressPoint = gest->position().toPoint();
+ point p;
+ p.x=pressPoint.x();
+ p.y=pressPoint.y();
+ qDebug() << "Sending t&h signal";
+ callback_list_call_attr_1(this->cbl, attr_signal_on_map_click, GINT_TO_POINTER(&p));
+ isTapAndHold = true;
+ }
+ }
+ }
+
+ event->accept();
+ return true;
+ } else if(event->type() == QEvent::TouchBegin) {
+ if (!gestureInProgress) {
+ qDebug() << "Touch begin";
+ QTouchEvent* te = static_cast<QTouchEvent*>(event);
+ QTouchEvent::TouchPoint p = te->touchPoints().at(0);
+ touchPosition = p.pos().toPoint();
+ firstTouchPosition = touchPosition;
+ qDebug() << "Touch point " << touchPosition;
+ mouseEvent(1, p.pos().toPoint());
+ }
+ event->accept();
+ } else if (event->type() == QEvent::TouchUpdate) {
+ if (!gestureInProgress) {
+ QTouchEvent* te = static_cast<QTouchEvent*>(event);
+ QTouchEvent::TouchPoint point = te->touchPoints().at(0);
+ struct point p;
+ p.x=point.pos().x();
+ p.y=point.pos().y();
+ touchPosition = point.pos().toPoint();
+ qDebug() << "Touch point " << touchPosition;
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+ }
+ event->accept();
+ } else if (event->type() == QEvent::TouchEnd) {
+ if (!gestureInProgress) {
+ QTouchEvent* te = static_cast<QTouchEvent*>(event);
+ QTouchEvent::TouchPoint p = te->touchPoints().at(0);
+ mouseEvent(0, p.pos().toPoint());
+ qDebug() << "First = " << firstTouchPosition << " last=" << touchPosition;
+ QRect firstRect (firstTouchPosition.x() - 2, firstTouchPosition.y() - 2, 4, 4);
+ QRect lastRect ( touchPosition.x() - 2, touchPosition.y() - 2, 4, 4);
+ qDebug() << "frect = " << firstRect << "lrect=" << lastRect;
+ if (firstRect.intersects(lastRect)) {
+ // this is a tap
+ if (!isTapAndHold) {
+ qDebug() << "Single tap detected!";
+ // callback_list_call_attr_1(this->cbl, attr_signal_on_map_click_tap, GINT_TO_POINTER(&p));
+ } else {
+ qDebug() << "Single tap, but t&h already sent";
+ }
+ } else {
+ if (!isTapAndHold) {
+ // this was a move opeartion
+ qDebug() << "Move gesture, sent click_tap";
+ // callback_list_call_attr_1(this->cbl, attr_signal_on_map_click_tap, GINT_TO_POINTER(&p));
+ }
+ }
+ touchPosition = p.pos().toPoint();
+ }
+ isTapAndHold = false;
+ event->accept();
+ } else {
+ return QWidget::event(event);
+ }
}
//##############################################################################################################
//# Description: QWidget:sizeHint
@@ -145,34 +263,36 @@ void RenderArea::resizeEvent(QResizeEvent * event)
//# Comment: Delegate of QWidget::mousePressEvent and QWidget::mouseReleaseEvent (see below)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::mouseEvent(int pressed, QMouseEvent *event)
-{
- struct point p;
- p.x=event->x();
- p.y=event->y();
- switch (event->button()) {
- case Qt::LeftButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
- break;
- case Qt::MidButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
- break;
- case Qt::RightButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
- break;
- default:
- break;
- }
+void RenderArea::mouseEvent(int pressed, QPoint point)
+{
+ dbg(lvl_debug,"mouseEvent\n");
+ struct point p;
+ p.x=point.x();
+ p.y=point.y();
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
}
void RenderArea::mousePressEvent(QMouseEvent *event)
{
- mouseEvent(1, event);
+ dbg(lvl_debug,"mousePressEvent\n");
+ struct point p;
+ mouseEvent(1, event->pos());
}
void RenderArea::mouseReleaseEvent(QMouseEvent *event)
{
- mouseEvent(0, event);
+ dbg(lvl_debug,"mouseReleaseEvent\n");
+ mouseEvent(0, event->pos());
+ struct point p;
+
+ p.x = event->pos().x();
+ p.y = event->pos().y();
+ if (!sentSignal) {
+ dbg(lvl_debug,"Sending click_tap singal\n");
+ // callback_list_call_attr_1(this->cbl, attr_signal_on_map_click_tap, GINT_TO_POINTER(&p));
+ }
+
+ sentSignal = false;
}
//##############################################################################################################
@@ -182,13 +302,14 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event)
//##############################################################################################################
void RenderArea::mouseMoveEvent(QMouseEvent *event)
{
- struct point p;
- p.x=event->x();
- p.y=event->y();
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+ dbg(lvl_error,"MouseMoveEvent\n");
+ qDebug() << Q_FUNC_INFO;
+ struct point p;
+ p.x=event->x();
+ p.y=event->y();
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
}
-
//##############################################################################################################
//# Description: Qt Event :: Zoom in/out with the mouse's scrollwheel
//# Comment:
@@ -196,92 +317,95 @@ void RenderArea::mouseMoveEvent(QMouseEvent *event)
//##############################################################################################################
void RenderArea::wheelEvent(QWheelEvent *event)
{
- struct point p;
- int button;
+ qDebug() <</* */Q_FUNC_INFO;
+ struct point p;
+ int button;
- p.x=event->x(); // xy-coordinates of the mouse pointer
- p.y=event->y();
+ p.x=event->x(); // xy-coordinates of the mouse pointer
+ p.y=event->y();
- if (event->delta() > 0) // wheel movement away from the person
- button=4;
- else if (event->delta() < 0) // wheel movement towards the person
- button=5;
- else
- button=-1;
+ if (event->delta() > 0) // wheel movement away from the person
+ button=4;
+ else if (event->delta() < 0) // wheel movement towards the person
+ button=5;
+ else
+ button=-1;
- if (button != -1) {
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- }
+ if (button != -1) {
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ }
- event->accept();
+ event->accept();
}
#define CASE(x) case x:
void RenderArea::keyPressEvent(QKeyEvent *event)
{
- QString str=event->text();
- const char *text=str.toUtf8().constData();
- dbg(lvl_debug,"enter text='%s' 0x%x (%zu) key=%d\n", text, text[0], strlen(text), event->key());
- if (!text || !text[0] || text[0] == 0x7f) {
- dbg(lvl_debug,"special key\n");
- switch (event->key()) {
- case 4099:
- {
- char text_backspace[] = {NAVIT_KEY_BACKSPACE,'\0'};
- text=text_backspace;
- }
- break;
- case 4101:
+ dbg(lvl_debug,"RenderArea::keyPressEvent\n");
+ qDebug() << Q_FUNC_INFO;
+ QString str=event->text();
+ const char *text=str.toUtf8().constData();
+ dbg(lvl_debug,"enter text='%s' 0x%x (%zu) key=%d\n", text, text[0], strlen(text), event->key());
+ if (!text || !text[0] || text[0] == 0x7f) {
+ dbg(lvl_debug,"special key\n");
+ switch (event->key()) {
+ case 4099:
+ {
+ char text_backspace[] = {NAVIT_KEY_BACKSPACE,'\0'};
+ text=text_backspace;
+ }
+ break;
+ case 4101:
#ifdef QT_QPAINTER_CUSTOM_RETURN
- QT_QPAINTER_CUSTOM_RETURN
+ QT_QPAINTER_CUSTOM_RETURN
#endif
- {
- char text_return[] = {NAVIT_KEY_RETURN,'\0'};
- text=text_return;
- }
- break;
- case 4114:
+ {
+ char text_return[] = {NAVIT_KEY_RETURN,'\0'};
+ text=text_return;
+ }
+ break;
+ case 4114:
#ifdef QT_QPAINTER_CUSTOM_LEFT
- QT_QPAINTER_CUSTOM_LEFT
+ QT_QPAINTER_CUSTOM_LEFT
#endif
- {
- char text_left[] = {NAVIT_KEY_LEFT,'\0'};
- text=text_left;
- }
- break;
- case 4115:
+ {
+ char text_left[] = {NAVIT_KEY_LEFT,'\0'};
+ text=text_left;
+ }
+ break;
+ case 4115:
#ifdef QT_QPAINTER_CUSTOM_UP
- QT_QPAINTER_CUSTOM_UP
+ QT_QPAINTER_CUSTOM_UP
#endif
- {
- char text_up[] = {NAVIT_KEY_UP,'\0'};
- text=text_up;
- }
- break;
- case 4116:
+ {
+ char text_up[] = {NAVIT_KEY_UP,'\0'};
+ text=text_up;
+ }
+ break;
+ case 4116:
#ifdef QT_QPAINTER_CUSTOM_RIGHT
- QT_QPAINTER_CUSTOM_RIGHT
+ QT_QPAINTER_CUSTOM_RIGHT
#endif
- {
- char text_right[] = {NAVIT_KEY_RIGHT,'\0'};
- text=text_right;
- }
- break;
- case 4117:
+ {
+ char text_right[] = {NAVIT_KEY_RIGHT,'\0'};
+ text=text_right;
+ }
+ break;
+ case 4117:
#ifdef QT_QPAINTER_CUSTOM_DOWN
- QT_QPAINTER_CUSTOM_DOWN
+ QT_QPAINTER_CUSTOM_DOWN
#endif
- {
- char text_down[] = {NAVIT_KEY_DOWN,'\0'};
- text=text_down;
- }
- break;
- }
- }
- callback_list_call_attr_1(this->cbl, attr_keypress, (void *)text);
- event->accept();
+ {
+ char text_down[] = {NAVIT_KEY_DOWN,'\0'};
+ text=text_down;
+ }
+ break;
+ }
+ }
+ callback_list_call_attr_1(this->cbl, attr_keypress, (void *)text);
+ event->accept();
}
void RenderArea::watchEvent(int fd)
@@ -293,6 +417,34 @@ void RenderArea::watchEvent(int fd)
#endif
}
+void RenderArea::mouseTimer()
+{
+ mouseTimerRunning = false;
+ qDebug() << Q_FUNC_INFO<< numberOfTaps << lastTouchEvent;
+ int button {0};
+ struct point p;
+
+ p.x = lastTouchEvent.x();
+ p.y = lastTouchEvent.y();
+
+ if (numberOfTaps > 3 || numberOfTaps == 1) {
+ // don't do anything
+ numberOfTaps = 0;
+ return;
+ }
+
+ if(numberOfTaps == 2) {
+ qDebug() << "zoom in";
+ button = 4;
+ } else if (numberOfTaps == 3) {
+ qDebug() << "zoom out";
+ button = 5;
+ }
+
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ numberOfTaps = 0;
+}
+
#ifdef QT_QPAINTER_USE_EVENT_QT
void RenderArea::timerEvent(QTimerEvent *event)
{
diff --git a/navit/graphics/qt_qpainter/RenderArea.h b/navit/graphics/qt_qpainter/RenderArea.h
index a78c23cab..884200eec 100644
--- a/navit/graphics/qt_qpainter/RenderArea.h
+++ b/navit/graphics/qt_qpainter/RenderArea.h
@@ -51,7 +51,7 @@ protected:
QSize sizeHint() const;
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
- void mouseEvent(int pressed, QMouseEvent *event);
+ void mouseEvent(int pressed, QPoint p);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
@@ -64,6 +64,7 @@ protected:
#endif
protected slots:
void watchEvent(int fd);
+ void mouseTimer();
};
#endif /* __RENDERAREA_H */
diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
index 3a7509b0d..1cdb92796 100644
--- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
+++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
@@ -519,7 +519,11 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
qt_qpainter_draw(gr, &r, 0);
}
if (!gr->parent)
- QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
+#if QT_VERSION >= 0x050000
+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::X11ExcludeTimers);
+#elif QT_VERSION >= 0x040000
+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
+#endif
}
gr->mode=mode;
}
@@ -578,6 +582,7 @@ static void * get_data(struct graphics_priv *this_, const char *type)
QSize size(this_->w,this_->h);
this_->widget->do_resize(size);
}
+ dbg(lvl_error,"get_data\n");
if (!strcmp(type, "qt_widget"))
return this_->widget;
if (!strcmp(type, "qt_pixmap"))
diff --git a/navit/gui/qml2/CMakeLists.txt b/navit/gui/qml2/CMakeLists.txt
new file mode 100644
index 000000000..636e59a2f
--- /dev/null
+++ b/navit/gui/qml2/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_definitions( -DMODULE=gui_qml2 )
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+module_add_library(gui_qml2 gui_qml2.cpp)
+target_link_libraries(gui_qml2 Qt5::Widgets Qt5::Quick)
diff --git a/navit/gui/qml2/gui_qml2.cpp b/navit/gui/qml2/gui_qml2.cpp
new file mode 100644
index 000000000..92b37d52a
--- /dev/null
+++ b/navit/gui/qml2/gui_qml2.cpp
@@ -0,0 +1,270 @@
+#include <glib.h>
+//#include <Qt5Core>
+//#include <QtGui>
+// #include <QtWidgets>
+//#include <QtQuick>
+//#include <QtXml>
+//#include <QApplication>
+#include "config.h"
+#ifdef HAVE_API_WIN32_BASE
+#include <windows.h>
+#endif
+#include "plugin.h"
+#include "item.h"
+#include "attr.h"
+#include "xmlconfig.h"
+#include "color.h"
+#include "gui.h"
+#include "callback.h"
+#include "debug.h"
+#include "navit.h"
+#include "point.h"
+#include "graphics.h"
+#include "event.h"
+#include "map.h"
+#include "coord.h"
+#include "vehicle.h"
+#include "coord.h"
+#include "transform.h"
+#include "mapset.h"
+#include "route.h"
+#include "country.h"
+#include "track.h"
+#include "search.h"
+#include "bookmarks.h"
+#include "command.h"
+#include "keys.h"
+
+#include "layout.h"
+
+#include <QtCore>
+#include <QtGui>
+#include <QtWidgets>
+#include <QtQuick/QQuickView>
+
+struct gui_priv {
+ struct navit *nav;
+ struct gui *gui;
+ struct attr self;
+ struct vehicle* currVehicle;
+
+ //configuration items
+ int fullscreen;
+ int menu_on_map_click;
+ int signal_on_map_click;
+ int w;
+ int h;
+ char *source;
+ char *skin;
+ char* icon_src;
+ int radius;
+ int pitch;
+ int lazy; //When TRUE - menu state will not be changed during map/menu switches, FALSE - menu will be always reset to main.qml
+
+ //Interface stuff
+ struct callback_list *cbl;
+ QCoreApplication *app;
+ struct window *win;
+ struct graphics *gra;
+ QWidget *mainWindow;
+ QWidget *graphicsWidget;
+ QQuickView *guiWidget;
+ // QQuickView *prevGuiWidget;
+ QStackedLayout *switcherWidget;
+ struct callback *button_cb;
+ struct callback *motion_cb;
+ struct callback *resize_cb;
+ struct callback *keypress_cb;
+ struct callback *window_closed_cb;
+
+ //Proxy objects
+ class NGQProxyGui* guiProxy;
+ class NGQProxyNavit* navitProxy;
+ class NGQProxyVehicle* vehicleProxy;
+ class NGQProxySearch* searchProxy;
+ class NGQProxyBookmarks* bookmarksProxy;
+ class NGQProxyRoute* routeProxy;
+ class NGQPoint* currentPoint;
+};
+
+// #include "proxy.h"
+// #include "ngqpoint.h"
+// #include "searchProxy.h"
+// #include "routeProxy.h"
+// #include "bookmarksProxy.h"
+// #include "vehicleProxy.h"
+// #include "navitProxy.h"
+// #include "guiProxy.h"
+
+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;
+ break;
+ case attr_pitch:
+ attr->u.num=this_->pitch;
+ break;
+ case attr_radius:
+ attr->u.num=this_->radius;
+ break;
+ 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:
+ this_->fullscreen=attr->u.num;
+ return 1;
+ case attr_pitch:
+ this_->pitch=attr->u.num;
+ return 1;
+ case attr_radius:
+ this_->radius=attr->u.num;
+ return 1;
+ default:
+ dbg(lvl_error,"unknown attr: %s\n",attr_to_name(attr->type));
+ return 1;
+ }
+}
+
+
+static void gui_qml_button(void *data, int pressed, int button, struct point *p)
+{
+ struct gui_priv *this_=(struct gui_priv*)data;
+ dbg(lvl_info, "gui button event\n");
+
+ // check whether the position of the mouse changed during press/release OR if it is the scrollwheel
+ if (!navit_handle_button(this_->nav, pressed, button, p, NULL)) {
+ dbg(lvl_debug,"navit has handled button\n");
+ return;
+ }
+
+ dbg(lvl_debug,"enter %d %d\n", pressed, button);
+ if (this_->signal_on_map_click) {
+ // gui_qml_dbus_signal(this_, p);
+ return;
+ }
+
+ if ( button == 1 && this_->menu_on_map_click ) {
+ // this_->guiProxy->switchToMenu(p);
+ }
+}
+
+
+//GUI interface calls
+static int argc=1;
+static char *argv[]={(char *)"navit",NULL};
+
+static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra)
+{
+ QWidget* _mainWindow;
+ this_->app=new QApplication(argc,argv);
+ this_->gra=gra;
+
+ this_->button_cb=callback_new_attr_1(callback_cast(gui_qml_button), attr_button, this_);
+ graphics_add_callback(gra, this_->button_cb);
+
+ this_->switcherWidget = new QStackedLayout();
+ _mainWindow = new QWidget();
+ this_->mainWindow=_mainWindow;
+ this_->mainWindow->setLayout(this_->switcherWidget);
+
+ 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. Try 'qt_qpainter'"));
+ dbg(lvl_error,"Sorry, current graphics type is incompatible with this gui. Try 'qt_qpainter'");
+ }
+
+ // A bunch of useless controls only to test layouts
+ QTabWidget* m_tabWindow = new QTabWidget;
+ QWidget* m_exitBtn = new QPushButton("Button");
+ QVBoxLayout *vLayout = new QVBoxLayout;
+ vLayout->addStretch();
+ QHBoxLayout *hLayout = new QHBoxLayout;
+ hLayout->addStretch();
+ hLayout->addWidget(m_exitBtn);
+ hLayout->addStretch();
+ vLayout->addLayout(hLayout);
+ vLayout->addStretch();
+
+ QWidget *w = new QWidget;
+ w->setLayout(vLayout);
+ m_tabWindow->addTab(w, "Basic");
+
+ m_tabWindow->addTab(this_->graphicsWidget, "Map ");
+ this_->switcherWidget->addWidget(m_tabWindow);
+// this_->switcherWidget->addWidget(this_->graphicsWidget);
+
+ navit_draw(this_->nav);
+ // this_->switcherWidget->addWidget(this_->guiWidget);
+ this_->switcherWidget->setCurrentWidget(this_->graphicsWidget);
+
+ this_->mainWindow->show();
+
+ return 0;
+}
+
+struct gui_methods gui_qml_methods = {
+ NULL,
+ NULL,
+ gui_qml_set_graphics,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ gui_qml_get_attr,
+ NULL,
+ gui_qml_set_attr,
+};
+
+static void
+gui_qml_command(struct gui_priv *this_, char *function, struct attr **in, struct attr ***out, int *valid) {
+ dbg(lvl_debug, "gui_qml_command called\n");
+ // this_->guiProxy->processCommand(function);
+}
+
+static struct command_table commands[] = {
+ {"*",command_cast(gui_qml_command)},
+};
+
+static struct gui_priv * gui_qml_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs, struct gui *gui)
+{
+ dbg(lvl_info,"Initializing qml2 gui\n");
+ struct gui_priv *this_;
+ struct attr *attr;
+ *meth=gui_qml_methods;
+ this_=g_new0(struct gui_priv, 1);
+
+ this_->nav=nav;
+ this_->gui=gui;
+
+ this_->self.type=attr_gui;
+ this_->self.u.gui=gui;
+
+ // navit_ignore_graphics_events(this_->nav, 1);
+
+ this_->menu_on_map_click = 1;
+
+ if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
+ command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), this_);
+ }
+
+ this_->cbl=callback_list_new();
+
+ return this_;
+}
+
+void plugin_init(void) {
+ plugin_register_gui_type("qml2",gui_qml_new);
+}