]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/BasicBlockWidget.cxx
Fix width of basic blocks
[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 , _proxy(this), name(name)
8 , block(block), mainwindow(mainwindow) {
9 next[0] = NULL; next[1] = NULL;
10 _widget.setStyleSheet("QWidget { background-color : #ddddff; }");
11 _widget.setLayout(&_layout);
12 _layout.setContentsMargins(0, 0, 0, 0);
13 _proxy.setWidget(&_widget);
14 _proxy.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
23 for (size_t i(0); i < num_bytes; ++i) {
24 const char * hexdigits = "0123456789ABCDEF";
25 bytestring += hexdigits[(bytes[i] >> 4) & 0xF];
26 bytestring += hexdigits[bytes[i] & 0xF];
27 bytestring += ' ';
28 }
29
30 int current_row = _layout.rowCount();
31 QLabel * bytestring_label = new QLabel(bytestring);
32 bytestring_label->setTextInteractionFlags(Qt::TextSelectableByMouse|
33 Qt::LinksAccessibleByMouse);
34 bytestring_label->setWordWrap(false);
35 _layout.addWidget(bytestring_label, current_row, 0);
36 bytestring_label->setVisible(true);
37
38 line = line.replace('\t', ' ').toHtmlEscaped();
39 if (href != "") {
40 line = "<a href=\"" + href + "\">" + line + "</a>";
41 }
42 QLabel * instruction_label = new QLabel(line);
43 instruction_label->setTextInteractionFlags(Qt::TextSelectableByMouse|
44 Qt::LinksAccessibleByMouse);
45 instruction_label->setWordWrap(false);
46 instruction_label->setFocusPolicy(Qt::StrongFocus);
47 if (href != "") {
48 QObject::connect(instruction_label, &QLabel::linkActivated,
49 [=](QString str) {
50 if (str.startsWith("function:")) {
51 QString address = str.remove("function:");
52 mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
53 }
54 });
55 }
56 _layout.addWidget(instruction_label, current_row, 1);
57 instruction_label->setVisible(true);
58
59 width = 12 + _widget.childrenRect().width();
60 height = 25 + _widget.childrenRect().height();
61
62 if (width < 250) width = 250;
63 _widget.resize(width - 12, height - 25);
64 }