32#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
33 QJSValue styleValue = engine->singletonInstance<QJSValue>(styleTypeId);
34 if (styleValue.isNull() || !styleValue.isQObject()) {
35 qWarning() <<
"Unable to load Style object";
39 QObject* styleObject = styleValue.toQObject();
43 QQmlComponent comp(engine);
48 readonly property var styleObject: Style
53 qWarning() << Q_FUNC_INFO <<
"Failed to create style accessor component" << comp.errors();
57 auto item = comp.create();
59 qWarning() << Q_FUNC_INFO <<
"Failed to create component instance";
63 QObject* styleObject = item->property(
"styleObject").value<QObject*>();
67 _themeColor = QColor{styleObject->property(
"themeColor").toString()};
68 _textColor = QColor{styleObject->property(
"baseTextColor").toString()};
69 _themeContrastColor = QColor{styleObject->property(
"themeContrastTextColor").toString()};
70 _activeColor = QColor{styleObject->property(
"activeColor").toString()};
71 _destructiveColor = QColor{styleObject->property(
"destructiveActionColor").toString()};
76 QString path =
":/icon/" + id;
77 QColor c = _themeColor;
79 auto queryPos =
id.indexOf(
'?');
81 path =
":/icon/" +
id.left(queryPos);
82 const QString q =
id.mid(queryPos + 1);
83 if (q.startsWith(
'#')) {
85 }
else if (q ==
"text") {
87 }
else if (q ==
"themeContrast") {
88 c = _themeContrastColor;
89 }
else if (q ==
"active") {
91 }
else if (q ==
"destructive") {
92 c = _destructiveColor;
93 }
else if (q ==
"theme") {
96 qWarning() << Q_FUNC_INFO <<
"Unrecognized color specification:" << id;
100 QImage originalImage = QImage{path};
101 if (originalImage.isNull()) {
102 qWarning() << Q_FUNC_INFO <<
"Failed to load image:" << path;
106 if (!originalImage.isGrayscale()) {
107 qWarning() << Q_FUNC_INFO <<
"Source image is not a greyscale mask:" << path;
110 const int baseRed = c.red();
111 const int baseGreen = c.green();
112 const int baseBlue = c.blue();
113 *size = originalImage.size();
116 QImage colored{originalImage.size(), QImage::Format_ARGB32_Premultiplied};
117 const int width = size->width();
118 const int height = size->height();
120 for (
int y = 0; y < height; ++y) {
121 for (
int x = 0; x < width; ++x) {
123 const int alpha = originalImage.pixel(x, y);
124 colored.setPixel(x, y, qPremultiply(qRgba(baseRed, baseGreen, baseBlue, alpha)));