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