On Thu, Sep 08, 2016 at 03:04:17PM +0200, Jean-Marc Lasgouttes wrote:

> Le 08/09/2016 à 03:31, Enrico Forestieri a écrit :
> > On Wed, Sep 07, 2016 at 03:13:38PM +0200, Jean-Marc Lasgouttes wrote:
> > 
> > > And of course, a screenshot (no you are not entitled to complain about the
> > > huge readonly icon, only to help me fix it).
> > 
> > Fixed in the attached.
> 
> Thanks a lot, but let me say: Ouch!

The following is needed for having a resonable size. Unless the text
is very tall, the nominal normal icon size will be used:

> +     QFontMetrics const fm(statusBar()->fontMetrics());
> +     int const roheight = max(int(d.normalIconSize), fm.height());
> +     QSize const rosize(roheight, roheight);

This provides a pixmap with the desired size.

> +     QPixmap readonly = QPixmap(rosize);

If we find the svgz icon, we ask the renderer to render it at the correct
size...

> +     QString imagedir = "images/";
> +     FileName fname = imageLibFileSearch(imagedir, "emblem-readonly", 
> "svgz");
> +     QSvgRenderer renderer(toqstr(fname.absFileName()));
> +     if (renderer.isValid()) {
> +             
> readonly.fill(statusBar()->palette().color(QWidget::backgroundRole()));
> +             QPainter painter(&readonly);
> +             renderer.render(&painter);
> +     } else {

... otherwise we scale a png image to the wanted size.

> +             readonly = getPixmap("images/", "emblem-readonly", 
> "png").scaled(rosize,
> Qt::KeepAspectRatio);
> +     }
> 
> How come that it is so complicated to load a mere svg icon?

It is complicated because we want the best quality, otherwise the code
in the else branch above would work equally... bad, because the image
would be rendered at an higher size and then the bitmap scaled down
(with awful results).

> However I
> still wonder why one cannot just tell to the icon: "take the size of the
> enclosing widget, don't try to grow more than that".

Yes, this is possible (see above) but with a final low quality. Doing it
for the png images is not so harmful because their size should already
be the same (or almost the same) as the wanted size, while the original
size for which the svg image was designed can be much larger.

> Your patch does not compile with Qt4, but removing the guard around #include
> <QSvgRenderer> fixes this. Was there a reason for this limitation?

Not my doing.

-- 
Enrico

Reply via email to