mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: move renderSVGIcon() to qthelper.cpp
The renderIcon() function was used by the thumbnailer to render SVG-based icons. Move it to the global qthelper.cpp so that it can also be used by the statistics module. Add "SVG" to the name to emphasize what it is used for. For consistency also move the renderSVGIconWidth() function, which renders to a fixed width, to qthelper.cpp Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4ca40bc152
commit
1d93926700
3 changed files with 33 additions and 28 deletions
|
@ -11,7 +11,6 @@
|
|||
#include <QString>
|
||||
#include <QImageReader>
|
||||
#include <QDataStream>
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
|
||||
#include <QtConcurrent>
|
||||
|
@ -154,33 +153,11 @@ Thumbnailer::Thumbnail Thumbnailer::getHashedImage(const QString &filename, bool
|
|||
return thumbnail;
|
||||
}
|
||||
|
||||
static QImage renderIcon(const char *id, int size)
|
||||
{
|
||||
QImage res(size, size, QImage::Format_RGB32);
|
||||
res.fill(Qt::white);
|
||||
QSvgRenderer svg{QString(id)};
|
||||
QPainter painter(&res);
|
||||
svg.render(&painter);
|
||||
return res;
|
||||
}
|
||||
|
||||
// As renderIcon, but render to a fixed width and scale height accordingly
|
||||
// and have a transparent background.
|
||||
static QImage renderIconWidth(const char *id, int size)
|
||||
{
|
||||
QSvgRenderer svg{QString(id)};
|
||||
QSize svgSize = svg.defaultSize();
|
||||
QImage res(size, size * svgSize.height() / svgSize.width(), QImage::Format_ARGB32);
|
||||
QPainter painter(&res);
|
||||
svg.render(&painter);
|
||||
return res;
|
||||
}
|
||||
|
||||
Thumbnailer::Thumbnailer() : failImage(renderIcon(":filter-close", maxThumbnailSize())), // TODO: Don't misuse filter close icon
|
||||
dummyImage(renderIcon(":camera-icon", maxThumbnailSize())),
|
||||
videoImage(renderIcon(":video-icon", maxThumbnailSize())),
|
||||
videoOverlayImage(renderIconWidth(":video-overlay", maxThumbnailSize())),
|
||||
unknownImage(renderIcon(":unknown-icon", maxThumbnailSize()))
|
||||
Thumbnailer::Thumbnailer() : failImage(renderSVGIcon(":filter-close", maxThumbnailSize())), // TODO: Don't misuse filter close icon
|
||||
dummyImage(renderSVGIcon(":camera-icon", maxThumbnailSize())),
|
||||
videoImage(renderSVGIcon(":video-icon", maxThumbnailSize())),
|
||||
videoOverlayImage(renderSVGIconWidth(":video-overlay", maxThumbnailSize())),
|
||||
unknownImage(renderSVGIcon(":unknown-icon", maxThumbnailSize()))
|
||||
{
|
||||
// Currently, we only process one image at a time. Stefan Fuchs reported problems when
|
||||
// calculating multiple thumbnails at once and this hopefully helps.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue