]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/BasicBlockWidget.cxx
Compactify BasicBlockWidget header
[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), name(name)
7 , _widget("", this), _table(NULL)
8 , block(block), mainwindow(mainwindow) {
9 next[0] = NULL; next[1] = NULL;
10 _widget.setPos(5, 20);
11 _widget.setTextInteractionFlags(Qt::TextSelectableByMouse|
12 Qt::LinksAccessibleByMouse);
13
14 if (width < 250) width = 250;
15 }
16
17 void BasicBlockWidget::addItem(uint8_t* bytes, size_t num_bytes,
18 QString line, const QString& href) {
19 QString bytestring;
20 int row;
21
22 if (_table) {
23 row = _table->rows();
24 _table->appendRows(1);
25 } else {
26 row = 0;
27 QTextTableFormat format;
28 format.setBorderStyle(QTextFrameFormat::BorderStyle_None);
29 format.setBorder(0);
30 _table = _widget.textCursor().insertTable(1, 3, format);
31 }
32
33 for (size_t i(0); i < num_bytes; ++i) {
34 const char * hexdigits = "0123456789ABCDEF";
35 bytestring += hexdigits[(bytes[i] >> 4) & 0xF];
36 bytestring += hexdigits[bytes[i] & 0xF];
37 bytestring += ' ';
38 }
39
40 _table->cellAt(row, 0).firstCursorPosition().insertText(bytestring);
41
42 line = line.replace('\t', ' ').toHtmlEscaped();
43 if (href != "") {
44 line = "<a href=\"" + href + "\">" + line + "</a>";
45 }
46
47 _table->cellAt(row, 1).firstCursorPosition().insertHtml(line);
48
49 QObject::connect(&_widget, &QGraphicsTextItem::linkActivated,
50 [=](QString str) {
51 if (str.startsWith("function:")) {
52 QString address = str.remove("function:");
53 mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
54 }
55 });
56
57 width = 10 + _widget.boundingRect().width();
58 height = 25 + _widget.boundingRect().height();
59
60 if (width < 250) width = 250;
61 }
62
63 void BasicBlockWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
64 QWidget *widget) {
65 painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff));
66 painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
67 painter->drawRect(0, 0, width, height);
68 painter->drawText(5, 15, name);
69 }
70
71 QRectF BasicBlockWidget::boundingRect() const {
72 qreal penWidth = 1;
73 QRectF result(- penWidth / 2, - penWidth / 2,
74 width + penWidth, height + penWidth);
75 return result;
76 }
77
78 std::array<QPointF, 3> BasicBlockWidget::getExits() const {
79 return { { mapToScene(QPointF( width/3, height)),
80 mapToScene(QPointF( width/2, height)),
81 mapToScene(QPointF(2*width/3, height)) } };
82 }
83