1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-07 10:51:45 +00:00

KStandardItemListWidget: Render pixmap with explicit dpr

Instead of using the one from QApplication, use the one from the window.
This commit is contained in:
Kai Uwe Broulik 2023-08-23 19:06:59 +02:00 committed by Méven Car
parent ae1980442d
commit 5a7b749f5b
2 changed files with 12 additions and 7 deletions

View File

@ -1540,13 +1540,18 @@ void KStandardItemListWidget::closeRoleEditor()
m_roleEditor = nullptr;
}
QPixmap KStandardItemListWidget::pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode)
QPixmap KStandardItemListWidget::pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode) const
{
static const QIcon fallbackIcon = QIcon::fromTheme(QStringLiteral("unknown"));
qreal dpr = qApp->devicePixelRatio();
if (scene() && !scene()->views().isEmpty()) {
dpr = scene()->views().constFirst()->devicePixelRatioF();
}
size *= qApp->devicePixelRatio();
size *= dpr;
const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(QLatin1Char(':')) % ":" % QString::number(size) % ":" % QString::number(mode);
const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(QLatin1Char(':')) % ":" % QString::number(size) % "@" % QString::number(dpr)
% ":" % QString::number(mode);
QPixmap pixmap;
if (!QPixmapCache::find(key, &pixmap)) {
@ -1554,11 +1559,11 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString &name, const QStrin
if (icon.isNull()) {
icon = QIcon(name);
}
if (icon.isNull() || icon.pixmap(size / qApp->devicePixelRatio(), size / qApp->devicePixelRatio(), mode).isNull()) {
if (icon.isNull() || icon.pixmap(size / dpr, size / dpr, mode).isNull()) {
icon = fallbackIcon;
}
pixmap = icon.pixmap(size / qApp->devicePixelRatio(), size / qApp->devicePixelRatio(), mode);
pixmap = icon.pixmap(QSize(size / dpr, size / dpr), dpr, mode);
if (pixmap.width() != size || pixmap.height() != size) {
KPixmapModifier::scale(pixmap, QSize(size, size));
}
@ -1595,7 +1600,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString &name, const QStrin
QPixmapCache::insert(key, pixmap);
}
pixmap.setDevicePixelRatio(qApp->devicePixelRatio());
pixmap.setDevicePixelRatio(dpr);
return pixmap;
}

View File

@ -215,7 +215,7 @@ private:
*/
void closeRoleEditor();
static QPixmap pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode);
QPixmap pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode) const;
/**
* @return Preferred size of the rating-image based on the given