aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2017-12-21 10:59:45 -0800
committerRoland Knall <rknall@gmail.com>2017-12-27 18:19:10 +0000
commite641846837477b6cefa3e70d25ee45f4713096b2 (patch)
treeaefc8a485bbd28e91e8af0c94ca6ea3ad7b22672 /ui/qt/widgets
parentf1edf22602cf5bdab93c4e1f6362419a0c261200 (diff)
Qt: Add "Copy as…" to the byte view.
Make ByteViewText an IDataPrintable and add "Copy as…" context menu actions. Remove some unused functions. Bug: 14276 Change-Id: Ie48c7c9b016de19fd8978397d03d23e9a7fe247a Reviewed-on: https://code.wireshark.org/review/24933 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/widgets')
-rw-r--r--ui/qt/widgets/byte_view_text.cpp42
-rw-r--r--ui/qt/widgets/byte_view_text.h19
2 files changed, 31 insertions, 30 deletions
diff --git a/ui/qt/widgets/byte_view_text.cpp b/ui/qt/widgets/byte_view_text.cpp
index 6a0e1b7046..e38b26ab57 100644
--- a/ui/qt/widgets/byte_view_text.cpp
+++ b/ui/qt/widgets/byte_view_text.cpp
@@ -18,7 +18,6 @@
#include "ui/recent.h"
#include <ui/qt/utils/data_printer.h>
-#include <ui/qt/utils/variant_pointer.h>
#include <QActionGroup>
#include <QMouseEvent>
@@ -37,10 +36,12 @@
Q_DECLARE_METATYPE(bytes_view_type)
Q_DECLARE_METATYPE(packet_char_enc)
+Q_DECLARE_METATYPE(DataPrinter::DumpType)
-ByteViewText::ByteViewText(QByteArray data, packet_char_enc encoding, QWidget *parent) :
+ByteViewText::ByteViewText(const QByteArray &data, packet_char_enc encoding, QWidget *parent) :
QAbstractScrollArea(parent),
layout_(new QTextLayout()),
+ data_(data),
encoding_(encoding),
hovered_byte_offset_(-1),
marked_byte_offset_(-1),
@@ -57,7 +58,6 @@ ByteViewText::ByteViewText(QByteArray data, packet_char_enc encoding, QWidget *p
font_width_(0),
line_height_(0)
{
- data_ = data;
layout_->setCacheEnabled(true);
offset_normal_fg_ = ColorUtils::alphaBlend(palette().windowText(), palette().window(), 0.35);
@@ -83,6 +83,10 @@ void ByteViewText::createContextMenu()
QActionGroup * format_actions_ = new QActionGroup(this);
QAction *action;
+ QActionGroup * copyEntries = DataPrinter::copyActions(this);
+ ctx_menu_.addActions(copyEntries->actions());
+ ctx_menu_.addSeparator();
+
action = format_actions_->addAction(tr("Show bytes as hexadecimal"));
action->setData(qVariantFromValue(BYTES_HEX));
action->setCheckable(true);
@@ -119,16 +123,6 @@ void ByteViewText::createContextMenu()
connect(encoding_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setCharacterEncoding(QAction*)));
}
-void ByteViewText::reset()
-{
- data_.clear();
-}
-
-QByteArray ByteViewText::viewData()
-{
- return data_;
-}
-
bool ByteViewText::isEmpty() const
{
return data_.isEmpty();
@@ -155,13 +149,6 @@ void ByteViewText::markField(int start, int length)
viewport()->update();
}
-void ByteViewText::moveToOffset(int pos)
-{
- scrollToByte(pos);
- viewport()->update();
-}
-
-
void ByteViewText::markAppendix(int start, int length)
{
field_a_start_ = start;
@@ -566,6 +553,21 @@ int ByteViewText::totalPixels()
return offsetPixels() + hexPixels() + asciiPixels();
}
+void ByteViewText::copyBytes(bool)
+{
+ QAction* action = qobject_cast<QAction*>(sender());
+ if (!action) {
+ return;
+ }
+
+ int dump_type = action->data().toInt();
+
+ if (dump_type <= DataPrinter::DP_Binary) {
+ DataPrinter printer;
+ printer.toClipboard((DataPrinter::DumpType) dump_type, this);
+ }
+}
+
// We do chunky (per-character) scrolling because it makes some of the
// math easier. Should we do smooth scrolling?
void ByteViewText::updateScrollbars()
diff --git a/ui/qt/widgets/byte_view_text.h b/ui/qt/widgets/byte_view_text.h
index 4da15e919f..c5abf8fab3 100644
--- a/ui/qt/widgets/byte_view_text.h
+++ b/ui/qt/widgets/byte_view_text.h
@@ -23,14 +23,17 @@
#include <QTextLayout>
#include <QVector>
+#include <ui/qt/utils/data_printer.h>
+
// XXX - Is there any reason we shouldn't add ByteViewImage, etc?
-class ByteViewText : public QAbstractScrollArea
+class ByteViewText : public QAbstractScrollArea, public IDataPrintable
{
Q_OBJECT
-public:
+ Q_INTERFACES(IDataPrintable)
- explicit ByteViewText(QByteArray data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = 0);
+public:
+ explicit ByteViewText(const QByteArray &data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = 0);
~ByteViewText();
virtual QSize minimumSizeHint() const;
@@ -38,23 +41,17 @@ public:
void setFormat(bytes_view_type format);
bool isEmpty() const;
- QByteArray viewData();
-
signals:
void byteHovered(int pos);
void byteSelected(int pos);
public slots:
- void reset();
-
void setMonospaceFont(const QFont &mono_font);
void markProtocol(int start, int length);
void markField(int start, int length);
void markAppendix(int start, int length);
- void moveToOffset(int pos);
-
protected:
virtual void paintEvent(QPaintEvent *);
virtual void resizeEvent(QResizeEvent *);
@@ -77,7 +74,7 @@ private:
} HighlightMode;
QTextLayout *layout_;
- QByteArray data_;
+ const QByteArray data_;
void drawLine(QPainter *painter, const int offset, const int row_y);
bool addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int start, int length, HighlightMode mode);
@@ -94,6 +91,7 @@ private:
int hexPixels();
int asciiPixels();
int totalPixels();
+ const QByteArray printableData() { return data_; }
static const int separator_interval_;
@@ -127,6 +125,7 @@ private:
QVector<int> x_pos_to_column_;
private slots:
+ void copyBytes(bool);
void setHexDisplayFormat(QAction *action);
void setCharacterEncoding(QAction *action);