From a90d1b24d3a126b8549797ec5c4d1572b3e4a452 Mon Sep 17 00:00:00 2001 From: mgr Date: Sun, 30 Sep 2018 23:51:49 +0200 Subject: [PATCH] Special copy for the binary editor including addresses, hex and ASCII #1485 Added a new copy action to the binary editor context menu for copying the selected text as seen by the user, instead of the stream of hexadecimal digits copied by default by qhexedit. In order to support copying from the context menu, qhexedit has been modified for not resetting the selection when the left mouse button is pressed. This will be converted to a pull request to qhexedit afterwards. See related issue #1485 --- libs/qhexedit/src/qhexedit.cpp | 15 +++++++++------ src/EditDialog.cpp | 7 +++++++ src/EditDialog.h | 1 + src/EditDialog.ui | 31 +++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/libs/qhexedit/src/qhexedit.cpp b/libs/qhexedit/src/qhexedit.cpp index 53798d63..417aa548 100644 --- a/libs/qhexedit/src/qhexedit.cpp +++ b/libs/qhexedit/src/qhexedit.cpp @@ -807,13 +807,16 @@ void QHexEdit::mouseMoveEvent(QMouseEvent * event) void QHexEdit::mousePressEvent(QMouseEvent * event) { - _blink = false; - viewport()->update(); - qint64 cPos = cursorPosition(event->pos()); - if (cPos >= 0) + if (event->button() != Qt::RightButton) { - resetSelection(cPos); - setCursorPosition(cPos); + _blink = false; + viewport()->update(); + qint64 cPos = cursorPosition(event->pos()); + if (cPos >= 0) + { + resetSelection(cPos); + setCursorPosition(cPos); + } } } diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 77936d8f..9c691199 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -19,6 +19,7 @@ #include #include #include +#include EditDialog::EditDialog(QWidget* parent) : QDialog(parent), @@ -58,6 +59,7 @@ EditDialog::EditDialog(QWidget* parent) // Add actions to editors that have a context menu based on actions. This also activates the shortcuts. ui->editorImage->addAction(ui->actionPrintImage); ui->editorBinary->addAction(ui->actionPrint); + ui->editorBinary->addAction(ui->actionCopyHexAscii); mustIndentAndCompact = Settings::getValue("databrowser", "indent_compact").toBool(); ui->buttonIndent->setChecked(mustIndentAndCompact); @@ -1085,3 +1087,8 @@ void EditDialog::openPrintImageDialog() delete dialog; } + +void EditDialog::copyHexAscii() +{ + QApplication::clipboard()->setText(hexEdit->selectionToReadableString()); +} diff --git a/src/EditDialog.h b/src/EditDialog.h index 4b1cba2e..3ec1efd5 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -45,6 +45,7 @@ private slots: void setMustIndentAndCompact(bool enable); void openPrintDialog(); void openPrintImageDialog(); + void copyHexAscii(); signals: void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& data, bool isBlob); diff --git a/src/EditDialog.ui b/src/EditDialog.ui index fff7d7ee..6a4910bc 100644 --- a/src/EditDialog.ui +++ b/src/EditDialog.ui @@ -339,6 +339,21 @@ Errors are indicated with a red squiggle underline. Ctrl+P + + + + :/icons/special_copy:/icons/special_copy + + + Copy Hex and ASCII + + + Copy selected hexadecimal and ASCII columns to the clipboard + + + Ctrl+Shift+C + + buttonExport @@ -508,6 +523,22 @@ Errors are indicated with a red squiggle underline. + + actionCopyHexAscii + triggered() + EditDialog + copyHexAscii() + + + -1 + -1 + + + 308 + 190 + + + importData()