-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSymView.h
322 lines (275 loc) · 6.52 KB
/
SymView.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
//
// filename: description
// Copyright (C) 2018 Gonzalo José Carracedo Carballal
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>
//
#ifndef SYMVIEW_H
#define SYMVIEW_H
#include <QFrame>
#include "Decider.h"
#include <QResizeEvent>
#include "ThrottleableWidget.h"
#define SYMVIEW_MAX_ZOOM 50
#define SYMVIEW_DEFAULT_BG_COLOR QColor(0, 0, 0)
#define SYMVIEW_DEFAULT_LO_COLOR QColor(0, 0, 0)
#define SYMVIEW_DEFAULT_HI_COLOR QColor(0xff, 0xff, 0xff)
class SymView : public ThrottleableWidget
{
Q_OBJECT
Q_PROPERTY(
QColor backgroundColor
READ getBackgroundColor
WRITE setBackgroundColor
NOTIFY backgroundColorChanged)
Q_PROPERTY(
QColor loColor
READ getLoColor
WRITE setLoColor
NOTIFY loColorChanged)
Q_PROPERTY(
QColor hiColor
READ getHiColor
WRITE setHiColor
NOTIFY hiColorChanged)
// Symbol buffer
std::vector<Symbol> buffer; // TODO: Allow loans
// Behavior
bool autoScroll = true;
bool autoStride = true;
bool reverse = false;
bool pad[6];
// Representation properties
unsigned int bps = 1; // Bits per symbol.
unsigned int zoom = 1; // Pixels per symbol
unsigned int offset = 0; // Offset (wrt buffer)
int hOffset = 0; // Horizontal offset
int stride = 1; // Image stride
int hoverX = -1;
int hoverY = -1;
bool selecting = false;
qint64 selStart = 0;
qint64 selEnd = 0;
unsigned int pad2;
QImage viewPort; // Current view. Matches geometry
QColor background;
QColor lowSym;
QColor highSym;
// Private methods
void assertImage(void);
void drawToImage(
QImage &image,
unsigned int start,
unsigned int end,
unsigned int zoom = 1,
unsigned int stride = 0,
unsigned int skip = 0,
unsigned int lineStart = 0,
bool showSelection = false);
public:
enum FileFormat {
FILE_FORMAT_TEXT,
FILE_FORMAT_RAW,
FILE_FORMAT_C_ARRAY,
FILE_FORMAT_BMP,
FILE_FORMAT_PNG,
FILE_FORMAT_JPEG,
FILE_FORMAT_PPM
};
void clear(void);
void save(QString const &dest, FileFormat format);
qint64 coordToOffset(int x, int y);
unsigned long
getLength(void) const
{
return this->buffer.size();
}
void
setAutoScroll(bool val)
{
this->autoScroll = val;
if (val)
this->scrollToBottom();
}
void
setAutoStride(bool val)
{
this->autoStride = val;
if (val)
this->setStride(static_cast<unsigned int>(this->width() / this->zoom));
}
bool
getReverse(void) const
{
return this->reverse;
}
void
setReverse(bool rev)
{
this->reverse = rev;
if (this->buffer.size() > 0)
this->invalidate();
}
bool
getAutoScroll(void) const
{
return this->autoStride;
}
bool
getAutoStride(void) const
{
return this->autoStride;
}
int
getLines(void) const
{
return (static_cast<int>(this->buffer.size()) + this->stride - 1)
/ this->stride;
}
void
setStride(unsigned int stride)
{
if (this->stride != static_cast<int>(stride)) {
this->stride = static_cast<int>(stride);
emit strideChanged(stride);
this->invalidate();
}
}
unsigned int
getStride(void) const
{
return static_cast<unsigned int>(this->stride);
}
unsigned int
getOffset(void) const
{
return this->offset;
}
void
setBitsPerSymbol(unsigned int bps)
{
if (this->bps != bps) {
this->bps = bps;
this->invalidate();
}
}
unsigned int
getBitsPerSymbol(void) const
{
return this->bps;
}
void
setOffset(unsigned int offset)
{
if (offset >= buffer.size())
offset = static_cast<unsigned int>(buffer.size());
if (offset != this->offset) {
this->offset = offset;
this->invalidate();
emit offsetChanged(offset);
}
}
void
setHOffset(int offset)
{
if (offset >= this->stride)
offset = this->stride - 1;
if (offset != this->hOffset) {
this->hOffset = offset;
this->invalidate();
emit hOffsetChanged(offset);
}
}
void
setZoom(unsigned int zoom)
{
if (zoom > 0 && zoom != this->zoom && zoom <= SYMVIEW_MAX_ZOOM) {
this->zoom = zoom;
this->setAutoStride(this->autoStride);
this->invalidate();
emit zoomChanged(zoom);
}
}
unsigned int
getZoom(void) const
{
return this->zoom;
}
void
setBackgroundColor(const QColor &c)
{
if (c != this->background) {
this->background = c;
this->invalidate();
emit backgroundColorChanged();
}
}
const QColor &
getBackgroundColor(void) const
{
return this->background;
}
void
setLoColor(const QColor &c)
{
if (c != this->lowSym) {
this->lowSym = c;
this->invalidate();
emit backgroundColorChanged();
}
}
const QColor &
getLoColor(void) const
{
return this->lowSym;
}
void
setHiColor(const QColor &c)
{
if (c != this->highSym) {
this->highSym = c;
this->invalidate();
emit backgroundColorChanged();
}
}
const QColor &
getHiColor(void) const
{
return this->highSym;
}
SymView(QWidget *parent = nullptr);
void scrollToBottom(void);
void feed(std::vector<Symbol> const &x);
void feed(const Symbol *data, unsigned int length);
void copyToClipboard(void);
// Virtual overrides
void draw(void) override;
void paint(void) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
signals:
void offsetChanged(unsigned int);
void hOffsetChanged(int);
void strideChanged(unsigned int);
void zoomChanged(unsigned int);
void hoverSymbol(unsigned int position);
void backgroundColorChanged();
void loColorChanged();
void hiColorChanged();
};
#endif