* @brief Decodes a base64-encoded SVG and renders it to a QImage. */
| 242 | * @brief Decodes a base64-encoded SVG and renders it to a QImage. |
| 243 | */ |
| 244 | QImage 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 | } |