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 Aug 9, 2024
1 parent b3a8752 commit 1cca216
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/settingsdialogextensionrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,46 @@

using namespace MOBase;

namespace
{

const auto& defaultIcon()
{
static QIcon icon;

if (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;
}
}
}
icon = QIcon(QPixmap::fromImage(grayIcon));
}

return icon;
}

} // namespace

ExtensionListItemWidget::ExtensionListItemWidget(const IExtension& extension)
: ui{new Ui::ExtensionListItemWidget()}, m_extension{&extension}
{
ui->setupUi(this);

const auto& metadata = extension.metadata();

const auto& icon = metadata.icon().isNull() ? defaultIcon() : metadata.icon();

QIcon icon = style()->standardIcon(QStyle::SP_DialogOkButton);
ui->extensionIcon->setPixmap(extension.metadata().icon().pixmap(QSize(48, 48)));
ui->extensionIcon->setPixmap(icon.pixmap(QSize(48, 48)));
ui->extensionName->setText(extension.metadata().name());

ui->extensionDescription->setText(extension.metadata().description());
Expand Down

0 comments on commit 1cca216

Please sign in to comment.