mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
[KStandardItemListWidget] Round to icon size before applying scaling
Otherwise for 22px icons on high dpi we will request either the wrong icons or scale them needlessly. Dolphin requests a pixmap of 22px, this is then multiplied by dpr resulting in 44 which isn't a valid icon size (only 32 or 48 are). Moreover, we will also hit the path where it will scale the pixmap to a proper icon size resulting in blurry icons (and a performance penalty). Differential Revision: https://phabricator.kde.org/D15260
This commit is contained in:
parent
5f252da8b5
commit
1e7e4fad49
|
@ -1462,32 +1462,32 @@ void KStandardItemListWidget::closeRoleEditor()
|
|||
QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStringList& overlays, int size, QIcon::Mode mode)
|
||||
{
|
||||
static const QIcon fallbackIcon = QIcon::fromTheme(QStringLiteral("unknown"));
|
||||
|
||||
int requestedSize = size;
|
||||
if (size <= KIconLoader::SizeSmall) {
|
||||
requestedSize = KIconLoader::SizeSmall;
|
||||
} else if (size <= KIconLoader::SizeSmallMedium) {
|
||||
requestedSize = KIconLoader::SizeSmallMedium;
|
||||
} else if (size <= KIconLoader::SizeMedium) {
|
||||
requestedSize = KIconLoader::SizeMedium;
|
||||
} else if (size <= KIconLoader::SizeLarge) {
|
||||
requestedSize = KIconLoader::SizeLarge;
|
||||
} else if (size <= KIconLoader::SizeHuge) {
|
||||
requestedSize = KIconLoader::SizeHuge;
|
||||
} else if (size <= KIconLoader::SizeEnormous) {
|
||||
requestedSize = KIconLoader::SizeEnormous;
|
||||
} else if (size <= KIconLoader::SizeEnormous * 2) {
|
||||
requestedSize = KIconLoader::SizeEnormous * 2;
|
||||
}
|
||||
size *= qApp->devicePixelRatio();
|
||||
requestedSize *= qApp->devicePixelRatio();
|
||||
|
||||
const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(QStringLiteral(":")) % ":" % QString::number(size) % ":" % QString::number(mode);
|
||||
QPixmap pixmap;
|
||||
|
||||
if (!QPixmapCache::find(key, pixmap)) {
|
||||
const QIcon icon = QIcon::fromTheme(name, fallbackIcon);
|
||||
|
||||
int requestedSize;
|
||||
if (size <= KIconLoader::SizeSmall) {
|
||||
requestedSize = KIconLoader::SizeSmall;
|
||||
} else if (size <= KIconLoader::SizeSmallMedium) {
|
||||
requestedSize = KIconLoader::SizeSmallMedium;
|
||||
} else if (size <= KIconLoader::SizeMedium) {
|
||||
requestedSize = KIconLoader::SizeMedium;
|
||||
} else if (size <= KIconLoader::SizeLarge) {
|
||||
requestedSize = KIconLoader::SizeLarge;
|
||||
} else if (size <= KIconLoader::SizeHuge) {
|
||||
requestedSize = KIconLoader::SizeHuge;
|
||||
} else if (size <= KIconLoader::SizeEnormous) {
|
||||
requestedSize = KIconLoader::SizeEnormous;
|
||||
} else if (size <= KIconLoader::SizeEnormous * 2) {
|
||||
requestedSize = KIconLoader::SizeEnormous * 2;
|
||||
} else {
|
||||
requestedSize = size;
|
||||
}
|
||||
|
||||
pixmap = icon.pixmap(requestedSize / qApp->devicePixelRatio(), requestedSize / qApp->devicePixelRatio(), mode);
|
||||
if (requestedSize != size) {
|
||||
KPixmapModifier::scale(pixmap, QSize(size, size));
|
||||
|
|
Loading…
Reference in a new issue