#include <KIO/ListJob>
#include <KIO/PreviewJob>
#include <KIconLoader>
+#include <KIconUtils>
#include <KJobWidgets>
#include <KOverlayIconPlugin>
#include <KPluginMetaData>
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.
- // It is more efficient to do it here, as KIconLoader::drawOverlays()
- // assumes that an overlay will be drawn and has some additional
- // setup time.
- 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
- KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop);
- break;
- }
- }
- }
-
- data.insert("iconPixmap", scaledPixmap);
+ data.insert("iconPixmap", transformPreviewPixmap(pixmap));
disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
m_model->setData(index, data);
connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
+ Q_EMIT previewJobFinished(); // For unit testing
m_finishedItems.insert(item);
}
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.
} 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()) {
{
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 {
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
}
}
- } else if (!pixmap.isNull()) {
+ } else {
KPixmapModifier::scale(scaledPixmap, m_iconSize * m_devicePixelRatio);
scaledPixmap.setDevicePixelRatio(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) {
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);