Navigate through graph view with arrows (#1441)

This commit is contained in:
optizone 2019-04-10 22:07:53 +03:00 committed by xarkes
parent 4673a23f05
commit 059723b013
3 changed files with 30 additions and 8 deletions

View File

@ -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();

View File

@ -5,6 +5,7 @@
#include <vector>
#include <QPainter>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QPropertyAnimation>
#ifndef QT_NO_OPENGL
@ -486,6 +487,33 @@ void GraphView::mouseDoubleClickEvent(QMouseEvent *event)
}
}
void GraphView::keyPressEvent(QKeyEvent* event)
{
const int delta = static_cast<int>(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

View File

@ -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();