Wireshark 4.5.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
55protected:
56 virtual void paintEvent(QPaintEvent *);
57 virtual void resizeEvent(QResizeEvent *);
58 virtual void mousePressEvent (QMouseEvent * event);
59 virtual void mouseMoveEvent (QMouseEvent * event);
60 virtual void leaveEvent(QEvent *event);
61 virtual void contextMenuEvent(QContextMenuEvent *event);
62
63private:
64 // Text highlight modes.
65 typedef enum {
66 ModeNormal,
67 ModeField,
68 ModeProtocol,
69 ModeOffsetNormal,
70 ModeOffsetField,
71 ModeNonPrintable
72 } HighlightMode;
73
74 QTextLayout *layout_;
75
76 void updateLayoutMetrics();
77 int stringWidth(const QString &line);
78 void drawLine(QPainter *painter, const int offset, const int row_y);
79 bool addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int start, int length, HighlightMode mode);
80 bool addHexFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
81 bool addAsciiFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
82 void scrollToByte(int byte);
83 void updateScrollbars();
84 int byteOffsetAtPixel(QPoint pos);
85
86 void createContextMenu();
87 void updateContextMenu();
88
89 int offsetChars(bool include_pad = true);
90 int offsetPixels();
91 int hexPixels();
92 int asciiPixels();
93 int totalPixels();
94 const QByteArray printableData() { return data_; }
95
96 static const int separator_interval_;
97
98 // Colors
99 QColor offset_normal_fg_;
100 QColor offset_field_fg_;
101
102 // Data
103 packet_char_enc encoding_; // ASCII or EBCDIC
104 QMenu ctx_menu_;
105
106 // Data highlight
107 int hovered_byte_offset_;
108 int marked_byte_offset_;
109 int proto_start_;
110 int proto_len_;
111 int field_start_;
112 int field_len_;
113 int field_a_start_;
114 int field_a_len_;
115
116 bool show_offset_; // Should we show the byte offset?
117 bool show_hex_; // Should we show the hex display?
118 bool show_ascii_; // Should we show the ASCII display?
119 int row_width_; // Number of bytes per line
120 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
121 int line_height_; // Font line spacing
122 QList<QRect> hover_outlines_; // Hovered byte outlines.
123
124 bool allow_hover_selection_;
125
126 // Data selection
127 QVector<int> x_pos_to_column_;
128
129 // Context menu actions
130 QAction *action_allow_hover_selection_;
131 QAction *action_bytes_hex_;
132 QAction *action_bytes_dec_;
133 QAction *action_bytes_oct_;
134 QAction *action_bytes_bits_;
135 QAction *action_bytes_enc_from_packet_;
136 QAction *action_bytes_enc_ascii_;
137 QAction *action_bytes_enc_ebcdic_;
138
139private slots:
140 void copyBytes(bool);
141 void setHexDisplayFormat(QAction *action);
142 void setCharacterEncoding(QAction *action);
143 void toggleHoverAllowed(bool);
144
145};
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