Qt: MemoryModel keyboard navigation
Jeffrey Pfau jeffrey@endrift.com
Sat, 13 Jun 2015 20:58:44 -0700
2 files changed,
49 insertions(+),
0 deletions(-)
M
src/platform/qt/MemoryModel.cpp
→
src/platform/qt/MemoryModel.cpp
@@ -273,6 +273,18 @@ case Qt::Key_E:
case Qt::Key_F: nybble = key - Qt::Key_A + 10; break; + case Qt::Key_Left: + adjustCursor(-1, event->modifiers() & Qt::ShiftModifier); + return; + case Qt::Key_Right: + adjustCursor(1, event->modifiers() & Qt::ShiftModifier); + return; + case Qt::Key_Up: + adjustCursor(-16, event->modifiers() & Qt::ShiftModifier); + return; + case Qt::Key_Down: + adjustCursor(16, event->modifiers() & Qt::ShiftModifier); + return; default: return; }@@ -340,3 +352,38 @@ }
o += QPointF(m_letterWidth * 2, 0); } } + +void MemoryModel::adjustCursor(int adjust, bool shift) { + if (m_selection.first >= m_selection.second) { + return; + } + if (shift) { + if (m_selectionAnchor == m_selection.first) { + adjust += m_selection.second; + if (adjust <= m_selection.first) { + m_selection.second = m_selection.first + 1; + m_selection.first = adjust - 1; + } else { + m_selection.second = adjust; + } + } else { + adjust += m_selection.first; + if (adjust >= m_selection.second) { + m_selection.first = m_selection.second - 1; + m_selection.second = adjust + 1; + } else { + m_selection.first = adjust; + } + } + } else { + if (m_selectionAnchor == m_selection.first) { + m_selectionAnchor = m_selection.second + shift - 1; + } else { + m_selectionAnchor = m_selection.first + shift; + } + m_selectionAnchor += adjust; + m_selection.first = m_selectionAnchor; + m_selection.second = m_selection.first + 1; + } + viewport()->update(); +}
M
src/platform/qt/MemoryModel.h
→
src/platform/qt/MemoryModel.h
@@ -53,6 +53,8 @@ bool isInSelection(uint32_t address);
bool isEditing(uint32_t address); void drawEditingText(QPainter& painter, const QPointF& origin); + void adjustCursor(int adjust, bool shift); + ARMCore* m_cpu; QFont m_font; int m_cellHeight;