diff options
author | Wildemann Stefan <stefan.wildemann@corpuls.com> | 2017-05-05 10:00:34 +0200 |
---|---|---|
committer | Stefan Wildemann <metalstrolch@users.noreply.github.com> | 2017-05-06 21:55:31 +0200 |
commit | 7fbe19bb9770cc9037a41532468391c5f10537b0 (patch) | |
tree | ab57e74082ff011d5dce2d2d900b5c1a1c64fa6a /navit | |
parent | 1715e677fd4a459c88491952af8dab7fe6262afa (diff) | |
download | navit-7fbe19bb9770cc9037a41532468391c5f10537b0.tar.gz |
Fix: Apply coding style to graphics_qt5
Diffstat (limited to 'navit')
-rw-r--r-- | navit/graphics/qt5/QNavitQuick.cpp | 313 | ||||
-rw-r--r-- | navit/graphics/qt5/QNavitQuick.h | 48 | ||||
-rw-r--r-- | navit/graphics/qt5/QNavitWidget.cpp | 355 | ||||
-rw-r--r-- | navit/graphics/qt5/QNavitWidget.h | 60 | ||||
-rw-r--r-- | navit/graphics/qt5/event_qt5.cpp | 196 | ||||
-rw-r--r-- | navit/graphics/qt5/event_qt5.h | 42 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.cpp | 1490 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.h | 98 |
8 files changed, 1301 insertions, 1301 deletions
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp index 798415f2c..b87aabc57 100644 --- a/navit/graphics/qt5/QNavitQuick.cpp +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -16,195 +16,189 @@ * 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 #include <unistd.h> #endif -extern"C" { +extern "C" { #include "config.h" +#include "item.h" /* needs to be first, as attr.h depends on it */ -#include "item.h" -#include "point.h" -#include "graphics.h" +#include "callback.h" #include "color.h" -#include "plugin.h" -#include "event.h" #include "debug.h" -#include "window.h" -#include "callback.h" +#include "event.h" + +#include "point.h" /* needs to be before graphics.h */ + +#include "graphics.h" #include "keys.h" +#include "plugin.h" +#include "window.h" } -#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE) +#if defined(WINDOWS) || defined(WIN32) || defined(HAVE_API_WIN32_CE) #include <windows.h> #endif -#include <QPainter> #include "QNavitQuick.h" #include "graphics_qt5.h" +#include <QPainter> -QNavitQuick::QNavitQuick(QQuickItem *parent) +QNavitQuick::QNavitQuick(QQuickItem* parent) : QQuickPaintedItem(parent) { setAcceptedMouseButtons(Qt::AllButtons); graphics_priv = NULL; } -void QNavitQuick::setGraphicContext(GraphicsPriv *gp) +void QNavitQuick::setGraphicContext(GraphicsPriv* gp) { - dbg(lvl_debug,"enter\n"); + dbg(lvl_debug, "enter\n"); 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); - while (g_hash_table_iter_next (&iter, (void **)&key, (void **)&value)) - { - 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->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); - } - } - } + GHashTableIter iter; + struct graphics_priv *key, *value; + g_hash_table_iter_init(&iter, gp->overlays); + while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) { + 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->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); + } + } + } } -void QNavitQuick::paint(QPainter *painter) +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)\n", boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()); /* color background if any */ - if (graphics_priv->background_graphics_gc_priv != NULL) - { - painter->setPen(*graphics_priv->background_graphics_gc_priv->pen); - painter->fillRect(boundingRect(),*graphics_priv->background_graphics_gc_priv->brush); + if (graphics_priv->background_graphics_gc_priv != NULL) { + painter->setPen(*graphics_priv->background_graphics_gc_priv->pen); + painter->fillRect(boundingRect(), *graphics_priv->background_graphics_gc_priv->brush); } /* draw base */ - painter->drawPixmap(0,0,*graphics_priv->pixmap, - boundingRect().x(), boundingRect().y(), - boundingRect().width(), boundingRect().height()); + painter->drawPixmap(0, 0, *graphics_priv->pixmap, + boundingRect().x(), boundingRect().y(), + boundingRect().width(), boundingRect().height()); paintOverlays(painter, graphics_priv, &event); } - -void QNavitQuick::keyPressEvent(QKeyEvent *event) +void QNavitQuick::keyPressEvent(QKeyEvent* event) { - dbg(lvl_debug,"enter\n"); - char key[2]; - int keycode; - char * text = NULL; - - keycode = event->key(); - key[0] = '\0'; - key[1] = '\0'; - switch (keycode) { - case Qt::Key_Up: - key[0]=NAVIT_KEY_UP; - break; - case Qt::Key_Down: - key[0]=NAVIT_KEY_DOWN; - break; - case Qt::Key_Left: - key[0]=NAVIT_KEY_LEFT; - break; - case Qt::Key_Right: - key[0]=NAVIT_KEY_RIGHT; - break; - case Qt::Key_Backspace: - key[0]=NAVIT_KEY_BACKSPACE; - break; - case Qt::Key_Tab: - key[0]=NAVIT_KEY_TAB; - break; - case Qt::Key_Delete: - key[0]=NAVIT_KEY_DELETE; - break; - case Qt::Key_Escape: - key[0]=NAVIT_KEY_BACK; - break; - case Qt::Key_Return: - case Qt::Key_Enter: - key[0]=NAVIT_KEY_RETURN; - break; - case Qt::Key_ZoomIn: - key[0]=NAVIT_KEY_ZOOM_IN; - break; - case Qt::Key_ZoomOut: - key[0]=NAVIT_KEY_ZOOM_OUT; - break; - case Qt::Key_PageUp: - key[0]=NAVIT_KEY_PAGE_UP; - break; - case Qt::Key_PageDown: - key[0]=NAVIT_KEY_PAGE_DOWN; - break; - default: - QString str=event->text(); - if((str != NULL) && (str.size() != 0)) - { - text=str.toUtf8().data(); - } - } - if(text != NULL) - callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void *)text); - 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, "enter\n"); + char key[2]; + int keycode; + char* text = NULL; + + keycode = event->key(); + key[0] = '\0'; + key[1] = '\0'; + switch (keycode) { + case Qt::Key_Up: + key[0] = NAVIT_KEY_UP; + break; + case Qt::Key_Down: + key[0] = NAVIT_KEY_DOWN; + break; + case Qt::Key_Left: + key[0] = NAVIT_KEY_LEFT; + break; + case Qt::Key_Right: + key[0] = NAVIT_KEY_RIGHT; + break; + case Qt::Key_Backspace: + key[0] = NAVIT_KEY_BACKSPACE; + break; + case Qt::Key_Tab: + key[0] = NAVIT_KEY_TAB; + break; + case Qt::Key_Delete: + key[0] = NAVIT_KEY_DELETE; + break; + case Qt::Key_Escape: + key[0] = NAVIT_KEY_BACK; + break; + case Qt::Key_Return: + case Qt::Key_Enter: + key[0] = NAVIT_KEY_RETURN; + break; + case Qt::Key_ZoomIn: + key[0] = NAVIT_KEY_ZOOM_IN; + break; + case Qt::Key_ZoomOut: + key[0] = NAVIT_KEY_ZOOM_OUT; + break; + case Qt::Key_PageUp: + key[0] = NAVIT_KEY_PAGE_UP; + break; + case Qt::Key_PageDown: + key[0] = NAVIT_KEY_PAGE_DOWN; + break; + default: + QString str = event->text(); + if ((str != NULL) && (str.size() != 0)) { + text = str.toUtf8().data(); + } + } + if (text != NULL) + callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)text); + 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); } -void QNavitQuick::keyReleaseEvent(QKeyEvent *event) +void QNavitQuick::keyReleaseEvent(QKeyEvent* event) { - dbg(lvl_debug,"enter\n"); + dbg(lvl_debug, "enter\n"); } -void QNavitQuick::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) { - dbg(lvl_debug,"enter\n"); - QQuickPaintedItem::geometryChanged(newGeometry,oldGeometry); - QPainter * painter = NULL; - if(graphics_priv == NULL) - { - dbg(lvl_debug,"Context not set, aborting\n"); - return; + dbg(lvl_debug, "enter\n"); + QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); + QPainter* painter = NULL; + if (graphics_priv == NULL) { + dbg(lvl_debug, "Context not set, aborting\n"); + return; } - if(graphics_priv->pixmap != NULL) - { - delete graphics_priv->pixmap; - graphics_priv->pixmap = NULL; + if (graphics_priv->pixmap != NULL) { + delete graphics_priv->pixmap; + 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) - { + 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\n", width(), height()); + dbg(lvl_debug, "pixmap %p %dx%d\n", 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()); + 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"); - p.x=event->x(); - p.y=event->y(); + dbg(lvl_debug, "enter\n"); + 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)); @@ -220,47 +214,46 @@ void QNavitQuick::mouseEvent(int pressed, QMouseEvent *event) } } -void QNavitQuick::mousePressEvent(QMouseEvent *event) +void QNavitQuick::mousePressEvent(QMouseEvent* event) { - dbg(lvl_debug,"enter\n"); + dbg(lvl_debug, "enter\n"); mouseEvent(1, event); } -void QNavitQuick::mouseReleaseEvent(QMouseEvent *event) +void QNavitQuick::mouseReleaseEvent(QMouseEvent* event) { - dbg(lvl_debug,"enter\n"); + dbg(lvl_debug, "enter\n"); mouseEvent(0, event); } -void QNavitQuick::mouseMoveEvent(QMouseEvent *event) +void QNavitQuick::mouseMoveEvent(QMouseEvent* event) { - dbg(lvl_debug,"enter\n"); + dbg(lvl_debug, "enter\n"); struct point p; - p.x=event->x(); - p.y=event->y(); - callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void *)&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"); - 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 (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)); - } - - event->accept(); -} + struct point p; + int button; + dbg(lvl_debug, "enter\n"); + 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 (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)); + } + + event->accept(); +} diff --git a/navit/graphics/qt5/QNavitQuick.h b/navit/graphics/qt5/QNavitQuick.h index d213bdac5..3679e8127 100644 --- a/navit/graphics/qt5/QNavitQuick.h +++ b/navit/graphics/qt5/QNavitQuick.h @@ -1,31 +1,49 @@ +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2017 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * 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 class QNavitQuick; -#include <QtQuick/QQuickPaintedItem> #include <QColor> +#include <QtQuick/QQuickPaintedItem> #include "graphics_qt5.h" -class QNavitQuick : public QQuickPaintedItem -{ +class QNavitQuick : public QQuickPaintedItem { Q_OBJECT public: - QNavitQuick(QQuickItem *parent = 0); + QNavitQuick(QQuickItem* parent = 0); - void paint(QPainter *painter); + void paint(QPainter* painter); - Q_INVOKABLE void setGraphicContext(GraphicsPriv *gp); + Q_INVOKABLE void setGraphicContext(GraphicsPriv* gp); protected: - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - virtual void mouseEvent(int pressed, QMouseEvent *event); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent *event); - + virtual void keyPressEvent(QKeyEvent* event); + virtual void keyReleaseEvent(QKeyEvent* event); + virtual void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry); + virtual void mouseEvent(int pressed, QMouseEvent* event); + virtual void mousePressEvent(QMouseEvent* event); + virtual void mouseReleaseEvent(QMouseEvent* event); + virtual void mouseMoveEvent(QMouseEvent* event); + virtual void wheelEvent(QWheelEvent* event); private: struct graphics_priv* graphics_priv; diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp index 20b1d852f..09034ce22 100644 --- a/navit/graphics/qt5/QNavitWidget.cpp +++ b/navit/graphics/qt5/QNavitWidget.cpp @@ -16,6 +16,7 @@ * 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 @@ -23,230 +24,224 @@ #endif extern "C" { #include "config.h" +#include "item.h" /* needs to be first, as attr.h depends on it */ -#include "item.h" -#include "point.h" -#include "graphics.h" +#include "callback.h" #include "color.h" -#include "plugin.h" -#include "event.h" #include "debug.h" -#include "window.h" -#include "callback.h" +#include "event.h" + +#include "point.h" /* needs to be before graphics.h */ + +#include "graphics.h" #include "keys.h" +#include "plugin.h" +#include "window.h" } -#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE) +#if defined(WINDOWS) || defined(WIN32) || defined(HAVE_API_WIN32_CE) #include <windows.h> #endif -#include "graphics_qt5.h" #include "QNavitWidget.h" #include "QNavitWidget.moc" +#include "graphics_qt5.h" -QNavitWidget :: QNavitWidget(struct graphics_priv *my_graphics_priv, - QWidget * parent, - Qt::WindowFlags flags): QWidget(parent, flags) +QNavitWidget::QNavitWidget(struct graphics_priv* my_graphics_priv, + 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 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); - while (g_hash_table_iter_next (&iter, (void **)&key, (void **)&value)) - { - 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->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); - } - } + GHashTableIter iter; + struct graphics_priv *key, *value; + g_hash_table_iter_init(&iter, gp->overlays); + while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) { + 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->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); + } } - + } } -void QNavitWidget :: paintEvent(QPaintEvent * event) +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()); - QPainter painter(this); - /* color background if any */ - if (graphics_priv->background_graphics_gc_priv != NULL) - { - painter.setPen(*graphics_priv->background_graphics_gc_priv->pen); - painter.fillRect(event->rect(),*graphics_priv->background_graphics_gc_priv->brush); - } - painter.drawPixmap(0,0,*graphics_priv->pixmap, - event->rect().x(), event->rect().y(), - event->rect().width(), event->rect().height()); - paintOverlays(&painter, graphics_priv, event); + dbg(lvl_debug, "enter (%d, %d, %d, %d)\n", 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) { + painter.setPen(*graphics_priv->background_graphics_gc_priv->pen); + painter.fillRect(event->rect(), *graphics_priv->background_graphics_gc_priv->brush); + } + painter.drawPixmap(0, 0, *graphics_priv->pixmap, + event->rect().x(), event->rect().y(), + event->rect().width(), event->rect().height()); + 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; - } - - 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()); - /* if the root window got resized, tell navit about it */ - if(graphics_priv->root) - resize_callback(graphics_priv,width(),height()); + QPainter* painter = NULL; + if (graphics_priv->pixmap != NULL) { + delete graphics_priv->pixmap; + graphics_priv->pixmap = NULL; + } + + 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()); + /* 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"); - 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)); - 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)); - 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)); - break; - default: - break; - } + struct point p; + // dbg(lvl_debug,"enter\n"); + 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)); + 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)); + 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)); + break; + default: + break; + } } -void QNavitWidget::keyPressEvent(QKeyEvent *event) +void QNavitWidget::keyPressEvent(QKeyEvent* event) { - dbg(lvl_debug,"enter\n"); - char key[2]; - int keycode; - char * text = NULL; - - keycode = event->key(); - key[0] = '\0'; - key[1] = '\0'; - switch (keycode) { - case Qt::Key_Up: - key[0]=NAVIT_KEY_UP; - break; - case Qt::Key_Down: - key[0]=NAVIT_KEY_DOWN; - break; - case Qt::Key_Left: - key[0]=NAVIT_KEY_LEFT; - break; - case Qt::Key_Right: - key[0]=NAVIT_KEY_RIGHT; - break; - case Qt::Key_Backspace: - key[0]=NAVIT_KEY_BACKSPACE; - break; - case Qt::Key_Tab: - key[0]=NAVIT_KEY_TAB; - break; - case Qt::Key_Delete: - key[0]=NAVIT_KEY_DELETE; - break; - case Qt::Key_Escape: - key[0]=NAVIT_KEY_BACK; - break; - case Qt::Key_Return: - case Qt::Key_Enter: - key[0]=NAVIT_KEY_RETURN; - break; - case Qt::Key_ZoomIn: - key[0]=NAVIT_KEY_ZOOM_IN; - break; - case Qt::Key_ZoomOut: - key[0]=NAVIT_KEY_ZOOM_OUT; - break; - case Qt::Key_PageUp: - key[0]=NAVIT_KEY_PAGE_UP; - break; - case Qt::Key_PageDown: - key[0]=NAVIT_KEY_PAGE_DOWN; - break; - default: - QString str=event->text(); - if((str != NULL) && (str.size() != 0)) - { - text=str.toUtf8().data(); - } - } - if(text != NULL) - callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void *)text); - 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, "enter\n"); + char key[2]; + int keycode; + char* text = NULL; + keycode = event->key(); + key[0] = '\0'; + key[1] = '\0'; + switch (keycode) { + case Qt::Key_Up: + key[0] = NAVIT_KEY_UP; + break; + case Qt::Key_Down: + key[0] = NAVIT_KEY_DOWN; + break; + case Qt::Key_Left: + key[0] = NAVIT_KEY_LEFT; + break; + case Qt::Key_Right: + key[0] = NAVIT_KEY_RIGHT; + break; + case Qt::Key_Backspace: + key[0] = NAVIT_KEY_BACKSPACE; + break; + case Qt::Key_Tab: + key[0] = NAVIT_KEY_TAB; + break; + case Qt::Key_Delete: + key[0] = NAVIT_KEY_DELETE; + break; + case Qt::Key_Escape: + key[0] = NAVIT_KEY_BACK; + break; + case Qt::Key_Return: + case Qt::Key_Enter: + key[0] = NAVIT_KEY_RETURN; + break; + case Qt::Key_ZoomIn: + key[0] = NAVIT_KEY_ZOOM_IN; + break; + case Qt::Key_ZoomOut: + key[0] = NAVIT_KEY_ZOOM_OUT; + break; + case Qt::Key_PageUp: + key[0] = NAVIT_KEY_PAGE_UP; + break; + case Qt::Key_PageDown: + key[0] = NAVIT_KEY_PAGE_DOWN; + break; + default: + QString str = event->text(); + if ((str != NULL) && (str.size() != 0)) { + text = str.toUtf8().data(); + } + } + if (text != NULL) + callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)text); + 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); +} -void QNavitWidget::mousePressEvent(QMouseEvent *event) +void QNavitWidget::mousePressEvent(QMouseEvent* event) { -// dbg(lvl_debug,"enter\n"); - mouseEvent(1, event); + // dbg(lvl_debug,"enter\n"); + mouseEvent(1, event); } -void QNavitWidget::mouseReleaseEvent(QMouseEvent *event) +void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) { -// dbg(lvl_debug,"enter\n"); - mouseEvent(0, event); + // dbg(lvl_debug,"enter\n"); + mouseEvent(0, event); } -void QNavitWidget::mouseMoveEvent(QMouseEvent *event) +void QNavitWidget::mouseMoveEvent(QMouseEvent* event) { - struct point p; -// dbg(lvl_debug,"enter\n"); - p.x=event->x(); - p.y=event->y(); - callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void *)&p); + struct point p; + // dbg(lvl_debug,"enter\n"); + 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"); - 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 (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)); - } - - event->accept(); + struct point p; + int button; + dbg(lvl_debug, "enter\n"); + 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 (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)); + } + + event->accept(); } diff --git a/navit/graphics/qt5/QNavitWidget.h b/navit/graphics/qt5/QNavitWidget.h index 727e7e130..674b69390 100644 --- a/navit/graphics/qt5/QNavitWidget.h +++ b/navit/graphics/qt5/QNavitWidget.h @@ -1,34 +1,52 @@ +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2017 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * 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 class QNavitWidget; #include "graphics_qt5.h" -#include <QPixmap> -#include <QWidget> +#include <QEvent> #include <QMouseEvent> +#include <QPixmap> #include <QWheelEvent> -#include <QEvent> +#include <QWidget> -class QNavitWidget : public QWidget -{ - Q_OBJECT +class QNavitWidget : public QWidget { + Q_OBJECT public: - QNavitWidget(struct graphics_priv *my_graphics_priv, - QWidget * parent, - Qt::WindowFlags flags); -protected: - virtual bool event(QEvent *event); - virtual void keyPressEvent(QKeyEvent *event); - virtual void paintEvent(QPaintEvent * event); - virtual void resizeEvent(QResizeEvent * event); - virtual void mouseEvent(int pressed, QMouseEvent *event); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent * event); + QNavitWidget(struct graphics_priv* my_graphics_priv, + QWidget* parent, + Qt::WindowFlags flags); +protected: + virtual bool event(QEvent* event); + virtual void keyPressEvent(QKeyEvent* event); + virtual void paintEvent(QPaintEvent* event); + virtual void resizeEvent(QResizeEvent* event); + virtual void mouseEvent(int pressed, QMouseEvent* event); + virtual void mousePressEvent(QMouseEvent* event); + virtual void mouseReleaseEvent(QMouseEvent* event); + virtual void mouseMoveEvent(QMouseEvent* event); + virtual void wheelEvent(QWheelEvent* event); private: - struct graphics_priv *graphics_priv; + struct graphics_priv* graphics_priv; }; #endif - diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp index 729e3903b..5eae821f6 100644 --- a/navit/graphics/qt5/event_qt5.cpp +++ b/navit/graphics/qt5/event_qt5.cpp @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2017 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,6 +16,7 @@ * 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> @@ -24,167 +25,164 @@ extern "C" { #include "config.h" -#include "navit/point.h" -#include "navit/item.h" -#include "navit/graphics.h" +#include "navit/callback.h" #include "navit/color.h" #include "navit/debug.h" -#include "navit/plugin.h" -#include "navit/callback.h" #include "navit/event.h" -#include "navit/window.h" + +#include "navit/point.h" /* needs to be before graphics.h */ + +#include "navit/graphics.h" +#include "navit/item.h" #include "navit/keys.h" #include "navit/navit.h" +#include "navit/plugin.h" +#include "navit/window.h" } -#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE) +#if defined(WINDOWS) || defined(WIN32) || defined(HAVE_API_WIN32_CE) #include <windows.h> #endif -#include <QSocketNotifier> -#include "graphics_qt5.h" #include "event_qt5.h" #include "event_qt5.moc" +#include "graphics_qt5.h" +#include <QSocketNotifier> struct event_watch { - QSocketNotifier *sn; - struct callback *cb; - int fd; + QSocketNotifier* sn; + struct callback* cb; + int fd; }; -static void event_qt5_remove_timeout(struct event_timeout *to); +static void event_qt5_remove_timeout(struct event_timeout* to); -qt5_navit_timer :: qt5_navit_timer (QObject * parent) : QObject(parent) +qt5_navit_timer::qt5_navit_timer(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"); + 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"); } -void qt5_navit_timer :: timerEvent (QTimerEvent * event) +void qt5_navit_timer::timerEvent(QTimerEvent* event) { - int id=event->timerId(); - void* multi = NULL; -// dbg(lvl_debug, "TimerEvent (%d)\n", id); - struct callback *cb=(struct callback *)g_hash_table_lookup(timer_callback, (void *)(long)id); - if (cb) - callback_call_0(cb); - /* remove timer if it was oneshot timer */ - if (g_hash_table_lookup_extended(timer_type, (void *)(long)id, NULL, &multi)) - { - /* it's still in the list */ - if(((int)(long)multi) == 0) - event_qt5_remove_timeout((struct event_timeout *)(long)id); - } -// dbg(lvl_debug, "TimerEvent (%d) leave\n", id); + int id = event->timerId(); + void* multi = NULL; + // dbg(lvl_debug, "TimerEvent (%d)\n", id); + struct callback* cb = (struct callback*)g_hash_table_lookup(timer_callback, (void*)(long)id); + if (cb) + callback_call_0(cb); + /* remove timer if it was oneshot timer */ + if (g_hash_table_lookup_extended(timer_type, (void*)(long)id, NULL, &multi)) { + /* it's still in the list */ + if (((int)(long)multi) == 0) + event_qt5_remove_timeout((struct event_timeout*)(long)id); + } + // dbg(lvl_debug, "TimerEvent (%d) leave\n", id); } -qt5_navit_timer * qt5_timer = NULL; +qt5_navit_timer* qt5_timer = NULL; static void event_qt5_main_loop_run(void) { - dbg(lvl_debug,"enter\n"); - if(navit_app != NULL) - navit_app->exec(); - + dbg(lvl_debug, "enter\n"); + if (navit_app != NULL) + navit_app->exec(); } static void event_qt5_main_loop_quit(void) { - dbg(lvl_debug,"enter\n"); - exit(0); + dbg(lvl_debug, "enter\n"); + exit(0); } -static struct event_watch * -event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) +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); - struct event_watch *ret=g_new0(struct event_watch, 1); - ret->fd=fd; - ret->cb=cb; - g_hash_table_insert(qt5_timer->watches, GINT_TO_POINTER(fd), ret); - ret->sn=new QSocketNotifier(fd, QSocketNotifier::Read, qt5_timer); - QObject::connect(ret->sn, SIGNAL(activated(int)), qt5_timer, SLOT(watchEvent(int))); - return ret; + dbg(lvl_debug, "enter fd=%d\n", (int)(long)fd); + struct event_watch* ret = g_new0(struct event_watch, 1); + ret->fd = fd; + ret->cb = cb; + g_hash_table_insert(qt5_timer->watches, GINT_TO_POINTER(fd), ret); + ret->sn = new QSocketNotifier(fd, QSocketNotifier::Read, qt5_timer); + QObject::connect(ret->sn, SIGNAL(activated(int)), qt5_timer, SLOT(watchEvent(int))); + return ret; } static void -event_qt5_remove_watch(struct event_watch *ev) +event_qt5_remove_watch(struct event_watch* ev) { - dbg(lvl_debug,"enter\n"); - g_hash_table_remove(qt5_timer->watches, GINT_TO_POINTER(ev->fd)); - delete(ev->sn); - g_free(ev); + dbg(lvl_debug, "enter\n"); + 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); - 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; + 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); + 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) +event_qt5_remove_timeout(struct event_timeout* to) { - dbg(lvl_debug,"remove timeout (%d)\n",(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); + dbg(lvl_debug, "remove timeout (%d)\n", (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) +static struct event_idle* +event_qt5_add_idle(int priority, struct callback* cb) { - dbg(lvl_debug,"add idle event\n"); - return (struct event_idle *)event_qt5_add_timeout(0, 1, cb); + dbg(lvl_debug, "add idle event\n"); + return (struct event_idle*)event_qt5_add_timeout(0, 1, cb); } static void -event_qt5_remove_idle(struct event_idle *ev) +event_qt5_remove_idle(struct event_idle* ev) { - dbg(lvl_debug,"Remove idle timeout\n"); - event_qt5_remove_timeout((struct event_timeout *) ev); + dbg(lvl_debug, "Remove idle timeout\n"); + event_qt5_remove_timeout((struct event_timeout*)ev); } static void -event_qt5_call_callback(struct callback_list *cb) +event_qt5_call_callback(struct callback_list* cb) { - dbg(lvl_debug,"enter\n"); + dbg(lvl_debug, "enter\n"); } static struct event_methods event_qt5_methods = { - event_qt5_main_loop_run, - event_qt5_main_loop_quit, - event_qt5_add_watch, - event_qt5_remove_watch, - event_qt5_add_timeout, - event_qt5_remove_timeout, - event_qt5_add_idle, - event_qt5_remove_idle, - event_qt5_call_callback, + event_qt5_main_loop_run, + event_qt5_main_loop_quit, + event_qt5_add_watch, + event_qt5_remove_watch, + event_qt5_add_timeout, + event_qt5_remove_timeout, + event_qt5_add_idle, + event_qt5_remove_idle, + 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; + *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); + 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 f999d3a46..59f168a9c 100644 --- a/navit/graphics/qt5/event_qt5.h +++ b/navit/graphics/qt5/event_qt5.h @@ -1,18 +1,36 @@ -#include <glib.h> +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2017 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * 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 +class qt5_navit_timer : public QObject { + Q_OBJECT public: - qt5_navit_timer(QObject * parent = 0); - GHashTable *timer_type; - GHashTable *timer_callback; - GHashTable *watches; + qt5_navit_timer(QObject* parent = 0); + GHashTable* timer_type; + GHashTable* timer_callback; + GHashTable* watches; + protected: - void timerEvent(QTimerEvent * event); + void timerEvent(QTimerEvent* event); }; - -void -qt5_event_init(void); +void qt5_event_init(void); diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index f03ad36e0..ddafd406a 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2017 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,6 +16,7 @@ * 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 @@ -23,47 +24,49 @@ #endif extern "C" { #include "config.h" +#include "item.h" /* needs to be first, as attr.h depends on it */ -#include "item.h" -#include "point.h" -#include "graphics.h" +#include "callback.h" #include "color.h" -#include "plugin.h" -#include "event.h" #include "debug.h" +#include "event.h" + +#include "point.h" /* needs to be before graphics.h */ + +#include "graphics.h" +#include "plugin.h" #include "window.h" -#include "callback.h" } -#include "graphics_qt5.h" #include "event_qt5.h" -#include <QGuiApplication> -#include <QPixmap> -#include <QPainter> -#include <QFont> -#include <QSvgRenderer> +#include "graphics_qt5.h" #include <QDBusConnection> #include <QDBusInterface> #include <QFile> +#include <QFont> +#include <QGuiApplication> +#include <QPainter> +#include <QPixmap> #include <QScreen> +#include <QSvgRenderer> #if USE_QML -#include <QQuickWindow> +#include "QNavitQuick.h" #include <QQmlApplicationEngine> #include <QQmlContext> -#include "QNavitQuick.h" +#include <QQuickWindow> #endif #if USE_QWIDGET -#include <QApplication> #include "QNavitWidget.h" +#include <QApplication> #endif -#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE) +#if defined(WINDOWS) || defined(WIN32) || defined(HAVE_API_WIN32_CE) #include <windows.h> #endif #if USE_QML -GraphicsPriv::GraphicsPriv(struct graphics_priv * gp) +GraphicsPriv::GraphicsPriv(struct graphics_priv* gp) { - this->gp = gp; + this->gp = gp; } GraphicsPriv::~GraphicsPriv() @@ -72,950 +75,891 @@ GraphicsPriv::~GraphicsPriv() void GraphicsPriv::emit_update() { - emit update(); + emit update(); } #endif -QGuiApplication * navit_app = NULL; +QGuiApplication* navit_app = NULL; struct graphics_font_priv { - QFont * font; + QFont* font; }; struct graphics_image_priv { - QPixmap * pixmap; + QPixmap* pixmap; }; static void -graphics_destroy(struct graphics_priv *gr) +graphics_destroy(struct graphics_priv* gr) { // dbg(lvl_debug,"enter\n"); #ifdef QT_QPAINTER_USE_FREETYPE - gr->freetype_methods.destroy(); -#endif - /* destroy painter */ - if(gr->painter != NULL) - delete(gr->painter); - /* destroy pixmap */ - if(gr->pixmap != NULL) - delete(gr->pixmap); - /* destroy widget if root window*/ - if(gr->root) - { + gr->freetype_methods.destroy(); +#endif + /* destroy painter */ + if (gr->painter != NULL) + delete (gr->painter); + /* destroy pixmap */ + if (gr->pixmap != NULL) + delete (gr->pixmap); + /* destroy widget if root window*/ + if (gr->root) { #if USE_QWIDGET - if(gr->widget != NULL) - delete(gr->widget); + if (gr->widget != NULL) + delete (gr->widget); #endif #if USE_QML - if(gr->GPriv != NULL) - delete(gr->GPriv); -#endif - } - /* unregister from parent, if any */ - if(gr->parent != NULL) - { - g_hash_table_remove(gr->parent->overlays, gr); - } + if (gr->GPriv != NULL) + delete (gr->GPriv); +#endif + } + /* unregister from parent, if any */ + if (gr->parent != NULL) { + g_hash_table_remove(gr->parent->overlays, gr); + } #ifdef SAILFISH_OS - if(gr->display_on_ev != NULL) - { - event_remove_timeout(gr->display_on_ev); - } - if(gr->display_on_cb != NULL) - { - g_free(gr->display_on_cb); + if (gr->display_on_ev != NULL) { + event_remove_timeout(gr->display_on_ev); + } + if (gr->display_on_cb != NULL) { + g_free(gr->display_on_cb); + } +#endif + /* destroy overlays hash */ + g_hash_table_destroy(gr->overlays); + /* destroy global application if destroying the last */ + if (gr->root) { + if (navit_app != NULL) { + delete (navit_app); } -#endif - /* destroy overlays hash */ - g_hash_table_destroy(gr->overlays); - /* destroy global application if destroying the last */ - if(gr->root) - { - if(navit_app != NULL) - { - delete (navit_app); - } - navit_app = NULL; - /* destroy argv if any */ - while(gr->argc > 0) - { - gr->argc --; - if(gr->argv[gr->argc] != NULL) - g_free(gr->argv[gr->argc]); - } + navit_app = NULL; + /* destroy argv if any */ + while (gr->argc > 0) { + gr->argc--; + if (gr->argv[gr->argc] != NULL) + g_free(gr->argv[gr->argc]); } - /* destroy self */ - g_free(gr); + } + /* destroy self */ + g_free(gr); } -static void font_destroy(struct graphics_font_priv *font) +static void font_destroy(struct graphics_font_priv* font) { -// dbg(lvl_debug,"enter\n"); - if(font->font != NULL) - delete(font->font); - g_free(font); - + // dbg(lvl_debug,"enter\n"); + if (font->font != NULL) + delete (font->font); + g_free(font); } static struct graphics_font_methods font_methods = { - font_destroy + font_destroy }; -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) { - struct graphics_font_priv *font_priv; -// dbg(lvl_debug,"enter (font %s, %d)\n", font, size); - font_priv = g_new0(struct graphics_font_priv, 1); - if(font != NULL) - font_priv->font=new QFont(font,size/16); - else - font_priv->font=new QFont("Arial",size/16); - font_priv->font->setStyleStrategy(QFont::NoAntialias); - *meth=font_methods; - return font_priv; + struct graphics_font_priv* font_priv; + // dbg(lvl_debug,"enter (font %s, %d)\n", font, size); + font_priv = g_new0(struct graphics_font_priv, 1); + if (font != NULL) + font_priv->font = new QFont(font, size / 16); + else + font_priv->font = new QFont("Arial", size / 16); + font_priv->font->setStyleStrategy(QFont::NoAntialias); + *meth = font_methods; + return font_priv; } static void -gc_destroy(struct graphics_gc_priv *gc) +gc_destroy(struct graphics_gc_priv* gc) { -// dbg(lvl_debug,"enter gc=%p\n", gc); - delete(gc->pen); - delete(gc->brush); - g_free(gc); + // dbg(lvl_debug,"enter gc=%p\n", gc); + delete (gc->pen); + delete (gc->brush); + g_free(gc); } static void -gc_set_linewidth(struct graphics_gc_priv *gc, int w) +gc_set_linewidth(struct graphics_gc_priv* gc, int w) { -// dbg(lvl_debug,"enter gc=%p, %d\n", gc, w); - gc->pen->setWidth(w); + // dbg(lvl_debug,"enter gc=%p, %d\n", 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) -{ - if(n <= 0) - { - dbg(lvl_error, "Refuse to set dashes without dash pattern"); - } - /* use Qt dash feature */ - QVector<qreal> dashes; - gc->pen->setWidth(w); - gc->pen->setDashOffset(offset); - for(int a = 0; a < n; a ++) - { - dashes << dash_list[a]; - } - /* Qt requires the pattern to have even element count. Add the last +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"); + } + /* use Qt dash feature */ + QVector<qreal> dashes; + gc->pen->setWidth(w); + gc->pen->setDashOffset(offset); + for (int a = 0; a < n; a++) { + dashes << dash_list[a]; + } + /* Qt requires the pattern to have even element count. Add the last * element twice if n doesn't divide by two */ - if((n % 2) != 0) - { - dashes << dash_list[n-1]; - } - gc->pen->setDashPattern(dashes); + if ((n % 2) != 0) { + dashes << dash_list[n - 1]; + } + gc->pen->setDashPattern(dashes); } static void -gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) +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); - gc->pen->setColor(col); - gc->brush->setColor(col); - //gc->c=*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); + gc->pen->setColor(col); + gc->brush->setColor(col); + //gc->c=*c; } static void -gc_set_background(struct graphics_gc_priv *gc, struct color *c) +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); - //gc->pen->setColor(col); - //gc->brush->setColor(col); + 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); + //gc->pen->setColor(col); + //gc->brush->setColor(col); } static struct graphics_gc_methods gc_methods = { - gc_destroy, - gc_set_linewidth, - gc_set_dashes, - gc_set_foreground, - gc_set_background + gc_destroy, + gc_set_linewidth, + gc_set_dashes, + gc_set_foreground, + 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); - graphics_gc_priv = g_new0(struct graphics_gc_priv, 1); - graphics_gc_priv->graphics_priv = gr; - graphics_gc_priv->pen=new QPen(); - graphics_gc_priv->brush=new QBrush(Qt::SolidPattern); + struct graphics_gc_priv* graphics_gc_priv = NULL; + // dbg(lvl_debug,"enter gr==%p\n", gr); + graphics_gc_priv = g_new0(struct graphics_gc_priv, 1); + graphics_gc_priv->graphics_priv = gr; + graphics_gc_priv->pen = new QPen(); + graphics_gc_priv->brush = new QBrush(Qt::SolidPattern); - *meth=gc_methods; - return graphics_gc_priv; + *meth = gc_methods; + return graphics_gc_priv; } -static void image_destroy(struct graphics_image_priv *img) +static void image_destroy(struct graphics_image_priv* img) { -// dbg(lvl_debug, "enter\n"); - if(img->pixmap != NULL) - delete(img->pixmap); + // dbg(lvl_debug, "enter\n"); + if (img->pixmap != NULL) + delete (img->pixmap); g_free(img); } -struct graphics_image_methods image_methods ={ - image_destroy +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) -{ - struct graphics_image_priv * image_priv; -// dbg(lvl_debug,"enter %s, %d %d\n", path, *w, *h); - if(path[0] == 0) - { - dbg(lvl_debug,"Refuse to load image without path\n"); - return NULL; - } - QString key(path); - QString renderer_key(key); - QString extension = key.right(key.lastIndexOf(".")); - QFile imagefile(key); - if(!imagefile.exists()) - { - /* file doesn't exit. Either navit wants us to guess file name by +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); + if (path[0] == 0) { + dbg(lvl_debug, "Refuse to load image without path\n"); + return NULL; + } + QString key(path); + QString renderer_key(key); + QString extension = key.right(key.lastIndexOf(".")); + QFile imagefile(key); + if (!imagefile.exists()) { + /* file doesn't exit. Either navit wants us to guess file name by * ommitting exstension, or the file does really not exist. */ - if(extension != "") - { - /*file doesn't exist. give up */ - dbg(lvl_debug,"File %s does not exist\n",path); - return NULL; - } - else - { - /* add ".svg" for renderer to try .svg file first in renderer */ - dbg(lvl_debug, "Guess extension on %s\n", path); - renderer_key += ".svg"; - } - } - image_priv = g_new0(struct graphics_image_priv, 1); - *meth = image_methods; - - /* check if this can be rendered */ - if(renderer_key.endsWith("svg")) - { - QSvgRenderer renderer(renderer_key); - if(renderer.isValid()) - { - dbg(lvl_debug,"render %s\n", path); - /* try to render this */ - /* assume "standard" size if size is not given */ - if(*w <= 0) *w = renderer.defaultSize().width(); - if(*h <= 0) *h = renderer.defaultSize().height(); - image_priv->pixmap=new QPixmap(*w, *h); - image_priv->pixmap->fill(Qt::transparent); - QPainter painter(image_priv->pixmap); - renderer.render(&painter); - } - } - - if (image_priv->pixmap == NULL) { - /*cannot be rendered. try to load it */ - dbg(lvl_debug,"cannot render %s\n",path); - image_priv->pixmap=new QPixmap(key); - } - - /* check if we got image */ - if (image_priv->pixmap->isNull()) { - g_free(image_priv); + if (extension != "") { + /*file doesn't exist. give up */ + dbg(lvl_debug, "File %s does not exist\n", path); return NULL; + } else { + /* add ".svg" for renderer to try .svg file first in renderer */ + dbg(lvl_debug, "Guess extension on %s\n", path); + renderer_key += ".svg"; } - 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); - QPixmap * scaled = new QPixmap(image_priv->pixmap->scaled(*w, *h,Qt::IgnoreAspectRatio,Qt::FastTransformation)); - delete (image_priv->pixmap); - image_priv->pixmap = scaled; - } + } + image_priv = g_new0(struct graphics_image_priv, 1); + *meth = image_methods; + + /* check if this can be rendered */ + if (renderer_key.endsWith("svg")) { + QSvgRenderer renderer(renderer_key); + if (renderer.isValid()) { + dbg(lvl_debug, "render %s\n", path); + /* try to render this */ + /* assume "standard" size if size is not given */ + if (*w <= 0) + *w = renderer.defaultSize().width(); + if (*h <= 0) + *h = renderer.defaultSize().height(); + image_priv->pixmap = new QPixmap(*w, *h); + image_priv->pixmap->fill(Qt::transparent); + QPainter painter(image_priv->pixmap); + renderer.render(&painter); + } + } + + if (image_priv->pixmap == NULL) { + /*cannot be rendered. try to load it */ + dbg(lvl_debug, "cannot render %s\n", path); + image_priv->pixmap = new QPixmap(key); + } + + /* check if we got image */ + if (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); + QPixmap* scaled = new QPixmap(image_priv->pixmap->scaled(*w, *h, Qt::IgnoreAspectRatio, Qt::FastTransformation)); + delete (image_priv->pixmap); + image_priv->pixmap = scaled; } } + } - *w=image_priv->pixmap->width(); - *h=image_priv->pixmap->height(); -// dbg(lvl_debug, "Got (%d,%d)\n", *w,*h); - if (hot) { - hot->x=*w/2; - hot->y=*h/2; - } + *w = image_priv->pixmap->width(); + *h = image_priv->pixmap->height(); + // dbg(lvl_debug, "Got (%d,%d)\n", *w,*h); + if (hot) { + hot->x = *w / 2; + hot->y = *h / 2; + } - return image_priv; + return image_priv; } static void -draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) +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); - if(gr->painter == NULL) - return; + int i; + QPolygon polygon; + // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)\n", gr, gc, p->x, p->y); + if (gr->painter == NULL) + return; - for (i = 0 ; i < count ; i++) - polygon.putPoints(i, 1, p[i].x, p[i].y); - gr->painter->setPen(*gc->pen); - gr->painter->drawPolyline(polygon); - + for (i = 0; i < count; i++) + polygon.putPoints(i, 1, p[i].x, p[i].y); + gr->painter->setPen(*gc->pen); + gr->painter->drawPolyline(polygon); } 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); - if(gr->painter == NULL) - return; - - for (i = 0 ; i < count ; i++) - polygon.putPoints(i, 1, p[i].x, p[i].y); - gr->painter->setPen(*gc->pen); - gr->painter->setBrush(*gc->brush); - /* if the polygon is transparent, we need to clear it first */ - if(!gc->brush->isOpaque()) - { - QPainter::CompositionMode mode = gr->painter->compositionMode(); - gr->painter->setCompositionMode(QPainter::CompositionMode_Clear); - gr->painter->drawPolygon(polygon); - gr->painter->setCompositionMode(mode); - } - gr->painter->drawPolygon(polygon); +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); + if (gr->painter == NULL) + return; + + for (i = 0; i < count; i++) + polygon.putPoints(i, 1, p[i].x, p[i].y); + gr->painter->setPen(*gc->pen); + gr->painter->setBrush(*gc->brush); + /* if the polygon is transparent, we need to clear it first */ + if (!gc->brush->isOpaque()) { + QPainter::CompositionMode mode = gr->painter->compositionMode(); + gr->painter->setCompositionMode(QPainter::CompositionMode_Clear); + gr->painter->drawPolygon(polygon); + gr->painter->setCompositionMode(mode); + } + 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); - if(gr->painter == NULL) - return; - /* if the rectangle is transparent, we need to clear it first */ - if(!gc->brush->isOpaque()) - { - QPainter::CompositionMode mode = gr->painter->compositionMode(); - gr->painter->setCompositionMode(QPainter::CompositionMode_Clear); - gr->painter->fillRect(p->x,p->y, w, h, *gc->brush); - gr->painter->setCompositionMode(mode); - } - gr->painter->fillRect(p->x,p->y, w, h, *gc->brush); +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); + if (gr->painter == NULL) + return; + /* if the rectangle is transparent, we need to clear it first */ + if (!gc->brush->isOpaque()) { + QPainter::CompositionMode mode = gr->painter->compositionMode(); + gr->painter->setCompositionMode(QPainter::CompositionMode_Clear); + gr->painter->fillRect(p->x, p->y, w, h, *gc->brush); + gr->painter->setCompositionMode(mode); + } + 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) +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); - if(gr->painter == NULL) - return; - gr->painter->setPen(*gc->pen); - gr->painter->drawArc(p->x-r/2, p->y-r/2, r, r, 0, 360*16); + // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d\n", gr, gc, p->x, p->y, r); + if (gr->painter == NULL) + return; + gr->painter->setPen(*gc->pen); + gr->painter->drawArc(p->x - r / 2, p->y - r / 2, r, r, 0, 360 * 16); } - 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) +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) %s\n", gr, fg, bg, p->x, p->y, text); - QPainter *painter=gr->painter; - if(painter == NULL) - return; + dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) %s\n", gr, fg, bg, p->x, p->y, text); + QPainter* painter = gr->painter; + if (painter == NULL) + return; #ifdef QT_QPAINTER_USE_FREETYPE - struct font_freetype_text *t; - struct font_freetype_glyph *g, **gp; - struct color transparent = {0x0000, 0x0000, 0x0000, 0x0000}; - struct color fgc; - struct color bgc; - QColor temp; - - int i,x,y; - - if (! font) - return; - /* extract colors */ - fgc.r = fg->pen->color().red() << 8; - fgc.g = fg->pen->color().green() << 8; - fgc.b = fg->pen->color().blue() << 8; - fgc.a = fg->pen->color().alpha() << 8; - if(bg != NULL) - { - bgc.r = bg->pen->color().red() << 8; - bgc.g = bg->pen->color().green() << 8; - bgc.b = bg->pen->color().blue() << 8; - bgc.a = bg->pen->color().alpha() << 8; + struct font_freetype_text* t; + struct font_freetype_glyph *g, **gp; + struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 }; + struct color fgc; + struct color bgc; + QColor temp; + + int i, x, y; + + if (!font) + return; + /* extract colors */ + fgc.r = fg->pen->color().red() << 8; + fgc.g = fg->pen->color().green() << 8; + fgc.b = fg->pen->color().blue() << 8; + fgc.a = fg->pen->color().alpha() << 8; + if (bg != NULL) { + bgc.r = bg->pen->color().red() << 8; + bgc.g = bg->pen->color().green() << 8; + bgc.b = bg->pen->color().blue() << 8; + bgc.a = bg->pen->color().alpha() << 8; + } else { + bgc = transparent; + } + + t = gr->freetype_methods.text_new(text, (struct font_freetype_font*)font, dx, dy); + x = p->x << 6; + y = p->y << 6; + gp = t->glyph; + i = t->glyph_count; + if (bg) { + while (i-- > 0) { + g = *gp++; + if (g->w && g->h) { + unsigned char* data; + QImage img(g->w + 2, g->h + 2, QImage::Format_ARGB32_Premultiplied); + data = img.bits(); + gr->freetype_methods.get_shadow(g, (unsigned char*)data, img.bytesPerLine(), &bgc, &transparent); + + painter->drawImage(((x + g->x) >> 6) - 1, ((y + g->y) >> 6) - 1, img); + } + x += g->dx; + y += g->dy; } - else - { - bgc = transparent; + } + x = p->x << 6; + y = p->y << 6; + gp = t->glyph; + i = t->glyph_count; + while (i-- > 0) { + g = *gp++; + if (g->w && g->h) { + unsigned char* data; + QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied); + data = img.bits(); + gr->freetype_methods.get_glyph(g, (unsigned char*)data, img.bytesPerLine(), &fgc, &bgc, &transparent); + painter->drawImage((x + g->x) >> 6, (y + g->y) >> 6, img); } - - t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy); - x=p->x << 6; - y=p->y << 6; - gp=t->glyph; - i=t->glyph_count; - if (bg) { - while (i-- > 0) { - g=*gp++; - if (g->w && g->h) { - unsigned char *data; - QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied); - data=img.bits(); - gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),&bgc,&transparent); - - painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img); - } - x+=g->dx; - y+=g->dy; - } - } - x=p->x << 6; - y=p->y << 6; - gp=t->glyph; - i=t->glyph_count; - while (i-- > 0) { - g=*gp++; - if (g->w && g->h) { - unsigned char *data; - QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied); - data=img.bits(); - gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),&fgc,&bgc,&transparent); - painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img); - } - x+=g->dx; - y+=g->dy; - } - gr->freetype_methods.text_destroy(t); + x += g->dx; + y += g->dy; + } + gr->freetype_methods.text_destroy(t); #else - QString tmp=QString::fromUtf8(text); - QMatrix sav=gr->painter->worldMatrix(); - QMatrix m(dx/65535.0,dy/65535.0,-dy/65535.0,dx/65535.0,p->x,p->y); - painter->setWorldMatrix(m,TRUE); - painter->setPen(*fg->pen); - painter->setFont(*font->font); - painter->drawText(0, 0, tmp); - painter->setWorldMatrix(sav); + QString tmp = QString::fromUtf8(text); + QMatrix sav = gr->painter->worldMatrix(); + QMatrix m(dx / 65535.0, dy / 65535.0, -dy / 65535.0, dx / 65535.0, p->x, p->y); + painter->setWorldMatrix(m, TRUE); + painter->setPen(*fg->pen); + painter->setFont(*font->font); + painter->drawText(0, 0, tmp); + painter->setWorldMatrix(sav); #endif } static void -draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) +draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img) { -// dbg(lvl_debug,"enter\n"); - 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,"enter\n"); + 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"); } -static void draw_drag(struct graphics_priv *gr, struct point *p) +static void draw_drag(struct graphics_priv* gr, struct point* p) { - if(p != NULL) - { -// dbg(lvl_debug,"enter %p (%d,%d)\n", gr, p->x, p->y); - gr->x = p->x; - gr->y = p->y; - } - else - { -// dbg(lvl_debug,"enter %p (NULL)\n", gr); - } + if (p != NULL) { + // dbg(lvl_debug,"enter %p (%d,%d)\n", gr, p->x, p->y); + gr->x = p->x; + gr->y = p->y; + } else { + // dbg(lvl_debug,"enter %p (NULL)\n", gr); + } } static void -background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) +background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc) { -// dbg(lvl_debug,"register context %p on %p\n", gc, gr); - gr->background_graphics_gc_priv = gc; + // dbg(lvl_debug,"register context %p on %p\n", gc, gr); + gr->background_graphics_gc_priv = gc; } 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); - gr->use_count ++; - if(gr->painter == NULL) - gr->painter = new QPainter(gr->pixmap); - else - dbg(lvl_debug, "drawing on %p already active\n", gr); - break; - case draw_mode_end: - dbg(lvl_debug,"End drawing on context %p (use == %d)\n", gr, gr->use_count); - gr->use_count --; - if(gr->use_count > 0) - { - dbg(lvl_debug, "drawing on %p still in use\n", gr); - } - else if(gr->painter != NULL) - { - gr->painter->end(); - delete(gr->painter); - gr->painter = NULL; +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); + gr->use_count++; + if (gr->painter == NULL) + gr->painter = new QPainter(gr->pixmap); + else + dbg(lvl_debug, "drawing on %p already active\n", gr); + break; + case draw_mode_end: + dbg(lvl_debug, "End drawing on context %p (use == %d)\n", gr, gr->use_count); + gr->use_count--; + if (gr->use_count > 0) { + dbg(lvl_debug, "drawing on %p still in use\n", gr); + } else if (gr->painter != NULL) { + gr->painter->end(); + delete (gr->painter); + gr->painter = NULL; #if USE_QWIDGET - /* call repaint on widget */ - if(gr->widget != NULL) - gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height()); + /* 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 - } - else - dbg(lvl_debug, "Context %p not active!\n", gr) - - break; - default: - dbg(lvl_debug,"Unknown drawing %d on context %p\n", mode, gr); - break; - } + if (gr->GPriv != NULL) + gr->GPriv->emit_update(); + +#endif + } else + dbg(lvl_debug, "Context %p not active!\n", gr) + + break; + default: + dbg(lvl_debug, "Unknown drawing %d on context %p\n", 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) +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)); + // 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)); } static int -graphics_qt5_fullscreen(struct window *w, int on) +graphics_qt5_fullscreen(struct window* w, int on) { - struct graphics_priv * gr; -// dbg(lvl_debug,"enter\n"); - gr = (struct graphics_priv *) w->priv; + struct graphics_priv* gr; + // dbg(lvl_debug,"enter\n"); + gr = (struct graphics_priv*)w->priv; #if USE_QML - if(gr->window != NULL) - { - if(on) - gr->window->setWindowState(Qt::WindowFullScreen); - else - gr->window->setWindowState(Qt::WindowMaximized); - } + if (gr->window != NULL) { + if (on) + gr->window->setWindowState(Qt::WindowFullScreen); + else + gr->window->setWindowState(Qt::WindowMaximized); + } #endif #if USE_QWIDGET - if(gr->widget != NULL) - { - if(on) - gr->widget->setWindowState(Qt::WindowFullScreen); - else - gr->widget->setWindowState(Qt::WindowMaximized); - } + if (gr->widget != NULL) { + if (on) + gr->widget->setWindowState(Qt::WindowFullScreen); + else + gr->widget->setWindowState(Qt::WindowMaximized); + } #endif - return 1; + return 1; } #ifdef SAILFISH_OS static void -keep_display_on(struct graphics_priv * priv) +keep_display_on(struct graphics_priv* priv) { -// dbg(lvl_debug,"enter\n"); - QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system"); - QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system); + // dbg(lvl_debug,"enter\n"); + QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system"); + QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system); - interface.call(QLatin1String("req_display_blanking_pause")); + interface.call(QLatin1String("req_display_blanking_pause")); } #endif - static void -graphics_qt5_disable_suspend(struct window *w) +graphics_qt5_disable_suspend(struct window* w) { // dbg(lvl_debug,"enter\n"); #ifdef SAILFISH_OS - struct graphics_priv * gr; - gr = (struct graphics_priv *) w->priv; - keep_display_on(gr); - /* to keep display on, d-bus trigger must be called at least once per second. + struct graphics_priv* gr; + gr = (struct graphics_priv*)w->priv; + keep_display_on(gr); + /* to keep display on, d-bus trigger must be called at least once per second. * to cope with fuzz, trigger it once per 30 seconds */ - gr->display_on_cb = callback_new_1(callback_cast(keep_display_on), gr); - gr->display_on_ev = event_add_timeout(30000, 1, gr->display_on_cb); -#endif -} - -static void * -get_data(struct graphics_priv *this_priv, char const *type) -{ -// dbg(lvl_debug,"enter: %s\n", type); - if (strcmp(type, "window") == 0) { - struct window *win; -// dbg(lvl_debug,"window detected\n"); - win = g_new0(struct window, 1); - win->priv = this_priv; - win->fullscreen = graphics_qt5_fullscreen; - win->disable_suspend = graphics_qt5_disable_suspend; - 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; -} - -static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) -{ -// dbg(lvl_debug,"enter\n"); - delete(priv->pixmap); - g_free(priv); -} - -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) -{ -// dbg(lvl_debug,"enter %s %d %d\n", text, dx, dy); - QPainter *painter=gr->painter; - QString tmp=QString::fromUtf8(text); - if(gr->painter != NULL) - { - gr->painter->setFont(*font->font); - QRect r=painter->boundingRect(0,0,gr->pixmap->width(),gr->pixmap->height(),0,tmp); -// dbg (lvl_debug, "Text bbox: %d %d (%d,%d),(%d,%d)\n",dx, dy, r.left(), r.top(), r.right(), r.bottom()); - /* low left */ - ret[0].x = r.left(); - ret[0].y = r.bottom(); - /* top left */ - ret[1].x = r.left(); - ret[1].y = r.top(); - /* top right */ - ret[2].x = r.right(); - ret[2].y = r.top(); - /* low right */ - ret[3].x = r.right(); - ret[3].y = r.bottom(); - } -} - -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); - - 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; - } -} - -static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) -{ -// dbg(lvl_debug,"enter\n"); - 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); - if(gr->painter != NULL) - gr->painter = new QPainter (gr->pixmap); + gr->display_on_cb = callback_new_1(callback_cast(keep_display_on), gr); + gr->display_on_ev = event_add_timeout(30000, 1, gr->display_on_cb); +#endif +} + +static void* +get_data(struct graphics_priv* this_priv, char const* type) +{ + // dbg(lvl_debug,"enter: %s\n", type); + if (strcmp(type, "window") == 0) { + struct window* win; + // dbg(lvl_debug,"window detected\n"); + win = g_new0(struct window, 1); + win->priv = this_priv; + win->fullscreen = graphics_qt5_fullscreen; + win->disable_suspend = graphics_qt5_disable_suspend; + 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; +} + +static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv) +{ + // dbg(lvl_debug,"enter\n"); + delete (priv->pixmap); + g_free(priv); +} + +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) +{ + // dbg(lvl_debug,"enter %s %d %d\n", text, dx, dy); + QPainter* painter = gr->painter; + QString tmp = QString::fromUtf8(text); + if (gr->painter != NULL) { + gr->painter->setFont(*font->font); + QRect r = painter->boundingRect(0, 0, gr->pixmap->width(), gr->pixmap->height(), 0, tmp); + // dbg (lvl_debug, "Text bbox: %d %d (%d,%d),(%d,%d)\n",dx, dy, r.left(), r.top(), r.right(), r.bottom()); + /* low left */ + ret[0].x = r.left(); + ret[0].y = r.bottom(); + /* top left */ + ret[1].x = r.left(); + ret[1].y = r.top(); + /* top right */ + ret[2].x = r.right(); + ret[2].y = r.top(); + /* low right */ + ret[3].x = r.right(); + ret[3].y = r.bottom(); + } +} + +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); + + 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; + } +} + +static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) +{ + // dbg(lvl_debug,"enter\n"); + 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); + if (gr->painter != NULL) + gr->painter = new QPainter(gr->pixmap); } static struct graphics_methods graphics_methods = { - graphics_destroy, - draw_mode, - draw_lines, - draw_polygon, - draw_rectangle, - draw_circle, - draw_text, - draw_image, - NULL, - draw_drag, - font_new, - gc_new, - background_gc, - overlay_new, - image_new, - get_data, - image_free, - get_text_bbox, - overlay_disable, - overlay_resize, + graphics_destroy, + draw_mode, + draw_lines, + draw_polygon, + draw_rectangle, + draw_circle, + draw_text, + draw_image, + NULL, + draw_drag, + font_new, + gc_new, + background_gc, + overlay_new, + image_new, + get_data, + image_free, + get_text_bbox, + overlay_disable, + overlay_resize, }; /* 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; + struct graphics_priv* graphics_priv = NULL; + graphics_priv = g_new0(struct graphics_priv, 1); + *meth = graphics_methods; #ifdef QT_QPAINTER_USE_FREETYPE - 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; - } + 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; + } #endif #if USE_QML - graphics_priv->window = gr->window; - graphics_priv->GPriv = gr->GPriv; + graphics_priv->window = gr->window; + graphics_priv->GPriv = gr->GPriv; #endif #if USE_QWIDGET - graphics_priv->widget = gr->widget; -#endif - graphics_priv->x = p->x; - graphics_priv->y = p->y; - graphics_priv->disable = false; - graphics_priv->callbacks = gr->callbacks; - graphics_priv->pixmap = new QPixmap(w, h); - graphics_priv->pixmap->fill(Qt::transparent); - graphics_priv->painter = NULL; - graphics_priv->use_count = 0; - graphics_priv->parent = gr; - graphics_priv->overlays=g_hash_table_new(NULL, NULL); - graphics_priv->root = false; - graphics_priv->argc = 0; - 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); - - return graphics_priv; + graphics_priv->widget = gr->widget; +#endif + graphics_priv->x = p->x; + graphics_priv->y = p->y; + graphics_priv->disable = false; + graphics_priv->callbacks = gr->callbacks; + graphics_priv->pixmap = new QPixmap(w, h); + graphics_priv->pixmap->fill(Qt::transparent); + graphics_priv->painter = NULL; + graphics_priv->use_count = 0; + graphics_priv->parent = gr; + graphics_priv->overlays = g_hash_table_new(NULL, NULL); + graphics_priv->root = false; + graphics_priv->argc = 0; + 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); + + 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) -{ - struct graphics_priv * graphics_priv = NULL; - struct attr * event_loop_system = NULL; - struct attr * platform = NULL; - struct attr * fullscreen = NULL; - struct attr * attr_widget = NULL; - bool use_qml = USE_QML; - bool use_qwidget = USE_QWIDGET; - - //dbg(lvl_debug,"enter\n"); - - /* get qt widget attr */ - if((attr_widget=attr_search(attrs, NULL, attr_qt5_widget))) - { - /* check if we shall use qml */ - if(strcmp (attr_widget->u.str, "qwidget") == 0) - { - use_qml = false; - } - /* check if we shall use qwidget */ - if(strcmp (attr_widget->u.str, "qml") == 0) - { - use_qwidget = false; - } - } - if(use_qml && use_qwidget) - { - /* both are possible, default to QML */ - use_qwidget = false; - } - - /*register graphic methods by copying in our predefined ones */ - *meth=graphics_methods; - - /* 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); - if (!event_request_system(event_loop_system->u.str, "graphics_qt5")) - return NULL; - } else { - /* no event system requested by config. Default to our own */ - if (!event_request_system("qt5", "graphics_qt5")) - return NULL; +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; + struct attr* fullscreen = NULL; + struct attr* attr_widget = NULL; + bool use_qml = USE_QML; + bool use_qwidget = USE_QWIDGET; + + //dbg(lvl_debug,"enter\n"); + + /* get qt widget attr */ + if ((attr_widget = attr_search(attrs, NULL, attr_qt5_widget))) { + /* check if we shall use qml */ + if (strcmp(attr_widget->u.str, "qwidget") == 0) { + use_qml = false; + } + /* check if we shall use qwidget */ + if (strcmp(attr_widget->u.str, "qml") == 0) { + use_qwidget = false; } + } + if (use_qml && use_qwidget) { + /* both are possible, default to QML */ + use_qwidget = false; + } + + /*register graphic methods by copying in our predefined ones */ + *meth = graphics_methods; + + /* 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); + if (!event_request_system(event_loop_system->u.str, "graphics_qt5")) + return NULL; + } else { + /* no event system requested by config. Default to our own */ + if (!event_request_system("qt5", "graphics_qt5")) + return NULL; + } #ifdef QT_QPAINTER_USE_FREETYPE - struct font_priv * (*font_freetype_new)(void *meth); - /* 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"); - return NULL; - } -#endif - - /* create root graphics layer */ - graphics_priv = g_new0(struct graphics_priv, 1); - /* Prepare argc and argv to call Qt application*/ - graphics_priv->root = true; - graphics_priv->argc = 0; - graphics_priv->argv[graphics_priv->argc] = g_strdup("navit"); - graphics_priv->argc ++; - /* Get qt platform from config */ - if ((platform=attr_search(attrs, NULL, attr_qt5_platform))) - { - graphics_priv->argv[graphics_priv->argc] = g_strdup("-platform"); - graphics_priv->argc ++; - graphics_priv->argv[graphics_priv->argc] = g_strdup(platform->u.str); - graphics_priv->argc ++; - } - /* create surrounding application */ + struct font_priv* (*font_freetype_new)(void* meth); + /* 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"); + return NULL; + } +#endif + + /* create root graphics layer */ + graphics_priv = g_new0(struct graphics_priv, 1); + /* Prepare argc and argv to call Qt application*/ + graphics_priv->root = true; + graphics_priv->argc = 0; + graphics_priv->argv[graphics_priv->argc] = g_strdup("navit"); + graphics_priv->argc++; + /* Get qt platform from config */ + if ((platform = attr_search(attrs, NULL, attr_qt5_platform))) { + graphics_priv->argv[graphics_priv->argc] = g_strdup("-platform"); + graphics_priv->argc++; + graphics_priv->argv[graphics_priv->argc] = g_strdup(platform->u.str); + graphics_priv->argc++; + } +/* create surrounding application */ #if USE_QWIDGET - QApplication * internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv); - navit_app = internal_app; + QApplication* internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv); + navit_app = internal_app; #else - navit_app = new QGuiApplication(graphics_priv->argc, graphics_priv->argv); + navit_app = new QGuiApplication(graphics_priv->argc, graphics_priv->argv); #endif #ifdef QT_QPAINTER_USE_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; -#endif - graphics_priv->callbacks = cbl; - graphics_priv->pixmap = NULL; - graphics_priv->use_count = 0; - graphics_priv->painter = NULL; - graphics_priv->parent = NULL; - graphics_priv->overlays=g_hash_table_new(NULL, NULL); - graphics_priv->x = 0; - graphics_priv->y = 0; - graphics_priv->disable = 0; + 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; +#endif + graphics_priv->callbacks = cbl; + graphics_priv->pixmap = NULL; + graphics_priv->use_count = 0; + graphics_priv->painter = NULL; + graphics_priv->parent = NULL; + graphics_priv->overlays = g_hash_table_new(NULL, NULL); + graphics_priv->x = 0; + 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) - { - /* 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 + graphics_priv->engine = NULL; + graphics_priv->window = NULL; + graphics_priv->GPriv = NULL; + if (use_qml) { + /* 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 */ - graphics_priv->engine = new QQmlApplicationEngine(); - if(graphics_priv->engine != NULL) - { - graphics_priv->GPriv = new GraphicsPriv(graphics_priv); - QQmlContext *context = graphics_priv->engine->rootContext(); - context->setContextProperty("graphics_qt5_context", graphics_priv->GPriv); - graphics_priv->engine->load(QUrl("qrc:///loader.qml")); - /* Get the engine's root window (for resizing) */ - QObject *toplevel = graphics_priv->engine->rootObjects().value(0); - graphics_priv->window = qobject_cast<QQuickWindow *> (toplevel); - } + graphics_priv->engine = new QQmlApplicationEngine(); + if (graphics_priv->engine != NULL) { + graphics_priv->GPriv = new GraphicsPriv(graphics_priv); + QQmlContext* context = graphics_priv->engine->rootContext(); + context->setContextProperty("graphics_qt5_context", graphics_priv->GPriv); + graphics_priv->engine->load(QUrl("qrc:///loader.qml")); + /* Get the engine's root window (for resizing) */ + QObject* toplevel = graphics_priv->engine->rootObjects().value(0); + graphics_priv->window = qobject_cast<QQuickWindow*>(toplevel); } + } #endif #if USE_QWIDGET - graphics_priv->widget = NULL; - if(use_qwidget) - { - graphics_priv->widget = new QNavitWidget(graphics_priv,NULL,Qt::Window); - } + graphics_priv->widget = NULL; + if (use_qwidget) { + graphics_priv->widget = new QNavitWidget(graphics_priv, NULL, Qt::Window); + } #endif - if ((fullscreen=attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) { - /* show this maximized */ + if ((fullscreen = attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) { +/* show this maximized */ #if USE_QML - if(graphics_priv->window != NULL) - graphics_priv->window->setWindowState(Qt::WindowFullScreen); + if (graphics_priv->window != NULL) + graphics_priv->window->setWindowState(Qt::WindowFullScreen); #endif #if USE_QWIDGET - if(graphics_priv->widget != NULL) - graphics_priv->widget->setWindowState(Qt::WindowFullScreen); -#endif + if (graphics_priv->widget != NULL) + graphics_priv->widget->setWindowState(Qt::WindowFullScreen); +#endif + } else { + /* not maximized. Check what size to use then */ + struct attr* w = NULL; + struct attr* h = NULL; + /* default to desktop size if nothing else is given */ + QRect geomet; + geomet.setHeight(100); + geomet.setWidth(100); + /* get desktop size */ + QScreen* primary = navit_app->primaryScreen(); + if (primary != NULL) { + geomet = primary->availableGeometry(); } - else - { - /* not maximized. Check what size to use then */ - struct attr * w = NULL; - struct attr * h = NULL; - /* default to desktop size if nothing else is given */ - QRect geomet; - geomet.setHeight(100); - geomet.setWidth(100); - /* get desktop size */ - QScreen *primary = navit_app->primaryScreen(); - if(primary != NULL) - { - geomet = primary->availableGeometry(); - } - /* check for height */ - if ((h = attr_search(attrs, NULL, attr_h)) && (h->u.num > 100)) - geomet.setHeight(h->u.num); - /* check for width */ - if ((w = attr_search(attrs, NULL, attr_w)) && (w->u.num > 100)) - geomet.setWidth(w->u.num); + /* check for height */ + if ((h = attr_search(attrs, NULL, attr_h)) && (h->u.num > 100)) + geomet.setHeight(h->u.num); + /* check for width */ + if ((w = attr_search(attrs, NULL, attr_w)) && (w->u.num > 100)) + geomet.setWidth(w->u.num); #if USE_QML - if(graphics_priv->window != NULL) - { - graphics_priv->window->resize(geomet.width(), geomet.height()); - //graphics_priv->window->setFixedSize(geomet.width(), geomet.height()); - } + if (graphics_priv->window != NULL) { + graphics_priv->window->resize(geomet.width(), geomet.height()); + //graphics_priv->window->setFixedSize(geomet.width(), geomet.height()); + } #endif #if USE_QWIDGET - if(graphics_priv->widget != NULL) - { - graphics_priv->widget->resize(geomet.width(), geomet.height()); - //graphics_priv->widget->setFixedSize(geomet.width(), geomet.height()); - } -#endif - } - /* generate initial pixmap same size as window */ - if(graphics_priv->pixmap == NULL) - { + if (graphics_priv->widget != NULL) { + graphics_priv->widget->resize(geomet.width(), geomet.height()); + //graphics_priv->widget->setFixedSize(geomet.width(), geomet.height()); + } +#endif + } + /* generate initial pixmap same size as window */ + if (graphics_priv->pixmap == NULL) { #if USE_QML - if(graphics_priv->window != NULL) - graphics_priv->pixmap = new QPixmap(graphics_priv->window->size()); + if (graphics_priv->window != NULL) + graphics_priv->pixmap = new QPixmap(graphics_priv->window->size()); #endif #if USE_QWIDGET - if(graphics_priv->widget != NULL) - graphics_priv->pixmap = new QPixmap(graphics_priv->widget->size()); + if (graphics_priv->widget != NULL) + graphics_priv->pixmap = new QPixmap(graphics_priv->widget->size()); #endif - if(graphics_priv->pixmap == NULL) - graphics_priv->pixmap = new QPixmap(100,100); - graphics_priv->pixmap->fill(Qt::black); - } + if (graphics_priv->pixmap == NULL) + graphics_priv->pixmap = new QPixmap(100, 100); + graphics_priv->pixmap->fill(Qt::black); + } - /* tell Navit our geometry */ - resize_callback(graphics_priv, graphics_priv->pixmap->width(),graphics_priv->pixmap->height()); + /* 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(); + if (graphics_priv->window != NULL) + graphics_priv->window->show(); #endif #if USE_QWIDGET - if(graphics_priv->widget != NULL) - graphics_priv->widget->show(); + if (graphics_priv->widget != NULL) + graphics_priv->widget->show(); #endif - return graphics_priv; + return graphics_priv; } -void -plugin_init(void) +void plugin_init(void) { #if USE_QML - Q_INIT_RESOURCE(graphics_qt5); + Q_INIT_RESOURCE(graphics_qt5); #endif -// dbg(lvl_debug,"enter\n"); - plugin_register_category_graphics("qt5", graphics_qt5_new); - qt5_event_init(); + // dbg(lvl_debug,"enter\n"); + 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 fad818773..cebbc6d67 100644 --- a/navit/graphics/qt5/graphics_qt5.h +++ b/navit/graphics/qt5/graphics_qt5.h @@ -1,3 +1,23 @@ +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2017 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * 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 @@ -9,16 +29,16 @@ #define USE_QML 0 #endif -#include <glib.h> +#include <QBrush> #include <QGuiApplication> -#include <QPixmap> #include <QPainter> #include <QPen> -#include <QBrush> +#include <QPixmap> +#include <glib.h> #if USE_QML +#include <QObject> #include <QQmlApplicationEngine> #include <QQuickWindow> -#include <QObject> #endif #if USE_QWIDGET #include "QNavitWidget.h" @@ -32,7 +52,6 @@ #define SAILFISH_OS 1 #endif - #ifdef QT_QPAINTER_USE_FREETYPE #include "navit/font/freetype/font_freetype.h" #endif @@ -41,63 +60,60 @@ struct graphics_gc_priv; struct graphics_priv; #if USE_QML -class GraphicsPriv : public QObject -{ - Q_OBJECT +class GraphicsPriv : public QObject { + Q_OBJECT public: - GraphicsPriv(struct graphics_priv * gp); - ~GraphicsPriv(); - void emit_update(); + GraphicsPriv(struct graphics_priv* gp); + ~GraphicsPriv(); + void emit_update(); - struct graphics_priv * gp; + struct graphics_priv* gp; signals: - void update(); + void update(); }; #endif struct graphics_priv { #if USE_QML - QQmlApplicationEngine * engine; - GraphicsPriv * GPriv; - QQuickWindow * window; + QQmlApplicationEngine* engine; + GraphicsPriv* GPriv; + QQuickWindow* window; #endif #if USE_QWIDGET - QNavitWidget * widget; + QNavitWidget* widget; #endif - QPixmap * pixmap; - QPainter * painter; - int use_count; - int disable; - int x; - int y; - struct graphics_gc_priv * background_graphics_gc_priv; + QPixmap* pixmap; + QPainter* painter; + int use_count; + int disable; + int x; + int y; + struct graphics_gc_priv* background_graphics_gc_priv; #ifdef QT_QPAINTER_USE_FREETYPE - struct font_priv * (*font_freetype_new)(void *meth); - struct font_freetype_methods freetype_methods; + struct font_priv* (*font_freetype_new)(void* meth); + struct font_freetype_methods freetype_methods; #endif #ifdef SAILFISH_OS - struct callback *display_on_cb; - struct event_timeout *display_on_ev; + struct callback* display_on_cb; + struct event_timeout* display_on_ev; #endif - struct callback_list* callbacks; - GHashTable *overlays; - struct graphics_priv * parent; - bool root; - int argc; - char * argv[4]; + struct callback_list* callbacks; + GHashTable* overlays; + struct graphics_priv* parent; + bool root; + int argc; + char* argv[4]; }; - struct graphics_gc_priv { - struct graphics_priv * graphics_priv; - QPen * pen; - QBrush * brush; + struct graphics_priv* graphics_priv; + QPen* pen; + QBrush* brush; }; /* central exported application info */ -extern QGuiApplication * navit_app; +extern QGuiApplication* navit_app; -void resize_callback(struct graphics_priv * gr, int w, int h); +void resize_callback(struct graphics_priv* gr, int w, int h); #endif - |