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