-BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block)
- : width(270), height(45)
- , name(name), block(block) {
- next[0] = NULL; next[1] = NULL;
- _widget.move(5, 20);
- _widget.setGridStyle(Qt::NoPen);
- _widget.setMinimumHeight(_widget.rowHeight(0) + 10);
- _widget.setMaximumHeight(20);
- _widget.resizeColumnToContents(0);
- _widget.resizeColumnToContents(1);
- _widget.resizeColumnToContents(2);
- _widget.updateGeometry();
- _widget.setMaximumWidth(260);
- _widget.setColumnCount(3);
- _widget.verticalHeader()->hide();
- _widget.horizontalHeader()->hide();
- width = _widget.rowHeight(0) + 20;
- if (width < 270) width = 270;
+class CustomQGraphicsTextItem : public QObject, public QGraphicsTextItem {
+public:
+ CustomQGraphicsTextItem(const QString& text, BasicBlockWidget* parent)
+ : QGraphicsTextItem(text, parent), parent(parent) {}
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent*);
+private:
+ void addComment(QTextTableCell cell, const QString& title);
+
+ BasicBlockWidget* parent;
+};
+
+void CustomQGraphicsTextItem::addComment(QTextTableCell cell, const QString& title) {
+ SimpleStringDialog dialog(title);
+ int result = dialog.exec();
+ if (QDialog::Accepted == result) {
+ LOG4CXX_DEBUG(parent->logger, "adding comment " << dialog.result().toStdString()
+ << " at row " << cell.row());
+ cell.firstCursorPosition().insertHtml(QString(";; ") + dialog.result());
+ } else {
+ LOG4CXX_DEBUG(parent->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,
+ [=]() {parent->mainwindow->requestNewFunctionByAddress(address);});
+ }
+
+ QTextTable* table = c.currentTable();
+ if (NULL != table) {
+ int row = table->cellAt(c).row();
+ QTextTableCell cell = table->cellAt(row, 2);
+ QAction* globalComment = menu.addAction("Add global Comment");
+ QAction* localComment = menu.addAction("Add local Comment");
+
+ QObject::connect(globalComment, &QAction::triggered,
+ [=]() { addComment(cell, "Global comment"); });
+ QObject::connect(localComment, &QAction::triggered,
+ [=]() { addComment(cell, "Local comment"); });
+ }
+
+ menu.exec(event->screenPos());