Desktop: Remove 'renderSVGIcon' methods.

Remove `renderSVGIcon()` and `renderSVGIconWidth()`, as QPixmaps can be
loaded directly from SVG, and support scaling.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2023-05-29 00:21:52 +12:00 committed by Dirk Hohndel
parent 2ef6cd89cc
commit 7ee5b10810
6 changed files with 15 additions and 37 deletions

View file

@ -10,6 +10,7 @@
#include <unistd.h> #include <unistd.h>
#include <QString> #include <QString>
#include <QImageReader> #include <QImageReader>
#include <QSvgRenderer>
#include <QDataStream> #include <QDataStream>
#include <QPainter> #include <QPainter>
@ -153,12 +154,18 @@ Thumbnailer::Thumbnail Thumbnailer::getHashedImage(const QString &filename, bool
return thumbnail; return thumbnail;
} }
Thumbnailer::Thumbnailer() : failImage(renderSVGIcon(":filter-close", maxThumbnailSize(), false)), // TODO: Don't misuse filter close icon Thumbnailer::Thumbnailer() : failImage(QPixmap(":filter-close").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()), // TODO: Don't misuse filter close icon
dummyImage(renderSVGIcon(":camera-icon", maxThumbnailSize(), false)), dummyImage(QPixmap(":camera-icon").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()),
videoImage(renderSVGIcon(":video-icon", maxThumbnailSize(), false)), videoImage(QPixmap(":video-icon").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()),
videoOverlayImage(renderSVGIconWidth(":video-overlay", maxThumbnailSize())), unknownImage(QPixmap(":unknown-icon").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage())
unknownImage(renderSVGIcon(":unknown-icon", maxThumbnailSize(), false))
{ {
// We have to do this little song and dance because QSvgRenderer produces artifacts when used with Qt::KeepAspectRatio
QSvgRenderer videoOverlayRenderer{QString(":video-overlay")};
QSize svgSize = videoOverlayRenderer.defaultSize();
videoOverlayImage = QImage(maxThumbnailSize(), maxThumbnailSize() * svgSize.height() / svgSize.width(), QImage::Format_ARGB32);
videoOverlayImage.fill(Qt::transparent);
QPainter painter(&videoOverlayImage);
videoOverlayRenderer.render(&painter);
// Currently, we only process one image at a time. Stefan Fuchs reported problems when // Currently, we only process one image at a time. Stefan Fuchs reported problems when
// calculating multiple thumbnails at once and this hopefully helps. // calculating multiple thumbnails at once and this hopefully helps.
pool.setMaxThreadCount(1); pool.setMaxThreadCount(1);

View file

@ -36,8 +36,6 @@
#include <QFont> #include <QFont>
#include <QApplication> #include <QApplication>
#include <QTextDocument> #include <QTextDocument>
#include <QPainter>
#include <QSvgRenderer>
#include <cstdarg> #include <cstdarg>
#include <cstdint> #include <cstdint>
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
@ -1687,26 +1685,3 @@ extern "C" void emit_reset_signal()
{ {
emit diveListNotifier.dataReset(); emit diveListNotifier.dataReset();
} }
QImage renderSVGIcon(const char *id, int size, bool transparent)
{
QImage res(size, size, transparent ? QImage::Format_ARGB32 : QImage::Format_RGB32);
res.fill(transparent ? Qt::transparent : Qt::white);
QSvgRenderer svg{QString(id)};
QPainter painter(&res);
svg.render(&painter);
return res;
}
// As renderSVGIcon(), but render to a fixed width and scale height accordingly
// and have a transparent background.
QImage renderSVGIconWidth(const char *id, int size)
{
QSvgRenderer svg{QString(id)};
QSize svgSize = svg.defaultSize();
QImage res(size, size * svgSize.height() / svgSize.width(), QImage::Format_ARGB32);
res.fill(Qt::transparent);
QPainter painter(&res);
svg.render(&painter);
return res;
}

View file

@ -96,8 +96,6 @@ QString getUserAgent();
QString printGPSCoords(const location_t *loc); QString printGPSCoords(const location_t *loc);
std::vector<int> get_cylinder_map_for_remove(int count, int n); std::vector<int> get_cylinder_map_for_remove(int count, int n);
std::vector<int> get_cylinder_map_for_add(int count, int n); std::vector<int> get_cylinder_map_for_add(int count, int n);
QImage renderSVGIcon(const char *id, int size, bool transparent);
QImage renderSVGIconWidth(const char *id, int size);
extern QString (*changesCallback)(); extern QString (*changesCallback)();
void uiNotification(const QString &msg); void uiNotification(const QString &msg);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 715 B

View file

@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "divepixmapcache.h" #include "divepixmapcache.h"
#include "core/metrics.h" #include "core/metrics.h"
#include "core/qthelper.h" // for renderSVGIconWidth
#include "core/color.h" #include "core/color.h"
#include <cmath> #include <cmath>
@ -31,7 +30,7 @@ DivePixmaps::DivePixmaps(int dpr) : dpr(dpr)
violation = createPixmap(":status-violation-icon", sz_pix); violation = createPixmap(":status-violation-icon", sz_pix);
bailout = createPixmap(":bailout-icon", sz_pix); bailout = createPixmap(":bailout-icon", sz_pix);
onCCRLoop = createPixmap(":onCCRLoop-icon", sz_pix); onCCRLoop = createPixmap(":onCCRLoop-icon", sz_pix);
bookmark = QPixmap::fromImage(renderSVGIconWidth(":dive-bookmark-icon", sz_pix)); bookmark = createPixmap(":dive-bookmark-icon", sz_pix);
gaschangeTrimixICD = createPixmap(":gaschange-trimix-ICD-icon", sz_bigger); gaschangeTrimixICD = createPixmap(":gaschange-trimix-ICD-icon", sz_bigger);
gaschangeTrimix = createPixmap(":gaschange-trimix-icon", sz_bigger); gaschangeTrimix = createPixmap(":gaschange-trimix-icon", sz_bigger);
gaschangeAirICD = createPixmap(":gaschange-air-ICD-icon", sz_bigger); gaschangeAirICD = createPixmap(":gaschange-air-ICD-icon", sz_bigger);

View file

@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "chartlistmodel.h" #include "chartlistmodel.h"
#include "core/metrics.h" #include "core/metrics.h"
#include "core/qthelper.h"
#include <QIcon> #include <QIcon>
#include <QFontMetrics> #include <QFontMetrics>
#include <QPainter> #include <QPainter>
@ -14,7 +13,7 @@ ChartListModel::ChartListModel() :
int fontHeight = fm.height(); int fontHeight = fm.height();
int iconSize = fontHeight * 2; int iconSize = fontHeight * 2;
warningPixmap = QPixmap::fromImage(renderSVGIcon(":chart-warning-icon", fontHeight, true)); warningPixmap = QPixmap(":chart-warning-icon").scaled(fontHeight, fontHeight, Qt::KeepAspectRatio);
initIcon(ChartSubType::Vertical, ":chart-bar-vertical-icon", iconSize); initIcon(ChartSubType::Vertical, ":chart-bar-vertical-icon", iconSize);
initIcon(ChartSubType::VerticalGrouped, ":chart-bar-grouped-vertical-icon", iconSize); initIcon(ChartSubType::VerticalGrouped, ":chart-bar-grouped-vertical-icon", iconSize);
initIcon(ChartSubType::VerticalStacked, ":chart-bar-stacked-vertical-icon", iconSize); initIcon(ChartSubType::VerticalStacked, ":chart-bar-stacked-vertical-icon", iconSize);
@ -32,7 +31,7 @@ ChartListModel::~ChartListModel()
void ChartListModel::initIcon(ChartSubType type, const char *name, int iconSize) void ChartListModel::initIcon(ChartSubType type, const char *name, int iconSize)
{ {
QPixmap icon = QPixmap::fromImage(renderSVGIcon(name, iconSize, true)); QPixmap icon = QPixmap(name).scaled(iconSize, iconSize, Qt::KeepAspectRatio);
QPixmap iconWarning = icon.copy(); QPixmap iconWarning = icon.copy();
QPainter painter(&iconWarning); QPainter painter(&iconWarning);
painter.drawPixmap(0, 0, warningPixmap); painter.drawPixmap(0, 0, warningPixmap);