Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
hex_data_source_view.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <config.h>
13
14#include "ui/recent.h"
15
16#include <QAbstractScrollArea>
17#include <QFont>
18#include <QVector>
19#include <QMenu>
20#include <QSize>
21#include <QString>
22#include <QTextLayout>
23#include <QVector>
24
26
29
30// XXX - Is there any reason we shouldn't add ImageDataSourceView, etc?
31
33{
34 Q_OBJECT
35 Q_INTERFACES(IDataPrintable)
36
37public:
38 explicit HexDataSourceView(const QByteArray &data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = nullptr);
40
41 void setFormat(bytes_view_type format);
42
43signals:
44 void byteViewSettingsChanged();
45
46public slots:
47 void setMonospaceFont(const QFont &mono_font);
48 void updateByteViewSettings();
49
50 void markProtocol(int start, int length);
51 void markField(int start, int length, bool scroll_to = true);
52 void markAppendix(int start, int length);
53 void unmarkField();
54 void saveSelected(int start);
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 selected_byte_offset_;
111 int proto_start_;
112 int proto_len_;
113 int field_start_;
114 int field_len_;
115 int field_a_start_;
116 int field_a_len_;
117
118 bool show_offset_; // Should we show the byte offset?
119 bool show_hex_; // Should we show the hex display?
120 bool show_ascii_; // Should we show the ASCII display?
121 int row_width_; // Number of bytes per line
122 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
123 int line_height_; // Font line spacing
124 QList<QRect> hover_outlines_; // Hovered byte outlines.
125
126 bool allow_hover_selection_;
127
128 // Data selection
129 QVector<int> x_pos_to_column_;
130
131 // Context menu actions
132 QAction *action_allow_hover_selection_;
133 QAction *action_bytes_hex_;
134 QAction *action_bytes_dec_;
135 QAction *action_bytes_oct_;
136 QAction *action_bytes_bits_;
137 QAction *action_bytes_enc_from_packet_;
138 QAction *action_bytes_enc_ascii_;
139 QAction *action_bytes_enc_ebcdic_;
140
141private slots:
142 void copyBytes(bool);
143 void setHexDisplayFormat(QAction *action);
144 void setCharacterEncoding(QAction *action);
145 void toggleHoverAllowed(bool);
146
147};
Definition base_data_source_view.h:17
Definition hex_data_source_view.h:33
Definition idata_printable.h:23
packet_char_enc
Definition frame_data.h:42