Switch again BasicBlockWidget base -- to QGraphicsTextItem
[frida/frida.git] / src / gui / widgets / BasicBlockWidget.cxx
1 #include "BasicBlockWidget.hxx"
2 #include "gui/Mainwindow.hxx"
3
4 BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block,
5 Mainwindow * mainwindow)
6 : width(270), height(45)
7 , _widget("", this)
8 , _table(NULL), name(name)
9 , block(block), mainwindow(mainwindow) {
10 next[0] = NULL; next[1] = NULL;
11 _widget.setTextInteractionFlags(Qt::TextSelectableByMouse|
12 Qt::LinksAccessibleByMouse);
13
14 _widget.setPos(5, 20);
15
16 if (width < 250) width = 250;
17 }
18
19 void BasicBlockWidget::addItem(uint8_t* bytes, size_t num_bytes,
20 QString line, const QString& href) {
21 QString bytestring;
22 int row;
23
24 if (_table) {
25 row = _table->rows();
26 _table->appendRows(1);
27 } else {
28 row = 0;
29 QTextTableFormat format;
30 format.setBorderStyle(QTextFrameFormat::BorderStyle_None);
31 format.setBorder(0);
32 _table = _widget.textCursor().insertTable(1, 3, format);
33 }
34
35 for (size_t i(0); i < num_bytes; ++i) {
36 const char * hexdigits = "0123456789ABCDEF";
37 bytestring += hexdigits[(bytes[i] >> 4) & 0xF];
38 bytestring += hexdigits[bytes[i] & 0xF];
39 bytestring += ' ';
40 }
41
42 _table->cellAt(row, 0).firstCursorPosition().insertText(bytestring);
43
44 line = line.replace('\t', ' ').toHtmlEscaped();
45 if (href != "") {
46 line = "<a href=\"" + href + "\">" + line + "</a>";
47 }
48
49 _table->cellAt(row, 1).firstCursorPosition().insertHtml(line);
50
51 QObject::connect(&_widget, &QGraphicsTextItem::linkActivated,
52 [=](QString str) {
53 if (str.startsWith("function:")) {
54 QString address = str.remove("function:");
55 mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
56 }
57 });
58
59 width = 10 + _widget.boundingRect().width();
60 height = 25 + _widget.boundingRect().height();
61
62 if (width < 250) width = 250;
63 }