]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/BasicBlockWidget.hxx
3c61121c75fa3da7f7e55894dc723c3f15e2e5be
[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 result |= QRectF(QPointF(x + dx/3, y+dy),
24 mapFromScene(next[0]->getEntry()));
25
26 if (next[1])
27 result |= QRectF(QPointF(x + 2*dx/3, y+dy),
28 mapFromScene(next[1]->getEntry()));
29
30 return result;
31 }
32 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
33 QGraphicsItem::mouseMoveEvent(event);
34 std::for_each(previous.begin(), previous.end(),
35 [&] (BasicBlockWidget * item) {
36 item->update(boundingRect() | item->boundingRect());
37 });
38 }
39
40 QPointF getEntry() const {
41 return mapToScene(QPointF(x + dx/2, y));
42 }
43
44 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
45 QWidget *widget) {
46 painter->fillRect(x, y, dx, dy, QColor(0xcc, 0xcc, 0xff, 0xff));
47 painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
48 painter->drawRect(x, y, dx, dy);
49 painter->drawText(0, -5, name);
50 if (_widget.rowCount() != 0)
51 _widget.render(painter);
52
53 painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
54 if (next[0])
55 painter->drawLine(QPointF(x + dx/3, y+dy),
56 mapFromScene(next[0]->getEntry()));
57
58 painter->setPen(QColor(0xff, 0x00, 0x00, 0xff));
59 if (next[1])
60 painter->drawLine(QPointF(x + 2*dx/3, y+dy),
61 mapFromScene(next[1]->getEntry()));
62
63 }
64
65 void addPrevious(BasicBlockWidget * widget) {
66 previous.push_back(widget);
67 }
68
69 void addNext(BasicBlockWidget * left, BasicBlockWidget * right) {
70 next[0] = left;
71 next[1] = right;
72 }
73
74 private:
75 int x, y, dx, dy;
76 QTableWidget _widget;
77 QString name;
78 BasicBlock * block;
79 std::vector<BasicBlockWidget*> previous;
80 BasicBlockWidget* next[2];
81 };
82
83 #endif