From: Christoph Egger Date: Wed, 18 Feb 2015 15:38:18 +0000 (+0100) Subject: Add option to comment on instructions (in GUI) X-Git-Tag: v0.1~106 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=7d4bf581b5f2885d00a86f8a6235bc12fca10731;p=frida%2Ffrida.git Add option to comment on instructions (in GUI) --- 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/RenameFunctionDialog.cxx deleted file mode 100644 index 1cd6ceb..0000000 --- a/src/gui/dialogs/RenameFunctionDialog.cxx +++ /dev/null @@ -1,26 +0,0 @@ -#include "RenameFunctionDialog.hxx" - -RenameFunctionDialog::RenameFunctionDialog() { - QGridLayout * layout = new QGridLayout; - - edit = new QLineEdit; - layout->addWidget(edit, 0, 0, 1, 2); - - QPushButton * cancelButton = new QPushButton("Cancel"); - QPushButton * okButton = new QPushButton("OK"); - layout->addWidget(okButton, 1, 1, 1, 1); - connect(okButton, SIGNAL(clicked()), - this, SLOT(accept())); - layout->addWidget(cancelButton, 1, 0, 1, 1); - connect(cancelButton, SIGNAL(clicked()), - this, SLOT(reject())); - - setLayout(layout); - setWindowTitle("Add function"); -} - -QString RenameFunctionDialog::result() { - bool ok; - QString result = edit->text(); - return result; -} diff --git a/src/gui/dialogs/RenameFunctionDialog.hxx b/src/gui/dialogs/RenameFunctionDialog.hxx deleted file mode 100644 index 8c02828..0000000 --- a/src/gui/dialogs/RenameFunctionDialog.hxx +++ /dev/null @@ -1,11 +0,0 @@ -#include "gui/qt.hxx" - -class RenameFunctionDialog : public QDialog { - Q_OBJECT -public: - RenameFunctionDialog(); - - QString result(); -private: - QLineEdit * edit; -}; diff --git a/src/gui/dialogs/SimpleStringDialog.cxx b/src/gui/dialogs/SimpleStringDialog.cxx new file mode 100644 index 0000000..8bea6e9 --- /dev/null +++ b/src/gui/dialogs/SimpleStringDialog.cxx @@ -0,0 +1,26 @@ +#include "SimpleStringDialog.hxx" + +SimpleStringDialog::SimpleStringDialog(const QString& title) { + QGridLayout * layout = new QGridLayout; + + edit = new QLineEdit; + layout->addWidget(edit, 0, 0, 1, 2); + + QPushButton * cancelButton = new QPushButton("Cancel"); + QPushButton * okButton = new QPushButton("OK"); + layout->addWidget(okButton, 1, 1, 1, 1); + connect(okButton, SIGNAL(clicked()), + this, SLOT(accept())); + layout->addWidget(cancelButton, 1, 0, 1, 1); + connect(cancelButton, SIGNAL(clicked()), + this, SLOT(reject())); + + setLayout(layout); + setWindowTitle(title); +} + +QString SimpleStringDialog::result() { + bool ok; + QString result = edit->text(); + return result; +} diff --git a/src/gui/dialogs/SimpleStringDialog.hxx b/src/gui/dialogs/SimpleStringDialog.hxx new file mode 100644 index 0000000..4fbb26c --- /dev/null +++ b/src/gui/dialogs/SimpleStringDialog.hxx @@ -0,0 +1,11 @@ +#include "gui/qt.hxx" + +class SimpleStringDialog : public QDialog { + Q_OBJECT +public: + SimpleStringDialog(const QString& title); + + QString result(); +private: + QLineEdit * edit; +}; 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);