From 059723b01344b3c464662fd67ff9315b20e14e3c Mon Sep 17 00:00:00 2001 From: optizone <42874998+optizone@users.noreply.github.com> Date: Wed, 10 Apr 2019 22:07:53 +0300 Subject: [PATCH] Navigate through graph view with arrows (#1441) --- src/widgets/DisassemblerGraphView.cpp | 8 -------- src/widgets/GraphView.cpp | 28 +++++++++++++++++++++++++++ src/widgets/GraphView.h | 2 ++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index d11d267b..89d9f9d5 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -91,12 +91,6 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent) QShortcut *shortcut_prev_instr = new QShortcut(QKeySequence(Qt::Key_K), this); shortcut_prev_instr->setContext(Qt::WidgetShortcut); connect(shortcut_prev_instr, SIGNAL(activated()), this, SLOT(prevInstr())); - QShortcut *shortcut_next_instr_arrow = new QShortcut(QKeySequence::MoveToNextLine, this); - shortcut_next_instr_arrow->setContext(Qt::WidgetShortcut); - connect(shortcut_next_instr_arrow, SIGNAL(activated()), this, SLOT(nextInstr())); - QShortcut *shortcut_prev_instr_arrow = new QShortcut(QKeySequence::MoveToPreviousLine, this); - shortcut_prev_instr_arrow->setContext(Qt::WidgetShortcut); - connect(shortcut_prev_instr_arrow, SIGNAL(activated()), this, SLOT(prevInstr())); shortcuts.append(shortcut_disassembly); shortcuts.append(shortcut_escape); shortcuts.append(shortcut_zoom_in); @@ -104,8 +98,6 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent) shortcuts.append(shortcut_zoom_reset); shortcuts.append(shortcut_next_instr); shortcuts.append(shortcut_prev_instr); - shortcuts.append(shortcut_next_instr_arrow); - shortcuts.append(shortcut_prev_instr_arrow); // Export Graph menu mMenu->addSeparator(); diff --git a/src/widgets/GraphView.cpp b/src/widgets/GraphView.cpp index 71f1a3c1..af57d748 100644 --- a/src/widgets/GraphView.cpp +++ b/src/widgets/GraphView.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #ifndef QT_NO_OPENGL @@ -486,6 +487,33 @@ void GraphView::mouseDoubleClickEvent(QMouseEvent *event) } } +void GraphView::keyPressEvent(QKeyEvent* event) +{ + const int delta = static_cast(30.0 / current_scale); + int dx = 0, dy = 0; + switch (event->key()) { + case Qt::Key_Up: + dy = -delta; + break; + case Qt::Key_Down: + dy = delta; + break; + case Qt::Key_Left: + dx = -delta; + break; + case Qt::Key_Right: + dx = delta; + break; + default: + QAbstractScrollArea::keyPressEvent(event); + return; + } + offset.rx() += dx; + offset.ry() += dy; + viewport()->update(); + event->accept(); +} + void GraphView::mouseReleaseEvent(QMouseEvent *event) { // TODO diff --git a/src/widgets/GraphView.h b/src/widgets/GraphView.h index 5943e141..8a573a39 100644 --- a/src/widgets/GraphView.h +++ b/src/widgets/GraphView.h @@ -87,6 +87,8 @@ protected: void mouseReleaseEvent(QMouseEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void paintEvent(QPaintEvent *event) override; void center();