summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wildemann <metalstrolch@users.noreply.github.com>2019-01-30 13:22:36 +0100
committerGitHub <noreply@github.com>2019-01-30 13:22:36 +0100
commit13b6ea56b8218c52f01596fb1dca8a4b557020f2 (patch)
tree2f8d746ba40876ba8d5de9b272fba83fb236dabb
parent962206c07db90761e34fcd72a48c525939b7e8d9 (diff)
parent33064cf47768f61479e277094862a806dc1421a7 (diff)
downloadnavit-13b6ea56b8218c52f01596fb1dca8a4b557020f2.tar.gz
Merge pull request #741 from navit-gps/qt5_osd_layer_fix
Fix:graphics_qt5:fix overlay handling This merge fixes graphics_qt5 to properly handle (osd) overlays. - They display properly - Enable and disable is handled right - They are redrawn after changes
-rw-r--r--navit/graphics/qt5/QNavitQuick.cpp17
-rw-r--r--navit/graphics/qt5/QNavitQuick.h3
-rw-r--r--navit/graphics/qt5/QNavitWidget.cpp17
-rw-r--r--navit/graphics/qt5/QNavitWidget.h8
-rw-r--r--navit/graphics/qt5/event_qt5.cpp1
-rw-r--r--navit/graphics/qt5/event_qt5.h4
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp75
-rw-r--r--navit/graphics/qt5/graphics_qt5.h4
8 files changed, 79 insertions, 50 deletions
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp
index 6981f3af7..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
@@ -91,7 +90,10 @@ void QNavitQuick::paint(QPainter* painter) {
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);
+ /* 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) {
@@ -171,11 +173,14 @@ void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGe
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;
diff --git a/navit/graphics/qt5/QNavitQuick.h b/navit/graphics/qt5/QNavitQuick.h
index 3679e8127..40c6639ae 100644
--- a/navit/graphics/qt5/QNavitQuick.h
+++ b/navit/graphics/qt5/QNavitQuick.h
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#ifndef QNAVITQUICK_H
#define QNAVITQUICK_H
@@ -29,9 +28,9 @@ class QNavitQuick;
class QNavitQuick : public QQuickPaintedItem {
Q_OBJECT
public:
+ void paint(QPainter* painter);
QNavitQuick(QQuickItem* parent = 0);
- void paint(QPainter* painter);
Q_INVOKABLE void setGraphicContext(GraphicsPriv* gp);
diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp
index 9c2b96505..355187b49 100644
--- a/navit/graphics/qt5/QNavitWidget.cpp
+++ b/navit/graphics/qt5/QNavitWidget.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#ifdef HAVE_UNISTD_H
@@ -89,17 +88,23 @@ void QNavitWidget::paintEvent(QPaintEvent* event) {
painter.drawPixmap(event->rect().x(), event->rect().y(), *graphics_priv->pixmap,
event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
event->rect().width(), event->rect().height());
- paintOverlays(&painter, graphics_priv, event);
+ /* disable on root pane disables ALL overlays (for drag of background) */
+ if(!(graphics_priv->disable)) {
+ paintOverlays(&painter, graphics_priv, event);
+ };
}
void QNavitWidget::resizeEvent(QResizeEvent* event) {
QPainter* painter = NULL;
if (graphics_priv->pixmap != NULL) {
- delete graphics_priv->pixmap;
- graphics_priv->pixmap = NULL;
+ if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) {
+ delete graphics_priv->pixmap;
+ graphics_priv->pixmap = NULL;
+ }
+ }
+ if (graphics_priv->pixmap == NULL) {
+ graphics_priv->pixmap = new QPixmap(size());
}
-
- graphics_priv->pixmap = new QPixmap(size());
painter = new QPainter(graphics_priv->pixmap);
if (painter != NULL) {
QBrush brush;
diff --git a/navit/graphics/qt5/QNavitWidget.h b/navit/graphics/qt5/QNavitWidget.h
index 674b69390..40fb88b19 100644
--- a/navit/graphics/qt5/QNavitWidget.h
+++ b/navit/graphics/qt5/QNavitWidget.h
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#ifndef __QNavitWidget_h
#define __QNavitWidget_h
@@ -30,10 +29,9 @@ class QNavitWidget;
class QNavitWidget : public QWidget {
Q_OBJECT
-public:
- QNavitWidget(struct graphics_priv* my_graphics_priv,
- QWidget* parent,
- Qt::WindowFlags flags);
+public: QNavitWidget(struct graphics_priv* my_graphics_priv,
+ QWidget* parent,
+ Qt::WindowFlags flags);
protected:
virtual bool event(QEvent* event);
diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp
index 5c7c3ca27..7186534fe 100644
--- a/navit/graphics/qt5/event_qt5.cpp
+++ b/navit/graphics/qt5/event_qt5.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#include <stdio.h>
diff --git a/navit/graphics/qt5/event_qt5.h b/navit/graphics/qt5/event_qt5.h
index 892e8fca8..7fe184cd1 100644
--- a/navit/graphics/qt5/event_qt5.h
+++ b/navit/graphics/qt5/event_qt5.h
@@ -16,15 +16,13 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <QObject>
#include <glib.h>
class qt5_navit_timer : public QObject {
Q_OBJECT
-public:
- qt5_navit_timer(QObject* parent = 0);
+public: qt5_navit_timer(QObject* parent = 0);
GHashTable* timer_type;
GHashTable* timer_callback;
GHashTable* watches;
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index c23a4f60f..e7b31c605 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#ifdef HAVE_UNISTD_H
@@ -180,7 +179,8 @@ static const char* fontfamilies[] = {
*
* Allocates a font handle and returnes filled interface stucture
*/
-static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, int size, int flags) {
+static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font,
+ int size, int flags) {
int a = 0;
struct graphics_font_priv* font_priv;
dbg(lvl_debug, "enter (font %s, %d, 0x%x)", font, size, flags);
@@ -295,7 +295,8 @@ struct graphics_image_methods image_methods = {
image_destroy
};
-static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot, int rotation) {
+static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path,
+ int* w, int* h, struct point* hot, int rotation) {
struct graphics_image_priv* image_priv;
// dbg(lvl_debug,"enter %s, %d %d", path, *w, *h);
if (path[0] == 0) {
@@ -304,7 +305,11 @@ static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct gr
}
QString key(path);
QString renderer_key(key);
- QString extension = key.right(key.lastIndexOf("."));
+ int index = key.lastIndexOf(".");
+ QString extension;
+ if(index > 0) {
+ extension = key.right(index);
+ }
QFile imagefile(key);
if (!imagefile.exists()) {
/* file doesn't exit. Either navit wants us to guess file name by
@@ -348,7 +353,7 @@ static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct gr
}
/* check if we got image */
- if (image_priv->pixmap->isNull()) {
+ if ((image_priv->pixmap == NULL) || (image_priv->pixmap->isNull())) {
g_free(image_priv);
return NULL;
} else {
@@ -444,7 +449,8 @@ static void draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, s
*
* Renders given text on gr surface. Draws nice contrast outline around text.
*/
-static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) {
+static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg,
+ struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) {
dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s", gr, fg, bg, p->x, p->y, dx, dy, text);
QPainter* painter = gr->painter;
if (painter == NULL)
@@ -535,7 +541,8 @@ static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, str
#endif
}
-static void draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img) {
+static void draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p,
+ struct graphics_image_priv* img) {
// dbg(lvl_debug,"enter");
if (gr->painter != NULL)
gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
@@ -635,7 +642,8 @@ static void draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) {
}
}
-static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound);
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound);
void resize_callback(struct graphics_priv* gr, int w, int h) {
// dbg(lvl_debug,"enter (%d, %d)", w, h);
@@ -725,7 +733,8 @@ static void image_free(struct graphics_priv* gr, struct graphics_image_priv* pri
*
* Calculates the bounding box around the given text.
*/
-static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, struct point* ret, int estimate) {
+static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy,
+ struct point* ret, int estimate) {
int i;
struct point pt;
QString tmp = QString::fromUtf8(text);
@@ -759,29 +768,45 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f
}
static void overlay_disable(struct graphics_priv* gr, int disable) {
- GHashTableIter iter;
- struct graphics_priv *key, *value;
- // dbg(lvl_debug,"enter gr=%p, %d", 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;
- }
+ //dbg(lvl_error,"enter gr=%p, %d", gr, disable);
+ gr->disable = disable;
+#if USE_QWIDGET
+ /* call repaint on widget */
+ if (gr->widget != NULL)
+ gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height());
+#endif
+#if USE_QML
+ if (gr->GPriv != NULL)
+ gr->GPriv->emit_update();
+
+#endif
}
static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) {
- // dbg(lvl_debug,"enter");
+ // dbg(lvl_debug,"enter %d %d %d %d %d", p->x, p->y, w, h, wraparound);
gr->x = p->x;
gr->y = p->y;
if (gr->painter != NULL) {
delete (gr->painter);
}
- delete (gr->pixmap);
- gr->pixmap = new QPixmap(w, h);
- gr->pixmap->fill(Qt::transparent);
+ /* replacing the pixmap clears the content. Only neccesary if size actually changes */
+ if((gr->pixmap->height() != h) || (gr->pixmap->width() != w)) {
+ delete (gr->pixmap);
+ gr->pixmap = new QPixmap(w, h);
+ gr->pixmap->fill(Qt::transparent);
+ }
if (gr->painter != NULL)
gr->painter = new QPainter(gr->pixmap);
+#if USE_QWIDGET
+ /* call repaint on widget */
+ if (gr->widget != NULL)
+ gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height());
+#endif
+#if USE_QML
+ if (gr->GPriv != NULL)
+ gr->GPriv->emit_update();
+
+#endif
}
static struct graphics_methods graphics_methods = {
@@ -808,7 +833,8 @@ static struct graphics_methods graphics_methods = {
};
/* create new graphics context on given context */
-static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound) {
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound) {
struct graphics_priv* graphics_priv = NULL;
graphics_priv = g_new0(struct graphics_priv, 1);
*meth = graphics_methods;
@@ -852,7 +878,8 @@ static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphi
}
/* create application and initial graphics context */
-static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl) {
+static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs,
+ struct callback_list* cbl) {
struct graphics_priv* graphics_priv = NULL;
struct attr* event_loop_system = NULL;
struct attr* platform = NULL;
diff --git a/navit/graphics/qt5/graphics_qt5.h b/navit/graphics/qt5/graphics_qt5.h
index f9d19616b..0eed89510 100644
--- a/navit/graphics/qt5/graphics_qt5.h
+++ b/navit/graphics/qt5/graphics_qt5.h
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#ifndef __graphics_qt_h
#define __graphics_qt_h
@@ -62,8 +61,7 @@ struct graphics_priv;
#if USE_QML
class GraphicsPriv : public QObject {
Q_OBJECT
-public:
- GraphicsPriv(struct graphics_priv* gp);
+public: GraphicsPriv(struct graphics_priv* gp);
~GraphicsPriv();
void emit_update();