+ 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(200), height(45), name(name)
+ , currentColor(defaultColor), _table(NULL)
+ , block(block), mainwindow(mainwindow)
+ , logger(log4cxx::Logger::getLogger("gui.BasicBlockWidget." + name.toStdString())) {
+ next[0] = NULL; next[1] = NULL;
+
+ QObject::connect(block->getManager(), &InformationManager::renameFunctionEvent,
+ [=](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));
+ } else if (str.startsWith("block:")) {
+ QString address = str.remove("block:");
+
+ /* next[0] is always the jumptarget. On a
+ * conditional jump, next[1] also
+ * contains the following instruction
+ *
+ * TODO: Verify we're switching to the
+ * right block -- the target
+ * address matches the next blocks
+ * start address
+ */
+ LOG4CXX_TRACE(logger, "Highlighting block at Address " << address.toStdString()
+ << " BasicBlockWidget " << std::hex << next[0]);
+ ((CFGScene*)this->scene())->highlightBlock(next[0]);
+ }
+ });
+ instructions = block->getInstructions();
+ populateWidget();
+ QObject::connect(block->getManager(), &InformationManager::changeCommentEvent,
+ [=](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());
+
+ /* This should select the function name. It stars
+ * by selecting the whole link fragment from back
+ * to front and then moves one word to the back
+ * again deselecting whatever mnemonic is used for
+ * the call instruction.
+ */
+ 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());
+
+ QGraphicsTextItem* item = _widget.get();
+ item->adjustSize();
+ }
+ }
+ }
+ b = b.next();