From 750027a03caf2018525b06ab957586f29627c547 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 13 Jun 2015 21:44:13 -0700 Subject: [PATCH] Qt: Memory viewer bounds and alignment fixes --- src/platform/qt/MemoryModel.cpp | 37 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/platform/qt/MemoryModel.cpp b/src/platform/qt/MemoryModel.cpp index 69fcbce09..4a33d0f7e 100644 --- a/src/platform/qt/MemoryModel.cpp +++ b/src/platform/qt/MemoryModel.cpp @@ -274,10 +274,10 @@ void MemoryModel::keyPressEvent(QKeyEvent* event) { nybble = key - Qt::Key_A + 10; break; case Qt::Key_Left: - adjustCursor(-1, event->modifiers() & Qt::ShiftModifier); + adjustCursor(-m_align, event->modifiers() & Qt::ShiftModifier); return; case Qt::Key_Right: - adjustCursor(1, event->modifiers() & Qt::ShiftModifier); + adjustCursor(m_align, event->modifiers() & Qt::ShiftModifier); return; case Qt::Key_Up: adjustCursor(-16, event->modifiers() & Qt::ShiftModifier); @@ -359,31 +359,48 @@ void MemoryModel::adjustCursor(int adjust, bool shift) { } if (shift) { if (m_selectionAnchor == m_selection.first) { + if (adjust < 0 && m_base - adjust > m_selection.second) { + adjust = m_base - m_selection.second + m_align; + } else if (adjust > 0 && m_selection.second + adjust > m_base + m_size) { + adjust = m_base + m_size - m_selection.second; + } adjust += m_selection.second; if (adjust <= m_selection.first) { - m_selection.second = m_selection.first + 1; - m_selection.first = adjust - 1; + m_selection.second = m_selection.first + m_align; + m_selection.first = adjust - m_align; } else { m_selection.second = adjust; } } else { + if (adjust < 0 && m_base - adjust > m_selection.first) { + adjust = m_base - m_selection.first; + } else if (adjust > 0 && m_selection.first + adjust > m_base + m_size) { + adjust = m_base + m_size - m_selection.first - m_align; + } adjust += m_selection.first; if (adjust >= m_selection.second) { - m_selection.first = m_selection.second - 1; - m_selection.second = adjust + 1; + m_selection.first = m_selection.second - m_align; + m_selection.second = adjust + m_align; } else { m_selection.first = adjust; } } } else { if (m_selectionAnchor == m_selection.first) { - m_selectionAnchor = m_selection.second + shift - 1; + m_selectionAnchor = m_selection.second - m_align; } else { - m_selectionAnchor = m_selection.first + shift; + m_selectionAnchor = m_selection.first; + } + if (adjust < 0 && m_base - adjust > m_selectionAnchor) { + m_selectionAnchor = m_base; + } else if (adjust > 0 && m_selectionAnchor + adjust > m_base + m_size) { + m_selectionAnchor = m_base + m_size - m_align; + } else { + m_selectionAnchor += adjust; } - m_selectionAnchor += adjust; m_selection.first = m_selectionAnchor; - m_selection.second = m_selection.first + 1; + m_selection.second = m_selection.first + m_align; } + emit selectionChanged(m_selection.first, m_selection.second); viewport()->update(); }