-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbinfileview.h
113 lines (98 loc) · 3.69 KB
/
binfileview.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
//*****************************************************************************
//
// binfileview.h
// Copyright(c) 2016 Juha T Nikkanen <[email protected]>
//
// --- Legal stuff ---
//
// 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 2.1 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, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//*****************************************************************************
#ifndef BINFILEVIEW_H
#define BINFILEVIEW_H
#include <QAbstractScrollArea>
class QMenu;
class QAction;
class BinFileView : public QAbstractScrollArea
{
Q_OBJECT
public:
enum Constants {
bytesPerGroup = 4,
minimumOfByteGroups = 4,
minimumOfLines = 16
};
BinFileView( QWidget* parent = nullptr );
virtual ~BinFileView();
virtual QSize viewportSizeHint() const;
virtual void setFont( QFont );
const uchar* data();
void setData( const uchar*, const qint64 );
void setColoringData( uchar* );
inline int capacity() { return _linesOnViewPort * _bytesPerLine; }
inline int addressCharacters() { return _addressChars; }
void setAddressCharacters( const int );
qint64 addressAddend();
signals:
void fileDropped( QString, BinFileView* );
void fileOpenRequested( BinFileView* );
void fileViewContentChanged( BinFileView* );
void defaultVisualsChanged( BinFileView* );
public slots:
void showContextMenu( const QPoint& );
void synchronizeVisuals( BinFileView* );
protected:
virtual void dragEnterEvent( QDragEnterEvent* );
virtual void dropEvent( QDropEvent* );
virtual void resizeEvent( QResizeEvent* );
virtual void paintEvent( QPaintEvent* );
virtual void scrollContentsBy( int, int );
private: // Methods
void calculateNumOfByteGroups();
void adjust( const int newByteGroups = 0 );
int preFitWidth( const int ) const;
void drawEmptyViewInstructions( QPainter& );
private: // No copying
BinFileView( const BinFileView& );
BinFileView& operator=( const BinFileView& );
private: // Data
QFont _font;
QMenu* _contextMenu;
QAction* _contextAction;
const uchar* _data; // ptr to raw binary data, not owned
const uchar* _colorData;
qint64 _size; // accessible file size
qint64 _upperMask; // masks for address area, address is drawn
qint64 _lowerMask; // like %0nX:%0nX where n is _addressChars / 2
qint64 _addend;
int _addressChars; // # of characters on address field
int _lineCount; // == division of size per # of bytes on one line
int _linesOnViewPort; // # of lines viewport is capable to draw
int _byteGroups;
int _bytesPerLine;
// Pixel measures
int _leftMargin;
int _rightMargin;
int _bottomMargin;
int _byteWidth;
int _groupWidth;
int _addressAreaWidth;
int _hexAreaWidth;
int _asciiAreaWidth;
int _groupGap;
// To fine tune widget viewport minimum size
int _vscrollBarWidth;
};
#endif // BINFILEVIEW_H