2017-04-13 15:14:02 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
|
2017-10-02 16:18:40 +00:00
|
|
|
#include "CommentsWidget.h"
|
|
|
|
#include "ui_CommentsWidget.h"
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
CommentsWidget::CommentsWidget(MainWindow *main, QWidget *parent) :
|
2017-11-19 12:56:10 +00:00
|
|
|
QDockWidget(parent),
|
2017-04-13 15:14:02 +00:00
|
|
|
ui(new Ui::CommentsWidget),
|
|
|
|
main(main)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
ui->commentsTreeWidget->hideColumn(0);
|
2017-11-26 21:31:27 +00:00
|
|
|
ui->commentsTreeWidget->sortByColumn(3, Qt::AscendingOrder);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
QTabBar *tabs = ui->tabWidget->tabBar();
|
|
|
|
tabs->setVisible(false);
|
|
|
|
|
|
|
|
// Use a custom context menu on the dock title bar
|
|
|
|
//this->title_bar = this->titleBarWidget();
|
|
|
|
ui->actionHorizontal->setChecked(true);
|
|
|
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
|
|
|
|
this, SLOT(showTitleContextMenu(const QPoint &)));
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshTree()));
|
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshTree()));
|
2017-07-11 11:05:42 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
// Hide the buttons frame
|
|
|
|
ui->frame->hide();
|
|
|
|
}
|
|
|
|
|
2017-10-02 09:41:28 +00:00
|
|
|
CommentsWidget::~CommentsWidget() {}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(column);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
// Get offset and name of item double clicked
|
2017-04-28 13:09:40 +00:00
|
|
|
CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>();
|
2017-10-09 18:08:35 +00:00
|
|
|
CutterCore::getInstance()->seek(comment.offset);
|
|
|
|
//CutterCore::getInstance()->seek(comment.offset, comment.name, true);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommentsWidget::on_toolButton_clicked()
|
|
|
|
{
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommentsWidget::on_toolButton_2_clicked()
|
|
|
|
{
|
|
|
|
ui->tabWidget->setCurrentIndex(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommentsWidget::showTitleContextMenu(const QPoint &pt)
|
|
|
|
{
|
|
|
|
// Set functions popup menu
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
menu->clear();
|
|
|
|
menu->addAction(ui->actionHorizontal);
|
|
|
|
menu->addAction(ui->actionVertical);
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
if (ui->tabWidget->currentIndex() == 0)
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->actionHorizontal->setChecked(true);
|
|
|
|
ui->actionVertical->setChecked(false);
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->actionVertical->setChecked(true);
|
|
|
|
ui->actionHorizontal->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
menu->exec(this->mapToGlobal(pt));
|
|
|
|
delete menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommentsWidget::on_actionHorizontal_triggered()
|
|
|
|
{
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommentsWidget::on_actionVertical_triggered()
|
|
|
|
{
|
|
|
|
ui->tabWidget->setCurrentIndex(1);
|
|
|
|
}
|
|
|
|
|
2017-04-10 10:25:33 +00:00
|
|
|
void CommentsWidget::resizeEvent(QResizeEvent *event)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-13 15:51:58 +00:00
|
|
|
if (main->responsive && isVisible())
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-10 10:25:33 +00:00
|
|
|
if (event->size().width() >= event->size().height())
|
|
|
|
{
|
|
|
|
// Set horizontal view (list)
|
|
|
|
on_actionHorizontal_triggered();
|
|
|
|
}
|
|
|
|
else
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-10 10:25:33 +00:00
|
|
|
// Set vertical view (Tree)
|
|
|
|
on_actionVertical_triggered();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-10 10:25:33 +00:00
|
|
|
QDockWidget::resizeEvent(event);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-04-28 13:09:40 +00:00
|
|
|
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
void CommentsWidget::refreshTree()
|
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
ui->nestedCmtsTreeWidget->clear();
|
2017-10-09 18:08:35 +00:00
|
|
|
QList<CommentDescription> comments = CutterCore::getInstance()->getAllComments("CCu");
|
2017-04-28 13:09:40 +00:00
|
|
|
|
|
|
|
for (CommentDescription comment : comments)
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
//this->main->add_debug_output(RAddressString(comment.offset));
|
2017-10-09 18:08:35 +00:00
|
|
|
QString fcn_name = CutterCore::getInstance()->cmdFunctionAt(comment.offset);
|
2017-04-28 13:09:40 +00:00
|
|
|
QTreeWidgetItem *item = qhelpers::appendRow(ui->commentsTreeWidget, RAddressString(comment.offset), fcn_name, comment.name);
|
|
|
|
item->setData(0, Qt::UserRole, QVariant::fromValue(comment));
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
qhelpers::adjustColumns(ui->commentsTreeWidget);
|
|
|
|
|
|
|
|
// Add nested comments
|
|
|
|
ui->nestedCmtsTreeWidget->clear();
|
2017-10-09 18:08:35 +00:00
|
|
|
QMap<QString, QList<QList<QString>>> cmts = CutterCore::getInstance()->getNestedComments();
|
2017-04-13 15:14:02 +00:00
|
|
|
for (auto cmt : cmts.keys())
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedCmtsTreeWidget);
|
|
|
|
item->setText(0, cmt);
|
2017-04-28 13:09:40 +00:00
|
|
|
QList<QList<QString>> meow = cmts.value(cmt);
|
2017-04-13 15:14:02 +00:00
|
|
|
for (int i = 0; i < meow.size(); ++i)
|
|
|
|
{
|
2017-04-28 13:09:40 +00:00
|
|
|
QList<QString> tmp = meow.at(i);
|
2017-04-13 15:14:02 +00:00
|
|
|
QTreeWidgetItem *it = new QTreeWidgetItem();
|
|
|
|
it->setText(0, tmp[1]);
|
2017-04-28 13:09:40 +00:00
|
|
|
it->setText(1, tmp[0].remove('"'));
|
2017-04-13 15:14:02 +00:00
|
|
|
item->addChild(it);
|
|
|
|
}
|
|
|
|
ui->nestedCmtsTreeWidget->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
qhelpers::adjustColumns(ui->nestedCmtsTreeWidget);
|
|
|
|
}
|