diff options
Diffstat (limited to 'navit/graphics/qt5/QNavitQuick.cpp')
-rw-r--r-- | navit/graphics/qt5/QNavitQuick.cpp | 108 |
1 files changed, 55 insertions, 53 deletions
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp index 7df3e0073..dcd0d2aa5 100644 --- a/navit/graphics/qt5/QNavitQuick.cpp +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -//Style with: clang-format -style=WebKit -i #include <glib.h> #ifdef HAVE_UNISTD_H @@ -46,21 +45,18 @@ extern "C" { #include <QPainter> QNavitQuick::QNavitQuick(QQuickItem* parent) - : QQuickPaintedItem(parent) -{ + : QQuickPaintedItem(parent) { setAcceptedMouseButtons(Qt::AllButtons); graphics_priv = NULL; } -void QNavitQuick::setGraphicContext(GraphicsPriv* gp) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::setGraphicContext(GraphicsPriv* gp) { + dbg(lvl_debug, "enter"); graphics_priv = gp->gp; QObject::connect(gp, SIGNAL(update()), this, SLOT(update())); } -static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) -{ +static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) { GHashTableIter iter; struct graphics_priv *key, *value; g_hash_table_iter_init(&iter, gp->overlays); @@ -68,7 +64,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve if (!value->disable) { QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height()); if (event->rect().intersects(rr)) { - dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)\n", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height()); + dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y, + value->pixmap->width(), value->pixmap->height()); painter->drawPixmap(value->x, value->y, *value->pixmap); /* draw overlays of overlay if any by recursive calling */ paintOverlays(painter, value, event); @@ -77,11 +74,12 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve } } -void QNavitQuick::paint(QPainter* painter) -{ - QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height())); +void QNavitQuick::paint(QPainter* painter) { + QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(), + boundingRect().height())); - dbg(lvl_debug, "enter (%f, %f, %f, %f)\n", boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()); + dbg(lvl_debug, "enter (%f, %f, %f, %f)", boundingRect().x(), boundingRect().y(), boundingRect().width(), + boundingRect().height()); /* color background if any */ if (graphics_priv->background_graphics_gc_priv != NULL) { @@ -90,14 +88,16 @@ void QNavitQuick::paint(QPainter* painter) } /* draw base */ painter->drawPixmap(graphics_priv->scroll_x, graphics_priv->scroll_y, *graphics_priv->pixmap, - boundingRect().x(), boundingRect().y(), - boundingRect().width(), boundingRect().height()); - paintOverlays(painter, graphics_priv, &event); + boundingRect().x(), boundingRect().y(), + boundingRect().width(), boundingRect().height()); + /* disable on root pane disables ALL overlays (for drag of background) */ + if(!(graphics_priv->disable)) { + paintOverlays(painter, graphics_priv, &event); + } } -void QNavitQuick::keyPressEvent(QKeyEvent* event) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::keyPressEvent(QKeyEvent* event) { + dbg(lvl_debug, "enter"); char key[2]; int keycode; char* text = NULL; @@ -157,89 +157,89 @@ void QNavitQuick::keyPressEvent(QKeyEvent* event) else if (key[0]) callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key); else - dbg(lvl_debug, "keyval 0x%x\n", keycode); + dbg(lvl_debug, "keyval 0x%x", keycode); } -void QNavitQuick::keyReleaseEvent(QKeyEvent* event) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::keyReleaseEvent(QKeyEvent* event) { + dbg(lvl_debug, "enter"); } -void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) { + dbg(lvl_debug, "enter"); QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); QPainter* painter = NULL; if (graphics_priv == NULL) { - dbg(lvl_debug, "Context not set, aborting\n"); + dbg(lvl_debug, "Context not set, aborting"); return; } if (graphics_priv->pixmap != NULL) { - delete graphics_priv->pixmap; - graphics_priv->pixmap = NULL; + if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) { + delete graphics_priv->pixmap; + graphics_priv->pixmap = NULL; + } + } + if (graphics_priv->pixmap == NULL) { + graphics_priv->pixmap = new QPixmap(width(), height()); } - - graphics_priv->pixmap = new QPixmap(width(), height()); painter = new QPainter(graphics_priv->pixmap); if (painter != NULL) { QBrush brush; painter->fillRect(0, 0, width(), height(), brush); delete painter; } - dbg(lvl_debug, "size %fx%f\n", width(), height()); - dbg(lvl_debug, "pixmap %p %dx%d\n", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height()); + dbg(lvl_debug, "size %fx%f", width(), height()); + dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), + graphics_priv->pixmap->height()); /* if the root window got resized, tell navit about it */ if (graphics_priv->root) resize_callback(graphics_priv, width(), height()); } -void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event) -{ +void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event) { struct point p; - dbg(lvl_debug, "enter\n"); + dbg(lvl_debug, "enter"); p.x = event->x(); p.y = event->y(); switch (event->button()) { case Qt::LeftButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), + GINT_TO_POINTER(&p)); break; case Qt::MidButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), + GINT_TO_POINTER(&p)); break; case Qt::RightButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), + GINT_TO_POINTER(&p)); break; default: break; } } -void QNavitQuick::mousePressEvent(QMouseEvent* event) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::mousePressEvent(QMouseEvent* event) { + dbg(lvl_debug, "enter"); mouseEvent(1, event); } -void QNavitQuick::mouseReleaseEvent(QMouseEvent* event) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::mouseReleaseEvent(QMouseEvent* event) { + dbg(lvl_debug, "enter"); mouseEvent(0, event); } -void QNavitQuick::mouseMoveEvent(QMouseEvent* event) -{ - dbg(lvl_debug, "enter\n"); +void QNavitQuick::mouseMoveEvent(QMouseEvent* event) { + dbg(lvl_debug, "enter"); struct point p; p.x = event->x(); p.y = event->y(); callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p); } -void QNavitQuick::wheelEvent(QWheelEvent* event) -{ +void QNavitQuick::wheelEvent(QWheelEvent* event) { struct point p; int button; - dbg(lvl_debug, "enter\n"); + dbg(lvl_debug, "enter"); p.x = event->x(); // xy-coordinates of the mouse pointer p.y = event->y(); @@ -251,8 +251,10 @@ void QNavitQuick::wheelEvent(QWheelEvent* event) button = -1; if (button != -1) { - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), + GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), + GINT_TO_POINTER(&p)); } event->accept(); |