70{
71 Q_UNUSED(event);
72
73 const qint32 border = 3;
74 const qint32 iconWidth = width() - (border*2);
75 const qint32 iconHeight = height() - (border*2);
76
77 auto makeIcon = [&](std::function<
void (QPainter &)> paintFn) {
78 QPixmap
pixmap(iconWidth * devicePixelRatioF(), iconHeight * devicePixelRatioF());
79 pixmap.setDevicePixelRatio(devicePixelRatioF());
82
83
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);
89
90 p.setClipRegion(clipRegion);
94 };
95
96 auto paintThumbnailIcon = [&](QPainter &
p) {
97 QImage img = QImage(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), QImage::Format_ARGB32);
98 img.setDevicePixelRatio(devicePixelRatioF());
101 QPainter paint2;
102 paint2.begin(&img);
106 }
107 }
108 } else {
109 img =
m_d->
thumbnail.scaled(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
110 }
111 p.drawImage(QRect(0, 0, iconWidth, iconHeight), img);
112 };
113
114 auto paintResourceIcon = [&](QPainter &
p) {
115 QImage img = QImage(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), QImage::Format_ARGB32);
116 img.setDevicePixelRatio(devicePixelRatioF());
119 QPainter paint2;
120 paint2.begin(&img);
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()) {
124 }
125 }
126 } else {
127 img =
m_d->
resource->image().scaled(iconWidth*devicePixelRatioF(), iconHeight*devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
128 }
129 p.drawImage(QRect(0, 0, iconWidth, iconHeight), img);
130 };
131
132 bool useCustomIcon = false;
133
138
140 if (isCachedPixmapOutdated) {
142 }
143 useCustomIcon = true;
147 }
148 useCustomIcon = true;
149 }
150
151 QStylePainter ps(this);
152 QStyleOptionToolButton opt;
153 initStyleOption(&opt);
154 if (useCustomIcon) {
155 opt.iconSize = QSize(iconWidth, iconHeight);
157 opt.toolButtonStyle = Qt::ToolButtonIconOnly;
158 }
159 ps.drawComplexControl(QStyle::CC_ToolButton, opt);
160}
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)