| 584 | } |
| 585 | |
| 586 | QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) |
| 587 | { |
| 588 | Q_UNUSED(state); |
| 589 | |
| 590 | // Ensure that basePixmap is lazily initialized before generating the |
| 591 | // key, otherwise the cache key is not unique |
| 592 | if (basePixmap.isNull()) |
| 593 | basePixmap.load(filename); |
| 594 | |
| 595 | QSize actualSize = basePixmap.size(); |
| 596 | if (!actualSize.isNull() && |
| 597 | (actualSize.width() > size.width() || actualSize.height() > size.height())) |
| 598 | actualSize.scale(size, Qt::KeepAspectRatio); |
| 599 | |
| 600 | QString key = QLatin1String("$qt_theme_") % HexString<qint64>(basePixmap.cacheKey()) % |
| 601 | HexString<int>(mode) % |
| 602 | HexString<qint64>(QGuiApplication::palette().cacheKey()) % |
| 603 | HexString<int>(actualSize.width()) % HexString<int>(actualSize.height()); |
| 604 | |
| 605 | QPixmap cachedPixmap; |
| 606 | if (QPixmapCache::find(key, &cachedPixmap)) |
| 607 | { |
| 608 | return cachedPixmap; |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | if (basePixmap.size() != actualSize) |
| 613 | { |
| 614 | cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 615 | } |
| 616 | else |
| 617 | { |
| 618 | cachedPixmap = basePixmap; |
| 619 | } |
| 620 | QPixmapCache::insert(key, cachedPixmap); |
| 621 | } |
| 622 | return cachedPixmap; |
| 623 | } |
| 624 | |
| 625 | QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) |
| 626 | { |