MCPcopy Create free account
hub / github.com/GENIVI/CANdevStudio / paint

Method paint

src/common/candbpainter.cpp:15–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13}
14
15void CanDbPainter::paint(QPainter* painter, QtNodes::NodeGeometry const& geom, QtNodes::NodeDataModel const* model,
16 QtNodes::NodeGraphicsObject const& graphicsObject)
17{
18 NodePainter::paint(painter, geom, model, graphicsObject);
19
20 QtNodes::NodeStyle const& nodeStyle = model->nodeStyle();
21
22 auto config = _component->getQConfig();
23 QString colorStr = config->property("color").toString();
24 if (colorStr.length() == 0) {
25 // Do not draw DB icon if DB is not set
26 return;
27 }
28
29 QColor gradientColor = QColor(colorStr);
30
31 if (nodeStyle.GradientColor0 == QColor("white")) {
32 _nodeColor = _lightColor;
33 } else {
34 _nodeColor = _darkColor;
35 }
36
37 if (_nodeColor != _prevNodeColor) {
38 _prevNodeColor = _nodeColor;
39
40 QFile f(":/images/files/images/db_icon.svg");
41
42 if (f.open(QFile::ReadOnly | QFile::Text)) {
43 QString tmp = QString::fromLatin1(f.readAll());
44 tmp = tmp.replace("fill:#000000", QString("fill:%1").arg(_nodeColor.name(QColor::HexRgb)));
45
46 _svg.load(tmp.toLatin1());
47 } else {
48 cds_error("Failed to load DB icon from resources");
49 }
50 }
51
52 QRectF svgRect((geom.width() - _s) / 2, (geom.height() - _s) / 2 + 12, _s, _s);
53 qreal innerMod = _s * 0.6;
54 QRectF innerEllipseRect(
55 (geom.width() - _s - innerMod) / 2, (geom.height() - _s - innerMod) / 2 + 12, _s + innerMod, _s + innerMod);
56 qreal outerMod = innerMod * 1.5;
57 QRectF outerEllipseRect(
58 (geom.width() - _s - outerMod) / 2, (geom.height() - _s - outerMod) / 2 + 12, _s + outerMod, _s + outerMod);
59
60 painter->setBrush(Qt::NoBrush);
61 painter->setPen(QPen(gradientColor, _s * 0.1));
62
63 painter->drawEllipse(outerEllipseRect);
64 painter->drawEllipse(innerEllipseRect);
65
66 _svg.render(painter, svgRect);
67}
68

Callers

nothing calls this directly

Calls 4

QStringClass · 0.85
getQConfigMethod · 0.45
nameMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected