| 1 | #ifndef HEXVIEWER_H |
| 2 | #define HEXVIEWER_H |
| 3 | |
| 4 | #include <QFrame> |
| 5 | #include <cstdint> |
| 6 | #include <vector> |
| 7 | |
| 8 | class HexRequest; |
| 9 | class QScrollBar; |
| 10 | class QPaintEvent; |
| 11 | |
| 12 | class HexViewer : public QFrame |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | public: |
| 16 | HexViewer(QWidget* parent = nullptr); |
| 17 | |
| 18 | enum Mode { FIXED, FILL_WIDTH, FILL_WIDTH_POWEROF2 }; |
| 19 | |
| 20 | void setDebuggable(const QString& name, int size); |
| 21 | void setIsInteractive(bool enabled); |
| 22 | void setUseMarker(bool enabled); |
| 23 | void setIsEditable(bool enabled); |
| 24 | |
| 25 | void setDisplayMode(Mode mode); |
| 26 | void setDisplayWidth(short width); |
| 27 | |
| 28 | QSize sizeHint() const override; |
| 29 | |
| 30 | void setLocation(int addr); |
| 31 | void setTopLocation(int addr); |
| 32 | void scrollBarChanged(int addr); |
| 33 | void settingsChanged(); |
| 34 | void refresh(); |
| 35 | |
| 36 | signals: |
| 37 | void locationChanged(int addr); |
| 38 | |
| 39 | private: |
| 40 | void wheelEvent(QWheelEvent* e) override; |
| 41 | void resizeEvent(QResizeEvent* e) override; |
| 42 | void paintEvent(QPaintEvent* e) override; |
| 43 | void mousePressEvent(QMouseEvent* e) override; |
| 44 | bool event(QEvent* e) override; |
| 45 | void keyPressEvent(QKeyEvent* e) override; |
| 46 | void focusInEvent(QFocusEvent* e) override; |
| 47 | void focusOutEvent(QFocusEvent* e) override; |
| 48 | |
| 49 | void createActions(); |
| 50 | |
| 51 | void setSizes(); |
| 52 | void hexdataTransfered(HexRequest* r); |
| 53 | void transferCancelled(HexRequest* r); |
| 54 | int coorToOffset(int x, int y) const; |
| 55 | |
| 56 | void changeWidth(); |
| 57 | |
| 58 | private: |
| 59 | QScrollBar* vertScrollBar; |
| 60 | QAction* fillWidthAction; |
| 61 | QAction* fillWidth2Action; |
| 62 | QAction* setWith8Action; |
| 63 | QAction* setWith16Action; |
| 64 | QAction* setWith32Action; |
| 65 | |
| 66 | int wheelRemainder = 0; |
| 67 | |
| 68 | // layout |
| 69 | int frameL, frameR, frameT, frameB; |
| 70 | int leftCharPos, leftValuePos, rightValuePos, rightCharPos; |
| 71 | Mode displayMode = FILL_WIDTH; |
| 72 | short horBytes = 16; |
| 73 | int visibleLines, partialBottomLine; |
| 74 | int lineHeight, xAddr, xData, xChar, dataWidth, charWidth, hexCharWidth; |
| 75 | int addressLength = 4; |
| 76 | |
| 77 | // data |
| 78 | QString debuggableName; |
| 79 | std::vector<uint8_t> hexData; |
| 80 | std::vector<uint8_t> previousHexData; |
| 81 | int debuggableSize = 0; |
| 82 | int hexTopAddress = 0; |
| 83 | int hexMarkAddress = 0; |
| 84 | bool waitingForData = false; |
| 85 | bool highlitChanges = true; |
| 86 | bool useMarker = false; |
| 87 | bool isInteractive = false; |
| 88 | bool isEditable = false; |
| 89 | bool beingEdited = false; |
| 90 | bool editedChars = false; |
| 91 | bool hasFocus = false; |
| 92 | int cursorPosition, editValue; |
| 93 | |
| 94 | friend class HexRequest; |
| 95 | }; |
| 96 | |
| 97 | #endif // HEXVIEWER_H |