CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
canloadpainter.h
Go to the documentation of this file.
1#ifndef __CANLOADPAINTER_H
2#define __CANLOADPAINTER_H
3
4#include "nodepainter.h"
5
6struct CanLoadPainter : public NodePainter {
7
8 CanLoadPainter(const QColor& headerColor, const uint8_t& load)
9 : NodePainter(headerColor)
10 , _load(load)
11 {
12 }
13
14 virtual void paint(QPainter* painter, QtNodes::NodeGeometry const& geom, QtNodes::NodeDataModel const* model,
15 QtNodes::NodeGraphicsObject const& graphicsObject) override
16 {
17 NodePainter::paint(painter, geom, model, graphicsObject);
18
19 QtNodes::NodeStyle const& nodeStyle = model->nodeStyle();
20 int s = 15;
21
22 painter->setPen(QPen(nodeStyle.FontColorFaded, 2));
23 painter->setBrush(Qt::NoBrush);
24
25 QFont font({ "Arial", 8 });
26 font.setBold(true);
27 painter->setFont(font);
28 QString val = QString::number(_load) + "%";
29 QFontMetrics metrics(font);
30 auto rect = metrics.boundingRect(val);
31
32 QPoint p(geom.width() / 2, geom.height() / 2 + 12);
33 painter->drawEllipse(p, s, s);
34
35 painter->setPen(nodeStyle.FontColor);
36 QPoint t(p.x() - rect.width() / 2 + 1, p.y() + 4);
37 painter->drawText(t, val);
38 }
39
40private:
41 const uint8_t& _load;
42};
43
44#endif /* !__CANLOADPAINTER_H */
Definition canloadpainter.h:6
CanLoadPainter(const QColor &headerColor, const uint8_t &load)
Definition canloadpainter.h:8
virtual void paint(QPainter *painter, QtNodes::NodeGeometry const &geom, QtNodes::NodeDataModel const *model, QtNodes::NodeGraphicsObject const &graphicsObject) override
Definition canloadpainter.h:14
Definition nodepainter.h:10
virtual void paint(QPainter *painter, QtNodes::NodeGeometry const &geom, QtNodes::NodeDataModel const *model, QtNodes::NodeGraphicsObject const &graphicsObject) override
Definition nodepainter.h:20