qhexedit_p.h 3.7 KB

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