73 const qint32 border = 3;
74 const qint32 iconWidth = width() - (border*2);
75 const qint32 iconHeight = height() - (border*2);
77 auto makeIcon = [&](std::function<
void (QPainter &)> paintFn) {
78 QPixmap pixmap(iconWidth * devicePixelRatioF(), iconHeight * devicePixelRatioF());
79 pixmap.setDevicePixelRatio(devicePixelRatioF());
84 QRegion clipRegion(0, 0, iconWidth, iconHeight);
85 clipRegion -= QRegion(0, 0, 1, 1);
86 clipRegion -= QRegion(iconWidth - 1, 0, 1, 1);
87 clipRegion -= QRegion(iconWidth - 1, iconHeight - 1, 1, 1);
88 clipRegion -= QRegion(0, iconHeight - 1, 1, 1);
90 p.setClipRegion(clipRegion);
96 auto paintThumbnailIcon = [&](QPainter &
p) {
97 QImage img = QImage(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), QImage::Format_ARGB32);
98 img.setDevicePixelRatio(devicePixelRatioF());
103 for (
int x = 0; x < iconWidth; x +=
m_d->
thumbnail.width()) {
104 for (
int y = 0; y < iconHeight; y+=
m_d->
thumbnail.height()) {
109 img =
m_d->
thumbnail.scaled(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
111 p.drawImage(QRect(0, 0, iconWidth, iconHeight), img);
114 auto paintResourceIcon = [&](QPainter &
p) {
115 QImage img = QImage(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), QImage::Format_ARGB32);
116 img.setDevicePixelRatio(devicePixelRatioF());
121 for (
int x = 0; x < iconWidth; x +=
m_d->
resource->image().width()) {
122 for (
int y = 0; y < iconHeight; y +=
m_d->
resource->image().height()) {
127 img =
m_d->
resource->image().scaled(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
129 p.drawImage(QRect(0, 0, iconWidth, iconHeight), img);
132 bool useCustomIcon =
false;
140 if (isCachedPixmapOutdated) {
143 useCustomIcon =
true;
148 useCustomIcon =
true;
151 QStylePainter ps(
this);
152 QStyleOptionToolButton opt;
153 initStyleOption(&opt);
155 opt.iconSize = QSize(iconWidth, iconHeight);
157 opt.toolButtonStyle = Qt::ToolButtonIconOnly;
159 ps.drawComplexControl(QStyle::CC_ToolButton, opt);