]> cloud.milkyroute.net Git - dolphin.git/commitdiff
KFileItemModelRolesUpdater: add utility cacheSize function
authorMéven Car <meven@kde.org>
Sat, 11 Jan 2025 12:07:40 +0000 (13:07 +0100)
committerMéven Car <meven@kde.org>
Sat, 11 Jan 2025 12:22:43 +0000 (13:22 +0100)
src/kitemviews/kfileitemmodelrolesupdater.cpp
src/kitemviews/kfileitemmodelrolesupdater.h

index 1b2c92a1a26698f3e7aeec53561ff894dfb43b5a..92bf2bf8d9a14f5301fd19c25b0b5fd387bc9cad 100644 (file)
@@ -552,9 +552,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem &item, const QPi
     }
 
     QHash<QByteArray, QVariant> data = rolesData(item, index);
-    const QStringList overlays = data["iconOverlays"].toStringList();
-
-    data.insert("iconPixmap", transformPreviewPixmap(pixmap, overlays));
+    data.insert("iconPixmap", transformPreviewPixmap(pixmap, data["iconOverlays"].toStringList()));
 
     disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
     m_model->setData(index, data);
@@ -632,7 +630,7 @@ void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem &it
     if (wap < 0.0f || loadedIndex < static_cast<int>(wap)) {
         // Add the preview to the model data
 
-        QPixmap scaledPixmap = transformPreviewPixmap(pixmap, data["iconOverlays"].toStringList());
+        const QPixmap scaledPixmap = transformPreviewPixmap(pixmap, data["iconOverlays"].toStringList());
 
         pixmaps.append(scaledPixmap);
         data["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps);
@@ -961,13 +959,6 @@ void KFileItemModelRolesUpdater::startPreviewJob()
         return;
     }
 
-    // PreviewJob internally caches items always with the size of
-    // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
-    // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
-    // do a downscaling anyhow because of the frame, so in this case only the provided
-    // cache sizes are requested.
-    const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) ? QSize(256, 256) : QSize(128, 128);
-
     // KIO::filePreview() will request the MIME-type of all passed items, which (in the
     // worst case) might block the application for several seconds. To prevent such
     // a blocking, we only pass items with known mime type to the preview job.
@@ -996,7 +987,7 @@ void KFileItemModelRolesUpdater::startPreviewJob()
         } while (!m_pendingPreviewItems.isEmpty() && timer.elapsed() < MaxBlockTimeout);
     }
 
-    KIO::PreviewJob *job = new KIO::PreviewJob(itemSubSet, cacheSize, &m_enabledPlugins);
+    KIO::PreviewJob *job = new KIO::PreviewJob(itemSubSet, cacheSize(), &m_enabledPlugins);
     job->setDevicePixelRatio(m_devicePixelRatio);
     job->setIgnoreMaximumSize(itemSubSet.first().isLocalFile() && !itemSubSet.first().isSlow() && m_localFileSizePreviewLimit <= 0);
     if (job->uiDelegate()) {
@@ -1052,13 +1043,22 @@ QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap &pixmap
     }
 
     if (!overlays.isEmpty()) {
-        const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) ? QSize(256, 256) : QSize(128, 128);
-        scaledPixmap = KIconUtils::addOverlays(scaledPixmap, overlays).pixmap(cacheSize, m_devicePixelRatio);
+        scaledPixmap = KIconUtils::addOverlays(scaledPixmap, overlays).pixmap(cacheSize(), m_devicePixelRatio);
     }
 
     return scaledPixmap;
 }
 
+QSize KFileItemModelRolesUpdater::cacheSize()
+{
+    // PreviewJob internally caches items always with the size of
+    // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
+    // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
+    // do a downscaling anyhow because of the frame, so in this case only the provided
+    // cache sizes are requested.
+    return (m_iconSize.width() > 128) || (m_iconSize.height() > 128) ? QSize(256, 256) : QSize(128, 128);
+}
+
 void KFileItemModelRolesUpdater::loadNextHoverSequencePreview()
 {
     if (m_hoverSequenceItem.isNull() || m_hoverSequencePreviewJob) {
@@ -1099,14 +1099,7 @@ void KFileItemModelRolesUpdater::loadNextHoverSequencePreview()
         return;
     }
 
-    // PreviewJob internally caches items always with the size of
-    // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
-    // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
-    // do a downscaling anyhow because of the frame, so in this case only the provided
-    // cache sizes are requested.
-    const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) ? QSize(256, 256) : QSize(128, 128);
-
-    KIO::PreviewJob *job = new KIO::PreviewJob({m_hoverSequenceItem}, cacheSize, &m_enabledPlugins);
+    KIO::PreviewJob *job = new KIO::PreviewJob({m_hoverSequenceItem}, cacheSize(), &m_enabledPlugins);
 
     job->setSequenceIndex(loadSeqIdx);
     job->setIgnoreMaximumSize(m_hoverSequenceItem.isLocalFile() && !m_hoverSequenceItem.isSlow() && m_localFileSizePreviewLimit <= 0);
index a5bacf947afa62a77ccc0d831744ed0c22440047..28a70cda3661d48166c68cd0681a8310196a95ab 100644 (file)
@@ -341,6 +341,7 @@ private:
     void trimHoverSequenceLoadedItems();
 
 private:
+    QSize cacheSize();
     /**
      * enqueue directory size counting for KFileItem item at index
      */