2012-01-04 22:13:01 +00:00
|
|
|
/* byte_view_text.h
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2016-11-25 18:50:46 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-01-04 22:13:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BYTE_VIEW_TEXT_H
|
|
|
|
#define BYTE_VIEW_TEXT_H
|
|
|
|
|
2015-04-26 17:21:09 +00:00
|
|
|
#include <config.h>
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2015-12-17 19:41:46 +00:00
|
|
|
#include "ui/recent.h"
|
2014-10-24 20:24:23 +00:00
|
|
|
|
|
|
|
#include <QAbstractScrollArea>
|
2017-10-25 13:39:35 +00:00
|
|
|
#include <QFont>
|
2016-11-25 18:50:46 +00:00
|
|
|
#include <QVector>
|
2014-10-27 17:28:45 +00:00
|
|
|
#include <QMenu>
|
2016-11-25 18:50:46 +00:00
|
|
|
#include <QSize>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTextLayout>
|
|
|
|
#include <QVector>
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
// XXX - Is there any reason we shouldn't add ByteViewImage, etc?
|
|
|
|
|
2014-10-24 20:24:23 +00:00
|
|
|
class ByteViewText : public QAbstractScrollArea
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-10-25 13:39:35 +00:00
|
|
|
|
|
|
|
explicit ByteViewText(QByteArray data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = 0);
|
2015-12-22 13:51:08 +00:00
|
|
|
~ByteViewText();
|
2017-10-25 13:39:35 +00:00
|
|
|
|
2017-03-02 21:10:36 +00:00
|
|
|
virtual QSize minimumSizeHint() const;
|
2015-12-22 13:51:08 +00:00
|
|
|
|
2012-10-30 19:21:24 +00:00
|
|
|
void setFormat(bytes_view_type format);
|
2017-10-25 13:39:35 +00:00
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
QByteArray viewData();
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2014-10-27 01:48:14 +00:00
|
|
|
signals:
|
2017-10-25 13:39:35 +00:00
|
|
|
void byteHovered(int pos);
|
|
|
|
void byteSelected(int pos);
|
2014-10-27 01:48:14 +00:00
|
|
|
|
2014-09-23 20:35:10 +00:00
|
|
|
public slots:
|
2017-10-25 13:39:35 +00:00
|
|
|
void reset();
|
|
|
|
|
2014-09-23 20:35:10 +00:00
|
|
|
void setMonospaceFont(const QFont &mono_font);
|
|
|
|
|
2016-11-25 18:50:46 +00:00
|
|
|
void markProtocol(int start, int length);
|
|
|
|
void markField(int start, int length);
|
|
|
|
void markAppendix(int start, int length);
|
2017-10-25 13:39:35 +00:00
|
|
|
|
|
|
|
void moveToOffset(int pos);
|
|
|
|
|
2014-10-24 20:24:23 +00:00
|
|
|
protected:
|
|
|
|
virtual void paintEvent(QPaintEvent *);
|
|
|
|
virtual void resizeEvent(QResizeEvent *);
|
2014-10-27 01:48:14 +00:00
|
|
|
virtual void mousePressEvent (QMouseEvent * event);
|
|
|
|
virtual void mouseMoveEvent (QMouseEvent * event);
|
|
|
|
virtual void leaveEvent(QEvent *event);
|
2014-10-27 17:28:45 +00:00
|
|
|
virtual void contextMenuEvent(QContextMenuEvent *event);
|
2014-10-24 20:24:23 +00:00
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
private:
|
2016-11-25 17:42:26 +00:00
|
|
|
// Text highlight modes.
|
2012-10-30 19:21:24 +00:00
|
|
|
typedef enum {
|
2016-11-25 17:42:26 +00:00
|
|
|
ModeNormal,
|
|
|
|
ModeField,
|
|
|
|
ModeProtocol,
|
|
|
|
ModeOffsetNormal,
|
|
|
|
ModeOffsetField,
|
|
|
|
ModeHover
|
|
|
|
} HighlightMode;
|
2012-10-30 19:21:24 +00:00
|
|
|
|
2016-11-25 18:50:46 +00:00
|
|
|
QTextLayout *layout_;
|
2017-10-25 13:39:35 +00:00
|
|
|
QByteArray data_;
|
|
|
|
|
2016-11-25 18:50:46 +00:00
|
|
|
void drawLine(QPainter *painter, const int offset, const int row_y);
|
|
|
|
bool addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int start, int length, HighlightMode mode);
|
|
|
|
bool addHexFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
|
|
|
|
bool addAsciiFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
|
2012-10-30 19:21:24 +00:00
|
|
|
void scrollToByte(int byte);
|
2017-10-25 13:39:35 +00:00
|
|
|
void updateScrollbars();
|
|
|
|
int byteOffsetAtPixel(QPoint pos);
|
|
|
|
|
|
|
|
void createContextMenu();
|
|
|
|
|
2016-11-25 18:50:46 +00:00
|
|
|
int offsetChars(bool include_pad = true);
|
2014-10-24 20:24:23 +00:00
|
|
|
int offsetPixels();
|
|
|
|
int hexPixels();
|
|
|
|
int asciiPixels();
|
|
|
|
int totalPixels();
|
|
|
|
|
|
|
|
static const int separator_interval_;
|
2014-10-25 19:36:32 +00:00
|
|
|
|
|
|
|
// Fonts and colors
|
|
|
|
QFont mono_font_;
|
2016-11-25 18:50:46 +00:00
|
|
|
QColor offset_normal_fg_;
|
|
|
|
QColor offset_field_fg_;
|
2012-10-30 19:21:24 +00:00
|
|
|
|
2014-10-27 01:48:14 +00:00
|
|
|
// Data
|
2016-06-30 16:24:57 +00:00
|
|
|
packet_char_enc encoding_; // ASCII or EBCDIC
|
2014-10-27 17:28:45 +00:00
|
|
|
QMenu ctx_menu_;
|
2012-10-30 19:21:24 +00:00
|
|
|
|
2014-10-27 01:48:14 +00:00
|
|
|
// Data highlight
|
2016-11-25 18:50:46 +00:00
|
|
|
int hovered_byte_offset_;
|
2016-09-17 15:48:41 +00:00
|
|
|
bool hovered_byte_lock_;
|
2016-11-25 18:50:46 +00:00
|
|
|
int proto_start_;
|
|
|
|
int proto_len_;
|
|
|
|
int field_start_;
|
|
|
|
int field_len_;
|
|
|
|
int field_a_start_;
|
|
|
|
int field_a_len_;
|
2014-10-24 20:24:23 +00:00
|
|
|
|
|
|
|
bool show_offset_; // Should we show the byte offset?
|
|
|
|
bool show_hex_; // Should we show the hex display?
|
|
|
|
bool show_ascii_; // Should we show the ASCII display?
|
2016-11-25 18:50:46 +00:00
|
|
|
int row_width_; // Number of bytes per line
|
|
|
|
qreal font_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
|
|
|
|
int line_height_; // Font line spacing
|
2014-10-24 20:24:23 +00:00
|
|
|
|
|
|
|
// Data selection
|
2016-11-25 18:50:46 +00:00
|
|
|
QVector<int> x_pos_to_column_;
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2014-10-27 17:28:45 +00:00
|
|
|
private slots:
|
|
|
|
void setHexDisplayFormat(QAction *action);
|
2016-06-30 16:24:57 +00:00
|
|
|
void setCharacterEncoding(QAction *action);
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BYTE_VIEW_TEXT_H
|
2012-09-04 08:18:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|