| 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
25#include "base_data_source_view.h"
26
27#include <ui/qt/utils/data_printer.h>
28#include <ui/qt/utils/idata_printable.h>
29
30// XXX - Is there any reason we shouldn't add ImageDataSourceView, etc?
31
32 class HexDataSourceView : public BaseDataSourceView, public IDataPrintable
33{
34 Q_OBJECT
35 Q_INTERFACES(IDataPrintable)
36
37 public:
38 explicit HexDataSourceView(const QByteArray &data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = nullptr);
39 ~HexDataSourceView();
40
41 void setFormat(bytes_view_type format);
42
43signals:
44 void byteViewSettingsChanged();
45
46 public 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
56 protected:
57 virtual void paintEvent(QPaintEvent *);
58 virtual void resizeEvent(QResizeEvent *);
59 virtual void showEvent(QShowEvent *);
60 virtual void mousePressEvent (QMouseEvent * event);
61 virtual void mouseMoveEvent (QMouseEvent * event);
62 virtual void leaveEvent(QEvent *event);
63 virtual void contextMenuEvent(QContextMenuEvent *event);
64
65 private:
66 // Text highlight modes.
67 typedef enum {
68 ModeNormal,
69 ModeField,
70 ModeProtocol,
71 ModeOffsetNormal,
72 ModeOffsetField,
73 ModeNonPrintable
74 } HighlightMode;
75
76 QTextLayout *layout_;
77
78 void updateLayoutMetrics();
79 int stringWidth(const QString &line);
80 void drawLine(QPainter *painter, const int offset, const int row_y);
81 bool addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int start, int length, HighlightMode mode);
82 bool addHexFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
83 bool addAsciiFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
84 void scrollToByte(int byte);
85 void updateScrollbars();
86 int byteOffsetAtPixel(QPoint pos);
87
88 void createContextMenu();
89 void updateContextMenu();
90
91 int offsetChars(bool include_pad = true);
92 int offsetPixels();
93 int hexPixels();
94 int asciiPixels();
95 int totalPixels();
96 const QByteArray printableData() { return data_; }
97
98 static const int separator_interval_;
99
100 bool layout_dirty_;
101
102 // Colors
103 QColor offset_normal_fg_;
104 QColor offset_field_fg_;
105
106 // Data
107 packet_char_enc encoding_; // ASCII or EBCDIC
108 QMenu ctx_menu_;
109
110 // Data highlight
111 int hovered_byte_offset_;
112 int marked_byte_offset_;
113 int selected_byte_offset_;
114 int proto_start_;
115 int proto_len_;
116 int field_start_;
117 int field_len_;
118 int field_a_start_;
119 int field_a_len_;
120
121 bool show_offset_; // Should we show the byte offset?
122 bool show_hex_; // Should we show the hex display?
123 bool show_ascii_; // Should we show the ASCII display?
124 int row_width_; // Number of bytes per line
125 int em_width_; // Single character width and text margin. NOTE: Use fontMetrics::width for multiple characters.
126 int line_height_; // Font line spacing
127 QList<QRect> hover_outlines_; // Hovered byte outlines.
128
129 bool allow_hover_selection_;
130
131 // Data selection
132 QVector<int> x_pos_to_column_;
133
134 // Context menu actions
135 QAction *action_allow_hover_selection_;
136 QAction *action_bytes_hex_;
137 QAction *action_bytes_dec_;
138 QAction *action_bytes_oct_;
139 QAction *action_bytes_bits_;
140 QAction *action_bytes_enc_from_packet_;
141 QAction *action_bytes_enc_ascii_;
142 QAction *action_bytes_enc_ebcdic_;
143
144 private slots:
145 void copyBytes(bool);
146 void setHexDisplayFormat(QAction *action);
147 void setCharacterEncoding(QAction *action);
148 void toggleHoverAllowed(bool);
149
150};
base_data_source_view.h
BaseDataSourceView
Definition base_data_source_view.h:17
HexDataSourceView
Definition hex_data_source_view.h:33
IDataPrintable
Definition idata_printable.h:23
data_printer.h
packet_char_enc
packet_char_enc
Definition frame_data.h:42
idata_printable.h
recent.h