-
Notifications
You must be signed in to change notification settings - Fork 33
/
svgimageprovider.cpp
41 lines (30 loc) · 1.04 KB
/
svgimageprovider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "svgimageprovider.h"
SvgImageProvider::SvgImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{
}
QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
Q_UNUSED(requestedSize);
QImage image;
if (id.startsWith("svg_icon_color_change:")) {
QStringList parts = id.split(':');
if (parts.size() == 3) {
QString svgFilePath = parts[1];
QString color = parts[2];
QSvgRenderer renderer(svgFilePath);
QSize imageSize = renderer.defaultSize();
if (size) {
*size = imageSize;
}
image = QImage(imageSize, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
QColor iconColor(color);
painter.setBrush(iconColor);
renderer.render(&painter);
}
}
return image;
}