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