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

Method renderColorizedSvg

app/src/Platform/CSD.cpp:561–592  ·  view source on GitHub ↗

* @brief Renders an SVG at native DPI and source-in composites it with the requested tint. */

Source from the content-addressed store, hash-verified

559 * @brief Renders an SVG at native DPI and source-in composites it with the requested tint.
560 */
561QPixmap Titlebar::renderColorizedSvg(const QString& svgPath,
562 const QSize& pixelSize,
563 const QRectF& logicalRect,
564 qreal dpr,
565 const QColor& iconColor) const
566{
567 QSvgRenderer renderer(svgPath);
568 if (!renderer.isValid())
569 return QPixmap();
570
571 QPixmap pixmap(pixelSize);
572 pixmap.setDevicePixelRatio(dpr);
573 pixmap.fill(Qt::transparent);
574
575 QPainter svgPainter(&pixmap);
576 svgPainter.setRenderHint(QPainter::Antialiasing);
577 svgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
578 renderer.render(&svgPainter, logicalRect);
579 svgPainter.end();
580
581 QPixmap colorized(pixelSize);
582 colorized.setDevicePixelRatio(dpr);
583 colorized.fill(Qt::transparent);
584
585 QPainter colorPainter(&colorized);
586 colorPainter.drawPixmap(0, 0, pixmap);
587 colorPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
588 colorPainter.fillRect(logicalRect, iconColor);
589 colorPainter.end();
590
591 return colorized;
592}
593
594/**
595 * @brief Draws a window control button with an SVG icon.

Callers

nothing calls this directly

Calls 4

fillRectMethod · 0.80
isValidMethod · 0.45
fillMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected