File indexing completed on 2024-04-21 05:53:04

0001 /*
0002     This file is part of the Okteta Gui library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2003, 2007-2009, 2019 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef OKTETA_ABSTRACTBYTEARRAYCOLUMNRENDERER_HPP
0010 #define OKTETA_ABSTRACTBYTEARRAYCOLUMNRENDERER_HPP
0011 
0012 // ColumnsView
0013 #include "abstractcolumnrenderer.hpp"
0014 #include "linepositionrange.hpp"
0015 #include "linerange.hpp"
0016 // Okteta core
0017 #include <Okteta/OktetaCore>
0018 #include <Okteta/Address>
0019 
0020 class QPainter;
0021 class QRect;
0022 class QFontMetrics;
0023 
0024 namespace Okteta {
0025 
0026 class Coord;
0027 class CharCodec;
0028 
0029 class ByteArrayTableRanges;
0030 class ByteArrayTableLayout;
0031 class AbstractByteArrayModel;
0032 
0033 class AbstractByteArrayColumnRendererPrivate;
0034 
0035 /** base class of all buffer column displayers
0036  * holds all information about the vertical layout of a buffer column
0037  * knows how to paint the data and the editing things (focus, cursor, selection)
0038  * but does not offer
0039  *
0040  * @author Friedrich W. H. Kossebau
0041  */
0042 class OKTETAGUI_EXPORT AbstractByteArrayColumnRenderer : public AbstractColumnRenderer
0043 {
0044 public:
0045     enum FrameStyle
0046     {
0047         Frame,
0048         Left,
0049         Right
0050     };
0051 
0052 protected:
0053     OKTETAGUI_NO_EXPORT explicit AbstractByteArrayColumnRenderer(AbstractByteArrayColumnRendererPrivate* d);
0054 
0055 public:
0056     ~AbstractByteArrayColumnRenderer() override;
0057 
0058 public: // AbstractColumnRenderer API
0059     void renderFirstLine(QPainter* painter, const PixelXRange& Xs, Line firstLineIndex) override;
0060     void renderNextLine(QPainter* painter) override;
0061 
0062 public:
0063     void prepareRendering(const PixelXRange& Xs);
0064 
0065 public:
0066     void renderLinePositions(QPainter* painter, Line lineIndex, const LineRange& linePositions);
0067     /** paints a cursor based on the type of the byte.
0068      * @param painter The QPainter
0069      * @param byteIndex Index of the byte to paint the cursor for. If -1 a space is used as char.
0070      */
0071     void renderCursor(QPainter* painter, Address byteIndex);
0072     /** paints the byte with background.
0073      * @param painter The QPainter
0074      * @param byteIndex Index of the byte to paint. If -1 only the background is painted.
0075      */
0076     void renderByte(QPainter* painter, Address byteIndex);
0077     /** paints the byte with background and a frame around.
0078      * @param painter The QPainter
0079      * @param byteIndex Index of the byte to paint the frame for. If -1 a space is used as char.
0080      * @param style the style of the framing
0081      */
0082     void renderFramedByte(QPainter* painter, Address byteIndex, FrameStyle style);
0083 
0084 public: // modification access
0085     /** sets the spacing in the hex column
0086      * @param byteSpacingWidth spacing between the bytes in pixels
0087      * @param noOfGroupedBytes numbers of grouped bytes, 0 means no grouping
0088      * @param groupSpacingWidth spacing between the groups in pixels
0089      * returns true if there was a change
0090      */
0091     bool setSpacing(PixelX byteSpacingWidth, int noOfGroupedBytes = 0, PixelX groupSpacingWidth = 0);
0092     /** sets the spacing between the bytes in the hex column
0093      * @param byteSpacingWidth spacing between the bytes in pixels
0094      * returns true if there was a change
0095      */
0096     bool setByteSpacingWidth(PixelX byteSpacingWidth);
0097     /** sets the number of grouped bytes in the hex column
0098      * @param noOfGroupedBytes numbers of grouped bytes, 0 means no grouping
0099      * returns true if there was a change
0100      */
0101     bool setNoOfGroupedBytes(int noOfGroupedBytes);
0102     /** sets the spacing between the groups of bytes in the hex column
0103      * @param groupSpacingWidth spacing between the groups in pixels
0104      * returns true if there was a change
0105      */
0106     bool setGroupSpacingWidth(PixelX groupSpacingWidth);
0107     /** sets the metrics of the used font
0108      */
0109     void setFontMetrics(const QFontMetrics& fontMetrics);
0110     /** */
0111     void set(AbstractByteArrayModel* byteArrayModel);
0112     /** creates new buffer for x-values; to be called on any change of NoOfBytesPerLine or metrics */
0113     void resetXBuffer();
0114     /** sets the codec to be used by the char column. */
0115     void setCharCodec(const CharCodec* charCodec);
0116 
0117     void setByteTypeColored(bool byteTypeColored);
0118 
0119 public: // functional logic
0120     /** returns byte linePositions covered by pixels with absolute x-coord x */
0121     LinePositionRange linePositionsOfX(PixelX x, PixelX width) const;
0122     /** returns byte pos at pixel with absolute x-coord x */
0123     LinePosition linePositionOfX(PixelX x) const;
0124     /** returns byte pos at pixel with absolute x-coord x, and sets the flag to true if we are closer to the right */
0125     LinePosition magneticLinePositionOfX(PixelX x) const;
0126     /** returns absolute x-coord of byte at position linePosition */
0127     PixelX xOfLinePosition(LinePosition linePosition) const;
0128     /** returns right absolute x-coord of byte at position linePosition */
0129     PixelX rightXOfLinePosition(LinePosition linePosition) const;
0130     /** returns byte pos at pixel with relative x-coord x */
0131     LinePosition linePositionOfColumnX(PixelX x) const;
0132     /** returns byte linePositions covered by pixels with relative x-coord x */
0133     LinePositionRange linePositionsOfColumnXs(PixelX x, PixelX width) const;
0134     /** returns relative x-coord of byte at position linePosition */
0135     PixelX columnXOfLinePosition(LinePosition linePosition) const;
0136     /** returns right relative x-coord of byte at position linePosition */
0137     PixelX columnRightXOfLinePosition(LinePosition linePosition) const;
0138     /** returns the linePositions that overlap with the x-coords relative to the view */
0139     LinePositionRange visibleLinePositions(PixelX x, PixelX width) const;
0140     /** returns the */
0141     PixelXRange xsOfLinePositionsInclSpaces(const LinePositionRange& linePositions) const;
0142     /** */
0143     PixelXRange columnXsOfLinePositionsInclSpaces(const LinePositionRange& linePositions) const;
0144 
0145     QRect byteRect(Coord coord) const;
0146 
0147 public: // value access
0148     PixelX byteWidth() const;
0149     PixelX digitWidth() const;
0150     PixelX groupSpacingWidth() const;
0151     PixelX byteSpacingWidth() const;
0152     int noOfGroupedBytes() const;
0153 
0154     LinePosition firstLinePos() const;
0155     LinePosition lastLinePos()  const;
0156     LinePositionRange visibleLinePositions() const;
0157     const ByteArrayTableLayout* layout() const;
0158     bool isByteTypeColored() const;
0159 
0160 private:
0161     Q_DECLARE_PRIVATE(AbstractByteArrayColumnRenderer)
0162 };
0163 
0164 }
0165 
0166 #endif