From 7ee5b108103cf586cbb191cb4936f1b05ea80ef8 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Mon, 29 May 2023 00:21:52 +1200 Subject: [PATCH] Desktop: Remove 'renderSVGIcon' methods. Remove `renderSVGIcon()` and `renderSVGIconWidth()`, as QPixmaps can be loaded directly from SVG, and support scaling. Signed-off-by: Michael Keller --- core/imagedownloader.cpp | 17 ++++++++++++----- core/qthelper.cpp | 25 ------------------------- core/qthelper.h | 2 -- icons/ruler.png | Bin 715 -> 0 bytes profile-widget/divepixmapcache.cpp | 3 +-- stats/chartlistmodel.cpp | 5 ++--- 6 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 icons/ruler.png diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp index 59f1da8b7..6c2837b20 100644 --- a/core/imagedownloader.cpp +++ b/core/imagedownloader.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -153,12 +154,18 @@ Thumbnailer::Thumbnail Thumbnailer::getHashedImage(const QString &filename, bool return thumbnail; } -Thumbnailer::Thumbnailer() : failImage(renderSVGIcon(":filter-close", maxThumbnailSize(), false)), // TODO: Don't misuse filter close icon - dummyImage(renderSVGIcon(":camera-icon", maxThumbnailSize(), false)), - videoImage(renderSVGIcon(":video-icon", maxThumbnailSize(), false)), - videoOverlayImage(renderSVGIconWidth(":video-overlay", maxThumbnailSize())), - unknownImage(renderSVGIcon(":unknown-icon", maxThumbnailSize(), false)) +Thumbnailer::Thumbnailer() : failImage(QPixmap(":filter-close").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()), // TODO: Don't misuse filter close icon + dummyImage(QPixmap(":camera-icon").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()), + videoImage(QPixmap(":video-icon").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()), + unknownImage(QPixmap(":unknown-icon").scaled(maxThumbnailSize(), maxThumbnailSize(), Qt::KeepAspectRatio).toImage()) { + // 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 // calculating multiple thumbnails at once and this hopefully helps. pool.setMaxThreadCount(1); diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 09020aaf0..afcf60bd5 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -36,8 +36,6 @@ #include #include #include -#include -#include #include #include #ifdef Q_OS_UNIX @@ -1687,26 +1685,3 @@ extern "C" void emit_reset_signal() { 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; -} diff --git a/core/qthelper.h b/core/qthelper.h index af73cc813..66df91b20 100644 --- a/core/qthelper.h +++ b/core/qthelper.h @@ -96,8 +96,6 @@ QString getUserAgent(); QString printGPSCoords(const location_t *loc); std::vector get_cylinder_map_for_remove(int count, int n); std::vector 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)(); void uiNotification(const QString &msg); diff --git a/icons/ruler.png b/icons/ruler.png deleted file mode 100644 index 849909c642150d7e44249fd8f09967e085f7084d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 715 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM3?#3wJbMaAv7|ftIx;Y9?C1WI$O_~uBzpw; zGB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpu~p&pAgso|NjG-LklP| zFbKk240Qb!1_mGrL_pu31dIQMi2!+#3=Dt3Tp1ww|G&(c6H|erUL`?(!3+lVfYnE5J`)3@N{pV<_SoWNWvHH^F-YdG+ zdc_wnJeguqq4qmR;@zVKZ`rh0&o$-%n#!2u?e4vL>2?Zd_b5nvu&>> zP;jrOi(`n!`Mnd}g_;5cT#k1{8a!{Xe9prraP;E)zx|JwFVJC~HZA|+Roi?^hW`g1 zmPnp`YuI)DAL$e>x;zuN^FM(4_Mf3?0D&O`sX2?X*(|Y@vQSrYQ8;}E$^Pwj&76h z?9H~ak75}t>`r8+KXQ?CpTME$|L2jXztD;FMKL}aPqdg @@ -31,7 +30,7 @@ DivePixmaps::DivePixmaps(int dpr) : dpr(dpr) violation = createPixmap(":status-violation-icon", sz_pix); bailout = createPixmap(":bailout-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); gaschangeTrimix = createPixmap(":gaschange-trimix-icon", sz_bigger); gaschangeAirICD = createPixmap(":gaschange-air-ICD-icon", sz_bigger); diff --git a/stats/chartlistmodel.cpp b/stats/chartlistmodel.cpp index 7f7afe4d0..1cf35e6e0 100644 --- a/stats/chartlistmodel.cpp +++ b/stats/chartlistmodel.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "chartlistmodel.h" #include "core/metrics.h" -#include "core/qthelper.h" #include #include #include @@ -14,7 +13,7 @@ ChartListModel::ChartListModel() : int fontHeight = fm.height(); 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::VerticalGrouped, ":chart-bar-grouped-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) { - QPixmap icon = QPixmap::fromImage(renderSVGIcon(name, iconSize, true)); + QPixmap icon = QPixmap(name).scaled(iconSize, iconSize, Qt::KeepAspectRatio); QPixmap iconWarning = icon.copy(); QPainter painter(&iconWarning); painter.drawPixmap(0, 0, warningPixmap);