Distinguish single edges from double edges
[frida/frida.git] / src / gui / widgets / BasicBlockWidget.hxx
1 #ifndef INCLUDE__BasicBlockWidget_hxx
2 #define INCLUDE__BasicBlockWidget_hxx
3
4 #include "gui/qt.hxx"
5 #include "disassembler/BasicBlock.hxx"
6 #include <vector>
7 #include <cassert>
8
9 class BasicBlockWidget : public QGraphicsItem
10 {
11 public:
12 BasicBlockWidget(const QString& name, BasicBlock * block);
13
14 void addItem(uint8_t* bytes, size_t num_bytes, const QString& line);
15
16 QRectF boundingRect() const {
17 qreal penWidth = 1;
18 QRectF result(x - penWidth / 2, y - penWidth / 2,
19 dx + penWidth, dy + penWidth);
20
21
22 if (next[0]) {
23 if (next[1]) {
24 result |= QRectF(QPointF(x + dx/3, y+dy),
25 mapFromScene(next[0]->getEntry()));
26 } else {
27 result |= QRectF(QPointF(x + dx/2, y+dy),
28 mapFromScene(next[0]->getEntry()));
29 }
30 }
31 if (next[1])
32 result |= QRectF(QPointF(x + 2*dx/3, y+dy),
33 mapFromScene(next[1]->getEntry()));
34
35 return result;
36 }
37 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
38 QGraphicsItem::mouseMoveEvent(event);
39 std::for_each(previous.begin(), previous.end(),
40 [&] (BasicBlockWidget * item) {
41 item->update(boundingRect() | item->boundingRect());
42 });
43 }
44
45 QPointF getEntry() const {
46 return mapToScene(QPointF(x + dx/2, y));
47 }
48
49 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
50 QWidget *widget) {
51 painter->fillRect(x, y, dx, dy, QColor(0xcc, 0xcc, 0xff, 0xff));
52 painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
53 painter->drawRect(x, y, dx, dy);
54 painter->drawText(0, -5, name);
55 if (_widget.rowCount() != 0)
56 _widget.render(painter);
57
58 if (next[0]) {
59 if (next[1]) {
60 painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
61 painter->drawLine(QPointF(x + dx/3, y+dy),
62 mapFromScene(next[0]->getEntry()));
63 } else {
64 painter->setPen(QColor(0x00, 0x00, 0x00, 0xff));
65 painter->drawLine(QPointF(x + dx/2, y+dy),
66 mapFromScene(next[0]->getEntry()));
67 }
68 }
69 painter->setPen(QColor(0xff, 0x00, 0x00, 0xff));
70 if (next[1])
71 painter->drawLine(QPointF(x + 2*dx/3, y+dy),
72 mapFromScene(next[1]->getEntry()));
73
74 }
75
76 void addPrevious(BasicBlockWidget * widget) {
77 previous.push_back(widget);
78 }
79
80 void addNext(BasicBlockWidget * left, BasicBlockWidget * right) {
81 next[0] = left;
82 next[1] = right;
83 }
84
85 private:
86 int x, y, dx, dy;
87 QTableWidget _widget;
88 QString name;
89 BasicBlock * block;
90 std::vector<BasicBlockWidget*> previous;
91 BasicBlockWidget* next[2];
92 };
93
94 #endif