Skip to content

Commit

Permalink
Default icon for extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Nov 10, 2023
1 parent d4669ec commit 356f605
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down

0 comments on commit 356f605

Please sign in to comment.