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