Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
byte_view_text.h
1 /* byte_view_text.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
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 
26 #include <ui/qt/utils/data_printer.h>
27 #include <ui/qt/utils/idata_printable.h>
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 
49 public slots:
50  void setMonospaceFont(const QFont &mono_font);
51 
52  void markProtocol(int start, int length);
53  void markField(int start, int length, bool scroll_to = true);
54  void markAppendix(int start, int length);
55 
56 protected:
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 
64 private:
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  const QByteArray data_;
77 
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 
88  int offsetChars(bool include_pad = true);
89  int offsetPixels();
90  int hexPixels();
91  int asciiPixels();
92  int totalPixels();
93  const QByteArray printableData() { return data_; }
94 
95  static const int separator_interval_;
96 
97  // Fonts and colors
98  QFont mono_font_;
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  qreal font_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  // Data selection
125  QVector<int> x_pos_to_column_;
126 
127 private slots:
128  void copyBytes(bool);
129  void setHexDisplayFormat(QAction *action);
130  void setCharacterEncoding(QAction *action);
131 
132 };
133 
134 #endif // BYTE_VIEW_TEXT_H
135 
136 /*
137  * Editor modelines
138  *
139  * Local Variables:
140  * c-basic-offset: 4
141  * tab-width: 8
142  * indent-tabs-mode: nil
143  * End:
144  *
145  * ex: set shiftwidth=4 tabstop=8 expandtab:
146  * :indentSize=4:tabSize=8:noTabs=true:
147  */
Definition: idata_printable.h:22
Definition: byte_view_text.h:31
packet_char_enc
Definition: frame_data.h:43