MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / requestImage

Method requestImage

app/src/Misc/IconEngine.cpp:244–278  ·  view source on GitHub ↗

* @brief Decodes a base64-encoded SVG and renders it to a QImage. */

Source from the content-addressed store, hash-verified

242 * @brief Decodes a base64-encoded SVG and renders it to a QImage.
243 */
244QImage Misc::ActionIconProvider::requestImage(const QString& id,
245 QSize* size,
246 const QSize& requestedSize)
247{
248 const auto svgData = QByteArray::fromBase64(id.toLatin1());
249 if (svgData.isEmpty()) {
250 if (size)
251 *size = QSize(0, 0);
252
253 return {};
254 }
255
256 QSvgRenderer renderer(svgData);
257 if (!renderer.isValid()) {
258 if (size)
259 *size = QSize(0, 0);
260
261 return {};
262 }
263
264 const int w = requestedSize.width() > 0 ? requestedSize.width() : 64;
265 const int h = requestedSize.height() > 0 ? requestedSize.height() : 64;
266
267 QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
268 image.fill(Qt::transparent);
269
270 QPainter painter(&image);
271 renderer.render(&painter);
272 painter.end();
273
274 if (size)
275 *size = image.size();
276
277 return image;
278}

Callers

nothing calls this directly

Calls 7

isEmptyMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
isValidMethod · 0.45
fillMethod · 0.45
renderMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected