From 7d4bf581b5f2885d00a86f8a6235bc12fca10731 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 18 Feb 2015 16:38:18 +0100 Subject: [PATCH] Add option to comment on instructions (in GUI) --- src/gui/Mainwindow.cxx | 4 +-- ...ctionDialog.cxx => SimpleStringDialog.cxx} | 8 ++--- ...ctionDialog.hxx => SimpleStringDialog.hxx} | 4 +-- src/gui/widgets/BasicBlockWidget.cxx | 36 ++++++++++++++++--- 4 files changed, 40 insertions(+), 12 deletions(-) rename src/gui/dialogs/{RenameFunctionDialog.cxx => SimpleStringDialog.cxx} (76%) rename src/gui/dialogs/{RenameFunctionDialog.hxx => SimpleStringDialog.hxx} (51%) diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 70d31d5..18dcc8b 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -4,7 +4,7 @@ #include "widgets/CFGScene.hxx" #include "dialogs/NewFunctionDialog.hxx" -#include "dialogs/RenameFunctionDialog.hxx" +#include "dialogs/SimpleStringDialog.hxx" #include @@ -140,7 +140,7 @@ void Mainwindow::requestNewFunctionByAddress(uint64_t address) { } void Mainwindow::renameFunction(QListWidgetItem * item) { - RenameFunctionDialog dialog; + SimpleStringDialog dialog("New name"); int result = dialog.exec(); if (QDialog::Accepted == result) { LOG4CXX_DEBUG(logger, "renaming Function " << item->text().toStdString() diff --git a/src/gui/dialogs/RenameFunctionDialog.cxx b/src/gui/dialogs/SimpleStringDialog.cxx similarity index 76% rename from src/gui/dialogs/RenameFunctionDialog.cxx rename to src/gui/dialogs/SimpleStringDialog.cxx index 1cd6ceb..8bea6e9 100644 --- a/src/gui/dialogs/RenameFunctionDialog.cxx +++ b/src/gui/dialogs/SimpleStringDialog.cxx @@ -1,6 +1,6 @@ -#include "RenameFunctionDialog.hxx" +#include "SimpleStringDialog.hxx" -RenameFunctionDialog::RenameFunctionDialog() { +SimpleStringDialog::SimpleStringDialog(const QString& title) { QGridLayout * layout = new QGridLayout; edit = new QLineEdit; @@ -16,10 +16,10 @@ RenameFunctionDialog::RenameFunctionDialog() { this, SLOT(reject())); setLayout(layout); - setWindowTitle("Add function"); + setWindowTitle(title); } -QString RenameFunctionDialog::result() { +QString SimpleStringDialog::result() { bool ok; QString result = edit->text(); return result; diff --git a/src/gui/dialogs/RenameFunctionDialog.hxx b/src/gui/dialogs/SimpleStringDialog.hxx similarity index 51% rename from src/gui/dialogs/RenameFunctionDialog.hxx rename to src/gui/dialogs/SimpleStringDialog.hxx index 8c02828..4fbb26c 100644 --- a/src/gui/dialogs/RenameFunctionDialog.hxx +++ b/src/gui/dialogs/SimpleStringDialog.hxx @@ -1,9 +1,9 @@ #include "gui/qt.hxx" -class RenameFunctionDialog : public QDialog { +class SimpleStringDialog : public QDialog { Q_OBJECT public: - RenameFunctionDialog(); + SimpleStringDialog(const QString& title); QString result(); private: diff --git a/src/gui/widgets/BasicBlockWidget.cxx b/src/gui/widgets/BasicBlockWidget.cxx index 586b707..454119e 100644 --- a/src/gui/widgets/BasicBlockWidget.cxx +++ b/src/gui/widgets/BasicBlockWidget.cxx @@ -1,6 +1,7 @@ #include "BasicBlockWidget.hxx" #include "CustomQGraphicsTextItem.hxx" #include "gui/Mainwindow.hxx" +#include "gui/dialogs/SimpleStringDialog.hxx" class CustomQGraphicsTextItem : public QObject, public QGraphicsTextItem { public: @@ -12,6 +13,20 @@ private: 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)); @@ -25,6 +40,20 @@ void CustomQGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* e QObject::connect(act, &QAction::triggered, [=]() {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()); } @@ -81,15 +110,14 @@ void BasicBlockWidget::addItem(uint8_t* bytes, size_t num_bytes, mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16)); } }); +} +void BasicBlockWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) { width = 10 + _widget->boundingRect().width(); height = 25 + _widget->boundingRect().height(); - if (width < 250) width = 250; -} -void BasicBlockWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) { painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff)); painter->setPen(QColor(0x00, 0x00, 0xff, 0xff)); painter->drawRect(0, 0, width, height); -- 2.39.5