From 8f9f35e7d63a474ddf4f47ad28c02cf2c3db4d5b Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Wed, 25 May 2022 17:09:43 -0500 Subject: [PATCH] checkpoint --- src/SeerHexWidget.cpp | 32 +++++++++++++++++++++++++------- src/SeerHexWidget.ui | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/SeerHexWidget.cpp b/src/SeerHexWidget.cpp index 92fb585..2b41d74 100644 --- a/src/SeerHexWidget.cpp +++ b/src/SeerHexWidget.cpp @@ -71,7 +71,7 @@ SeerHexWidget::SeerHexWidget(QWidget* parent) : QWidget(parent), _pdata(NULL) { plainTextEdit->setFont(font); plainTextEdit->setFocusPolicy(Qt::StrongFocus); - plainTextEdit->setTextInteractionFlags(Qt::TextSelectableByMouse); + plainTextEdit->setTextInteractionFlags(Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse); _memoryMode = SeerHexWidget::HexMemoryMode; _charMode = SeerHexWidget::AsciiCharMode; @@ -310,20 +310,38 @@ void SeerHexWidget::handleByteOffsetChanged (int byte) { int pos_s = SeerHexWidget::HexFieldWidth + (pos * hexCharsPerByte()); int pos_e = pos_s + hexCharsPerByte() - 1; + int pos_a = SeerHexWidget::HexFieldWidth + hexCharsPerLine() + pos + 4; // 4 == ' ' .... ' | ' + + // Highlight the text in the hex region and the ascii region. QList extraSelections; { + // Get a cursor to the current line. QTextBlock block = plainTextEdit->document()->findBlockByLineNumber(line); QTextCursor cursor = QTextCursor(block); - cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, pos_s); - cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, pos_e - pos_s + 1); + // Highlight the current hex value. + cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, pos_s); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, pos_e - pos_s + 1); - QTextEdit::ExtraSelection extra; + // Add it to the extra selections. + QTextEdit::ExtraSelection extra_byte; + extra_byte.format.setBackground(plainTextEdit->palette().highlight().color()); + extra_byte.cursor = cursor; - extra.format.setBackground(plainTextEdit->palette().highlight().color()); - extra.cursor = cursor; + extraSelections.append(extra_byte); - extraSelections.append(extra); + // Highlight the current ascii value. + cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, pos_a); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1); + + // Add it to the extra selections. + QTextEdit::ExtraSelection extra_ascii; + extra_ascii.format.setBackground(plainTextEdit->palette().highlight().color()); + extra_ascii.cursor = cursor; + + extraSelections.append(extra_ascii); } plainTextEdit->setExtraSelections(extraSelections); diff --git a/src/SeerHexWidget.ui b/src/SeerHexWidget.ui index 022c289..2e21ed9 100644 --- a/src/SeerHexWidget.ui +++ b/src/SeerHexWidget.ui @@ -180,7 +180,7 @@ - Stream Length + Text Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter