mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 09:50:12 +00:00
[KItemListSelectionToggle] Adjust painting icon for high dpi scaling
Instead of using KIconLoader which currently doesn't support high dpi scaling, use QIcon::fromTheme which can. Differential Revision: https://phabricator.kde.org/D14222
This commit is contained in:
parent
4536e25ac9
commit
80bc133da9
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
#include <KIconLoader>
|
#include <KIconLoader>
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
|
||||||
KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem* parent) :
|
KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem* parent) :
|
||||||
QGraphicsWidget(parent, nullptr),
|
QGraphicsWidget(parent, nullptr),
|
||||||
m_checked(false),
|
m_checked(false),
|
||||||
|
@ -67,8 +67,8 @@ void KItemListSelectionToggle::paint(QPainter* painter, const QStyleOptionGraphi
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal x = (size().width() - qreal(m_pixmap.width())) / 2;
|
const qreal x = (size().width() - qreal(m_pixmap.width() / m_pixmap.devicePixelRatioF())) / 2;
|
||||||
const qreal y = (size().height() - qreal(m_pixmap.height())) / 2;
|
const qreal y = (size().height() - qreal(m_pixmap.height() / m_pixmap.devicePixelRatioF())) / 2;
|
||||||
painter->drawPixmap(x, y, m_pixmap);
|
painter->drawPixmap(x, y, m_pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event)
|
||||||
QGraphicsWidget::resizeEvent(event);
|
QGraphicsWidget::resizeEvent(event);
|
||||||
|
|
||||||
if (!m_pixmap.isNull()) {
|
if (!m_pixmap.isNull()) {
|
||||||
const int pixmapSize = m_pixmap.size().width(); // Pixmap width is always equal pixmap height
|
const int pixmapSize = m_pixmap.size().width() / m_pixmap.devicePixelRatioF(); // Pixmap width is always equal pixmap height
|
||||||
|
|
||||||
if (pixmapSize != iconSize()) {
|
if (pixmapSize != iconSize()) {
|
||||||
// If the required icon size is different from the actual pixmap size,
|
// If the required icon size is different from the actual pixmap size,
|
||||||
|
@ -91,8 +91,7 @@ void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event)
|
||||||
void KItemListSelectionToggle::updatePixmap()
|
void KItemListSelectionToggle::updatePixmap()
|
||||||
{
|
{
|
||||||
const QString icon = m_checked ? QStringLiteral("emblem-remove") : QStringLiteral("emblem-added");
|
const QString icon = m_checked ? QStringLiteral("emblem-remove") : QStringLiteral("emblem-added");
|
||||||
const KIconLoader::States state = m_hovered ? KIconLoader::ActiveState : KIconLoader::DisabledState;
|
m_pixmap = QIcon::fromTheme(icon).pixmap(iconSize(), m_hovered ? QIcon::Active : QIcon::Disabled);
|
||||||
m_pixmap = KIconLoader::global()->loadIcon(icon, KIconLoader::Desktop, iconSize(), state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int KItemListSelectionToggle::iconSize() const
|
int KItemListSelectionToggle::iconSize() const
|
||||||
|
|
Loading…
Reference in a new issue