Move the svg rendering part in a lambda
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 23 Jul 2020 17:06:09 +0000 (19:06 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Tue, 28 Jul 2020 09:20:34 +0000 (09:20 +0000)
This simplifies the loop body a bit, opening the door to what's next.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/theme.cpp

index 50e5de836ea88a939a5e43c03d5c4c651f643e3c..b62736860743e2583e0749aa3331cc251da7a9ea 100644 (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);
         QSvgRenderer renderer(svgName);
-
-        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) {
+        const auto createPixmapFromSvg = [&renderer] (int size) {
             QImage img(size, size, QImage::Format_ARGB32);
             img.fill(Qt::GlobalColor::transparent);
             QPainter imgPainter(&img);
             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
             if (qgetenv("DESKTOP_SESSION") == "ubuntu") {
                 QBitmap mask = px.createMaskFromColor(Qt::white, Qt::MaskOutColor);