|
3 | 3 | // SPDX-License-Identifier: LGPL-3.0-or-later |
4 | 4 |
|
5 | 5 | #include "dlabel.h" |
6 | | -#include "private/dlabel_p.h" |
7 | 6 | #include "dtooltip.h" |
| 7 | +#include "private/dlabel_p.h" |
8 | 8 |
|
9 | 9 | #include <DPaletteHelper> |
10 | 10 |
|
@@ -257,48 +257,73 @@ void DLabel::paintEvent(QPaintEvent *event) |
257 | 257 | } |
258 | 258 | } else |
259 | 259 | #endif |
260 | | - if (d->pixmap && !d->pixmap->isNull()) { |
261 | | - QPixmap pix; |
262 | | - if (d->scaledcontents) { |
263 | | - QSize scaledSize = cr.size() * devicePixelRatioF(); |
264 | | - if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) { |
| 260 | +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 261 | + if (d->pixmap && !d->pixmap->isNull()) { |
| 262 | +#else |
| 263 | + if (d->icon && !d->icon->isNull()) { |
| 264 | +#endif |
| 265 | + QPixmap pix; |
| 266 | + if (d->scaledcontents) { |
| 267 | + const auto dpr = devicePixelRatioF(); |
| 268 | + QSize scaledSize = cr.size() * dpr; |
| 269 | +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 270 | + if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) { |
| 271 | +#else |
| 272 | + auto mode = isEnabled() ? QIcon::Normal : QIcon::Disabled; |
| 273 | + pix = d->icon->pixmap(scaledSize, dpr, mode); |
| 274 | + if (d->scaledcontents && pix.size() != cr.size() * dpr) { |
| 275 | +#endif |
265 | 276 | #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) |
266 | | - if (!d->cachedimage) |
| 277 | + if (!d->cachedimage) |
267 | 278 | #endif |
268 | 279 | #if QT_VERSION < QT_VERSION_CHECK(6, 4, 2) |
269 | | - d->cachedimage = new QImage(d->pixmap->toImage()); |
270 | | - delete d->scaledpixmap; |
| 280 | + d->cachedimage = new QImage(d->pixmap->toImage()); |
| 281 | + delete d->scaledpixmap; |
271 | 282 | #else |
272 | 283 | #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) |
273 | | - d->cachedimage = QImage(d->pixmap->toImage()); |
| 284 | + d->cachedimage = QImage(d->pixmap->toImage()); |
274 | 285 | #endif |
275 | | - d->scaledpixmap.reset(); |
| 286 | +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 287 | + d->scaledpixmap.reset(); |
276 | 288 | #endif |
| 289 | +#endif |
| 290 | + |
277 | 291 | #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) |
278 | | - QImage scaledImage = |
279 | | - d->cachedimage->scaled(scaledSize, |
280 | | - Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 292 | + QImage scaledImage = d->cachedimage->scaled( |
| 293 | + scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 294 | +#elif QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 295 | + QImage scaledImage = d->pixmap->scaled( |
| 296 | + scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
281 | 297 | #else |
282 | | - d->scaledpixmap = d->pixmap->scaled(scaledSize, |
283 | | - Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 298 | + pix = pix.scaled(scaledSize, Qt::IgnoreAspectRatio, |
| 299 | + Qt::SmoothTransformation); |
| 300 | + pix.setDevicePixelRatio(dpr); |
| 301 | + d->icon->addPixmap(pix, mode); |
284 | 302 | #endif |
285 | 303 | #if QT_VERSION < QT_VERSION_CHECK(6, 4, 2) |
286 | | - d->scaledpixmap = new QPixmap(QPixmap::fromImage(scaledImage)); |
| 304 | + d->scaledpixmap = new QPixmap(QPixmap::fromImage(scaledImage)); |
| 305 | +#elif QT_VERSION < QT_VERSION_CHECK(6, 8, 0) |
| 306 | + d->scaledpixmap = QPixmap(QPixmap::fromImage(scaledImage)); |
| 307 | +#endif |
| 308 | +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 309 | + d->scaledpixmap->setDevicePixelRatio(dpr); |
| 310 | +#endif |
| 311 | + } |
| 312 | +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 313 | + pix = *d->scaledpixmap; |
| 314 | + } else { |
| 315 | + pix = *d->pixmap; |
| 316 | + } |
287 | 317 | #else |
288 | | -#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) |
289 | | - d->scaledpixmap = QPixmap(QPixmap::fromImage(scaledImage)); |
| 318 | + } |
290 | 319 | #endif |
| 320 | + QStyleOption opt; |
| 321 | + opt.initFrom(this); |
| 322 | +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) |
| 323 | + if (!isEnabled()) |
| 324 | + pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt); |
291 | 325 | #endif |
292 | | - d->scaledpixmap->setDevicePixelRatio(devicePixelRatioF()); |
293 | | - } |
294 | | - pix = *d->scaledpixmap; |
295 | | - } else |
296 | | - pix = *d->pixmap; |
297 | | - QStyleOption opt; |
298 | | - opt.initFrom(this); |
299 | | - if (!isEnabled()) |
300 | | - pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt); |
301 | | - style->drawItemPixmap(&painter, cr, align, pix); |
| 326 | + style->drawItemPixmap(&painter, cr, align, pix); |
302 | 327 | } |
303 | 328 | } |
304 | 329 |
|
|
0 commit comments