+QPixmap
+KStandardItemListWidget::addOverlays(const QPixmap &pixmap, const QHash<Qt::Corner, QString> &overlays, const QSize &size, qreal dpr, QIcon::Mode mode) const
+{
+ // similar to KIconUtils::addOverlays, keep in sync preferrably
+ if (overlays.isEmpty()) {
+ return pixmap;
+ }
+
+ int width = size.width();
+ int height = size.height();
+ const int iconSize = qMin(width, height);
+
+ // Determine the overlay icon
+ int overlaySize;
+ if (iconSize < 32) {
+ overlaySize = 8;
+ } else if (iconSize <= 48) {
+ overlaySize = 16;
+ } else if (iconSize <= 96) {
+ overlaySize = 22;
+ } else if (iconSize < 256) {
+ overlaySize = 32;
+ } else {
+ overlaySize = 64;
+ }
+
+ auto phyiscalSize = QSize(std::clamp(pixmap.width(), qFloor(2 * overlaySize * dpr), qFloor(size.width() * dpr)),
+ std::clamp(pixmap.height(), qFloor(2 * overlaySize * dpr), qFloor(size.height() * dpr)));
+
+ QPixmap output(phyiscalSize);
+ output.setDevicePixelRatio(dpr);
+ output.fill(Qt::transparent);
+
+ QPainter painter(&output);
+ painter.drawPixmap(qFloor(phyiscalSize.width() / dpr / 2) - qFloor(pixmap.width() / pixmap.devicePixelRatio() / 2),
+ // align the icon to the bottom to match the behavior elsewhere
+ qFloor(phyiscalSize.height() / dpr) - qFloor(pixmap.height() / pixmap.devicePixelRatio()),
+ pixmap);
+
+ width = qCeil(phyiscalSize.width() / dpr);
+ height = qCeil(phyiscalSize.height() / dpr);
+
+ // Iterate over stored overlays
+ for (const auto &[corner, overlay] : overlays.asKeyValueRange()) {
+ const QPixmap overlayPixmap = QIcon::fromTheme(overlay).pixmap(QSize{overlaySize, overlaySize}, dpr, mode);
+ if (overlayPixmap.isNull()) {
+ continue;
+ }
+
+ QPoint startPoint;
+ switch (corner) {
+ case Qt::BottomLeftCorner:
+ startPoint = QPoint{0, height - overlaySize};
+ break;
+ case Qt::BottomRightCorner:
+ startPoint = QPoint{width - overlaySize, height - overlaySize};
+ break;
+ case Qt::TopRightCorner:
+ startPoint = QPoint{width - overlaySize, 0};
+ break;
+ case Qt::TopLeftCorner:
+ startPoint = QPoint{};
+ break;
+ }
+ painter.drawPixmap(startPoint, overlayPixmap);
+ }
+
+ return output;
+}
+