1 /* 2 This file is part of the Okteta Gui library, made within the KDE community. 3 4 SPDX-FileCopyrightText: 2003, 2007-2009, 2019 Friedrich W. H. Kossebau <kossebau@kde.org> 5 6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 7 */ 8 9 #ifndef OKTETA_ABSTRACTBYTEARRAYCOLUMNRENDERER_HPP 10 #define OKTETA_ABSTRACTBYTEARRAYCOLUMNRENDERER_HPP 11 12 // ColumnsView 13 #include "abstractcolumnrenderer.hpp" 14 #include "linepositionrange.hpp" 15 #include "linerange.hpp" 16 // Okteta core 17 #include <Okteta/OktetaCore> 18 #include <Okteta/Address> 19 20 class QPainter; 21 class QRect; 22 class QFontMetrics; 23 24 namespace Okteta { 25 26 class Coord; 27 class CharCodec; 28 29 class ByteArrayTableRanges; 30 class ByteArrayTableLayout; 31 class AbstractByteArrayModel; 32 33 class AbstractByteArrayColumnRendererPrivate; 34 35 /** base class of all buffer column displayers 36 * holds all information about the vertical layout of a buffer column 37 * knows how to paint the data and the editing things (focus, cursor, selection) 38 * but does not offer 39 * 40 * @author Friedrich W. H. Kossebau 41 */ 42 class OKTETAGUI_EXPORT AbstractByteArrayColumnRenderer : public AbstractColumnRenderer 43 { 44 public: 45 enum FrameStyle 46 { 47 Frame, 48 Left, 49 Right 50 }; 51 52 protected: 53 explicit AbstractByteArrayColumnRenderer(AbstractByteArrayColumnRendererPrivate* d); 54 55 public: 56 ~AbstractByteArrayColumnRenderer() override; 57 58 public: // AbstractColumnRenderer API 59 void renderFirstLine(QPainter* painter, const PixelXRange& Xs, Line firstLineIndex) override; 60 void renderNextLine(QPainter* painter) override; 61 62 public: 63 void prepareRendering(const PixelXRange& Xs); 64 65 public: 66 void renderLinePositions(QPainter* painter, Line lineIndex, const LineRange& linePositions); 67 /** paints a cursor based on the type of the byte. 68 * @param painter The QPainter 69 * @param byteIndex Index of the byte to paint the cursor for. If -1 a space is used as char. 70 */ 71 void renderCursor(QPainter* painter, Address byteIndex); 72 /** paints the byte with background. 73 * @param painter The QPainter 74 * @param byteIndex Index of the byte to paint. If -1 only the background is painted. 75 */ 76 void renderByte(QPainter* painter, Address byteIndex); 77 /** paints the byte with background and a frame around. 78 * @param painter The QPainter 79 * @param byteIndex Index of the byte to paint the frame for. If -1 a space is used as char. 80 * @param style the style of the framing 81 */ 82 void renderFramedByte(QPainter* painter, Address byteIndex, FrameStyle style); 83 84 public: // modification access 85 /** sets the spacing in the hex column 86 * @param byteSpacingWidth spacing between the bytes in pixels 87 * @param noOfGroupedBytes numbers of grouped bytes, 0 means no grouping 88 * @param groupSpacingWidth spacing between the groups in pixels 89 * returns true if there was a change 90 */ 91 bool setSpacing(PixelX byteSpacingWidth, int noOfGroupedBytes = 0, PixelX groupSpacingWidth = 0); 92 /** sets the spacing between the bytes in the hex column 93 * @param byteSpacingWidth spacing between the bytes in pixels 94 * returns true if there was a change 95 */ 96 bool setByteSpacingWidth(PixelX byteSpacingWidth); 97 /** sets the number of grouped bytes in the hex column 98 * @param noOfGroupedBytes numbers of grouped bytes, 0 means no grouping 99 * returns true if there was a change 100 */ 101 bool setNoOfGroupedBytes(int noOfGroupedBytes); 102 /** sets the spacing between the groups of bytes in the hex column 103 * @param groupSpacingWidth spacing between the groups in pixels 104 * returns true if there was a change 105 */ 106 bool setGroupSpacingWidth(PixelX groupSpacingWidth); 107 /** sets the metrics of the used font 108 */ 109 void setFontMetrics(const QFontMetrics& fontMetrics); 110 /** */ 111 void set(AbstractByteArrayModel* byteArrayModel); 112 /** creates new buffer for x-values; to be called on any change of NoOfBytesPerLine or metrics */ 113 void resetXBuffer(); 114 /** sets the codec to be used by the char column. */ 115 void setCharCodec(const CharCodec* charCodec); 116 117 void setByteTypeColored(bool byteTypeColored); 118 119 public: // functional logic 120 /** returns byte linePositions covered by pixels with absolute x-coord x */ 121 LinePositionRange linePositionsOfX(PixelX x, PixelX width) const; 122 /** returns byte pos at pixel with absolute x-coord x */ 123 LinePosition linePositionOfX(PixelX x) const; 124 /** returns byte pos at pixel with absolute x-coord x, and sets the flag to true if we are closer to the right */ 125 LinePosition magneticLinePositionOfX(PixelX x) const; 126 /** returns absolute x-coord of byte at position posInLine */ 127 PixelX xOfLinePosition(LinePosition posInLine) const; 128 /** returns right absolute x-coord of byte at position posInLine */ 129 PixelX rightXOfLinePosition(LinePosition posInLine) const; 130 /** returns byte pos at pixel with relative x-coord x */ 131 LinePosition linePositionOfColumnX(PixelX x) const; 132 /** returns byte linePositions covered by pixels with relative x-coord x */ 133 LinePositionRange linePositionsOfColumnXs(PixelX x, PixelX width) const; 134 /** returns relative x-coord of byte at position posInLine */ 135 PixelX columnXOfLinePosition(LinePosition posInLine) const; 136 /** returns right relative x-coord of byte at position posInLine */ 137 PixelX columnRightXOfLinePosition(LinePosition posInLine) const; 138 /** returns the linePositions that overlap with the x-coords relative to the view */ 139 LinePositionRange visibleLinePositions(PixelX x, PixelX width) const; 140 /** returns the */ 141 PixelXRange xsOfLinePositionsInclSpaces(const LinePositionRange& linePositions) const; 142 /** */ 143 PixelXRange columnXsOfLinePositionsInclSpaces(const LinePositionRange& linePositions) const; 144 145 QRect byteRect(const Coord& coord) const; 146 147 public: // value access 148 PixelX byteWidth() const; 149 PixelX digitWidth() const; 150 PixelX groupSpacingWidth() const; 151 PixelX byteSpacingWidth() const; 152 int noOfGroupedBytes() const; 153 154 LinePosition firstLinePos() const; 155 LinePosition lastLinePos() const; 156 LinePositionRange visibleLinePositions() const; 157 const ByteArrayTableLayout* layout() const; 158 bool isByteTypeColored() const; 159 160 private: 161 Q_DECLARE_PRIVATE(AbstractByteArrayColumnRenderer) 162 }; 163 164 } 165 166 #endif 167