+ const bool isFontPreview = mimeType.right(slashIndex).contains(QLatin1String("font"));
+ const bool isFolderPreview = item.isDir();
+ const bool isWindowsExePreview = mimeType == QLatin1String("application/x-ms-dos-executable") ||
+ mimeType == QLatin1String("application/x-msdownload");
+
+ if (!isFolderPreview && !isFontPreview && !isWindowsExePreview) {
+ if (m_enlargeSmallPreviews) {
+ KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
+ } else {
+ // Assure that small previews don't get enlarged. Instead they
+ // should be shown centered within the frame.
+ const QSize contentSize = KPixmapModifier::sizeInsideFrame(m_iconSize);
+ const bool enlargingRequired = scaledPixmap.width() < contentSize.width() &&
+ scaledPixmap.height() < contentSize.height();
+ if (enlargingRequired) {
+ QSize frameSize = scaledPixmap.size() / scaledPixmap.devicePixelRatio();
+ frameSize.scale(m_iconSize, Qt::KeepAspectRatio);
+
+ QPixmap largeFrame(frameSize);
+ largeFrame.fill(Qt::transparent);
+
+ KPixmapModifier::applyFrame(largeFrame, frameSize);
+
+ QPainter painter(&largeFrame);
+ painter.drawPixmap((largeFrame.width() - scaledPixmap.width() / scaledPixmap.devicePixelRatio()) / 2,
+ (largeFrame.height() - scaledPixmap.height() / scaledPixmap.devicePixelRatio()) / 2,
+ scaledPixmap);
+ scaledPixmap = largeFrame;
+ } else {
+ // The image must be shrinked as it is too large to fit into
+ // the available icon size
+ KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
+ }
+ }