]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/BasicBlockWidget.hxx
30f2babce3ff260d84b0152b9987423739304408
[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 #include <tuple>
9 #include <array>
10
11 class BasicBlockWidget : public QGraphicsItem
12 {
13 public:
14 BasicBlockWidget(const QString& name, BasicBlock * block);
15
16 void addItem(uint8_t* bytes, size_t num_bytes, QString line, const QString& href);
17
18 QRectF boundingRect() const {
19 qreal penWidth = 1;
20 QRectF result(- penWidth / 2, - penWidth / 2,
21 width + penWidth, height + penWidth);
22 return result;
23 }
24
25 void mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
26 QGraphicsItem::mouseMoveEvent(event);
27 scene()->update();
28 }
29
30 QPointF getEntry() const {
31 return mapToScene(QPointF(width/2, 0));
32 }
33
34 std::array<QPointF, 3> getExits() const {
35 return { { mapToScene(QPointF( width/3, height)),
36 mapToScene(QPointF( width/2, height)),
37 mapToScene(QPointF(2*width/3, height)) } };
38 }
39
40 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
41 QWidget *widget) {
42 painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff));
43 painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
44 painter->drawRect(0, 0, width, height);
45 painter->drawText(5, 15, name);
46 }
47
48 void addPrevious(BasicBlockWidget * widget) {
49 previous.push_back(widget);
50 }
51
52 void addNext(BasicBlockWidget * left, BasicBlockWidget * right) {
53 next[0] = left;
54 next[1] = right;
55 }
56
57 BasicBlockWidget ** getNext() {
58 return next;
59 }
60
61 QString getName() const {
62 return name;
63 }
64 private:
65 uint32_t width, height;
66 QGraphicsProxyWidget _proxy;
67 QTableWidget _widget;
68 QString name;
69 BasicBlock * block;
70 std::vector<BasicBlockWidget*> previous;
71 BasicBlockWidget* next[2];
72 };
73
74 #endif