summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wildemann <metalstrolch@metalstrolche.de>2015-12-11 10:42:54 +0100
committerStefan Wildemann <gta04@metalstrolche.de>2017-02-04 20:03:52 +0100
commit4f0f856d89aebe0b5f2bd20c8ba638f7499e4f7e (patch)
tree408e77d7319f97002e22a91b9a6a40032aa44f31
parent7d08c6dfae0171c6f9a6b8ba8edf2f340a9c3865 (diff)
downloadnavit-4f0f856d89aebe0b5f2bd20c8ba638f7499e4f7e.tar.gz
Qt5 image loading more robust on navit image guessing
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp97
1 files changed, 70 insertions, 27 deletions
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index 73095d759..a2e9ca127 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -220,37 +220,80 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *p
{
struct graphics_image_priv * image_priv;
// dbg(lvl_debug,"enter %s, %d %d\n", path, *w, *h);
- if(*w == -1) *w = 16;
- if(*h == -1) *h = 16;
-// QPixmap *cachedPixmap;
+ 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;
-// cachedPixmap=QPixmapCache::find(key);
-// if (!cachedPixmap) {
- if(1/*key.endsWith(".svg", Qt::CaseInsensitive)*/) {
- QSvgRenderer renderer(key);
- if (!renderer.isValid()) {
- g_free(image_priv);
- return NULL;
- }
- image_priv->pixmap=new QPixmap(/*renderer.defaultSize()*/*w, *h);
- image_priv->pixmap->fill(Qt::transparent);
- QPainter painter(image_priv->pixmap);
- renderer.render(&painter);
-
- } else {
- image_priv->pixmap=new QPixmap(path);
- }
- if (image_priv->pixmap->isNull()) {
- g_free(image_priv);
- return NULL;
+
+ /* 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 16 pixel if size is not given */
+ if(*w <= 0) *w = 16;
+ if(*h <= 0) *h = 16;
+ 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;
}
-
-// QPixmapCache::insert(key,QPixmap(*image_priv->pixmap));
-// } else {
-// image_priv->pixmap=new QPixmap(*cachedPixmap);
-// }
+ }
+ }
*w=image_priv->pixmap->width();
*h=image_priv->pixmap->height();