Qt: MemoryModel keyboard navigation

This commit is contained in:
Jeffrey Pfau 2015-06-13 20:58:44 -07:00
parent e9d8f1ca46
commit de6808f3c8
2 changed files with 49 additions and 0 deletions

View File

@ -273,6 +273,18 @@ void MemoryModel::keyPressEvent(QKeyEvent* event) {
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 @@ void MemoryModel::drawEditingText(QPainter& painter, const QPointF& origin) {
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();
}

View File

@ -53,6 +53,8 @@ private:
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;