forked from neundorf/CuteCom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datadisplay.h
175 lines (131 loc) · 3.96 KB
/
datadisplay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copyright (c) 2015-2016 Meinhard Ritscher <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
#ifndef DATADISPLAY_H
#define DATADISPLAY_H
#include <QPlainTextEdit>
#include <QTime>
#include <QTimer>
class TimeView;
class SearchPanel;
class DataDisplayPrivate;
class QAction;
class DataHighlighter;
class DataDisplay : public QWidget
{
Q_OBJECT
struct DisplayLine {
QString data;
QString trailer;
};
public:
explicit DataDisplay(QWidget *parent = 0);
void clear();
void setReadOnly(bool readonly);
void setUndoRedoEnabled(bool enabled);
void startSearch();
void displayData(const QByteArray &data);
void setDisplayTime(bool displayTime);
void setDisplayHex(bool displayHex);
void setDisplayCtrlCharacters(bool displayCtrlCharacters);
void setLinebreakChar(const QString &chars);
QTextDocument *getTextDocument();
private:
void find(const QString &, QTextDocument::FindFlags);
void insertSpaces(QString &data, unsigned int step = 1);
bool formatHexData(const QByteArray &inData);
void constructDisplayLine(const QByteArray &inData);
void setupTextFormats();
DataDisplayPrivate *m_dataDisplay;
SearchPanel *m_searchPanel;
int m_searchAreaHeight;
/**
* @brief m_timestamp
*/
QTime m_timestamp;
/**
* @brief m_hexBytes
*/
quint64 m_hexBytes;
/**
* In case the last printed hex line
* contained less than 16 bytes,
* The line's raw content will be stored
* here so it can be reprinted in the next round
* @brief m_hexLeftOver
*/
QByteArray m_hexLeftOver;
/**
* Data is displayed as hexadecimal values.
* @brief m_displayHex
*/
bool m_displayHex;
/**
* Ctrl characters like LF and Tabs are visualized
* with symbols
* @brief m_displayCtrlCharacters
*/
bool m_displayCtrlCharacters;
/**
* defines characters at which a new line is generated.
*/
char m_linebreakChar;
/**
* The container to store multiple formated
* lines before beeing printed
* @brief m_data
*/
QList<DisplayLine> m_data;
bool m_previous_ended_with_nl;
QTextCharFormat *m_format_data;
QTextCharFormat *m_format_hex;
QTextCharFormat *m_format_ascii;
QVector<QTime> *m_timestamps;
DataHighlighter *m_highlighter;
bool m_redisplay;
QTimer m_bufferingIncomingDataTimer;
private slots:
void displayDataFromBuffer(void);
};
class DataDisplayPrivate : public QPlainTextEdit
{
Q_OBJECT
public:
explicit DataDisplayPrivate(DataDisplay *parent = 0);
void timeViewPaintEvent(QPaintEvent *event);
int timeViewWidth();
void setTimestampFormat(const QString ×tampFormat);
void setTimeFormat(QTextCharFormat *format_time);
QVector<QTime> *timestamps();
void setDisplayTime(bool displayTime);
protected:
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
void updateTimeView(const QRect &, int);
private:
QTextCharFormat *m_format_time;
/**
* @brief m_timestampFormat
*/
QString m_timestampFormat;
int m_time_width;
TimeView *m_timeView;
QVector<QTime> *m_timestamps;
};
#endif // DATADISPLAY_H