* @brief Renders an SVG at native DPI and source-in composites it with the requested tint. */
| 559 | * @brief Renders an SVG at native DPI and source-in composites it with the requested tint. |
| 560 | */ |
| 561 | QPixmap 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. |