mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-05 16:19:10 +00:00
Make KPixmapModifier::applyFrame handle high DPI images
This commit is contained in:
parent
00b00d2371
commit
35c0972671
|
@ -493,7 +493,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
|
|||
const QString mimeTypeGroup = mimeType.left(slashIndex);
|
||||
if (mimeTypeGroup == QLatin1String("image")) {
|
||||
if (m_enlargeSmallPreviews) {
|
||||
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize * qApp->devicePixelRatio());
|
||||
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize * scaledPixmap.devicePixelRatio());
|
||||
} else {
|
||||
// Assure that small previews don't get enlarged. Instead they
|
||||
// should be shown centered within the frame.
|
||||
|
@ -502,7 +502,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
|
|||
scaledPixmap.height() < contentSize.height();
|
||||
if (enlargingRequired) {
|
||||
QSize frameSize = scaledPixmap.size();
|
||||
frameSize.scale(m_iconSize * qApp->devicePixelRatio(), Qt::KeepAspectRatio);
|
||||
frameSize.scale(m_iconSize * scaledPixmap.devicePixelRatio(), Qt::KeepAspectRatio);
|
||||
|
||||
QPixmap largeFrame(frameSize);
|
||||
largeFrame.fill(Qt::transparent);
|
||||
|
@ -517,13 +517,12 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
|
|||
} else {
|
||||
// The image must be shrinked as it is too large to fit into
|
||||
// the available icon size
|
||||
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize * qApp->devicePixelRatio());
|
||||
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize * scaledPixmap.devicePixelRatio());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
KPixmapModifier::scale(scaledPixmap, m_iconSize * qApp->devicePixelRatio());
|
||||
KPixmapModifier::scale(scaledPixmap, m_iconSize * scaledPixmap.devicePixelRatio());
|
||||
}
|
||||
scaledPixmap.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||
|
||||
QHash<QByteArray, QVariant> data = rolesData(item);
|
||||
|
||||
|
|
|
@ -374,14 +374,16 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize)
|
|||
void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize)
|
||||
{
|
||||
static TileSet tileSet;
|
||||
qreal dpr = icon.devicePixelRatio();
|
||||
|
||||
// Resize the icon to the maximum size minus the space required for the frame
|
||||
const QSize size(scaledSize.width() - TileSet::LeftMargin - TileSet::RightMargin,
|
||||
scaledSize.height() - TileSet::TopMargin - TileSet::BottomMargin);
|
||||
const QSize size(scaledSize.width() - (TileSet::LeftMargin + TileSet::RightMargin) * dpr,
|
||||
scaledSize.height() - (TileSet::TopMargin + TileSet::BottomMargin) * dpr);
|
||||
scale(icon, size);
|
||||
|
||||
QPixmap framedIcon(icon.size().width() + TileSet::LeftMargin + TileSet::RightMargin,
|
||||
icon.size().height() + TileSet::TopMargin + TileSet::BottomMargin);
|
||||
QPixmap framedIcon(icon.size().width() + (TileSet::LeftMargin + TileSet::RightMargin) * dpr,
|
||||
icon.size().height() + (TileSet::TopMargin + TileSet::BottomMargin * dpr) );
|
||||
framedIcon.setDevicePixelRatio(dpr);
|
||||
framedIcon.fill(Qt::transparent);
|
||||
|
||||
QPainter painter;
|
||||
|
|
|
@ -28,8 +28,25 @@ class QSize;
|
|||
class DOLPHIN_EXPORT KPixmapModifier
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Scale a pixmap to a given size.
|
||||
* @arg scaledSize is assumed to be the scaled to the same device pixel ratio as the source pixmap
|
||||
* @arg scaledSize is in device pixels
|
||||
*/
|
||||
static void scale(QPixmap& pixmap, const QSize& scaledSize);
|
||||
|
||||
/**
|
||||
* Resize and paint a frame round an icon
|
||||
* @arg scaledSize is assumed to be the scaled to the same device pixel ratio as the source icon
|
||||
*/
|
||||
static void applyFrame(QPixmap& icon, const QSize& scaledSize);
|
||||
|
||||
/**
|
||||
* return and paint a frame round an icon
|
||||
* @arg framesize is in device-independent pixels
|
||||
* @return is in device-indepent pixels
|
||||
*/
|
||||
|
||||
static QSize sizeInsideFrame(const QSize& frameSize);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue