]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make KPixmapModifier::applyFrame handle high DPI images
authorDavid Edmundson <kde@davidedmundson.co.uk>
Thu, 26 Mar 2015 15:06:52 +0000 (16:06 +0100)
committerDavid Edmundson <kde@davidedmundson.co.uk>
Thu, 26 Mar 2015 15:06:52 +0000 (16:06 +0100)
src/kitemviews/kfileitemmodelrolesupdater.cpp
src/kitemviews/private/kpixmapmodifier.cpp
src/kitemviews/private/kpixmapmodifier.h

index c6ce877e32383c9e35e1d927a3d74738b37bd7fb..068118983ea3aa8cb16417fa7804b161d797c224 100644 (file)
@@ -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);
 
index ee1f84366f5d0d3d298c786eeae8d83d65373da0..3e0edf02c48eef2a5126ed29a88ee91807b82f96 100644 (file)
@@ -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;
index e8ca11ac1bf03ca2f3cd5adbbb8014be8d84e8cf..9089a100174c7763d56a5734c5fd83dcdb6878b7 100644 (file)
@@ -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);
 };