]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[KStandardItemListWidget] Request the pixmap size we want and let the icon loader...
authorKai Uwe Broulik <kde@privat.broulik.de>
Mon, 16 Sep 2019 06:52:05 +0000 (08:52 +0200)
committerKai Uwe Broulik <kde@privat.broulik.de>
Mon, 16 Sep 2019 06:52:05 +0000 (08:52 +0200)
I noticed that depending on the configured icon size it would spend a significant amount of time in KPixmapModifier::scale.
I don't see a point in requesting a fixed icon size and then scale it down manually as opposed to having the KIconLoader do the scaling for us.
Especially for SVGs it could then even serve us a properly rendered SVG for this size rather than a scaled down pixmap version.

Differential Revision: https://phabricator.kde.org/D22116

src/kitemviews/kstandarditemlistwidget.cpp

index 617ed57f87ad7846a015e021aa75482b1b9e56ae..c963b719664ee3fd85c034dcd965de71a362e334 100644 (file)
@@ -1463,24 +1463,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
 {
     static const QIcon fallbackIcon = QIcon::fromTheme(QStringLiteral("unknown"));
 
-    int requestedSize = size;
-    if (size <= KIconLoader::SizeSmall) {
-        requestedSize = KIconLoader::SizeSmall;
-    } else if (size <= KIconLoader::SizeSmallMedium) {
-        requestedSize = KIconLoader::SizeSmallMedium;
-    } else if (size <= KIconLoader::SizeMedium) {
-        requestedSize = KIconLoader::SizeMedium;
-    } else if (size <= KIconLoader::SizeLarge) {
-        requestedSize = KIconLoader::SizeLarge;
-    } else if (size <= KIconLoader::SizeHuge) {
-        requestedSize = KIconLoader::SizeHuge;
-    } else if (size <= KIconLoader::SizeEnormous) {
-        requestedSize = KIconLoader::SizeEnormous;
-    } else if (size <= KIconLoader::SizeEnormous * 2) {
-        requestedSize = KIconLoader::SizeEnormous * 2;
-    }
     size *= qApp->devicePixelRatio();
-    requestedSize *= qApp->devicePixelRatio();
 
     const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(QLatin1Char(':')) % ":" % QString::number(size) % ":" % QString::number(mode);
     QPixmap pixmap;
@@ -1488,8 +1471,8 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
     if (!QPixmapCache::find(key, pixmap)) {
         const QIcon icon = QIcon::fromTheme(name, fallbackIcon);
 
-        pixmap = icon.pixmap(requestedSize / qApp->devicePixelRatio(), requestedSize / qApp->devicePixelRatio(), mode);
-        if (requestedSize != size) {
+        pixmap = icon.pixmap(size / qApp->devicePixelRatio(), size / qApp->devicePixelRatio(), mode);
+        if (pixmap.width() != size || pixmap.height() != size) {
             KPixmapModifier::scale(pixmap, QSize(size, size));
         }