Move the svg rendering part in a lambda

This simplifies the loop body a bit, opening the door to what's next.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
Kevin Ottens 2020-07-23 19:06:09 +02:00 committed by Kevin Ottens (Rebase PR Action)
parent 73c3aa7898
commit 72eba2b93d

View file

@ -146,15 +146,18 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray) const
const auto svgName = QString::fromLatin1(":/client/theme/%1/%2.svg").arg(flavor).arg(name); const auto svgName = QString::fromLatin1(":/client/theme/%1/%2.svg").arg(flavor).arg(name);
QSvgRenderer renderer(svgName); QSvgRenderer renderer(svgName);
const auto createPixmapFromSvg = [&renderer] (int size) {
const auto sizes = isBranded() ? QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 }
: QVector<int>{ 16, 32, 64, 128, 256 };
for (int size : sizes) {
QImage img(size, size, QImage::Format_ARGB32); QImage img(size, size, QImage::Format_ARGB32);
img.fill(Qt::GlobalColor::transparent); img.fill(Qt::GlobalColor::transparent);
QPainter imgPainter(&img); QPainter imgPainter(&img);
renderer.render(&imgPainter); renderer.render(&imgPainter);
auto px = QPixmap::fromImage(img); return QPixmap::fromImage(img);
};
const auto sizes = isBranded() ? QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 }
: QVector<int>{ 16, 32, 64, 128, 256 };
for (int size : sizes) {
auto px = createPixmapFromSvg(size);
// HACK, get rid of it by supporting FDO icon themes, this is really just emulating ubuntu-mono // HACK, get rid of it by supporting FDO icon themes, this is really just emulating ubuntu-mono
if (qgetenv("DESKTOP_SESSION") == "ubuntu") { if (qgetenv("DESKTOP_SESSION") == "ubuntu") {
QBitmap mask = px.createMaskFromColor(Qt::white, Qt::MaskOutColor); QBitmap mask = px.createMaskFromColor(Qt::white, Qt::MaskOutColor);