Changeset View
Changeset View
Standalone View
Standalone View
src/kiconengine.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 69 | { | |||
---|---|---|---|---|---|
70 | if (!mIconLoader) { | 70 | if (!mIconLoader) { | ||
71 | return; | 71 | return; | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | const qreal dpr = painter->device()->devicePixelRatioF(); | 74 | const qreal dpr = painter->device()->devicePixelRatioF(); | ||
75 | painter->drawPixmap(rect, pixmap(rect.size() * dpr, mode, state)); | 75 | painter->drawPixmap(rect, pixmap(rect.size() * dpr, mode, state)); | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | QPixmap KIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) | 78 | QPixmap KIconEngine::createPixmap(const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state) | ||
79 | { | 79 | { | ||
80 | Q_UNUSED(state) | 80 | Q_UNUSED(state) | ||
81 | 81 | | |||
82 | if (scale < 1) { | ||||
83 | scale = 1; | ||||
84 | } | ||||
85 | | ||||
82 | if (size.isEmpty()) { | 86 | if (size.isEmpty()) { | ||
83 | return QPixmap(); | 87 | return QPixmap(); | ||
84 | } | 88 | } | ||
85 | 89 | | |||
86 | if (!mIconLoader) { | 90 | if (!mIconLoader) { | ||
87 | QPixmap pm(size); | 91 | QPixmap pm(size); | ||
92 | pm.setDevicePixelRatio(scale); | ||||
88 | pm.fill(Qt::transparent); | 93 | pm.fill(Qt::transparent); | ||
89 | return pm; | 94 | return pm; | ||
90 | } | 95 | } | ||
91 | 96 | | |||
97 | const QSize scaledSize = size / scale; | ||||
92 | 98 | | |||
93 | const int kstate = qIconModeToKIconState(mode); | 99 | const int kstate = qIconModeToKIconState(mode); | ||
94 | const int iconSize = qMin(size.width(), size.height()); | 100 | const int iconSize = qMin(scaledSize.width(), scaledSize.height()); | ||
95 | QPixmap pix = mIconLoader.data()->loadIcon(mIconName, KIconLoader::Desktop, iconSize, kstate, mOverlays); | 101 | QPixmap pix = mIconLoader.data()->loadScaledIcon(mIconName, KIconLoader::Desktop, scale, iconSize, kstate, mOverlays); | ||
96 | 102 | | |||
97 | if (pix.size() == size) { | 103 | if (pix.size() == size) { | ||
98 | return pix; | 104 | return pix; | ||
99 | } | 105 | } | ||
100 | 106 | | |||
101 | QPixmap pix2(size); | 107 | QPixmap pix2(size * scale); | ||
108 | pix2.setDevicePixelRatio(scale); | ||||
102 | pix2.fill(QColor(0, 0, 0, 0)); | 109 | pix2.fill(QColor(0, 0, 0, 0)); | ||
103 | 110 | | |||
104 | QPainter painter(&pix2); | 111 | QPainter painter(&pix2); | ||
105 | painter.drawPixmap(QPoint((pix2.width() - pix.width()) / 2, (pix2.height() - pix.height()) / 2), pix); | 112 | painter.drawPixmap(QPoint((pix2.width() - pix.width()) / 2, (pix2.height() - pix.height()) / 2), pix); | ||
106 | 113 | | |||
107 | return pix2; | 114 | return pix2; | ||
108 | } | 115 | } | ||
109 | 116 | | |||
117 | QPixmap KIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) | ||||
118 | { | ||||
119 | return createPixmap(size, 1 /*scale*/, mode, state); | ||||
120 | } | ||||
121 | | ||||
110 | QString KIconEngine::iconName() const | 122 | QString KIconEngine::iconName() const | ||
111 | { | 123 | { | ||
112 | if (!mIconLoader || !mIconLoader->hasIcon(mIconName)) { | 124 | if (!mIconLoader || !mIconLoader->hasIcon(mIconName)) { | ||
113 | return QString(); | 125 | return QString(); | ||
114 | } | 126 | } | ||
115 | return mIconName; | 127 | return mIconName; | ||
116 | } | 128 | } | ||
117 | 129 | | |||
Show All 34 Lines | 162 | { | |||
152 | return true; | 164 | return true; | ||
153 | } | 165 | } | ||
154 | 166 | | |||
155 | void KIconEngine::virtual_hook(int id, void *data) | 167 | void KIconEngine::virtual_hook(int id, void *data) | ||
156 | { | 168 | { | ||
157 | if (id == QIconEngine::IsNullHook) { | 169 | if (id == QIconEngine::IsNullHook) { | ||
158 | *reinterpret_cast<bool*>(data) = !mIconLoader || !mIconLoader->hasIcon(mIconName); | 170 | *reinterpret_cast<bool*>(data) = !mIconLoader || !mIconLoader->hasIcon(mIconName); | ||
159 | } | 171 | } | ||
172 | #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) | ||||
173 | if (id == QIconEngine::ScaledPixmapHook) { | ||||
174 | auto *info = reinterpret_cast<ScaledPixmapArgument *>(data); | ||||
175 | info->pixmap = createPixmap(info->size, info->scale, info->mode, info->state); | ||||
176 | return; | ||||
177 | } | ||||
178 | #endif | ||||
160 | QIconEngine::virtual_hook(id, data); | 179 | QIconEngine::virtual_hook(id, data); | ||
161 | } | 180 | } |