]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kfilepreviewgenerator.cpp
The else path is never reached -> removed it (thanks to Simon St James for the hint)
[dolphin.git] / src / kfilepreviewgenerator.cpp
index f614aae63740f126f2914139efb4fd27d39e635d..f78305d02c11d0947a5800131adce00da6472a82 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "kfilepreviewgenerator.h"
 
+#include <kfileitem.h>
 #include <kiconeffect.h>
 #include <kio/previewjob.h>
 #include <kdirlister.h>
 #include <QAbstractItemView>
 #include <QClipboard>
 #include <QColor>
+#include <QList>
 #include <QListView>
 #include <QPainter>
+#include <QPixmap>
 #include <QScrollBar>
 #include <QIcon>
 
+#ifdef Q_WS_X11
+#  include <QX11Info>
+#  include <X11/Xlib.h>
+#  include <X11/extensions/Xrender.h>
+#endif
+
 /**
  * If the passed item view is an instance of QListView, expensive
  * layout operations are blocked in the constructor and are unblocked
@@ -575,7 +584,35 @@ bool KFilePreviewGenerator::Private::applyImageFrame(QPixmap& icon)
 void KFilePreviewGenerator::Private::limitToSize(QPixmap& icon, const QSize& maxSize)
 {
     if ((icon.width() > maxSize.width()) || (icon.height() > maxSize.height())) {
+#ifdef Q_WS_X11
+        // Assume that the texture size limit is 2048x2048
+        if ((icon.width() <= 2048) && (icon.height() <= 2048)) {
+            QSize size = icon.size();
+            size.scale(maxSize, Qt::KeepAspectRatio);
+
+            const qreal factor = size.width() / qreal(icon.width());
+
+            XTransform xform = {{
+                { XDoubleToFixed(1 / factor), 0, 0 },
+                { 0, XDoubleToFixed(1 / factor), 0 },
+                { 0, 0, XDoubleToFixed(1) }
+            }};
+
+            QPixmap pixmap(size);
+            pixmap.fill(Qt::transparent);
+
+            Display *dpy = QX11Info::display();
+            XRenderSetPictureFilter(dpy, icon.x11PictureHandle(), FilterBilinear, 0, 0);
+            XRenderSetPictureTransform(dpy, icon.x11PictureHandle(), &xform);
+            XRenderComposite(dpy, PictOpOver, icon.x11PictureHandle(), None, pixmap.x11PictureHandle(),
+                             0, 0, 0, 0, 0, 0, pixmap.width(), pixmap.height());
+            icon = pixmap;
+        } else {
+            icon = icon.scaled(maxSize, Qt::KeepAspectRatio, Qt::FastTransformation);
+        }
+#else
         icon = icon.scaled(maxSize, Qt::KeepAspectRatio, Qt::FastTransformation);
+#endif
     }
 }