Binary editor: Support ctrl+(page)up/down

Only scroll without changing the cursor position when pressing ctrl.

Task-number: QTCREATORBUG-11386
Change-Id: I850da6f42696d6b5d9db488562aa56903c4ce970
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Eike Ziller
2015-03-17 11:25:36 +01:00
parent d0835af5f9
commit 887d8809c9

View File

@@ -1279,11 +1279,18 @@ void BinEditorWidget::keyPressEvent(QKeyEvent *e)
MoveMode moveMode = e->modifiers() & Qt::ShiftModifier ? KeepAnchor : MoveAnchor;
bool ctrlPressed = e->modifiers() & Qt::ControlModifier;
switch (e->key()) {
case Qt::Key_Up:
if (ctrlPressed)
verticalScrollBar()->triggerAction(QScrollBar::SliderSingleStepSub);
else
setCursorPosition(m_cursorPosition - m_bytesPerLine, moveMode);
break;
case Qt::Key_Down:
if (ctrlPressed)
verticalScrollBar()->triggerAction(QScrollBar::SliderSingleStepAdd);
else
setCursorPosition(m_cursorPosition + m_bytesPerLine, moveMode);
break;
case Qt::Key_Right:
@@ -1297,12 +1304,13 @@ void BinEditorWidget::keyPressEvent(QKeyEvent *e)
int line = qMax(0, m_cursorPosition / m_bytesPerLine - verticalScrollBar()->value());
verticalScrollBar()->triggerAction(e->key() == Qt::Key_PageUp ?
QScrollBar::SliderPageStepSub : QScrollBar::SliderPageStepAdd);
if (!ctrlPressed)
setCursorPosition((verticalScrollBar()->value() + line) * m_bytesPerLine + m_cursorPosition % m_bytesPerLine, moveMode);
} break;
case Qt::Key_Home: {
int pos;
if (e->modifiers() & Qt::ControlModifier)
if (ctrlPressed)
pos = 0;
else
pos = m_cursorPosition/m_bytesPerLine * m_bytesPerLine;
@@ -1310,7 +1318,7 @@ void BinEditorWidget::keyPressEvent(QKeyEvent *e)
} break;
case Qt::Key_End: {
int pos;
if (e->modifiers() & Qt::ControlModifier)
if (ctrlPressed)
pos = m_size;
else
pos = m_cursorPosition/m_bytesPerLine * m_bytesPerLine + 15;