Qt: Memory view scrolling with cursor

This commit is contained in:
Jeffrey Pfau 2015-06-13 22:05:49 -07:00
parent 750027a03c
commit edb91143d0
1 changed files with 12 additions and 0 deletions

View File

@ -357,6 +357,7 @@ void MemoryModel::adjustCursor(int adjust, bool shift) {
if (m_selection.first >= m_selection.second) { if (m_selection.first >= m_selection.second) {
return; return;
} }
int cursorPosition = m_top;
if (shift) { if (shift) {
if (m_selectionAnchor == m_selection.first) { if (m_selectionAnchor == m_selection.first) {
if (adjust < 0 && m_base - adjust > m_selection.second) { if (adjust < 0 && m_base - adjust > m_selection.second) {
@ -368,8 +369,10 @@ void MemoryModel::adjustCursor(int adjust, bool shift) {
if (adjust <= m_selection.first) { if (adjust <= m_selection.first) {
m_selection.second = m_selection.first + m_align; m_selection.second = m_selection.first + m_align;
m_selection.first = adjust - m_align; m_selection.first = adjust - m_align;
cursorPosition = m_selection.first;
} else { } else {
m_selection.second = adjust; m_selection.second = adjust;
cursorPosition = m_selection.second;
} }
} else { } else {
if (adjust < 0 && m_base - adjust > m_selection.first) { if (adjust < 0 && m_base - adjust > m_selection.first) {
@ -381,10 +384,13 @@ void MemoryModel::adjustCursor(int adjust, bool shift) {
if (adjust >= m_selection.second) { if (adjust >= m_selection.second) {
m_selection.first = m_selection.second - m_align; m_selection.first = m_selection.second - m_align;
m_selection.second = adjust + m_align; m_selection.second = adjust + m_align;
cursorPosition = m_selection.second;
} else { } else {
m_selection.first = adjust; m_selection.first = adjust;
cursorPosition = m_selection.first;
} }
} }
cursorPosition = (cursorPosition - m_base) / 16;
} else { } else {
if (m_selectionAnchor == m_selection.first) { if (m_selectionAnchor == m_selection.first) {
m_selectionAnchor = m_selection.second - m_align; m_selectionAnchor = m_selection.second - m_align;
@ -400,6 +406,12 @@ void MemoryModel::adjustCursor(int adjust, bool shift) {
} }
m_selection.first = m_selectionAnchor; m_selection.first = m_selectionAnchor;
m_selection.second = m_selection.first + m_align; m_selection.second = m_selection.first + m_align;
cursorPosition = (m_selectionAnchor - m_base) / 16;
}
if (cursorPosition < m_top) {
m_top = cursorPosition;
} else if (cursorPosition >= m_top + viewport()->size().height() / m_cellHeight - 1) {
m_top = cursorPosition - viewport()->size().height() / m_cellHeight + 2;
} }
emit selectionChanged(m_selection.first, m_selection.second); emit selectionChanged(m_selection.first, m_selection.second);
viewport()->update(); viewport()->update();