summaryrefslogtreecommitdiff
path: root/navit/graphics/qt5/graphics_qt5.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'navit/graphics/qt5/graphics_qt5.cpp')
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp307
1 files changed, 141 insertions, 166 deletions
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index f7ac15f43..e7b31c605 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -16,7 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-// style with: clang-format -style=WebKit -i *
#include <glib.h>
#ifdef HAVE_UNISTD_H
@@ -64,17 +63,14 @@ extern "C" {
#endif
#if USE_QML
-GraphicsPriv::GraphicsPriv(struct graphics_priv* gp)
-{
+GraphicsPriv::GraphicsPriv(struct graphics_priv* gp) {
this->gp = gp;
}
-GraphicsPriv::~GraphicsPriv()
-{
+GraphicsPriv::~GraphicsPriv() {
}
-void GraphicsPriv::emit_update()
-{
+void GraphicsPriv::emit_update() {
emit update();
}
#endif
@@ -89,10 +85,8 @@ struct graphics_image_priv {
QPixmap* pixmap;
};
-static void
-graphics_destroy(struct graphics_priv* gr)
-{
-// dbg(lvl_debug,"enter\n");
+static void graphics_destroy(struct graphics_priv* gr) {
+// dbg(lvl_debug,"enter");
#if HAVE_FREETYPE
gr->freetype_methods.destroy();
#endif
@@ -144,9 +138,8 @@ graphics_destroy(struct graphics_priv* gr)
g_free(gr);
}
-static void font_destroy(struct graphics_font_priv* font)
-{
- // dbg(lvl_debug,"enter\n");
+static void font_destroy(struct graphics_font_priv* font) {
+ // dbg(lvl_debug,"enter");
if (font->font != NULL)
delete (font->font);
g_free(font);
@@ -186,11 +179,11 @@ static const char* fontfamilies[] = {
*
* Allocates a font handle and returnes filled interface stucture
*/
-static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, int size, int flags)
-{
+static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font,
+ int size, int flags) {
int a = 0;
struct graphics_font_priv* font_priv;
- dbg(lvl_debug, "enter (font %s, %d, 0x%x)\n", font, size, flags);
+ dbg(lvl_debug, "enter (font %s, %d, 0x%x)", font, size, flags);
font_priv = g_new0(struct graphics_font_priv, 1);
font_priv->font = new QFont(fontfamilies[0]);
if (font != NULL)
@@ -201,7 +194,7 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
a++;
}
if (font_priv->font->exactMatch()) {
- dbg(lvl_debug, "Exactly matching font: %s\n", font_priv->font->family().toUtf8().data());
+ dbg(lvl_debug, "Exactly matching font: %s", font_priv->font->family().toUtf8().data());
} else {
/* set any font*/
if (font != NULL) {
@@ -209,7 +202,7 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
} else {
font_priv->font->setFamily(fontfamilies[0]);
}
- dbg(lvl_debug, "No matching font. Resort to: %s\n", font_priv->font->family().toUtf8().data());
+ dbg(lvl_debug, "No matching font. Resort to: %s", font_priv->font->family().toUtf8().data());
}
/* No clue why factor 20. Found this by comparing to Freetype rendering. */
@@ -224,25 +217,19 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
return font_priv;
}
-static void
-gc_destroy(struct graphics_gc_priv* gc)
-{
- // dbg(lvl_debug,"enter gc=%p\n", gc);
+static void gc_destroy(struct graphics_gc_priv* gc) {
+ // dbg(lvl_debug,"enter gc=%p", gc);
delete (gc->pen);
delete (gc->brush);
g_free(gc);
}
-static void
-gc_set_linewidth(struct graphics_gc_priv* gc, int w)
-{
- // dbg(lvl_debug,"enter gc=%p, %d\n", gc, w);
+static void gc_set_linewidth(struct graphics_gc_priv* gc, int w) {
+ // dbg(lvl_debug,"enter gc=%p, %d", gc, w);
gc->pen->setWidth(w);
}
-static void
-gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n)
-{
+static void gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n) {
if (n <= 0) {
dbg(lvl_error, "Refuse to set dashes without dash pattern");
}
@@ -262,21 +249,17 @@ gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* das
gc->pen->setDashPattern(dashes);
}
-static void
-gc_set_foreground(struct graphics_gc_priv* gc, struct color* c)
-{
+static void gc_set_foreground(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
- // dbg(lvl_debug,"context %p: color %02x%02x%02x\n",gc, c->r >> 8, c->g >> 8, c->b >> 8);
+ // dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
gc->pen->setColor(col);
gc->brush->setColor(col);
//gc->c=*c;
}
-static void
-gc_set_background(struct graphics_gc_priv* gc, struct color* c)
-{
+static void gc_set_background(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
- // dbg(lvl_debug,"context %p: color %02x%02x%02x\n",gc, c->r >> 8, c->g >> 8, c->b >> 8);
+ // dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
//gc->pen->setColor(col);
//gc->brush->setColor(col);
}
@@ -289,10 +272,9 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth)
-{
+static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth) {
struct graphics_gc_priv* graphics_gc_priv = NULL;
- // dbg(lvl_debug,"enter gr==%p\n", gr);
+ // dbg(lvl_debug,"enter gr==%p", gr);
graphics_gc_priv = g_new0(struct graphics_gc_priv, 1);
graphics_gc_priv->graphics_priv = gr;
graphics_gc_priv->pen = new QPen();
@@ -302,9 +284,8 @@ static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics
return graphics_gc_priv;
}
-static void image_destroy(struct graphics_image_priv* img)
-{
- // dbg(lvl_debug, "enter\n");
+static void image_destroy(struct graphics_image_priv* img) {
+ // dbg(lvl_debug, "enter");
if (img->pixmap != NULL)
delete (img->pixmap);
g_free(img);
@@ -314,18 +295,21 @@ struct graphics_image_methods image_methods = {
image_destroy
};
-static struct graphics_image_priv*
-image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot, int rotation)
-{
+static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path,
+ int* w, int* h, struct point* hot, int rotation) {
struct graphics_image_priv* image_priv;
- // dbg(lvl_debug,"enter %s, %d %d\n", path, *w, *h);
+ // dbg(lvl_debug,"enter %s, %d %d", path, *w, *h);
if (path[0] == 0) {
- dbg(lvl_debug, "Refuse to load image without path\n");
+ dbg(lvl_debug, "Refuse to load image without path");
return NULL;
}
QString key(path);
QString renderer_key(key);
- QString extension = key.right(key.lastIndexOf("."));
+ int index = key.lastIndexOf(".");
+ QString extension;
+ if(index > 0) {
+ extension = key.right(index);
+ }
QFile imagefile(key);
if (!imagefile.exists()) {
/* file doesn't exit. Either navit wants us to guess file name by
@@ -333,11 +317,11 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
*/
if (extension != "") {
/*file doesn't exist. give up */
- dbg(lvl_debug, "File %s does not exist\n", path);
+ dbg(lvl_debug, "File %s does not exist", path);
return NULL;
} else {
/* add ".svg" for renderer to try .svg file first in renderer */
- dbg(lvl_debug, "Guess extension on %s\n", path);
+ dbg(lvl_debug, "Guess extension on %s", path);
renderer_key += ".svg";
}
}
@@ -348,7 +332,7 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
if (renderer_key.endsWith("svg")) {
QSvgRenderer renderer(renderer_key);
if (renderer.isValid()) {
- dbg(lvl_debug, "render %s\n", path);
+ dbg(lvl_debug, "render %s", path);
/* try to render this */
/* assume "standard" size if size is not given */
if (*w <= 0)
@@ -364,19 +348,20 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
if (image_priv->pixmap == NULL) {
/*cannot be rendered. try to load it */
- dbg(lvl_debug, "cannot render %s\n", path);
+ dbg(lvl_debug, "cannot render %s", path);
image_priv->pixmap = new QPixmap(key);
}
/* check if we got image */
- if (image_priv->pixmap->isNull()) {
+ if ((image_priv->pixmap == NULL) || (image_priv->pixmap->isNull())) {
g_free(image_priv);
return NULL;
} else {
/* check if we need to scale this */
if ((*w > 0) && (*h > 0)) {
if ((image_priv->pixmap->width() != *w) || (image_priv->pixmap->height() != *h)) {
- dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d\n", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(), *h);
+ dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(),
+ *h);
QPixmap* scaled = new QPixmap(image_priv->pixmap->scaled(*w, *h, Qt::IgnoreAspectRatio, Qt::FastTransformation));
delete (image_priv->pixmap);
image_priv->pixmap = scaled;
@@ -386,7 +371,7 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
*w = image_priv->pixmap->width();
*h = image_priv->pixmap->height();
- // dbg(lvl_debug, "Got (%d,%d)\n", *w,*h);
+ // dbg(lvl_debug, "Got (%d,%d)", *w,*h);
if (hot) {
hot->x = *w / 2;
hot->y = *h / 2;
@@ -395,12 +380,10 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
return image_priv;
}
-static void
-draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+static void draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
- // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)\n", gr, gc, p->x, p->y);
+ // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
if (gr->painter == NULL)
return;
@@ -410,12 +393,10 @@ draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
gr->painter->drawPolyline(polygon);
}
-static void
-draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+static void draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
- // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)\n", gr, gc, p->x, p->y);
+ // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
if (gr->painter == NULL)
return;
@@ -433,10 +414,8 @@ draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point
gr->painter->drawPolygon(polygon);
}
-static void
-draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h)
-{
- // dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d\n", gr, gc, p->x, p->y, w, h);
+static void draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h) {
+ // dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
if (gr->painter == NULL)
return;
/* if the rectangle is transparent, we need to clear it first */
@@ -449,10 +428,8 @@ draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct poi
gr->painter->fillRect(p->x, p->y, w, h, *gc->brush);
}
-static void
-draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r)
-{
- // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d\n", gr, gc, p->x, p->y, r);
+static void draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r) {
+ // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d", gr, gc, p->x, p->y, r);
if (gr->painter == NULL)
return;
gr->painter->setPen(*gc->pen);
@@ -472,10 +449,9 @@ draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
*
* Renders given text on gr surface. Draws nice contrast outline around text.
*/
-static void
-draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy)
-{
- dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s\n", gr, fg, bg, p->x, p->y, dx, dy, text);
+static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg,
+ struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) {
+ dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s", gr, fg, bg, p->x, p->y, dx, dy, text);
QPainter* painter = gr->painter;
if (painter == NULL)
return;
@@ -565,14 +541,13 @@ draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics
#endif
}
-static void
-draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img)
-{
- // dbg(lvl_debug,"enter\n");
+static void draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p,
+ struct graphics_image_priv* img) {
+ // dbg(lvl_debug,"enter");
if (gr->painter != NULL)
gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
else
- dbg(lvl_debug, "Try to draw image, but no painter\n");
+ dbg(lvl_debug, "Try to draw image, but no painter");
}
/**
@@ -584,15 +559,14 @@ draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point*
* called for root layer. There the content of the root layer is to be moved
* by given vector. On root layer, NULL indicates the end of a drag.
*/
-static void draw_drag(struct graphics_priv* gr, struct point* p)
-{
+static void draw_drag(struct graphics_priv* gr, struct point* p) {
struct point vector;
if (p != NULL) {
- dbg(lvl_debug, "enter %p (%d,%d)\n", gr, p->x, p->y);
+ dbg(lvl_debug, "enter %p (%d,%d)", gr, p->x, p->y);
vector = *p;
} else {
- dbg(lvl_debug, "enter %p (NULL)\n", gr);
+ dbg(lvl_debug, "enter %p (NULL)", gr);
vector.x = 0;
vector.y = 0;
}
@@ -621,38 +595,34 @@ static void draw_drag(struct graphics_priv* gr, struct point* p)
}
}
-static void
-background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc)
-{
- // dbg(lvl_debug,"register context %p on %p\n", gc, gr);
+static void background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc) {
+ // dbg(lvl_debug,"register context %p on %p", gc, gr);
gr->background_graphics_gc_priv = gc;
}
-static void
-draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
-{
+static void draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) {
switch (mode) {
case draw_mode_begin:
- dbg(lvl_debug, "Begin drawing on context %p (use == %d)\n", gr, gr->use_count);
+ dbg(lvl_debug, "Begin drawing on context %p (use == %d)", gr, gr->use_count);
gr->use_count++;
if (gr->painter == NULL)
gr->painter = new QPainter(gr->pixmap);
else
- dbg(lvl_debug, "drawing on %p already active\n", gr);
+ dbg(lvl_debug, "drawing on %p already active", gr);
break;
case draw_mode_end:
- dbg(lvl_debug, "End drawing on context %p (use == %d)\n", gr, gr->use_count);
+ dbg(lvl_debug, "End drawing on context %p (use == %d)", gr, gr->use_count);
gr->use_count--;
if (gr->use_count < 0)
gr->use_count = 0;
if (gr->use_count > 0) {
- dbg(lvl_debug, "drawing on %p still in use\n", gr);
+ dbg(lvl_debug, "drawing on %p still in use", gr);
} else if (gr->painter != NULL) {
gr->painter->end();
delete (gr->painter);
gr->painter = NULL;
} else {
- dbg(lvl_debug, "Context %p not active!\n", gr)
+ dbg(lvl_debug, "Context %p not active!", gr)
}
#if USE_QWIDGET
/* call repaint on widget */
@@ -667,25 +637,22 @@ draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
break;
default:
- dbg(lvl_debug, "Unknown drawing %d on context %p\n", mode, gr);
+ dbg(lvl_debug, "Unknown drawing %d on context %p", mode, gr);
break;
}
}
-static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound);
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound);
-void resize_callback(struct graphics_priv* gr, int w, int h)
-{
- // dbg(lvl_debug,"enter (%d, %d)\n", w, h);
- callback_list_call_attr_2(gr->callbacks, attr_resize,
- GINT_TO_POINTER(w), GINT_TO_POINTER(h));
+void resize_callback(struct graphics_priv* gr, int w, int h) {
+ // dbg(lvl_debug,"enter (%d, %d)", w, h);
+ callback_list_call_attr_2(gr->callbacks, attr_resize, GINT_TO_POINTER(w), GINT_TO_POINTER(h));
}
-static int
-graphics_qt5_fullscreen(struct window* w, int on)
-{
+static int graphics_qt5_fullscreen(struct window* w, int on) {
struct graphics_priv* gr;
- // dbg(lvl_debug,"enter\n");
+ // dbg(lvl_debug,"enter");
gr = (struct graphics_priv*)w->priv;
#if USE_QML
if (gr->window != NULL) {
@@ -707,10 +674,8 @@ graphics_qt5_fullscreen(struct window* w, int on)
}
#ifdef SAILFISH_OS
-static void
-keep_display_on(struct graphics_priv* priv)
-{
- // dbg(lvl_debug,"enter\n");
+static void keep_display_on(struct graphics_priv* priv) {
+ // dbg(lvl_debug,"enter");
QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system);
@@ -718,10 +683,8 @@ keep_display_on(struct graphics_priv* priv)
}
#endif
-static void
-graphics_qt5_disable_suspend(struct window* w)
-{
-// dbg(lvl_debug,"enter\n");
+static void graphics_qt5_disable_suspend(struct window* w) {
+// dbg(lvl_debug,"enter");
#ifdef SAILFISH_OS
struct graphics_priv* gr;
gr = (struct graphics_priv*)w->priv;
@@ -733,13 +696,11 @@ graphics_qt5_disable_suspend(struct window* w)
#endif
}
-static void*
-get_data(struct graphics_priv* this_priv, char const* type)
-{
- // dbg(lvl_debug,"enter: %s\n", type);
+static void* get_data(struct graphics_priv* this_priv, char const* type) {
+ // dbg(lvl_debug,"enter: %s", type);
if (strcmp(type, "window") == 0) {
struct window* win;
- // dbg(lvl_debug,"window detected\n");
+ // dbg(lvl_debug,"window detected");
win = g_new0(struct window, 1);
win->priv = this_priv;
win->fullscreen = graphics_qt5_fullscreen;
@@ -748,15 +709,14 @@ get_data(struct graphics_priv* this_priv, char const* type)
return win;
}
if (strcmp(type, "engine") == 0) {
- dbg(lvl_debug, "Hand over QQmlApplicationEngine\n");
+ dbg(lvl_debug, "Hand over QQmlApplicationEngine");
return (this_priv->engine);
}
return NULL;
}
-static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv)
-{
- // dbg(lvl_debug,"enter\n");
+static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv) {
+ // dbg(lvl_debug,"enter");
delete (priv->pixmap);
g_free(priv);
}
@@ -773,13 +733,13 @@ static void image_free(struct graphics_priv* gr, struct graphics_image_priv* pri
*
* Calculates the bounding box around the given text.
*/
-static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, struct point* ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy,
+ struct point* ret, int estimate) {
int i;
struct point pt;
QString tmp = QString::fromUtf8(text);
QRect r;
- // dbg(lvl_debug,"enter %s %d %d\n", text, dx, dy);
+ // dbg(lvl_debug,"enter %s %d %d", text, dx, dy);
/* use QFontMetrix for bbox calculation as we do not always have a painter */
QFontMetrics fm(*font->font);
@@ -807,32 +767,46 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f
}
}
-static void overlay_disable(struct graphics_priv* gr, int disable)
-{
- GHashTableIter iter;
- struct graphics_priv *key, *value;
- // dbg(lvl_debug,"enter gr=%p, %d\n", gr, disable);
+static void overlay_disable(struct graphics_priv* gr, int disable) {
+ //dbg(lvl_error,"enter gr=%p, %d", gr, disable);
+ gr->disable = disable;
+#if USE_QWIDGET
+ /* call repaint on widget */
+ if (gr->widget != NULL)
+ gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height());
+#endif
+#if USE_QML
+ if (gr->GPriv != NULL)
+ gr->GPriv->emit_update();
- g_hash_table_iter_init(&iter, gr->overlays);
- while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) {
- /* disable or enable all overlays of this pane */
- value->disable = disable;
- }
+#endif
}
-static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound)
-{
- // dbg(lvl_debug,"enter\n");
+static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) {
+ // dbg(lvl_debug,"enter %d %d %d %d %d", p->x, p->y, w, h, wraparound);
gr->x = p->x;
gr->y = p->y;
if (gr->painter != NULL) {
delete (gr->painter);
}
- delete (gr->pixmap);
- gr->pixmap = new QPixmap(w, h);
- gr->pixmap->fill(Qt::transparent);
+ /* replacing the pixmap clears the content. Only neccesary if size actually changes */
+ if((gr->pixmap->height() != h) || (gr->pixmap->width() != w)) {
+ delete (gr->pixmap);
+ gr->pixmap = new QPixmap(w, h);
+ gr->pixmap->fill(Qt::transparent);
+ }
if (gr->painter != NULL)
gr->painter = new QPainter(gr->pixmap);
+#if USE_QWIDGET
+ /* call repaint on widget */
+ if (gr->widget != NULL)
+ gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height());
+#endif
+#if USE_QML
+ if (gr->GPriv != NULL)
+ gr->GPriv->emit_update();
+
+#endif
}
static struct graphics_methods graphics_methods = {
@@ -859,9 +833,8 @@ static struct graphics_methods graphics_methods = {
};
/* create new graphics context on given context */
-static struct graphics_priv*
-overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound)
-{
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound) {
struct graphics_priv* graphics_priv = NULL;
graphics_priv = g_new0(struct graphics_priv, 1);
*meth = graphics_methods;
@@ -869,8 +842,10 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
if (gr->font_freetype_new) {
graphics_priv->font_freetype_new = gr->font_freetype_new;
gr->font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
}
#endif
#if USE_QML
@@ -897,15 +872,14 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
graphics_priv->argv[0] = NULL;
/* register on parent */
g_hash_table_insert(gr->overlays, graphics_priv, graphics_priv);
- // dbg(lvl_debug,"New overlay: %p\n", graphics_priv);
+ // dbg(lvl_debug,"New overlay: %p", graphics_priv);
return graphics_priv;
}
/* create application and initial graphics context */
-static struct graphics_priv*
-graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl)
-{
+static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs,
+ struct callback_list* cbl) {
struct graphics_priv* graphics_priv = NULL;
struct attr* event_loop_system = NULL;
struct attr* platform = NULL;
@@ -914,7 +888,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
bool use_qml = USE_QML;
bool use_qwidget = USE_QWIDGET;
- //dbg(lvl_debug,"enter\n");
+ //dbg(lvl_debug,"enter");
/* get qt widget attr */
if ((attr_widget = attr_search(attrs, NULL, attr_qt5_widget))) {
@@ -938,7 +912,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* get event loop from config and request event loop*/
event_loop_system = attr_search(attrs, NULL, attr_event_loop_system);
if (event_loop_system && event_loop_system->u.str) {
- //dbg(lvl_debug, "event_system is %s\n", event_loop_system->u.str);
+ //dbg(lvl_debug, "event_system is %s", event_loop_system->u.str);
if (!event_request_system(event_loop_system->u.str, "graphics_qt5"))
return NULL;
} else {
@@ -952,7 +926,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* get font plugin if present */
font_freetype_new = (struct font_priv * (*)(void*))plugin_get_category_font("freetype");
if (!font_freetype_new) {
- dbg(lvl_error, "no freetype\n");
+ dbg(lvl_error, "no freetype");
return NULL;
}
#endif
@@ -971,7 +945,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
graphics_priv->argv[graphics_priv->argc] = g_strdup(platform->u.str);
graphics_priv->argc++;
}
-/* create surrounding application */
+ /* create surrounding application */
#if USE_QWIDGET
QApplication* internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv);
navit_app = internal_app;
@@ -982,8 +956,10 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
#if HAVE_FREETYPE
graphics_priv->font_freetype_new = font_freetype_new;
font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
#endif
graphics_priv->callbacks = cbl;
graphics_priv->pixmap = NULL;
@@ -1004,7 +980,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* register our QtQuick widget to allow it's usage within QML */
qmlRegisterType<QNavitQuick>("com.navit.graphics_qt5", 1, 0, "QNavitQuick");
/* get our qml application from embedded resources. May be replaced by the
- * QtQuick gui component if enabled */
+ * QtQuick gui component if enabled */
graphics_priv->engine = new QQmlApplicationEngine();
if (graphics_priv->engine != NULL) {
graphics_priv->GPriv = new GraphicsPriv(graphics_priv);
@@ -1024,7 +1000,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
}
#endif
if ((fullscreen = attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) {
-/* show this maximized */
+ /* show this maximized */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->setWindowState(Qt::WindowFullScreen);
@@ -1083,7 +1059,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* tell Navit our geometry */
resize_callback(graphics_priv, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
-/* show our window */
+ /* show our window */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->show();
@@ -1096,12 +1072,11 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
return graphics_priv;
}
-void plugin_init(void)
-{
+void plugin_init(void) {
#if USE_QML
Q_INIT_RESOURCE(graphics_qt5);
#endif
- // dbg(lvl_debug,"enter\n");
+ // dbg(lvl_debug,"enter");
plugin_register_category_graphics("qt5", graphics_qt5_new);
qt5_event_init();
}