Wireshark  4.3.0
The Wireshark network protocol analyzer
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 
28 
29 // XXX - Is there any reason we shouldn't add ByteViewImage, etc?
30 
31 class ByteViewText : public QAbstractScrollArea, public IDataPrintable
32 {
33  Q_OBJECT
34  Q_INTERFACES(IDataPrintable)
35 
36 public:
37  explicit ByteViewText(const QByteArray &data, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII, QWidget *parent = 0);
38  ~ByteViewText();
39 
40  virtual QSize minimumSizeHint() const;
41 
42  void setFormat(bytes_view_type format);
43  bool isEmpty() const;
44 
45 signals:
46  void byteHovered(int pos);
47  void byteSelected(int pos);
48  void byteViewSettingsChanged();
49 
50 public slots:
51  void setMonospaceFont(const QFont &mono_font);
52  void updateByteViewSettings();
53  void detachData();
54 
55  void markProtocol(int start, int length);
56  void markField(int start, int length, bool scroll_to = true);
57  void markAppendix(int start, int length);
58 
59 protected:
60  virtual void paintEvent(QPaintEvent *);
61  virtual void resizeEvent(QResizeEvent *);
62  virtual void mousePressEvent (QMouseEvent * event);
63  virtual void mouseMoveEvent (QMouseEvent * event);
64  virtual void leaveEvent(QEvent *event);
65  virtual void contextMenuEvent(QContextMenuEvent *event);
66 
67 private:
68  // Text highlight modes.
69  typedef enum {
70  ModeNormal,
71  ModeField,
72  ModeProtocol,
73  ModeOffsetNormal,
74  ModeOffsetField,
75  ModeNonPrintable
76  } HighlightMode;
77 
78  QTextLayout *layout_;
79  QByteArray data_;
80 
81  void updateLayoutMetrics();
82  int stringWidth(const QString &line);
83  void drawLine(QPainter *painter, const int offset, const int row_y);
84  bool addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int start, int length, HighlightMode mode);
85  bool addHexFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
86  bool addAsciiFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int mark_start, int mark_length, int tvb_offset, int max_tvb_pos, HighlightMode mode);
87  void scrollToByte(int byte);
88  void updateScrollbars();
89  int byteOffsetAtPixel(QPoint pos);
90 
91  void createContextMenu();
92  void updateContextMenu();
93 
94  int offsetChars(bool include_pad = true);
95  int offsetPixels();
96  int hexPixels();
97  int asciiPixels();
98  int totalPixels();
99  const QByteArray printableData() { return data_; }
100 
101  static const int separator_interval_;
102 
103  // Colors
104  QColor offset_normal_fg_;
105  QColor offset_field_fg_;
106 
107  // Data
108  packet_char_enc encoding_; // ASCII or EBCDIC
109  QMenu ctx_menu_;
110 
111  // Data highlight
112  int hovered_byte_offset_;
113  int marked_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 };
151 
152 #endif // BYTE_VIEW_TEXT_H
Definition: byte_view_text.h:32
Definition: idata_printable.h:23
packet_char_enc
Definition: frame_data.h:42