Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/private/kitemlistselectiontoggle.cpp
Show All 15 Lines | |||||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "kitemlistselectiontoggle.h" | 20 | #include "kitemlistselectiontoggle.h" | ||
21 | 21 | | |||
22 | #include <KIconLoader> | 22 | #include <KIconLoader> | ||
23 | 23 | | |||
24 | #include <QIcon> | ||||
24 | #include <QPainter> | 25 | #include <QPainter> | ||
25 | 26 | | |||
26 | | ||||
27 | KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem* parent) : | 27 | KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem* parent) : | ||
28 | QGraphicsWidget(parent, nullptr), | 28 | QGraphicsWidget(parent, nullptr), | ||
29 | m_checked(false), | 29 | m_checked(false), | ||
30 | m_hovered(false) | 30 | m_hovered(false) | ||
31 | { | 31 | { | ||
32 | } | 32 | } | ||
33 | 33 | | |||
34 | KItemListSelectionToggle::~KItemListSelectionToggle() | 34 | KItemListSelectionToggle::~KItemListSelectionToggle() | ||
Show All 27 Lines | |||||
62 | { | 62 | { | ||
63 | Q_UNUSED(option); | 63 | Q_UNUSED(option); | ||
64 | Q_UNUSED(widget); | 64 | Q_UNUSED(widget); | ||
65 | 65 | | |||
66 | if (m_pixmap.isNull()) { | 66 | if (m_pixmap.isNull()) { | ||
67 | updatePixmap(); | 67 | updatePixmap(); | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | const qreal x = (size().width() - qreal(m_pixmap.width())) / 2; | 70 | const qreal x = (size().width() - qreal(m_pixmap.width() / m_pixmap.devicePixelRatioF())) / 2; | ||
71 | const qreal y = (size().height() - qreal(m_pixmap.height())) / 2; | 71 | const qreal y = (size().height() - qreal(m_pixmap.height() / m_pixmap.devicePixelRatioF())) / 2; | ||
72 | painter->drawPixmap(x, y, m_pixmap); | 72 | painter->drawPixmap(x, y, m_pixmap); | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event) | 75 | void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event) | ||
76 | { | 76 | { | ||
77 | QGraphicsWidget::resizeEvent(event); | 77 | QGraphicsWidget::resizeEvent(event); | ||
78 | 78 | | |||
79 | if (!m_pixmap.isNull()) { | 79 | if (!m_pixmap.isNull()) { | ||
80 | const int pixmapSize = m_pixmap.size().width(); // Pixmap width is always equal pixmap height | 80 | const int pixmapSize = m_pixmap.size().width() / m_pixmap.devicePixelRatioF(); // Pixmap width is always equal pixmap height | ||
81 | 81 | | |||
82 | if (pixmapSize != iconSize()) { | 82 | if (pixmapSize != iconSize()) { | ||
83 | // If the required icon size is different from the actual pixmap size, | 83 | // If the required icon size is different from the actual pixmap size, | ||
84 | // overwrite the m_pixmap with an empty pixmap and reload the new | 84 | // overwrite the m_pixmap with an empty pixmap and reload the new | ||
85 | // icon on next re-painting. | 85 | // icon on next re-painting. | ||
86 | m_pixmap = QPixmap(); | 86 | m_pixmap = QPixmap(); | ||
87 | } | 87 | } | ||
88 | } | 88 | } | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | void KItemListSelectionToggle::updatePixmap() | 91 | void KItemListSelectionToggle::updatePixmap() | ||
92 | { | 92 | { | ||
93 | const QString icon = m_checked ? QStringLiteral("emblem-remove") : QStringLiteral("emblem-added"); | 93 | const QString icon = m_checked ? QStringLiteral("emblem-remove") : QStringLiteral("emblem-added"); | ||
94 | const KIconLoader::States state = m_hovered ? KIconLoader::ActiveState : KIconLoader::DisabledState; | 94 | m_pixmap = QIcon::fromTheme(icon).pixmap(iconSize(), m_hovered ? QIcon::Active : QIcon::Disabled); | ||
95 | m_pixmap = KIconLoader::global()->loadIcon(icon, KIconLoader::Desktop, iconSize(), state); | | |||
96 | } | 95 | } | ||
97 | 96 | | |||
98 | int KItemListSelectionToggle::iconSize() const | 97 | int KItemListSelectionToggle::iconSize() const | ||
99 | { | 98 | { | ||
100 | const int iconSize = qMin(size().width(), size().height()); | 99 | const int iconSize = qMin(size().width(), size().height()); | ||
101 | 100 | | |||
102 | if (iconSize < KIconLoader::SizeSmallMedium) { | 101 | if (iconSize < KIconLoader::SizeSmallMedium) { | ||
103 | return KIconLoader::SizeSmall; | 102 | return KIconLoader::SizeSmall; | ||
Show All 13 Lines |