#ifndef HEXVIEWERWIDGET_H #define HEXVIEWERWIDGET_H #include #include #include #include #include #include #include #include #include #include "settings.h" // Custom hex view widget with virtualized rendering and selection class HexView : public QAbstractScrollArea { Q_OBJECT public: enum class SelectionSource { None, Hex, Decoded }; explicit HexView(QWidget *parent = nullptr); void setData(const QByteArray &data); void setTheme(const Theme &theme); void setBytesPerLine(int bytes); int bytesPerLine() const { return mBytesPerLine; } // Selection void clearSelection(); bool hasSelection() const; QString getSelectedHex() const; // Returns hex without spaces QString getSelectedDecoded() const; // Returns decoded ASCII/Latin-1 void copyToClipboard(); protected: void paintEvent(QPaintEvent *event) override; void resizeEvent(QResizeEvent *event) override; void scrollContentsBy(int dx, int dy) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void keyPressEvent(QKeyEvent *event) override; private: void updateScrollBars(); void recalculateBytesPerLine(); QColor getByteColor(quint8 byte) const; QColor getAsciiColor(quint8 byte) const; int byteIndexAtPos(const QPoint &pos, SelectionSource *source = nullptr) const; void updateColumnPositions(); QByteArray mData; QFont mMonoFont; int mBytesPerLine = 16; int mCharWidth = 0; int mLineHeight = 0; // Column positions (calculated once, updated on resize) int mOffsetX = 0; int mHexX = 0; int mAsciiX = 0; int mHeaderHeight = 0; // Selection state int mSelectionStart = -1; int mSelectionEnd = -1; SelectionSource mSelectionSource = SelectionSource::None; bool mSelecting = false; // Theme colors QColor mBgColor; QColor mTextColor; QColor mOffsetColor; QColor mNullColor; QColor mHighColor; QColor mPrintableColor; QColor mControlColor; QColor mNonPrintableColor; QColor mBorderColor; QColor mSelectionColor; }; class HexViewerWidget : public QWidget { Q_OBJECT public: explicit HexViewerWidget(QWidget *parent = nullptr); ~HexViewerWidget() = default; void setData(const QByteArray &data, const QString &filename); void setMetadata(const QVariantMap &metadata); private slots: void applyTheme(const Theme &theme); private: QByteArray mData; QString mFilename; QSplitter *mSplitter; QLabel *mInfoLabel; HexView *mHexView; QTreeWidget *mMetadataTree; Theme mCurrentTheme; }; #endif // HEXVIEWERWIDGET_H