mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Paint icons at the correct size
This commit is contained in:
parent
ebd03cc205
commit
00b00d2371
|
@ -40,6 +40,8 @@
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
#include <QTextLine>
|
#include <QTextLine>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
// #define KSTANDARDITEMLISTWIDGET_DEBUG
|
// #define KSTANDARDITEMLISTWIDGET_DEBUG
|
||||||
|
|
||||||
|
@ -342,6 +344,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
|
||||||
*/
|
*/
|
||||||
// Paint pixmap1 so that pixmap1 = m_pixmap * (1.0 - hoverOpacity())
|
// Paint pixmap1 so that pixmap1 = m_pixmap * (1.0 - hoverOpacity())
|
||||||
QPixmap pixmap1(m_pixmap.size());
|
QPixmap pixmap1(m_pixmap.size());
|
||||||
|
pixmap1.setDevicePixelRatio(m_pixmap.devicePixelRatio());
|
||||||
pixmap1.fill(Qt::transparent);
|
pixmap1.fill(Qt::transparent);
|
||||||
{
|
{
|
||||||
QPainter p(&pixmap1);
|
QPainter p(&pixmap1);
|
||||||
|
@ -351,6 +354,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
|
||||||
|
|
||||||
// Paint pixmap2 so that pixmap2 = m_hoverPixmap * hoverOpacity()
|
// Paint pixmap2 so that pixmap2 = m_hoverPixmap * hoverOpacity()
|
||||||
QPixmap pixmap2(pixmap1.size());
|
QPixmap pixmap2(pixmap1.size());
|
||||||
|
pixmap2.setDevicePixelRatio(pixmap1.devicePixelRatio());
|
||||||
pixmap2.fill(Qt::transparent);
|
pixmap2.fill(Qt::transparent);
|
||||||
{
|
{
|
||||||
QPainter p(&pixmap2);
|
QPainter p(&pixmap2);
|
||||||
|
@ -952,10 +956,12 @@ void KStandardItemListWidget::updatePixmapCache()
|
||||||
}
|
}
|
||||||
const QStringList overlays = values["iconOverlays"].toStringList();
|
const QStringList overlays = values["iconOverlays"].toStringList();
|
||||||
m_pixmap = pixmapForIcon(iconName, overlays, maxIconHeight);
|
m_pixmap = pixmapForIcon(iconName, overlays, maxIconHeight);
|
||||||
} else if (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight) {
|
// qDebug() << "attempt 2 - setting pixmap to one of size " << m_pixmap.size() << m_pixmap.devicePixelRatio();
|
||||||
|
|
||||||
|
} else if (m_pixmap.width() / qApp->devicePixelRatio() != maxIconWidth || m_pixmap.height() / qApp->devicePixelRatio() != maxIconHeight) {
|
||||||
// A custom pixmap has been applied. Assure that the pixmap
|
// A custom pixmap has been applied. Assure that the pixmap
|
||||||
// is scaled to the maximum available size.
|
// is scaled to the maximum available size.
|
||||||
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight));
|
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight) * qApp->devicePixelRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_isCut) {
|
if (m_isCut) {
|
||||||
|
@ -1351,9 +1357,9 @@ void KStandardItemListWidget::updateAdditionalInfoTextColor()
|
||||||
|
|
||||||
void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
|
void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
|
||||||
{
|
{
|
||||||
if (m_scaledPixmapSize != pixmap.size()) {
|
if (m_scaledPixmapSize * qApp->devicePixelRatio() != pixmap.size()) {
|
||||||
QPixmap scaledPixmap = pixmap;
|
QPixmap scaledPixmap = pixmap;
|
||||||
KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize);
|
KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize * qApp->devicePixelRatio());
|
||||||
painter->drawPixmap(m_pixmapPos, scaledPixmap);
|
painter->drawPixmap(m_pixmapPos, scaledPixmap);
|
||||||
|
|
||||||
#ifdef KSTANDARDITEMLISTWIDGET_DEBUG
|
#ifdef KSTANDARDITEMLISTWIDGET_DEBUG
|
||||||
|
@ -1435,6 +1441,7 @@ void KStandardItemListWidget::closeRoleEditor()
|
||||||
|
|
||||||
QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStringList& overlays, int size)
|
QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStringList& overlays, int size)
|
||||||
{
|
{
|
||||||
|
size *= qApp->devicePixelRatio();
|
||||||
const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(":") % ":" % QString::number(size);
|
const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(":") % ":" % QString::number(size);
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
|
|
||||||
|
@ -1460,7 +1467,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
|
||||||
requestedSize = size;
|
requestedSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmap = icon.pixmap(requestedSize, requestedSize);
|
pixmap = icon.pixmap(requestedSize / qApp->devicePixelRatio(), requestedSize / qApp->devicePixelRatio());
|
||||||
if (requestedSize != size) {
|
if (requestedSize != size) {
|
||||||
KPixmapModifier::scale(pixmap, QSize(size, size));
|
KPixmapModifier::scale(pixmap, QSize(size, size));
|
||||||
}
|
}
|
||||||
|
@ -1481,6 +1488,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
|
||||||
|
|
||||||
QPixmapCache::insert(key, pixmap);
|
QPixmapCache::insert(key, pixmap);
|
||||||
}
|
}
|
||||||
|
pixmap.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||||
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ private:
|
||||||
Layout m_layout;
|
Layout m_layout;
|
||||||
QPointF m_pixmapPos;
|
QPointF m_pixmapPos;
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
QSize m_scaledPixmapSize;
|
QSize m_scaledPixmapSize; //Size of the pixmap in device independent pixels
|
||||||
|
|
||||||
QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
|
QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
|
||||||
QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
|
QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
|
||||||
|
|
Loading…
Reference in a new issue