#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
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
}
}