]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/BasicBlockWidget.hxx
Remove grid
[frida/frida.git] / src / gui / widgets / BasicBlockWidget.hxx
1 #include "gui/qt.hxx"
2
3 class BasicBlockWidget : public QGraphicsItem
4 {
5 public:
6 BasicBlockWidget(const QString& name)
7 : x(-5), y(-20)
8 , dx(270), dy(45)
9 , name(name) {
10 _widget.setGridStyle(Qt::NoPen);
11 _widget.setMinimumHeight(_widget.rowHeight(0) + 10);
12 _widget.setMaximumHeight(20);
13 _widget.resizeColumnToContents(0);
14 _widget.resizeColumnToContents(1);
15 _widget.resizeColumnToContents(2);
16 _widget.updateGeometry();
17 _widget.setMaximumWidth(260);
18 _widget.setColumnCount(3);
19 _widget.verticalHeader()->hide();
20 _widget.horizontalHeader()->hide();
21 dx = _widget.rowHeight(0) + 20;
22 if (dx < 270) dx = 270;
23 }
24
25 void addItem(uint8_t* bytes, size_t num_bytes,
26 const QString& line) {
27 size_t current_row = _widget.rowCount();
28 int column_width;
29
30 QString bytestring;
31
32 for (size_t i(0); i < num_bytes; ++i) {
33 const char * hexdigits = "0123456789ABCDEF";
34 bytestring += hexdigits[(bytes[i] >> 4) & 0xF];
35 bytestring += hexdigits[bytes[i] & 0xF];
36 bytestring += ' ';
37 }
38
39 _widget.setRowCount(current_row + 1);
40
41 _widget.setItem(current_row, 0, new QTableWidgetItem(bytestring));
42 _widget.setItem(current_row, 1, new QTableWidgetItem(line));
43 _widget.setItem(current_row, 2, new QTableWidgetItem(""));
44 _widget.updateGeometry();
45
46 _widget.resizeColumnToContents(0);
47 _widget.resizeColumnToContents(1);
48 _widget.resizeColumnToContents(2);
49
50 _widget.resizeRowToContents(current_row);
51
52 column_width =
53 _widget.columnWidth(0) +
54 _widget.columnWidth(1) +
55 _widget.columnWidth(2) +
56 2;
57
58 _widget.setMinimumWidth(column_width);
59 _widget.setMinimumHeight(_widget.rowHeight(1) * (_widget.rowCount()) + 2);
60 _widget.setMaximumHeight(_widget.rowHeight(1) * (_widget.rowCount()) + 2);
61
62
63 dy = _widget.rowHeight(0) * (_widget.rowCount()) + 25;
64 dx = column_width + 10;
65 if (dx < 270) dx = 270;
66 }
67
68 QRectF boundingRect() const
69 {
70 qreal penWidth = 1;
71 return QRectF(x - penWidth / 2, y - penWidth / 2,
72 dx + penWidth, dy + penWidth);
73 }
74
75 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
76 QWidget *widget)
77 {
78 painter->fillRect(x, y, dx, dy, QColor(0xcc, 0xcc, 0xff, 0xff));
79 painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
80 painter->drawRect(x, y, dx, dy);
81 painter->drawText(0, -5, name);
82 _widget.render(painter);
83 }
84 private:
85 int x, y, dx, dy;
86 QTableWidget _widget;
87 QString name;
88 };