CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
nodepainter.h
Go to the documentation of this file.
1#ifndef __NODEPAINTER_H
2#define __NODEPAINTER_H
3
4#include <QPainter>
5#include <QtWidgets/QGraphicsEffect>
6#include <nodes/Node>
7#include <nodes/NodeDataModel>
8#include <nodes/NodePainterDelegate>
9
10struct NodePainter : public QtNodes::NodePainterDelegate {
11
12 NodePainter() = default;
13 virtual ~NodePainter() = default;
14
15 NodePainter(const QColor& headerColor)
16 : _headerColor(headerColor)
17 {
18 }
19
20 virtual void paint(QPainter* painter, QtNodes::NodeGeometry const& geom, QtNodes::NodeDataModel const* model,
21 QtNodes::NodeGraphicsObject const& graphicsObject) override
22 {
23 QtNodes::NodeStyle const& nodeStyle = model->nodeStyle();
24
25 auto color = nodeStyle.NormalBoundaryColor;
26
27 QPen p(color, nodeStyle.PenWidth);
28 painter->setPen(Qt::NoPen);
29 painter->setBrush(QBrush(_headerColor));
30
31 float diam = nodeStyle.ConnectionPointDiameter;
32
33 QRectF boundary;
34 QRectF boundary2;
35 double radius;
36 if (geom.hovered()) {
37 boundary = QRectF(-diam + 1, -diam + 1, 2.0 * diam + geom.width() - 2, 21);
38 boundary2 = QRectF(-diam + 1, -diam + 11, 2.0 * diam + geom.width() - 2, 12);
39 radius = 2.3;
40 } else if (graphicsObject.isSelected()) {
41 boundary = QRectF(-diam + 0.75, -diam + 0.75, 2.0 * diam + geom.width() - 1.5, 21.25);
42 boundary2 = QRectF(-diam + 0.75, -diam + 11, 2.0 * diam + geom.width() - 1.5, 12);
43 radius = 2.1;
44 } else {
45 boundary = QRectF(-diam - 0.75, -diam - 0.75, 2.0 * diam + geom.width() + 1.5, 22.75);
46 boundary2 = QRectF(-diam - 0.75, -diam + 11, 2.0 * diam + geom.width() + 1.5, 12);
47 radius = 3;
48 }
49
50 painter->drawRoundedRect(boundary, radius, radius);
51 painter->drawRect(boundary2);
52
53 painter->setPen({ Qt::white, 1 });
54 QFont font({ "Arial", 10 });
55 font.setBold(true);
56 painter->setFont(font);
57 painter->drawText(-diam + 6, -diam + 16, model->caption());
58 }
59
60private:
61 const QColor _headerColor;
62};
63
64#endif /* !__NODEPAINTER_H */
Definition nodepainter.h:10
NodePainter()=default
virtual ~NodePainter()=default
NodePainter(const QColor &headerColor)
Definition nodepainter.h:15
virtual void paint(QPainter *painter, QtNodes::NodeGeometry const &geom, QtNodes::NodeDataModel const *model, QtNodes::NodeGraphicsObject const &graphicsObject) override
Definition nodepainter.h:20