diff --git a/src/widgets/previewjob.h b/src/widgets/previewjob.h --- a/src/widgets/previewjob.h +++ b/src/widgets/previewjob.h @@ -186,6 +186,8 @@ **/ int sequenceIndex() const; + void setDevicePixelRatio(qreal dpr); + /** * Returns a list of all available preview plugins. The list * contains the basenames of the plugins' .desktop files (no path, diff --git a/src/widgets/previewjob.cpp b/src/widgets/previewjob.cpp --- a/src/widgets/previewjob.cpp +++ b/src/widgets/previewjob.cpp @@ -150,6 +150,7 @@ QString thumbRoot; // List of encrypted mount points for checking if we should save thumbnail KMountPoint::List encryptedMountsList; + qreal devicePixelRatio = 1; void getOrCreateThumbnail(); bool statResultThumbnail(); @@ -427,6 +428,11 @@ return d_func()->sequenceIndex; } +void KIO::PreviewJob::setDevicePixelRatio(qreal dpr) +{ + d_func()->devicePixelRatio = dpr; +} + void PreviewJob::setIgnoreMaximumSize(bool ignoreSize) { d_func()->ignoreMaximumSize = ignoreSize; @@ -564,6 +570,10 @@ thumb.text(QStringLiteral("Thumb::MTime")).toLongLong() != tOrig.toSecsSinceEpoch()) { return false; } + if (thumb.textKeys().contains(QStringLiteral("Thumb::DevicePixelRatio"))) { + qreal dpr = thumb.text(QStringLiteral("Thumb::DevicePixelRatio")).toDouble(); + thumb.setDevicePixelRatio(dpr); + } QString thumbnailerVersion = currentItem.plugin->property(QStringLiteral("ThumbnailerVersion"), QVariant::String).toString(); @@ -659,6 +669,7 @@ job->addMetaData(QStringLiteral("iconAlpha"), QString().setNum(iconAlpha)); job->addMetaData(QStringLiteral("plugin"), currentItem.plugin->library()); job->addMetaData(QStringLiteral("enabledPlugins"), enabledPlugins.join(QLatin1Char(','))); + job->addMetaData(QStringLiteral("devicePixelRatio"), QString::number(devicePixelRatio)); if (sequenceIndex) { job->addMetaData(QStringLiteral("sequence-index"), QString().setNum(sequenceIndex)); } @@ -669,7 +680,7 @@ shmdt((char *)shmaddr); shmctl(shmid, IPC_RMID, nullptr); } - shmid = shmget(IPC_PRIVATE, cacheWidth * cacheHeight * 4, IPC_CREAT | 0600); + shmid = shmget(IPC_PRIVATE, cacheWidth * cacheHeight * 4 * devicePixelRatio * devicePixelRatio, IPC_CREAT | 0600); if (shmid != -1) { shmaddr = (uchar *)(shmat(shmid, nullptr, SHM_RDONLY)); if (shmaddr == (uchar *) - 1) { @@ -702,9 +713,11 @@ QDataStream str(data); int width, height; quint8 iFormat; - str >> width >> height >> iFormat; + qreal imgDevicePixelRatio; + str >> width >> height >> iFormat >> imgDevicePixelRatio; QImage::Format format = static_cast(iFormat); thumb = QImage(shmaddr, width, height, format).copy(); + thumb.setDevicePixelRatio(imgDevicePixelRatio); } else #endif thumb.loadFromData(data); @@ -719,6 +732,7 @@ thumb.setText(QStringLiteral("Thumb::MTime"), QString::number(tOrig.toSecsSinceEpoch())); thumb.setText(QStringLiteral("Thumb::Size"), number(currentItem.item.size())); thumb.setText(QStringLiteral("Thumb::Mimetype"), currentItem.item.mimetype()); + thumb.setText(QStringLiteral("Thumb::DevicePixelRatio"), QString::number(thumb.devicePixelRatio())); QString thumbnailerVersion = currentItem.plugin->property(QStringLiteral("ThumbnailerVersion"), QVariant::String).toString(); QString signature = QLatin1String("KDE Thumbnail Generator ") + currentItem.plugin->name(); if (!thumbnailerVersion.isEmpty()) { @@ -740,11 +754,12 @@ { Q_Q(PreviewJob); QPixmap pix; - if (thumb.width() > width || thumb.height() > height) { - pix = QPixmap::fromImage(thumb.scaled(QSize(width, height), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + if (thumb.width() > width * devicePixelRatio || thumb.height() > height * devicePixelRatio) { + pix = QPixmap::fromImage(thumb.scaled(QSize(width * devicePixelRatio, height * devicePixelRatio), Qt::KeepAspectRatio, Qt::SmoothTransformation)); } else { pix = QPixmap::fromImage(thumb); } + pix.setDevicePixelRatio(thumb.devicePixelRatioF()); emit q->gotPreview(currentItem.item, pix); } diff --git a/src/widgets/thumbcreator.h b/src/widgets/thumbcreator.h --- a/src/widgets/thumbcreator.h +++ b/src/widgets/thumbcreator.h @@ -20,6 +20,8 @@ #ifndef _THUMBCREATOR_H_ #define _THUMBCREATOR_H_ +#include + #include "kiowidgets_export.h" class QString; @@ -129,11 +131,12 @@ * @param height The requested preview height (see the note on scaling * above). * @param img The QImage to store the preview in. + * @param devicePixelRatio * * @return @c true if a preview was successfully generated and store in @p * img, @c false otherwise. */ - virtual bool create(const QString &path, int width, int height, QImage &img) = 0; // KF6 TODO: turn first arg into QUrl (see thumbnail/htmlcreator.cpp) + virtual bool create(const QString &path, int width, int height, QImage &img, qreal devicePixelRatio = 1.0) = 0; // KF6 TODO: turn first arg into QUrl (see thumbnail/htmlcreator.cpp) /** * Returns the flags for this plugin.