From b222cff4cb5fa878860a9172aac8c22861b4fadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Mon, 31 Jul 2023 20:22:16 +0200 Subject: [PATCH] Default icon for extension. --- src/extension.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/extension.cpp b/src/extension.cpp index ffdb0260..f610fc60 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -80,7 +80,28 @@ ExtensionMetaData::ExtensionMetaData(std::filesystem::path const& path, m_TranslationContext = jsonData["translationContext"].toString(""); if (jsonData.contains("icon")) { - m_Icon = QIcon(QDir(path).filePath(jsonData["icon"].toString())); + const QFileInfo icon{QDir(path), jsonData["icon"].toString()}; + if (icon.exists()) { + m_Icon = QIcon(icon.absoluteFilePath()); + } + } + + // TODO: move code in a better place or use a custom icon + if (m_Icon.isNull()) { + const QImage baseIcon(":/MO/gui/app_icon"); + QImage grayIcon = baseIcon.convertToFormat(QImage::Format_ARGB32); + { + for (int y = 0; y < grayIcon.height(); ++y) { + QRgb* scanLine = (QRgb*)grayIcon.scanLine(y); + for (int x = 0; x < grayIcon.width(); ++x) { + QRgb pixel = *scanLine; + uint ci = uint(qGray(pixel)); + *scanLine = qRgba(ci, ci, ci, qAlpha(pixel) / 3); + ++scanLine; + } + } + } + m_Icon = QIcon(QPixmap::fromImage(grayIcon)); } if (jsonData.contains("contributors")) {