Skip to content

Commit

Permalink
fix:graphics/qt5: Allow to draw transparent polygons (#878)
Browse files Browse the repository at this point in the history
There is a "misconception" in qt5 graphics about how to draw transparent stuff causing transparent items on the map to not correctly work. This PR changes qt5 graphics to force-clear overlays on starting to draw them instead of force clearing the shape of a transparent item. While this imposes the limitation that the content of an overlay cannot be drawn in multiple runs, it allows to draw transparent stuff on the map.
Luckily I don't know of any overlay item yet that is not drawn in one run. So this seems to work OK.
  • Loading branch information
metalstrolch authored Sep 20, 2019
1 parent a9a1375 commit deccb6c
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions navit/graphics/qt5/graphics_qt5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,7 @@ static void draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc,
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);
}

Expand Down Expand Up @@ -446,27 +440,13 @@ static void draw_polygon_with_holes (struct graphics_priv *gr, struct graphics_g
if(hole_count > 0)
path = path.subtracted(inner);

/* 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->drawPath(path);
gr->painter->setCompositionMode(mode);
}
gr->painter->drawPath(path);
}

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 */
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);
}

Expand Down Expand Up @@ -647,9 +627,11 @@ static void draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) {
case draw_mode_begin:
dbg(lvl_debug, "Begin drawing on context %p (use == %d)", gr, gr->use_count);
gr->use_count++;
if (gr->painter == NULL)
if (gr->painter == NULL) {
if(gr->parent != NULL)
gr->pixmap->fill(QColor(0,0,0,0));
gr->painter = new QPainter(gr->pixmap);
else
} else
dbg(lvl_debug, "drawing on %p already active", gr);
break;
case draw_mode_end:
Expand Down

0 comments on commit deccb6c

Please sign in to comment.