summaryrefslogtreecommitdiff
path: root/navit/graphics/qt5
diff options
context:
space:
mode:
Diffstat (limited to 'navit/graphics/qt5')
-rw-r--r--navit/graphics/qt5/CMakeLists.txt12
-rw-r--r--navit/graphics/qt5/QNavitQuick.cpp108
-rw-r--r--navit/graphics/qt5/QNavitQuick.h3
-rw-r--r--navit/graphics/qt5/QNavitWidget.cpp98
-rw-r--r--navit/graphics/qt5/QNavitWidget.h8
-rw-r--r--navit/graphics/qt5/event_qt5.cpp79
-rw-r--r--navit/graphics/qt5/event_qt5.h4
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp307
-rw-r--r--navit/graphics/qt5/graphics_qt5.h4
-rw-r--r--navit/graphics/qt5/loader.qml2
10 files changed, 292 insertions, 333 deletions
diff --git a/navit/graphics/qt5/CMakeLists.txt b/navit/graphics/qt5/CMakeLists.txt
index ff359e88f..0ba6dbc62 100644
--- a/navit/graphics/qt5/CMakeLists.txt
+++ b/navit/graphics/qt5/CMakeLists.txt
@@ -15,20 +15,20 @@ set(HAVE_FREETYPE 0)
# check if we have FREETYPE
if(font/freetype)
- set(HAVE_FREETYPE 1)
+ set(HAVE_FREETYPE 1)
endif()
# check if we have QML
if(USE_QML)
- set(QML 1)
- qt5_add_resources(QT5_QRC "graphics_qt5.qrc")
- set(GRAPHICS_QT5_ADDITIONAL ${GRAPHICS_QT5_ADDITIONAL} "QNavitQuick.cpp" ${QT5_QRC})
+ set(QML 1)
+ qt5_add_resources(QT5_QRC "graphics_qt5.qrc")
+ set(GRAPHICS_QT5_ADDITIONAL ${GRAPHICS_QT5_ADDITIONAL} "QNavitQuick.cpp" ${QT5_QRC})
endif ()
#check if we have QWIDGET
if(USE_QWIDGET)
- set(QWIDGET 1)
- set(GRAPHICS_QT5_ADDITIONAL ${GRAPHICS_QT5_ADDITIONAL} "QNavitWidget.cpp")
+ set(QWIDGET 1)
+ set(GRAPHICS_QT5_ADDITIONAL ${GRAPHICS_QT5_ADDITIONAL} "QNavitWidget.cpp")
endif ()
module_add_library(graphics_qt5 graphics_qt5.cpp event_qt5.cpp ${GRAPHICS_QT5_ADDITIONAL})
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp
index 7df3e0073..dcd0d2aa5 100644
--- a/navit/graphics/qt5/QNavitQuick.cpp
+++ b/navit/graphics/qt5/QNavitQuick.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-//Style with: clang-format -style=WebKit -i
#include <glib.h>
#ifdef HAVE_UNISTD_H
@@ -46,21 +45,18 @@ extern "C" {
#include <QPainter>
QNavitQuick::QNavitQuick(QQuickItem* parent)
- : QQuickPaintedItem(parent)
-{
+ : QQuickPaintedItem(parent) {
setAcceptedMouseButtons(Qt::AllButtons);
graphics_priv = NULL;
}
-void QNavitQuick::setGraphicContext(GraphicsPriv* gp)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::setGraphicContext(GraphicsPriv* gp) {
+ dbg(lvl_debug, "enter");
graphics_priv = gp->gp;
QObject::connect(gp, SIGNAL(update()), this, SLOT(update()));
}
-static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event)
-{
+static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) {
GHashTableIter iter;
struct graphics_priv *key, *value;
g_hash_table_iter_init(&iter, gp->overlays);
@@ -68,7 +64,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
if (!value->disable) {
QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height());
if (event->rect().intersects(rr)) {
- dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)\n", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height());
+ dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y,
+ value->pixmap->width(), value->pixmap->height());
painter->drawPixmap(value->x, value->y, *value->pixmap);
/* draw overlays of overlay if any by recursive calling */
paintOverlays(painter, value, event);
@@ -77,11 +74,12 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
}
}
-void QNavitQuick::paint(QPainter* painter)
-{
- QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()));
+void QNavitQuick::paint(QPainter* painter) {
+ QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(),
+ boundingRect().height()));
- dbg(lvl_debug, "enter (%f, %f, %f, %f)\n", boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height());
+ dbg(lvl_debug, "enter (%f, %f, %f, %f)", boundingRect().x(), boundingRect().y(), boundingRect().width(),
+ boundingRect().height());
/* color background if any */
if (graphics_priv->background_graphics_gc_priv != NULL) {
@@ -90,14 +88,16 @@ void QNavitQuick::paint(QPainter* painter)
}
/* draw base */
painter->drawPixmap(graphics_priv->scroll_x, graphics_priv->scroll_y, *graphics_priv->pixmap,
- boundingRect().x(), boundingRect().y(),
- boundingRect().width(), boundingRect().height());
- paintOverlays(painter, graphics_priv, &event);
+ boundingRect().x(), boundingRect().y(),
+ boundingRect().width(), boundingRect().height());
+ /* disable on root pane disables ALL overlays (for drag of background) */
+ if(!(graphics_priv->disable)) {
+ paintOverlays(painter, graphics_priv, &event);
+ }
}
-void QNavitQuick::keyPressEvent(QKeyEvent* event)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::keyPressEvent(QKeyEvent* event) {
+ dbg(lvl_debug, "enter");
char key[2];
int keycode;
char* text = NULL;
@@ -157,89 +157,89 @@ void QNavitQuick::keyPressEvent(QKeyEvent* event)
else if (key[0])
callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key);
else
- dbg(lvl_debug, "keyval 0x%x\n", keycode);
+ dbg(lvl_debug, "keyval 0x%x", keycode);
}
-void QNavitQuick::keyReleaseEvent(QKeyEvent* event)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::keyReleaseEvent(QKeyEvent* event) {
+ dbg(lvl_debug, "enter");
}
-void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
+ dbg(lvl_debug, "enter");
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
QPainter* painter = NULL;
if (graphics_priv == NULL) {
- dbg(lvl_debug, "Context not set, aborting\n");
+ dbg(lvl_debug, "Context not set, aborting");
return;
}
if (graphics_priv->pixmap != NULL) {
- delete graphics_priv->pixmap;
- graphics_priv->pixmap = NULL;
+ if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) {
+ delete graphics_priv->pixmap;
+ graphics_priv->pixmap = NULL;
+ }
+ }
+ if (graphics_priv->pixmap == NULL) {
+ graphics_priv->pixmap = new QPixmap(width(), height());
}
-
- graphics_priv->pixmap = new QPixmap(width(), height());
painter = new QPainter(graphics_priv->pixmap);
if (painter != NULL) {
QBrush brush;
painter->fillRect(0, 0, width(), height(), brush);
delete painter;
}
- dbg(lvl_debug, "size %fx%f\n", width(), height());
- dbg(lvl_debug, "pixmap %p %dx%d\n", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
+ dbg(lvl_debug, "size %fx%f", width(), height());
+ dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(),
+ graphics_priv->pixmap->height());
/* if the root window got resized, tell navit about it */
if (graphics_priv->root)
resize_callback(graphics_priv, width(), height());
}
-void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event)
-{
+void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event) {
struct point p;
- dbg(lvl_debug, "enter\n");
+ dbg(lvl_debug, "enter");
p.x = event->x();
p.y = event->y();
switch (event->button()) {
case Qt::LeftButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1),
+ GINT_TO_POINTER(&p));
break;
case Qt::MidButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2),
+ GINT_TO_POINTER(&p));
break;
case Qt::RightButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3),
+ GINT_TO_POINTER(&p));
break;
default:
break;
}
}
-void QNavitQuick::mousePressEvent(QMouseEvent* event)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::mousePressEvent(QMouseEvent* event) {
+ dbg(lvl_debug, "enter");
mouseEvent(1, event);
}
-void QNavitQuick::mouseReleaseEvent(QMouseEvent* event)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::mouseReleaseEvent(QMouseEvent* event) {
+ dbg(lvl_debug, "enter");
mouseEvent(0, event);
}
-void QNavitQuick::mouseMoveEvent(QMouseEvent* event)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitQuick::mouseMoveEvent(QMouseEvent* event) {
+ dbg(lvl_debug, "enter");
struct point p;
p.x = event->x();
p.y = event->y();
callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p);
}
-void QNavitQuick::wheelEvent(QWheelEvent* event)
-{
+void QNavitQuick::wheelEvent(QWheelEvent* event) {
struct point p;
int button;
- dbg(lvl_debug, "enter\n");
+ dbg(lvl_debug, "enter");
p.x = event->x(); // xy-coordinates of the mouse pointer
p.y = event->y();
@@ -251,8 +251,10 @@ void QNavitQuick::wheelEvent(QWheelEvent* event)
button = -1;
if (button != -1) {
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
}
event->accept();
diff --git a/navit/graphics/qt5/QNavitQuick.h b/navit/graphics/qt5/QNavitQuick.h
index 3679e8127..40c6639ae 100644
--- a/navit/graphics/qt5/QNavitQuick.h
+++ b/navit/graphics/qt5/QNavitQuick.h
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#ifndef QNAVITQUICK_H
#define QNAVITQUICK_H
@@ -29,9 +28,9 @@ class QNavitQuick;
class QNavitQuick : public QQuickPaintedItem {
Q_OBJECT
public:
+ void paint(QPainter* painter);
QNavitQuick(QQuickItem* parent = 0);
- void paint(QPainter* painter);
Q_INVOKABLE void setGraphicContext(GraphicsPriv* gp);
diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp
index 5a5bd303b..355187b49 100644
--- a/navit/graphics/qt5/QNavitWidget.cpp
+++ b/navit/graphics/qt5/QNavitWidget.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#ifdef HAVE_UNISTD_H
@@ -46,23 +45,20 @@ extern "C" {
#include "graphics_qt5.h"
QNavitWidget::QNavitWidget(struct graphics_priv* my_graphics_priv,
- QWidget* parent,
- Qt::WindowFlags flags)
- : QWidget(parent, flags)
-{
+ QWidget* parent,
+ Qt::WindowFlags flags)
+ : QWidget(parent, flags) {
graphics_priv = my_graphics_priv;
}
-bool QNavitWidget::event(QEvent* event)
-{
+bool QNavitWidget::event(QEvent* event) {
if (event->type() == QEvent::Gesture)
dbg(lvl_debug, "Gesture event caught");
//return gestureEvent(static_cast<QGestureEvent*>(event));
return QWidget::event(event);
}
-static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event)
-{
+static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) {
GHashTableIter iter;
struct graphics_priv *key, *value;
g_hash_table_iter_init(&iter, gp->overlays);
@@ -70,7 +66,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
if (!value->disable) {
QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height());
if (event->rect().intersects(rr)) {
- dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)\n", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height());
+ dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y,
+ value->pixmap->width(), value->pixmap->height());
painter->drawPixmap(value->x + value->scroll_x, value->y + value->scroll_y, *value->pixmap);
/* draw overlays of overlay if any by recursive calling */
paintOverlays(painter, value, event);
@@ -79,9 +76,9 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
}
}
-void QNavitWidget::paintEvent(QPaintEvent* event)
-{
- dbg(lvl_debug, "enter (%d, %d, %d, %d)\n", event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height());
+void QNavitWidget::paintEvent(QPaintEvent* event) {
+ dbg(lvl_debug, "enter (%d, %d, %d, %d)", event->rect().x(), event->rect().y(), event->rect().width(),
+ event->rect().height());
QPainter painter(this);
/* color background if any */
if (graphics_priv->background_graphics_gc_priv != NULL) {
@@ -89,57 +86,64 @@ void QNavitWidget::paintEvent(QPaintEvent* event)
painter.fillRect(event->rect(), *graphics_priv->background_graphics_gc_priv->brush);
}
painter.drawPixmap(event->rect().x(), event->rect().y(), *graphics_priv->pixmap,
- event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
- event->rect().width(), event->rect().height());
- paintOverlays(&painter, graphics_priv, event);
+ event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
+ event->rect().width(), event->rect().height());
+ /* disable on root pane disables ALL overlays (for drag of background) */
+ if(!(graphics_priv->disable)) {
+ paintOverlays(&painter, graphics_priv, event);
+ };
}
-void QNavitWidget::resizeEvent(QResizeEvent* event)
-{
+void QNavitWidget::resizeEvent(QResizeEvent* event) {
QPainter* painter = NULL;
if (graphics_priv->pixmap != NULL) {
- delete graphics_priv->pixmap;
- graphics_priv->pixmap = NULL;
+ if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) {
+ delete graphics_priv->pixmap;
+ graphics_priv->pixmap = NULL;
+ }
+ }
+ if (graphics_priv->pixmap == NULL) {
+ graphics_priv->pixmap = new QPixmap(size());
}
-
- graphics_priv->pixmap = new QPixmap(size());
painter = new QPainter(graphics_priv->pixmap);
if (painter != NULL) {
QBrush brush;
painter->fillRect(0, 0, width(), height(), brush);
delete painter;
}
- dbg(lvl_debug, "size %dx%d\n", width(), height());
- dbg(lvl_debug, "pixmap %p %dx%d\n", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
+ dbg(lvl_debug, "size %dx%d", width(), height());
+ dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(),
+ graphics_priv->pixmap->height());
/* if the root window got resized, tell navit about it */
if (graphics_priv->root)
resize_callback(graphics_priv, width(), height());
}
-void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event)
-{
+void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) {
struct point p;
- // dbg(lvl_debug,"enter\n");
+ // dbg(lvl_debug,"enter");
p.x = event->x();
p.y = event->y();
switch (event->button()) {
case Qt::LeftButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1),
+ GINT_TO_POINTER(&p));
break;
case Qt::MidButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2),
+ GINT_TO_POINTER(&p));
break;
case Qt::RightButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3),
+ GINT_TO_POINTER(&p));
break;
default:
break;
}
}
-void QNavitWidget::keyPressEvent(QKeyEvent* event)
-{
- dbg(lvl_debug, "enter\n");
+void QNavitWidget::keyPressEvent(QKeyEvent* event) {
+ dbg(lvl_debug, "enter");
char key[2];
int keycode;
char* text = NULL;
@@ -199,35 +203,31 @@ void QNavitWidget::keyPressEvent(QKeyEvent* event)
else if (key[0])
callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key);
else
- dbg(lvl_debug, "keyval 0x%x\n", keycode);
+ dbg(lvl_debug, "keyval 0x%x", keycode);
}
-void QNavitWidget::mousePressEvent(QMouseEvent* event)
-{
- // dbg(lvl_debug,"enter\n");
+void QNavitWidget::mousePressEvent(QMouseEvent* event) {
+ // dbg(lvl_debug,"enter");
mouseEvent(1, event);
}
-void QNavitWidget::mouseReleaseEvent(QMouseEvent* event)
-{
- // dbg(lvl_debug,"enter\n");
+void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) {
+ // dbg(lvl_debug,"enter");
mouseEvent(0, event);
}
-void QNavitWidget::mouseMoveEvent(QMouseEvent* event)
-{
+void QNavitWidget::mouseMoveEvent(QMouseEvent* event) {
struct point p;
- // dbg(lvl_debug,"enter\n");
+ // dbg(lvl_debug,"enter");
p.x = event->x();
p.y = event->y();
callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p);
}
-void QNavitWidget::wheelEvent(QWheelEvent* event)
-{
+void QNavitWidget::wheelEvent(QWheelEvent* event) {
struct point p;
int button;
- dbg(lvl_debug, "enter\n");
+ dbg(lvl_debug, "enter");
p.x = event->x(); // xy-coordinates of the mouse pointer
p.y = event->y();
@@ -239,8 +239,10 @@ void QNavitWidget::wheelEvent(QWheelEvent* event)
button = -1;
if (button != -1) {
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
}
event->accept();
diff --git a/navit/graphics/qt5/QNavitWidget.h b/navit/graphics/qt5/QNavitWidget.h
index 674b69390..40fb88b19 100644
--- a/navit/graphics/qt5/QNavitWidget.h
+++ b/navit/graphics/qt5/QNavitWidget.h
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#ifndef __QNavitWidget_h
#define __QNavitWidget_h
@@ -30,10 +29,9 @@ class QNavitWidget;
class QNavitWidget : public QWidget {
Q_OBJECT
-public:
- QNavitWidget(struct graphics_priv* my_graphics_priv,
- QWidget* parent,
- Qt::WindowFlags flags);
+public: QNavitWidget(struct graphics_priv* my_graphics_priv,
+ QWidget* parent,
+ Qt::WindowFlags flags);
protected:
virtual bool event(QEvent* event);
diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp
index 08fb6e525..70870ece7 100644
--- a/navit/graphics/qt5/event_qt5.cpp
+++ b/navit/graphics/qt5/event_qt5.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#include <stdio.h>
@@ -58,12 +57,20 @@ struct event_watch {
static void event_qt5_remove_timeout(struct event_timeout* to);
qt5_navit_timer::qt5_navit_timer(QObject* parent)
- : QObject(parent)
-{
+ : QObject(parent) {
timer_type = g_hash_table_new(NULL, NULL);
timer_callback = g_hash_table_new(NULL, NULL);
watches = g_hash_table_new(NULL, NULL);
- dbg(lvl_debug, "qt5_navit_timer object created\n");
+ dbg(lvl_debug, "qt5_navit_timer object created");
+}
+
+void qt5_navit_timer::watchEvent(int id) {
+ struct event_watch* ret = g_new0(struct event_watch, 1);
+ ret = (struct event_watch*)g_hash_table_lookup(watches, (void*)(long)id);
+ if (ret) {
+ dbg(lvl_debug, "callback found, calling it");
+ callback_call_0(ret->cb);
+ }
}
void qt5_navit_timer::watchEvent(int id)
@@ -80,7 +87,7 @@ void qt5_navit_timer::timerEvent(QTimerEvent* event)
{
int id = event->timerId();
void* multi = NULL;
- // dbg(lvl_debug, "TimerEvent (%d)\n", id);
+ // dbg(lvl_debug, "TimerEvent (%d)", id);
struct callback* cb = (struct callback*)g_hash_table_lookup(timer_callback, (void*)(long)id);
if (cb)
callback_call_0(cb);
@@ -90,30 +97,25 @@ void qt5_navit_timer::timerEvent(QTimerEvent* event)
if (((int)(long)multi) == 0)
event_qt5_remove_timeout((struct event_timeout*)(long)id);
}
- // dbg(lvl_debug, "TimerEvent (%d) leave\n", id);
+ // dbg(lvl_debug, "TimerEvent (%d) leave", id);
}
qt5_navit_timer* qt5_timer = NULL;
-static void
-event_qt5_main_loop_run(void)
-{
+static void event_qt5_main_loop_run(void) {
- dbg(lvl_debug, "enter\n");
+ dbg(lvl_debug, "enter");
if (navit_app != NULL)
navit_app->exec();
}
-static void event_qt5_main_loop_quit(void)
-{
- dbg(lvl_debug, "enter\n");
+static void event_qt5_main_loop_quit(void) {
+ dbg(lvl_debug, "enter");
exit(0);
}
-static struct event_watch*
-event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb)
-{
- dbg(lvl_debug, "enter fd=%d\n", (int)(long)fd);
+static struct event_watch* event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb) {
+ dbg(lvl_debug, "enter fd=%d", (int)(long)fd);
struct event_watch* ret = g_new0(struct event_watch, 1);
ret->fd = fd;
ret->cb = cb;
@@ -123,54 +125,42 @@ event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb)
return ret;
}
-static void
-event_qt5_remove_watch(struct event_watch* ev)
-{
- dbg(lvl_debug, "enter\n");
+static void event_qt5_remove_watch(struct event_watch* ev) {
+ dbg(lvl_debug, "enter");
g_hash_table_remove(qt5_timer->watches, GINT_TO_POINTER(ev->fd));
delete (ev->sn);
g_free(ev);
}
-static struct event_timeout*
-event_qt5_add_timeout(int timeout, int multi, struct callback* cb)
-{
+static struct event_timeout* event_qt5_add_timeout(int timeout, int multi, struct callback* cb) {
int id;
dbg(lvl_debug, "add timeout %d, mul %d, %p ==", timeout, multi, cb);
id = qt5_timer->startTimer(timeout);
- dbg(lvl_debug, "%d\n", id);
+ dbg(lvl_debug, "%d", id);
g_hash_table_insert(qt5_timer->timer_callback, (void*)(long)id, cb);
g_hash_table_insert(qt5_timer->timer_type, (void*)(long)id, (void*)(long)!!multi);
return (struct event_timeout*)(long)id;
}
-static void
-event_qt5_remove_timeout(struct event_timeout* to)
-{
- dbg(lvl_debug, "remove timeout (%d)\n", (int)(long)to);
+static void event_qt5_remove_timeout(struct event_timeout* to) {
+ dbg(lvl_debug, "remove timeout (%d)", (int)(long)to);
qt5_timer->killTimer((int)(long)to);
g_hash_table_remove(qt5_timer->timer_callback, to);
g_hash_table_remove(qt5_timer->timer_type, to);
}
-static struct event_idle*
-event_qt5_add_idle(int priority, struct callback* cb)
-{
- dbg(lvl_debug, "add idle event\n");
+static struct event_idle* event_qt5_add_idle(int priority, struct callback* cb) {
+ dbg(lvl_debug, "add idle event");
return (struct event_idle*)event_qt5_add_timeout(0, 1, cb);
}
-static void
-event_qt5_remove_idle(struct event_idle* ev)
-{
- dbg(lvl_debug, "Remove idle timeout\n");
+static void event_qt5_remove_idle(struct event_idle* ev) {
+ dbg(lvl_debug, "Remove idle timeout");
event_qt5_remove_timeout((struct event_timeout*)ev);
}
-static void
-event_qt5_call_callback(struct callback_list* cb)
-{
- dbg(lvl_debug, "enter\n");
+static void event_qt5_call_callback(struct callback_list* cb) {
+ dbg(lvl_debug, "enter");
}
static struct event_methods event_qt5_methods = {
@@ -185,15 +175,12 @@ static struct event_methods event_qt5_methods = {
event_qt5_call_callback,
};
-static struct event_priv*
-event_qt5_new(struct event_methods* meth)
-{
+static struct event_priv* event_qt5_new(struct event_methods* meth) {
*meth = event_qt5_methods;
qt5_timer = new qt5_navit_timer(NULL);
return NULL;
}
-void qt5_event_init(void)
-{
+void qt5_event_init(void) {
plugin_register_category_event("qt5", event_qt5_new);
}
diff --git a/navit/graphics/qt5/event_qt5.h b/navit/graphics/qt5/event_qt5.h
index 892e8fca8..7fe184cd1 100644
--- a/navit/graphics/qt5/event_qt5.h
+++ b/navit/graphics/qt5/event_qt5.h
@@ -16,15 +16,13 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <QObject>
#include <glib.h>
class qt5_navit_timer : public QObject {
Q_OBJECT
-public:
- qt5_navit_timer(QObject* parent = 0);
+public: qt5_navit_timer(QObject* parent = 0);
GHashTable* timer_type;
GHashTable* timer_callback;
GHashTable* watches;
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index f7ac15f43..e7b31c605 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#ifdef HAVE_UNISTD_H
@@ -64,17 +63,14 @@ extern "C" {
#endif
#if USE_QML
-GraphicsPriv::GraphicsPriv(struct graphics_priv* gp)
-{
+GraphicsPriv::GraphicsPriv(struct graphics_priv* gp) {
this->gp = gp;
}
-GraphicsPriv::~GraphicsPriv()
-{
+GraphicsPriv::~GraphicsPriv() {
}
-void GraphicsPriv::emit_update()
-{
+void GraphicsPriv::emit_update() {
emit update();
}
#endif
@@ -89,10 +85,8 @@ struct graphics_image_priv {
QPixmap* pixmap;
};
-static void
-graphics_destroy(struct graphics_priv* gr)
-{
-// dbg(lvl_debug,"enter\n");
+static void graphics_destroy(struct graphics_priv* gr) {
+// dbg(lvl_debug,"enter");
#if HAVE_FREETYPE
gr->freetype_methods.destroy();
#endif
@@ -144,9 +138,8 @@ graphics_destroy(struct graphics_priv* gr)
g_free(gr);
}
-static void font_destroy(struct graphics_font_priv* font)
-{
- // dbg(lvl_debug,"enter\n");
+static void font_destroy(struct graphics_font_priv* font) {
+ // dbg(lvl_debug,"enter");
if (font->font != NULL)
delete (font->font);
g_free(font);
@@ -186,11 +179,11 @@ static const char* fontfamilies[] = {
*
* Allocates a font handle and returnes filled interface stucture
*/
-static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, int size, int flags)
-{
+static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font,
+ int size, int flags) {
int a = 0;
struct graphics_font_priv* font_priv;
- dbg(lvl_debug, "enter (font %s, %d, 0x%x)\n", font, size, flags);
+ dbg(lvl_debug, "enter (font %s, %d, 0x%x)", font, size, flags);
font_priv = g_new0(struct graphics_font_priv, 1);
font_priv->font = new QFont(fontfamilies[0]);
if (font != NULL)
@@ -201,7 +194,7 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
a++;
}
if (font_priv->font->exactMatch()) {
- dbg(lvl_debug, "Exactly matching font: %s\n", font_priv->font->family().toUtf8().data());
+ dbg(lvl_debug, "Exactly matching font: %s", font_priv->font->family().toUtf8().data());
} else {
/* set any font*/
if (font != NULL) {
@@ -209,7 +202,7 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
} else {
font_priv->font->setFamily(fontfamilies[0]);
}
- dbg(lvl_debug, "No matching font. Resort to: %s\n", font_priv->font->family().toUtf8().data());
+ dbg(lvl_debug, "No matching font. Resort to: %s", font_priv->font->family().toUtf8().data());
}
/* No clue why factor 20. Found this by comparing to Freetype rendering. */
@@ -224,25 +217,19 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
return font_priv;
}
-static void
-gc_destroy(struct graphics_gc_priv* gc)
-{
- // dbg(lvl_debug,"enter gc=%p\n", gc);
+static void gc_destroy(struct graphics_gc_priv* gc) {
+ // dbg(lvl_debug,"enter gc=%p", gc);
delete (gc->pen);
delete (gc->brush);
g_free(gc);
}
-static void
-gc_set_linewidth(struct graphics_gc_priv* gc, int w)
-{
- // dbg(lvl_debug,"enter gc=%p, %d\n", gc, w);
+static void gc_set_linewidth(struct graphics_gc_priv* gc, int w) {
+ // dbg(lvl_debug,"enter gc=%p, %d", gc, w);
gc->pen->setWidth(w);
}
-static void
-gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n)
-{
+static void gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n) {
if (n <= 0) {
dbg(lvl_error, "Refuse to set dashes without dash pattern");
}
@@ -262,21 +249,17 @@ gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* das
gc->pen->setDashPattern(dashes);
}
-static void
-gc_set_foreground(struct graphics_gc_priv* gc, struct color* c)
-{
+static void gc_set_foreground(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
- // dbg(lvl_debug,"context %p: color %02x%02x%02x\n",gc, c->r >> 8, c->g >> 8, c->b >> 8);
+ // dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
gc->pen->setColor(col);
gc->brush->setColor(col);
//gc->c=*c;
}
-static void
-gc_set_background(struct graphics_gc_priv* gc, struct color* c)
-{
+static void gc_set_background(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
- // dbg(lvl_debug,"context %p: color %02x%02x%02x\n",gc, c->r >> 8, c->g >> 8, c->b >> 8);
+ // dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
//gc->pen->setColor(col);
//gc->brush->setColor(col);
}
@@ -289,10 +272,9 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth)
-{
+static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth) {
struct graphics_gc_priv* graphics_gc_priv = NULL;
- // dbg(lvl_debug,"enter gr==%p\n", gr);
+ // dbg(lvl_debug,"enter gr==%p", gr);
graphics_gc_priv = g_new0(struct graphics_gc_priv, 1);
graphics_gc_priv->graphics_priv = gr;
graphics_gc_priv->pen = new QPen();
@@ -302,9 +284,8 @@ static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics
return graphics_gc_priv;
}
-static void image_destroy(struct graphics_image_priv* img)
-{
- // dbg(lvl_debug, "enter\n");
+static void image_destroy(struct graphics_image_priv* img) {
+ // dbg(lvl_debug, "enter");
if (img->pixmap != NULL)
delete (img->pixmap);
g_free(img);
@@ -314,18 +295,21 @@ struct graphics_image_methods image_methods = {
image_destroy
};
-static struct graphics_image_priv*
-image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot, int rotation)
-{
+static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path,
+ int* w, int* h, struct point* hot, int rotation) {
struct graphics_image_priv* image_priv;
- // dbg(lvl_debug,"enter %s, %d %d\n", path, *w, *h);
+ // dbg(lvl_debug,"enter %s, %d %d", path, *w, *h);
if (path[0] == 0) {
- dbg(lvl_debug, "Refuse to load image without path\n");
+ dbg(lvl_debug, "Refuse to load image without path");
return NULL;
}
QString key(path);
QString renderer_key(key);
- QString extension = key.right(key.lastIndexOf("."));
+ int index = key.lastIndexOf(".");
+ QString extension;
+ if(index > 0) {
+ extension = key.right(index);
+ }
QFile imagefile(key);
if (!imagefile.exists()) {
/* file doesn't exit. Either navit wants us to guess file name by
@@ -333,11 +317,11 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
*/
if (extension != "") {
/*file doesn't exist. give up */
- dbg(lvl_debug, "File %s does not exist\n", path);
+ dbg(lvl_debug, "File %s does not exist", path);
return NULL;
} else {
/* add ".svg" for renderer to try .svg file first in renderer */
- dbg(lvl_debug, "Guess extension on %s\n", path);
+ dbg(lvl_debug, "Guess extension on %s", path);
renderer_key += ".svg";
}
}
@@ -348,7 +332,7 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
if (renderer_key.endsWith("svg")) {
QSvgRenderer renderer(renderer_key);
if (renderer.isValid()) {
- dbg(lvl_debug, "render %s\n", path);
+ dbg(lvl_debug, "render %s", path);
/* try to render this */
/* assume "standard" size if size is not given */
if (*w <= 0)
@@ -364,19 +348,20 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
if (image_priv->pixmap == NULL) {
/*cannot be rendered. try to load it */
- dbg(lvl_debug, "cannot render %s\n", path);
+ dbg(lvl_debug, "cannot render %s", path);
image_priv->pixmap = new QPixmap(key);
}
/* check if we got image */
- if (image_priv->pixmap->isNull()) {
+ if ((image_priv->pixmap == NULL) || (image_priv->pixmap->isNull())) {
g_free(image_priv);
return NULL;
} else {
/* check if we need to scale this */
if ((*w > 0) && (*h > 0)) {
if ((image_priv->pixmap->width() != *w) || (image_priv->pixmap->height() != *h)) {
- dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d\n", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(), *h);
+ dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(),
+ *h);
QPixmap* scaled = new QPixmap(image_priv->pixmap->scaled(*w, *h, Qt::IgnoreAspectRatio, Qt::FastTransformation));
delete (image_priv->pixmap);
image_priv->pixmap = scaled;
@@ -386,7 +371,7 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
*w = image_priv->pixmap->width();
*h = image_priv->pixmap->height();
- // dbg(lvl_debug, "Got (%d,%d)\n", *w,*h);
+ // dbg(lvl_debug, "Got (%d,%d)", *w,*h);
if (hot) {
hot->x = *w / 2;
hot->y = *h / 2;
@@ -395,12 +380,10 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
return image_priv;
}
-static void
-draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+static void draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
- // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)\n", gr, gc, p->x, p->y);
+ // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
if (gr->painter == NULL)
return;
@@ -410,12 +393,10 @@ draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
gr->painter->drawPolyline(polygon);
}
-static void
-draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+static void draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
- // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)\n", gr, gc, p->x, p->y);
+ // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
if (gr->painter == NULL)
return;
@@ -433,10 +414,8 @@ draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point
gr->painter->drawPolygon(polygon);
}
-static void
-draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h)
-{
- // dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d\n", gr, gc, p->x, p->y, w, h);
+static void draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h) {
+ // dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
if (gr->painter == NULL)
return;
/* if the rectangle is transparent, we need to clear it first */
@@ -449,10 +428,8 @@ draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct poi
gr->painter->fillRect(p->x, p->y, w, h, *gc->brush);
}
-static void
-draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r)
-{
- // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d\n", gr, gc, p->x, p->y, r);
+static void draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r) {
+ // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d", gr, gc, p->x, p->y, r);
if (gr->painter == NULL)
return;
gr->painter->setPen(*gc->pen);
@@ -472,10 +449,9 @@ draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
*
* Renders given text on gr surface. Draws nice contrast outline around text.
*/
-static void
-draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy)
-{
- dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s\n", gr, fg, bg, p->x, p->y, dx, dy, text);
+static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg,
+ struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) {
+ dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s", gr, fg, bg, p->x, p->y, dx, dy, text);
QPainter* painter = gr->painter;
if (painter == NULL)
return;
@@ -565,14 +541,13 @@ draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics
#endif
}
-static void
-draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img)
-{
- // dbg(lvl_debug,"enter\n");
+static void draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p,
+ struct graphics_image_priv* img) {
+ // dbg(lvl_debug,"enter");
if (gr->painter != NULL)
gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
else
- dbg(lvl_debug, "Try to draw image, but no painter\n");
+ dbg(lvl_debug, "Try to draw image, but no painter");
}
/**
@@ -584,15 +559,14 @@ draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point*
* called for root layer. There the content of the root layer is to be moved
* by given vector. On root layer, NULL indicates the end of a drag.
*/
-static void draw_drag(struct graphics_priv* gr, struct point* p)
-{
+static void draw_drag(struct graphics_priv* gr, struct point* p) {
struct point vector;
if (p != NULL) {
- dbg(lvl_debug, "enter %p (%d,%d)\n", gr, p->x, p->y);
+ dbg(lvl_debug, "enter %p (%d,%d)", gr, p->x, p->y);
vector = *p;
} else {
- dbg(lvl_debug, "enter %p (NULL)\n", gr);
+ dbg(lvl_debug, "enter %p (NULL)", gr);
vector.x = 0;
vector.y = 0;
}
@@ -621,38 +595,34 @@ static void draw_drag(struct graphics_priv* gr, struct point* p)
}
}
-static void
-background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc)
-{
- // dbg(lvl_debug,"register context %p on %p\n", gc, gr);
+static void background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc) {
+ // dbg(lvl_debug,"register context %p on %p", gc, gr);
gr->background_graphics_gc_priv = gc;
}
-static void
-draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
-{
+static void draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) {
switch (mode) {
case draw_mode_begin:
- dbg(lvl_debug, "Begin drawing on context %p (use == %d)\n", gr, gr->use_count);
+ dbg(lvl_debug, "Begin drawing on context %p (use == %d)", gr, gr->use_count);
gr->use_count++;
if (gr->painter == NULL)
gr->painter = new QPainter(gr->pixmap);
else
- dbg(lvl_debug, "drawing on %p already active\n", gr);
+ dbg(lvl_debug, "drawing on %p already active", gr);
break;
case draw_mode_end:
- dbg(lvl_debug, "End drawing on context %p (use == %d)\n", gr, gr->use_count);
+ dbg(lvl_debug, "End drawing on context %p (use == %d)", gr, gr->use_count);
gr->use_count--;
if (gr->use_count < 0)
gr->use_count = 0;
if (gr->use_count > 0) {
- dbg(lvl_debug, "drawing on %p still in use\n", gr);
+ dbg(lvl_debug, "drawing on %p still in use", gr);
} else if (gr->painter != NULL) {
gr->painter->end();
delete (gr->painter);
gr->painter = NULL;
} else {
- dbg(lvl_debug, "Context %p not active!\n", gr)
+ dbg(lvl_debug, "Context %p not active!", gr)
}
#if USE_QWIDGET
/* call repaint on widget */
@@ -667,25 +637,22 @@ draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
break;
default:
- dbg(lvl_debug, "Unknown drawing %d on context %p\n", mode, gr);
+ dbg(lvl_debug, "Unknown drawing %d on context %p", mode, gr);
break;
}
}
-static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound);
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound);
-void resize_callback(struct graphics_priv* gr, int w, int h)
-{
- // dbg(lvl_debug,"enter (%d, %d)\n", w, h);
- callback_list_call_attr_2(gr->callbacks, attr_resize,
- GINT_TO_POINTER(w), GINT_TO_POINTER(h));
+void resize_callback(struct graphics_priv* gr, int w, int h) {
+ // dbg(lvl_debug,"enter (%d, %d)", w, h);
+ callback_list_call_attr_2(gr->callbacks, attr_resize, GINT_TO_POINTER(w), GINT_TO_POINTER(h));
}
-static int
-graphics_qt5_fullscreen(struct window* w, int on)
-{
+static int graphics_qt5_fullscreen(struct window* w, int on) {
struct graphics_priv* gr;
- // dbg(lvl_debug,"enter\n");
+ // dbg(lvl_debug,"enter");
gr = (struct graphics_priv*)w->priv;
#if USE_QML
if (gr->window != NULL) {
@@ -707,10 +674,8 @@ graphics_qt5_fullscreen(struct window* w, int on)
}
#ifdef SAILFISH_OS
-static void
-keep_display_on(struct graphics_priv* priv)
-{
- // dbg(lvl_debug,"enter\n");
+static void keep_display_on(struct graphics_priv* priv) {
+ // dbg(lvl_debug,"enter");
QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system);
@@ -718,10 +683,8 @@ keep_display_on(struct graphics_priv* priv)
}
#endif
-static void
-graphics_qt5_disable_suspend(struct window* w)
-{
-// dbg(lvl_debug,"enter\n");
+static void graphics_qt5_disable_suspend(struct window* w) {
+// dbg(lvl_debug,"enter");
#ifdef SAILFISH_OS
struct graphics_priv* gr;
gr = (struct graphics_priv*)w->priv;
@@ -733,13 +696,11 @@ graphics_qt5_disable_suspend(struct window* w)
#endif
}
-static void*
-get_data(struct graphics_priv* this_priv, char const* type)
-{
- // dbg(lvl_debug,"enter: %s\n", type);
+static void* get_data(struct graphics_priv* this_priv, char const* type) {
+ // dbg(lvl_debug,"enter: %s", type);
if (strcmp(type, "window") == 0) {
struct window* win;
- // dbg(lvl_debug,"window detected\n");
+ // dbg(lvl_debug,"window detected");
win = g_new0(struct window, 1);
win->priv = this_priv;
win->fullscreen = graphics_qt5_fullscreen;
@@ -748,15 +709,14 @@ get_data(struct graphics_priv* this_priv, char const* type)
return win;
}
if (strcmp(type, "engine") == 0) {
- dbg(lvl_debug, "Hand over QQmlApplicationEngine\n");
+ dbg(lvl_debug, "Hand over QQmlApplicationEngine");
return (this_priv->engine);
}
return NULL;
}
-static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv)
-{
- // dbg(lvl_debug,"enter\n");
+static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv) {
+ // dbg(lvl_debug,"enter");
delete (priv->pixmap);
g_free(priv);
}
@@ -773,13 +733,13 @@ static void image_free(struct graphics_priv* gr, struct graphics_image_priv* pri
*
* Calculates the bounding box around the given text.
*/
-static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, struct point* ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy,
+ struct point* ret, int estimate) {
int i;
struct point pt;
QString tmp = QString::fromUtf8(text);
QRect r;
- // dbg(lvl_debug,"enter %s %d %d\n", text, dx, dy);
+ // dbg(lvl_debug,"enter %s %d %d", text, dx, dy);
/* use QFontMetrix for bbox calculation as we do not always have a painter */
QFontMetrics fm(*font->font);
@@ -807,32 +767,46 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f
}
}
-static void overlay_disable(struct graphics_priv* gr, int disable)
-{
- GHashTableIter iter;
- struct graphics_priv *key, *value;
- // dbg(lvl_debug,"enter gr=%p, %d\n", gr, disable);
+static void overlay_disable(struct graphics_priv* gr, int disable) {
+ //dbg(lvl_error,"enter gr=%p, %d", gr, disable);
+ gr->disable = disable;
+#if USE_QWIDGET
+ /* call repaint on widget */
+ if (gr->widget != NULL)
+ gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height());
+#endif
+#if USE_QML
+ if (gr->GPriv != NULL)
+ gr->GPriv->emit_update();
- g_hash_table_iter_init(&iter, gr->overlays);
- while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) {
- /* disable or enable all overlays of this pane */
- value->disable = disable;
- }
+#endif
}
-static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound)
-{
- // dbg(lvl_debug,"enter\n");
+static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) {
+ // dbg(lvl_debug,"enter %d %d %d %d %d", p->x, p->y, w, h, wraparound);
gr->x = p->x;
gr->y = p->y;
if (gr->painter != NULL) {
delete (gr->painter);
}
- delete (gr->pixmap);
- gr->pixmap = new QPixmap(w, h);
- gr->pixmap->fill(Qt::transparent);
+ /* replacing the pixmap clears the content. Only neccesary if size actually changes */
+ if((gr->pixmap->height() != h) || (gr->pixmap->width() != w)) {
+ delete (gr->pixmap);
+ gr->pixmap = new QPixmap(w, h);
+ gr->pixmap->fill(Qt::transparent);
+ }
if (gr->painter != NULL)
gr->painter = new QPainter(gr->pixmap);
+#if USE_QWIDGET
+ /* call repaint on widget */
+ if (gr->widget != NULL)
+ gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height());
+#endif
+#if USE_QML
+ if (gr->GPriv != NULL)
+ gr->GPriv->emit_update();
+
+#endif
}
static struct graphics_methods graphics_methods = {
@@ -859,9 +833,8 @@ static struct graphics_methods graphics_methods = {
};
/* create new graphics context on given context */
-static struct graphics_priv*
-overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound)
-{
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound) {
struct graphics_priv* graphics_priv = NULL;
graphics_priv = g_new0(struct graphics_priv, 1);
*meth = graphics_methods;
@@ -869,8 +842,10 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
if (gr->font_freetype_new) {
graphics_priv->font_freetype_new = gr->font_freetype_new;
gr->font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
}
#endif
#if USE_QML
@@ -897,15 +872,14 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
graphics_priv->argv[0] = NULL;
/* register on parent */
g_hash_table_insert(gr->overlays, graphics_priv, graphics_priv);
- // dbg(lvl_debug,"New overlay: %p\n", graphics_priv);
+ // dbg(lvl_debug,"New overlay: %p", graphics_priv);
return graphics_priv;
}
/* create application and initial graphics context */
-static struct graphics_priv*
-graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl)
-{
+static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs,
+ struct callback_list* cbl) {
struct graphics_priv* graphics_priv = NULL;
struct attr* event_loop_system = NULL;
struct attr* platform = NULL;
@@ -914,7 +888,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
bool use_qml = USE_QML;
bool use_qwidget = USE_QWIDGET;
- //dbg(lvl_debug,"enter\n");
+ //dbg(lvl_debug,"enter");
/* get qt widget attr */
if ((attr_widget = attr_search(attrs, NULL, attr_qt5_widget))) {
@@ -938,7 +912,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* get event loop from config and request event loop*/
event_loop_system = attr_search(attrs, NULL, attr_event_loop_system);
if (event_loop_system && event_loop_system->u.str) {
- //dbg(lvl_debug, "event_system is %s\n", event_loop_system->u.str);
+ //dbg(lvl_debug, "event_system is %s", event_loop_system->u.str);
if (!event_request_system(event_loop_system->u.str, "graphics_qt5"))
return NULL;
} else {
@@ -952,7 +926,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* get font plugin if present */
font_freetype_new = (struct font_priv * (*)(void*))plugin_get_category_font("freetype");
if (!font_freetype_new) {
- dbg(lvl_error, "no freetype\n");
+ dbg(lvl_error, "no freetype");
return NULL;
}
#endif
@@ -971,7 +945,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
graphics_priv->argv[graphics_priv->argc] = g_strdup(platform->u.str);
graphics_priv->argc++;
}
-/* create surrounding application */
+ /* create surrounding application */
#if USE_QWIDGET
QApplication* internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv);
navit_app = internal_app;
@@ -982,8 +956,10 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
#if HAVE_FREETYPE
graphics_priv->font_freetype_new = font_freetype_new;
font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
#endif
graphics_priv->callbacks = cbl;
graphics_priv->pixmap = NULL;
@@ -1004,7 +980,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* register our QtQuick widget to allow it's usage within QML */
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 */
+ * QtQuick gui component if enabled */
graphics_priv->engine = new QQmlApplicationEngine();
if (graphics_priv->engine != NULL) {
graphics_priv->GPriv = new GraphicsPriv(graphics_priv);
@@ -1024,7 +1000,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
}
#endif
if ((fullscreen = attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) {
-/* show this maximized */
+ /* show this maximized */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->setWindowState(Qt::WindowFullScreen);
@@ -1083,7 +1059,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* tell Navit our geometry */
resize_callback(graphics_priv, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
-/* show our window */
+ /* show our window */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->show();
@@ -1096,12 +1072,11 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
return graphics_priv;
}
-void plugin_init(void)
-{
+void plugin_init(void) {
#if USE_QML
Q_INIT_RESOURCE(graphics_qt5);
#endif
- // dbg(lvl_debug,"enter\n");
+ // dbg(lvl_debug,"enter");
plugin_register_category_graphics("qt5", graphics_qt5_new);
qt5_event_init();
}
diff --git a/navit/graphics/qt5/graphics_qt5.h b/navit/graphics/qt5/graphics_qt5.h
index f9d19616b..0eed89510 100644
--- a/navit/graphics/qt5/graphics_qt5.h
+++ b/navit/graphics/qt5/graphics_qt5.h
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#ifndef __graphics_qt_h
#define __graphics_qt_h
@@ -62,8 +61,7 @@ struct graphics_priv;
#if USE_QML
class GraphicsPriv : public QObject {
Q_OBJECT
-public:
- GraphicsPriv(struct graphics_priv* gp);
+public: GraphicsPriv(struct graphics_priv* gp);
~GraphicsPriv();
void emit_update();
diff --git a/navit/graphics/qt5/loader.qml b/navit/graphics/qt5/loader.qml
index 9882cb23a..29dcb7832 100644
--- a/navit/graphics/qt5/loader.qml
+++ b/navit/graphics/qt5/loader.qml
@@ -4,7 +4,7 @@ import QtQuick.Window 2.0
Window {
width: 200; height: 200
-
+
Item {
id: root
anchors.fill: parent