| 436 | } |
| 437 | |
| 438 | void HexWidget::keyPressEvent(QKeyEvent *event) { |
| 439 | int addr = m_cursorOffset; |
| 440 | if (event->matches(QKeySequence::MoveToNextChar)) { |
| 441 | setCursorOffset(m_asciiEdit ? addr + 2 : addr + 1); |
| 442 | } else |
| 443 | if (event->matches(QKeySequence::MoveToPreviousChar)) { |
| 444 | setCursorOffset(m_asciiEdit ? addr - 2 : addr - 1); |
| 445 | } else |
| 446 | if (event->matches(QKeySequence::MoveToEndOfLine)) { |
| 447 | setCursorOffset(addr | (m_bytesPerLine * 2 - 1)); |
| 448 | } else |
| 449 | if (event->matches(QKeySequence::MoveToStartOfLine)) { |
| 450 | setCursorOffset(addr - (m_cursorOffset % (m_bytesPerLine * 2))); |
| 451 | } else |
| 452 | if (event->matches(QKeySequence::MoveToPreviousLine)) { |
| 453 | setCursorOffset(addr - m_bytesPerLine * 2); |
| 454 | } else |
| 455 | if (event->matches(QKeySequence::MoveToNextLine)) { |
| 456 | setCursorOffset(addr + m_bytesPerLine * 2); |
| 457 | } else |
| 458 | if (event->matches(QKeySequence::MoveToPreviousPage)) { |
| 459 | setCursorOffset(addr - (m_visibleRows - 1) * m_bytesPerLine * 2); |
| 460 | } else |
| 461 | if (event->matches(QKeySequence::MoveToNextPage)) { |
| 462 | setCursorOffset(addr + (m_visibleRows - 1) * m_bytesPerLine * 2); |
| 463 | } else |
| 464 | if (event->matches(QKeySequence::MoveToEndOfDocument)) { |
| 465 | setCursorOffset(m_size * 2); |
| 466 | } else |
| 467 | if (event->matches(QKeySequence::MoveToStartOfDocument)){ |
| 468 | setCursorOffset(0); |
| 469 | } else |
| 470 | if (event->matches(QKeySequence::Copy) && isSelected()) { |
| 471 | if (m_asciiEdit) { |
| 472 | QByteArray ba = m_data.mid(m_selectStart, m_selectLen); |
| 473 | QByteArray ascii; |
| 474 | for (const char ch : ba) { |
| 475 | ascii.append((ch < 0x20 || ch > 0x7e) ? '.' : ch); |
| 476 | } |
| 477 | ascii.append('\0'); |
| 478 | qApp->clipboard()->setText(ascii); |
| 479 | } else { |
| 480 | QByteArray ba = m_data.mid(m_selectStart, m_selectLen).toHex(); |
| 481 | qApp->clipboard()->setText(ba); |
| 482 | } |
| 483 | } else |
| 484 | if (event->matches(QKeySequence::Paste)) { |
| 485 | QByteArray ba = qApp->clipboard()->text().toLatin1(); |
| 486 | if (!m_asciiEdit) { |
| 487 | ba = QByteArray::fromHex(ba); |
| 488 | } |
| 489 | overwrite(addr, ba.size(), ba); |
| 490 | setCursorOffset(addr + ba.size() * 2); |
| 491 | } else |
| 492 | if (event->matches(QKeySequence::Delete)) { |
| 493 | if (isSelected()) { |
| 494 | setSelected(0); |
| 495 | } else { |
nothing calls this directly
no outgoing calls
no test coverage detected