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
This commit is contained in:
mgr
2018-09-30 23:51:49 +02:00
parent 1c06066258
commit a90d1b24d3
4 changed files with 48 additions and 6 deletions

View File

@@ -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);
}
}
}

View File

@@ -19,6 +19,7 @@
#include <QPrinter>
#include <QPrintPreviewDialog>
#include <QPainter>
#include <QClipboard>
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());
}

View File

@@ -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);

View File

@@ -339,6 +339,21 @@ Errors are indicated with a red squiggle underline.</string>
<string>Ctrl+P</string>
</property>
</action>
<action name="actionCopyHexAscii">
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/special_copy</normaloff>:/icons/special_copy</iconset>
</property>
<property name="text">
<string>Copy Hex and ASCII</string>
</property>
<property name="toolTip">
<string>Copy selected hexadecimal and ASCII columns to the clipboard</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+C</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>buttonExport</tabstop>
@@ -508,6 +523,22 @@ Errors are indicated with a red squiggle underline.</string>
</hint>
</hints>
</connection>
<connection>
<sender>actionCopyHexAscii</sender>
<signal>triggered()</signal>
<receiver>EditDialog</receiver>
<slot>copyHexAscii()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
<y>190</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>importData()</slot>