+ QTextTable* table = c.currentTable();
+ if (NULL != table) {
+ int row = table->cellAt(c).row();
+ QAction* globalComment = menu.addAction("Add global Comment");
+ QAction* localComment = menu.addAction("Add local Comment");
+
+ QObject::connect(globalComment, &QAction::triggered,
+ [=]() { addComment(row, true); });
+ QObject::connect(localComment, &QAction::triggered,
+ [=]() { addComment(row, false); });
+ }
+
+ menu.exec(event->screenPos());
+}
+
+BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block,
+ Mainwindow * mainwindow)
+ : width(270), height(45), name(name)
+ , _table(NULL)
+ , block(block), mainwindow(mainwindow)
+ , logger(log4cxx::Logger::getLogger("gui.BasicBlockWidget." + name.toStdString())) {
+ next[0] = NULL; next[1] = NULL;
+
+ block->getManager()->registerRenameFunctionEvent([=](RenameFunctionEvent* event) {updateFunctionName(event);});
+
+ _widget.reset(new CustomQGraphicsTextItem("", this));
+ _widget->setPos(5, 20);
+ _widget->setTextInteractionFlags(Qt::TextSelectableByMouse|
+ Qt::LinksAccessibleByMouse);
+
+ if (width < 250) width = 250;
+
+ QObject::connect(_widget.get(), &QGraphicsTextItem::linkActivated,
+ [=](QString str) {
+ if (str.startsWith("function:")) {
+ QString address = str.remove("function:");
+ mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
+ }
+ });
+ instructions = block->getInstructions();
+ populateWidget();
+ block->getManager()->registerChangeCommentEvent([=](ChangeCommentEvent* e) {changeCommentHandler(e);});
+}
+
+void BasicBlockWidget::updateFunctionName(RenameFunctionEvent *event) {
+ QString search = QString("function:") + QString::number(event->address, 16);
+ QTextDocument *document = _widget->document();
+ QTextBlock b = document->begin();
+ while (b.isValid()) {
+ for (QTextBlock::iterator i = b.begin(); !i.atEnd(); ++i) {
+ QTextCharFormat format = i.fragment().charFormat();
+ bool isLink = format.isAnchor();
+ if (isLink)
+ {
+ if (search == format.anchorHref()) {
+ LOG4CXX_DEBUG(logger, i.fragment().text().toStdString() << " ---> " << format.anchorHref().toStdString());
+ QTextCursor c(b);
+ c.setPosition(i.fragment().position());
+ c.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, i.fragment().length());
+ c.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, i.fragment().length());
+ c.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);
+ c.insertText(event->new_name.c_str());
+ }
+ }
+ }
+ b = b.next();