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