2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2018-03-16 21:46:57 +00:00
|
|
|
#include "GraphWidget.h"
|
|
|
|
#include "DisassemblerGraphView.h"
|
2018-10-16 06:25:09 +00:00
|
|
|
#include "WidgetShortcuts.h"
|
2019-06-29 06:28:35 +00:00
|
|
|
#include <QVBoxLayout>
|
2018-03-16 21:46:57 +00:00
|
|
|
|
2019-02-19 15:56:50 +00:00
|
|
|
GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
|
2019-07-19 19:21:12 +00:00
|
|
|
MemoryDockWidget(MemoryWidgetType::Graph, main, action)
|
2018-03-16 21:46:57 +00:00
|
|
|
{
|
2019-06-20 14:28:35 +00:00
|
|
|
setObjectName(main
|
|
|
|
? main->getUniqueObjectName(getWidgetType())
|
|
|
|
: getWidgetType());
|
2019-06-18 17:57:07 +00:00
|
|
|
|
2019-03-18 06:44:14 +00:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
2019-06-29 06:28:35 +00:00
|
|
|
|
|
|
|
auto *layoutWidget = new QWidget(this);
|
|
|
|
setWidget(layoutWidget);
|
|
|
|
auto *layout = new QVBoxLayout(layoutWidget);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layoutWidget->setLayout(layout);
|
|
|
|
|
|
|
|
header = new QLineEdit(this);
|
|
|
|
header->setReadOnly(true);
|
|
|
|
layout->addWidget(header);
|
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
graphView = new DisassemblerGraphView(layoutWidget, seekable, main);
|
2019-06-29 06:28:35 +00:00
|
|
|
layout->addWidget(graphView);
|
2018-03-16 21:46:57 +00:00
|
|
|
|
2018-10-16 06:25:09 +00:00
|
|
|
// getting the name of the class is implementation defined, and cannot be
|
|
|
|
// used reliably across different compilers.
|
|
|
|
//QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts[typeid(this).name()], main);
|
|
|
|
QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts["GraphWidget"], main);
|
2018-10-16 14:49:26 +00:00
|
|
|
connect(toggle_shortcut, &QShortcut::activated, this, [ = ]() {
|
2018-10-16 06:25:09 +00:00
|
|
|
toggleDockWidget(true);
|
2018-10-16 14:49:26 +00:00
|
|
|
});
|
2018-10-16 06:25:09 +00:00
|
|
|
|
2019-06-18 13:02:41 +00:00
|
|
|
connect(graphView, &DisassemblerGraphView::nameChanged, this, &MemoryDockWidget::updateWindowTitle);
|
|
|
|
|
2018-10-16 14:49:26 +00:00
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [ = ](bool visibility) {
|
2019-02-19 15:56:50 +00:00
|
|
|
main->toggleOverview(visibility, this);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (visibility) {
|
2019-03-18 06:44:14 +00:00
|
|
|
graphView->onSeekChanged(Core()->getOffset());
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
QAction *switchAction = new QAction(this);
|
|
|
|
switchAction->setShortcut(Qt::Key_Space);
|
|
|
|
switchAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
addAction(switchAction);
|
|
|
|
connect(switchAction, &QAction::triggered, this, [this] {
|
|
|
|
mainWindow->showMemoryWidget(MemoryWidgetType::Disassembly);
|
|
|
|
});
|
|
|
|
|
2019-02-19 15:56:50 +00:00
|
|
|
connect(graphView, &DisassemblerGraphView::graphMoved, this, [ = ]() {
|
|
|
|
main->toggleOverview(true, this);
|
2019-01-24 17:13:04 +00:00
|
|
|
});
|
2019-06-29 06:28:35 +00:00
|
|
|
connect(seekable, &CutterSeekable::seekableSeekChanged, this, &GraphWidget::prepareHeader);
|
|
|
|
connect(Core(), &CutterCore::functionRenamed, this, &GraphWidget::prepareHeader);
|
2019-07-19 19:21:12 +00:00
|
|
|
graphView->installEventFilter(this);
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 08:24:54 +00:00
|
|
|
QWidget *GraphWidget::widgetToFocusOnRaise()
|
|
|
|
{
|
|
|
|
return graphView;
|
|
|
|
}
|
2019-02-24 07:15:40 +00:00
|
|
|
|
|
|
|
void GraphWidget::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
CutterDockWidget::closeEvent(event);
|
2019-04-14 12:18:24 +00:00
|
|
|
emit graphClosed();
|
2019-02-24 07:15:40 +00:00
|
|
|
}
|
2019-03-27 08:24:54 +00:00
|
|
|
|
2019-06-18 13:02:41 +00:00
|
|
|
QString GraphWidget::getWindowTitle() const
|
|
|
|
{
|
|
|
|
return graphView->windowTitle;
|
|
|
|
}
|
|
|
|
|
2019-03-27 08:24:54 +00:00
|
|
|
DisassemblerGraphView *GraphWidget::getGraphView() const
|
|
|
|
{
|
|
|
|
return graphView;
|
|
|
|
}
|
2019-06-18 13:02:41 +00:00
|
|
|
|
|
|
|
QString GraphWidget::getWidgetType()
|
|
|
|
{
|
|
|
|
return "Graph";
|
|
|
|
}
|
2019-06-29 06:28:35 +00:00
|
|
|
|
|
|
|
void GraphWidget::prepareHeader()
|
|
|
|
{
|
|
|
|
QString afcf = Core()->cmd(QString("afcf @%1").arg(seekable->getOffset())).trimmed();
|
|
|
|
if (afcf.isEmpty()) {
|
|
|
|
header->hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
header->show();
|
|
|
|
header->setText(afcf);
|
|
|
|
}
|
|
|
|
|