cutter/src/widgets/GraphWidget.cpp

95 lines
2.9 KiB
C++
Raw Normal View History

#include "core/MainWindow.h"
#include "GraphWidget.h"
#include "DisassemblerGraphView.h"
#include "WidgetShortcuts.h"
#include <QVBoxLayout>
2021-01-24 14:50:13 +00:00
GraphWidget::GraphWidget(MainWindow *main) : MemoryDockWidget(MemoryWidgetType::Graph, main)
{
2021-01-24 14:50:13 +00:00
setObjectName(main ? main->getUniqueObjectName(getWidgetType()) : getWidgetType());
setAllowedAreas(Qt::AllDockWidgetAreas);
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);
2021-01-24 14:50:13 +00:00
graphView = new DisassemblerGraphView(layoutWidget, seekable, main, { &syncAction });
layout->addWidget(graphView);
// Title needs to get set after graphView is defined
updateWindowTitle();
// getting the name of the class is implementation defined, and cannot be
// used reliably across different compilers.
2021-01-24 14:50:13 +00:00
// QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts[typeid(this).name()], main);
QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts["GraphWidget"], main);
2021-01-24 14:50:13 +00:00
connect(toggle_shortcut, &QShortcut::activated, this, [=]() { toggleDockWidget(true); });
2021-01-24 14:50:13 +00:00
connect(graphView, &DisassemblerGraphView::nameChanged, this,
&MemoryDockWidget::updateWindowTitle);
2021-01-24 14:50:13 +00:00
connect(this, &QDockWidget::visibilityChanged, this, [=](bool visibility) {
main->toggleOverview(visibility, this);
2018-03-21 20:32:32 +00:00
if (visibility) {
graphView->onSeekChanged(Core()->getOffset());
}
});
QAction *switchAction = new QAction(this);
switchAction->setShortcut(Qt::Key_Space);
switchAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
addAction(switchAction);
2021-01-24 14:50:13 +00:00
connect(switchAction, &QAction::triggered, this,
[this] { mainWindow->showMemoryWidget(MemoryWidgetType::Disassembly); });
2021-01-24 14:50:13 +00:00
connect(graphView, &DisassemblerGraphView::graphMoved, this,
[=]() { main->toggleOverview(true, this); });
connect(seekable, &CutterSeekable::seekableSeekChanged, this, &GraphWidget::prepareHeader);
connect(Core(), &CutterCore::functionRenamed, this, &GraphWidget::prepareHeader);
graphView->installEventFilter(this);
}
QWidget *GraphWidget::widgetToFocusOnRaise()
{
return graphView;
}
void GraphWidget::closeEvent(QCloseEvent *event)
{
CutterDockWidget::closeEvent(event);
emit graphClosed();
}
QString GraphWidget::getWindowTitle() const
{
return graphView->windowTitle;
}
DisassemblerGraphView *GraphWidget::getGraphView() const
{
return graphView;
}
QString GraphWidget::getWidgetType()
{
return "Graph";
}
void GraphWidget::prepareHeader()
{
2020-03-20 18:13:58 +00:00
QString afcf = Core()->cmdRawAt("afcf", seekable->getOffset()).trimmed();
if (afcf.isEmpty()) {
header->hide();
return;
}
header->show();
header->setText(afcf);
}