]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodelrolesupdater.cpp
dolphinview: Add widget parameter to elided QToolTip::showText
[dolphin.git] / src / kitemviews / kfileitemmodelrolesupdater.cpp
index f5fae6f34fc1cc03bdae31af4eb194faff79f8f0..97b51ae84e14357c135abd5a9203bd24a3fbb8f3 100644 (file)
@@ -551,26 +551,8 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem &item, const QPi
         return;
     }
 
-    QPixmap scaledPixmap = transformPreviewPixmap(pixmap);
-
     QHash<QByteArray, QVariant> data = rolesData(item, index);
-
-    const QStringList overlays = data["iconOverlays"].toStringList();
-    // Strangely KFileItem::overlays() returns empty string-values, so
-    // we need to check first whether an overlay must be drawn at all.
-    if (!scaledPixmap.isNull()) {
-        for (const QString &overlay : overlays) {
-            if (!overlay.isEmpty()) {
-                // There is at least one overlay, draw all overlays above m_pixmap
-                // and cancel the check
-                const QSize logicalSize = scaledPixmap.size() / scaledPixmap.devicePixelRatioF();
-                scaledPixmap = KIconUtils::addOverlays(scaledPixmap, overlays).pixmap(logicalSize, scaledPixmap.devicePixelRatioF());
-                break;
-            }
-        }
-    }
-
-    data.insert("iconPixmap", scaledPixmap);
+    data.insert("iconPixmap", transformPreviewPixmap(pixmap));
 
     disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
     m_model->setData(index, data);
@@ -977,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.
@@ -1012,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()) {
@@ -1030,7 +1005,11 @@ QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap &pixmap
 {
     QPixmap scaledPixmap = pixmap;
 
-    if (!pixmap.hasAlpha() && !pixmap.isNull() && m_iconSize.width() > KIconLoader::SizeSmallMedium && m_iconSize.height() > KIconLoader::SizeSmallMedium) {
+    if (pixmap.isNull()) {
+        return scaledPixmap;
+    }
+
+    if (!pixmap.hasAlpha() && m_iconSize.width() > KIconLoader::SizeSmallMedium && m_iconSize.height() > KIconLoader::SizeSmallMedium) {
         if (m_enlargeSmallPreviews) {
             KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
         } else {
@@ -1058,7 +1037,7 @@ QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap &pixmap
                 KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
             }
         }
-    } else if (!pixmap.isNull()) {
+    } else {
         KPixmapModifier::scale(scaledPixmap, m_iconSize * m_devicePixelRatio);
         scaledPixmap.setDevicePixelRatio(m_devicePixelRatio);
     }
@@ -1066,6 +1045,16 @@ QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap &pixmap
     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) {
@@ -1106,14 +1095,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);