QHexEdit
 All Classes Functions Properties
qhexedit_p.h
1 #ifndef QHEXEDIT_P_H
2 #define QHEXEDIT_P_H
3 
6 #include <QtGui>
7 #include <QWidget>
8 #include <QScrollArea>
9 #include <QUndoStack>
10 #include "xbytearray.h"
11 
12 class QHexEditPrivate : public QWidget
13 {
14 Q_OBJECT
15 
16 public:
17  QHexEditPrivate(QScrollArea *parent);
18 
19  void setAddressAreaColor(QColor const &color);
20  QColor addressAreaColor();
21 
22  void setAddressOffset(int offset);
23  int addressOffset();
24 
25  void setCursorPos(int position);
26  int cursorPos();
27 
28  void setData(QByteArray const &data);
29  QByteArray data();
30 
31  void setHighlightingColor(QColor const &color);
32  QColor highlightingColor();
33 
34  void setOverwriteMode(bool overwriteMode);
35  bool overwriteMode();
36 
37  void setReadOnly(bool readOnly);
38  bool isReadOnly();
39 
40  void setSelectionColor(QColor const &color);
41  QColor selectionColor();
42 
43  XByteArray & xData();
44 
45  int indexOf(const QByteArray & ba, int from = 0);
46  void insert(int index, const QByteArray & ba);
47  void insert(int index, char ch);
48  int lastIndexOf(const QByteArray & ba, int from = 0);
49  void remove(int index, int len=1);
50  void replace(int index, char ch);
51  void replace(int index, const QByteArray & ba);
52  void replace(int pos, int len, const QByteArray & after);
53 
54  void setAddressArea(bool addressArea);
55  void setAddressWidth(int addressWidth);
56  void setAsciiArea(bool asciiArea);
57  void setHighlighting(bool mode);
58  virtual void setFont(const QFont &font);
59 
60  void undo();
61  void redo();
62 
63  QString toRedableString();
64  QString selectionToReadableString();
65 
66 signals:
67  void currentAddressChanged(int address);
68  void currentSizeChanged(int size);
69  void dataChanged();
70  void overwriteModeChanged(bool state);
71 
72 protected:
73  void keyPressEvent(QKeyEvent * event);
74  void mouseMoveEvent(QMouseEvent * event);
75  void mousePressEvent(QMouseEvent * event);
76 
77  void paintEvent(QPaintEvent *event);
78 
79  int cursorPos(QPoint pos); // calc cursorpos from graphics position. DOES NOT STORE POSITION
80 
81  void resetSelection(int pos); // set selectionStart and selectionEnd to pos
82  void resetSelection(); // set selectionEnd to selectionStart
83  void setSelection(int pos); // set min (if below init) or max (if greater init)
84  int getSelectionBegin();
85  int getSelectionEnd();
86 
87 
88 private slots:
89  void updateCursor();
90  void adjust();
91 
92 private:
93  void ensureVisible();
94 
95  QColor _addressAreaColor;
96  QColor _highlightingColor;
97  QColor _selectionColor;
98  QScrollArea *_scrollArea;
99  QTimer _cursorTimer;
100  QUndoStack *_undoStack;
101 
102  XByteArray _xData; // Hält den Inhalt des Hex Editors
103 
104  bool _blink; // true: then cursor blinks
105  bool _renderingRequired; // Flag to store that rendering is necessary
106  bool _addressArea; // left area of QHexEdit
107  bool _asciiArea; // medium area
108  bool _highlighting; // highlighting of changed bytes
109  bool _overwriteMode;
110  bool _readOnly; // true: the user can only look and navigate
111 
112  int _charWidth, _charHeight; // char dimensions (dpendend on font)
113  int _cursorX, _cursorY; // graphics position of the cursor
114  int _cursorPosition; // character positioin in stream (on byte ends in to steps)
115  int _xPosAdr, _xPosHex, _xPosAscii; // graphics x-position of the areas
116 
117  int _selectionBegin; // First selected char
118  int _selectionEnd; // Last selected char
119  int _selectionInit; // That's, where we pressed the mouse button
120 
121  int _size;
122 };
123 
126 #endif
127