Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
byte_view_text.h
Go to the documentation of this file.
1
10#ifndef BYTE_VIEW_TEXT_H
11#define BYTE_VIEW_TEXT_H
12
13#include <config.h>
14
15#include "ui/recent.h"
16
17#include <QAbstractScrollArea>
18#include <QFont>
19#include <QVector>
20#include <QMenu>
21#include <QSize>
22#include <QString>
23#include <QTextLayout>
24#include <QVector>
25
27
30
31// XXX - Is there any reason we shouldn't add ByteViewImage, etc?
32
34{
35 Q_OBJECT
36 Q_INTERFACES(IDataPrintable)
37
38public:
39 explicit ByteViewText(const QByteArray &data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = nullptr);
41
42 void setFormat(bytes_view_type format);
43
44signals:
45 void byteViewSettingsChanged();
46
47public slots:
48 void setMonospaceFont(const QFont &mono_font);
49 void updateByteViewSettings();
50
51 void markProtocol(int start, int length);
52 void markField(int start, int length, bool scroll_to = true);
53 void markAppendix(int start, int length);
54 void unmarkField();
55
56protected:
57 virtual void paintEvent(QPaintEvent *);
58 virtual void resizeEvent(QResizeEvent *);
59 virtual void mousePressEvent (QMouseEvent * event);
60 virtual void mouseMoveEvent (QMouseEvent * event);
61 virtual void leaveEvent(QEvent *event);
62 virtual void contextMenuEvent(QContextMenuEvent *event);
63
64private:
65 // Text highlight modes.
66 typedef enum {
67 ModeNormal,
68 ModeField,
69 ModeProtocol,
70 ModeOffsetNormal,
71 ModeOffsetField,
72 ModeNonPrintable
73 } HighlightMode;
74
75 QTextLayout *layout_;
76
77 void updateLayoutMetrics();
78 int stringWidth(const QString &line);
79 void drawLine(QPainter *painter, const int offset, const int row_y);
80 bool addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int start, int length, HighlightMode mode);
81 bool addHexFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
82 bool addAsciiFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
83 void scrollToByte(int byte);
84 void updateScrollbars();
85 int byteOffsetAtPixel(QPoint pos);
86
87 void createContextMenu();
88 void updateContextMenu();
89
90 int offsetChars(bool include_pad = true);
91 int offsetPixels();
92 int hexPixels();
93 int asciiPixels();
94 int totalPixels();
95 const QByteArray printableData() { return data_; }
96
97 static const int separator_interval_;
98
99 // Colors
100 QColor offset_normal_fg_;
101 QColor offset_field_fg_;
102
103 // Data
104 packet_char_enc encoding_; // ASCII or EBCDIC
105 QMenu ctx_menu_;
106
107 // Data highlight
108 int hovered_byte_offset_;
109 int marked_byte_offset_;
110 int proto_start_;
111 int proto_len_;
112 int field_start_;
113 int field_len_;
114 int field_a_start_;
115 int field_a_len_;
116
117 bool show_offset_; // Should we show the byte offset?
118 bool show_hex_; // Should we show the hex display?
119 bool show_ascii_; // Should we show the ASCII display?
120 int row_width_; // Number of bytes per line
121 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
122 int line_height_; // Font line spacing
123 QList<QRect> hover_outlines_; // Hovered byte outlines.
124
125 bool allow_hover_selection_;
126
127 // Data selection
128 QVector<int> x_pos_to_column_;
129
130 // Context menu actions
131 QAction *action_allow_hover_selection_;
132 QAction *action_bytes_hex_;
133 QAction *action_bytes_dec_;
134 QAction *action_bytes_oct_;
135 QAction *action_bytes_bits_;
136 QAction *action_bytes_enc_from_packet_;
137 QAction *action_bytes_enc_ascii_;
138 QAction *action_bytes_enc_ebcdic_;
139
140private slots:
141 void copyBytes(bool);
142 void setHexDisplayFormat(QAction *action);
143 void setCharacterEncoding(QAction *action);
144 void toggleHoverAllowed(bool);
145
146};
147
148#endif // BYTE_VIEW_TEXT_H
Definition base_data_source_view.h:17
Definition byte_view_text.h:34
Definition idata_printable.h:23
packet_char_enc
Definition frame_data.h:42