diff options
| author | David Edmundson <[email protected]> | 2015-03-30 13:39:17 +0200 |
|---|---|---|
| committer | David Edmundson <[email protected]> | 2015-03-30 13:39:17 +0200 |
| commit | 4ed0b82b02aa787ba25bdc5a5e5a99037fdb6efa (patch) | |
| tree | dac01c877cd1b93a721ff7a7e5873fb173eb58b0 /src/kitemviews/private | |
| parent | fba5dd58a55e191a3368cc85735826c2b9e18a8b (diff) | |
| parent | 1b6ee5d6cd918b81c59a5163c9d6371f35f9885c (diff) | |
Merge branch 'davidedmundson/highdpi'
REVIEW: 123137
Diffstat (limited to 'src/kitemviews/private')
| -rw-r--r-- | src/kitemviews/private/kpixmapmodifier.cpp | 15 | ||||
| -rw-r--r-- | src/kitemviews/private/kpixmapmodifier.h | 18 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/kitemviews/private/kpixmapmodifier.cpp b/src/kitemviews/private/kpixmapmodifier.cpp index c564ecc30..4693b313a 100644 --- a/src/kitemviews/private/kpixmapmodifier.cpp +++ b/src/kitemviews/private/kpixmapmodifier.cpp @@ -38,6 +38,7 @@ #include <QPainter> #include <QPixmap> #include <QSize> +#include <QGuiApplication> #include <config-X11.h> // for HAVE_XRENDER @@ -347,6 +348,7 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize) }}; QPixmap scaledPixmap(scaledPixmapSize); + scaledPixmap.setDevicePixelRatio(pixmap.devicePixelRatio()); scaledPixmap.fill(Qt::transparent); Display* dpy = QX11Info::display(); @@ -364,27 +366,32 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize) pixmap = pixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } #else + qreal dpr = pixmap.devicePixelRatio(); pixmap = pixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + pixmap.setDevicePixelRatio(dpr); #endif } void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize) { static TileSet tileSet; + qreal dpr = qApp->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); - scale(icon, size); + scale(icon, size * dpr); + icon.setDevicePixelRatio(dpr); - 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; painter.begin(&framedIcon); painter.setCompositionMode(QPainter::CompositionMode_Source); - tileSet.paint(&painter, framedIcon.rect()); + tileSet.paint(&painter, QRect(QPoint(0,0), framedIcon.size() / dpr)); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(TileSet::LeftMargin, TileSet::TopMargin, icon); diff --git a/src/kitemviews/private/kpixmapmodifier.h b/src/kitemviews/private/kpixmapmodifier.h index e8ca11ac1..e48abf515 100644 --- a/src/kitemviews/private/kpixmapmodifier.h +++ b/src/kitemviews/private/kpixmapmodifier.h @@ -28,8 +28,26 @@ 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 in device-independent pixels + * The returned image will be scaled by the application devicePixelRatio + */ 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); }; |
