qhexedit_p.h 3.7 KB

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