-BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block)
- : width(270), height(45)
- , name(name), block(block)
- , _proxy(this) {
- next[0] = NULL; next[1] = NULL;
- _proxy.setWidget(&_widget);
- _widget.setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::LinksAccessibleByMouse);
+class CustomQGraphicsTextItem : public QObject, public QGraphicsTextItem {
+public:
+ CustomQGraphicsTextItem(const QString& text, BasicBlockWidget* parent, Mainwindow* mainwindow)
+ : QGraphicsTextItem(text, parent), parent(parent), mainwindow(mainwindow) {}
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent*);
+private:
+ BasicBlockWidget* parent;
+ Mainwindow* mainwindow;
+};
+
+namespace {
+ void addComment(QTextTableCell cell, const QString& title) {
+ SimpleStringDialog dialog(title);
+ int result = dialog.exec();
+ if (QDialog::Accepted == result) {
+ // LOG4CXX_DEBUG(logger, "adding comment " << dialog.result().toStdString()
+ // << " at row " << cell.row());
+ cell.firstCursorPosition().insertHtml(QString(";; ") + dialog.result());
+ } else {
+ // LOG4CXX_DEBUG(logger, "addComment aborted");
+ }
+ }
+}
+
+void CustomQGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
+ QTextCursor c = textCursor();
+ c.setPosition(document()->documentLayout()->hitTest(event->pos(), Qt::FuzzyHit));
+ c.select(QTextCursor::WordUnderCursor);
+
+ QMenu menu;
+ bool ok;
+ uint64_t address = c.selectedText().toLongLong(&ok, 16);
+ if (ok) {
+ QAction* act = menu.addAction(c.selectedText() + " is a Function");
+ QObject::connect(act, &QAction::triggered,
+ [=]() {mainwindow->requestNewFunctionByAddress(address);});
+ }