File indexing completed on 2024-03-24 17:26:46
0001 /* 0002 This file is part of the Okteta Gui library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2008-2009 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_BYTEARRAYROWCOLUMNRENDERER_HPP 0010 #define OKTETA_BYTEARRAYROWCOLUMNRENDERER_HPP 0011 0012 // lib 0013 #include "abstractbytearrayview.hpp" 0014 // ColumnsView 0015 #include "abstractcolumnrenderer.hpp" 0016 #include "linepositionrange.hpp" 0017 // Okteta core 0018 #include <Okteta/OktetaCore> 0019 #include <Okteta/Byte> 0020 0021 class QFontMetrics; 0022 class QRect; 0023 0024 namespace Okteta { 0025 0026 class Coord; 0027 class CharCodec; 0028 class ValueCodec; 0029 0030 class ByteArrayTableRanges; 0031 class ByteArrayTableLayout; 0032 class AbstractByteArrayModel; 0033 0034 class ByteArrayRowColumnRendererPrivate; 0035 0036 /** base class of all buffer column displayers 0037 * holds all information about the vertical layout of a buffer column 0038 * knows how to paint the data and the editing things (focus, cursor, selection) 0039 * but does not offer 0040 * 0041 * @author Friedrich W. H. Kossebau 0042 */ 0043 class OKTETAGUI_EXPORT ByteArrayRowColumnRenderer : public AbstractColumnRenderer 0044 { 0045 public: 0046 enum FrameStyle 0047 { 0048 Frame, 0049 Left, 0050 Right 0051 }; 0052 0053 public: 0054 ByteArrayRowColumnRenderer(AbstractColumnStylist* stylist, 0055 AbstractByteArrayModel* byteArrayModel, ByteArrayTableLayout* layout, ByteArrayTableRanges* ranges); 0056 ~ByteArrayRowColumnRenderer() 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 /** paints a cursor based on the type of the byte. 0067 * @param painter The QPainter. 0068 * @param byteIndex Index of the byte to paint the cursor for. If -1 a space is used as char. 0069 * @param codingId The coding identifier. 0070 */ 0071 void renderCursor(QPainter* painter, Address byteIndex, AbstractByteArrayView::CodingTypeId codingId); 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 * @param codingId The coding identifier. 0076 */ 0077 void renderByte(QPainter* painter, Address byteIndex, AbstractByteArrayView::CodingTypeId codingId); 0078 /** paints the byte with background and a frame around. 0079 * @param painter The QPainter. 0080 * @param byteIndex Index of the byte to paint the frame for. If -1 a space is used as char. 0081 * @param codingId The coding identifier. 0082 * @param style the style of the framing 0083 */ 0084 void renderFramedByte(QPainter* painter, Address byteIndex, AbstractByteArrayView::CodingTypeId codingId, FrameStyle style); 0085 0086 void renderEditedByte(QPainter* painter, Byte byte, const QString& editBuffer); 0087 0088 public: // modification access 0089 /** sets the spacing in the hex column 0090 * @param byteSpacingWidth spacing between the bytes in pixels 0091 * @param noOfGroupedBytes numbers of grouped bytes, 0 means no grouping 0092 * @param groupSpacingWidth spacing between the groups in pixels 0093 * returns true if there was a change 0094 */ 0095 bool setSpacing(PixelX byteSpacingWidth, Size noOfGroupedBytes = 0, PixelX groupSpacingWidth = 0); 0096 /** sets the spacing between the bytes in the hex column 0097 * @param byteSpacingWidth spacing between the bytes in pixels 0098 * returns true if there was a change 0099 */ 0100 bool setByteSpacingWidth(PixelX byteSpacingWidth); 0101 /** sets the number of grouped bytes in the hex column 0102 * @param noOfGroupedBytes numbers of grouped bytes, 0 means no grouping 0103 * returns true if there was a change 0104 */ 0105 bool setNoOfGroupedBytes(Size noOfGroupedBytes); 0106 /** sets the spacing between the groups of bytes in the hex column 0107 * @param groupSpacingWidth spacing between the groups in pixels 0108 * returns true if there was a change 0109 */ 0110 bool setGroupSpacingWidth(PixelX groupSpacingWidth); 0111 /** sets the metrics of the used font 0112 */ 0113 void setFontMetrics(const QFontMetrics& fontMetrics); 0114 /** */ 0115 void set(AbstractByteArrayModel* byteArrayModel); 0116 /** creates new buffer for x-values; to be called on any change of NoOfBytesPerLine or metrics */ 0117 void resetXBuffer(); 0118 /** sets the codec to be used by the char column. */ 0119 void setCharCodec(const CharCodec* charCodec); 0120 0121 void setValueCodec(ValueCoding valueCoding, const ValueCodec* valueCodec); 0122 /** sets the spacing in the middle of a binary byte in the value column 0123 * @param binaryGapWidth spacing in the middle of a binary in pixels 0124 * returns true if there was a change 0125 */ 0126 bool setBinaryGapWidth(PixelX binaryGapWidth); 0127 0128 void setByteTypeColored(bool byteTypeColored); 0129 0130 /** sets whether "unprintable" chars (>32) should be displayed in the char column 0131 * with their corresponding character. 0132 * @param showingNonprinting 0133 * returns true if there was a change 0134 */ 0135 bool setShowingNonprinting(bool showingNonprinting = true); 0136 /** sets the substitute character for "unprintable" chars 0137 * returns true if there was a change 0138 */ 0139 bool setSubstituteChar(QChar substituteChar); 0140 /** sets the undefined character for "undefined" chars 0141 * returns true if there was a change 0142 */ 0143 bool setUndefinedChar(QChar undefinedChar); 0144 0145 void setVisibleCodings(int visibleCodings); 0146 0147 public: // functional logic 0148 /** returns byte linePositions covered by pixels with absolute x-coord x */ 0149 LinePositionRange linePositionsOfX(PixelX x, PixelX width) const; 0150 /** returns byte pos at pixel with absolute x-coord x */ 0151 LinePosition linePositionOfX(PixelX x) const; 0152 /** returns byte pos at pixel with absolute x-coord x, and sets the flag to true if we are closer to the right */ 0153 LinePosition magneticLinePositionOfX(PixelX x) const; 0154 /** returns absolute x-coord of byte at position posInLine */ 0155 PixelX xOfLinePosition(LinePosition posInLine) const; 0156 /** returns right absolute x-coord of byte at position posInLine */ 0157 PixelX rightXOfLinePosition(LinePosition posInLine) const; 0158 /** returns byte pos at pixel with relative x-coord x */ 0159 LinePosition linePositionOfColumnX(PixelX x) const; 0160 /** returns byte linePositions covered by pixels with relative x-coord x */ 0161 LinePositionRange linePositionsOfColumnXs(PixelX x, PixelX width) const; 0162 /** returns relative x-coord of byte at position posInLine */ 0163 PixelX columnXOfLinePosition(LinePosition posInLine) const; 0164 /** returns right relative x-coord of byte at position posInLine */ 0165 PixelX columnRightXOfLinePosition(LinePosition posInLine) const; 0166 /** returns the linePositions that overlap with the x-coords relative to the view */ 0167 LinePositionRange visibleLinePositions(PixelX x, PixelX width) const; 0168 /** returns the */ 0169 PixelXRange xsOfLinePositionsInclSpaces(const LinePositionRange& linePositions) const; 0170 /** */ 0171 PixelXRange columnXsOfLinePositionsInclSpaces(const LinePositionRange& linePositions) const; 0172 0173 QRect byteRect(const Coord& coord) const; 0174 QRect byteRect(const Coord& coord, AbstractByteArrayView::CodingTypeId codingId) const; 0175 0176 AbstractByteArrayView::CodingTypeId codingIdofY(PixelY y) const; 0177 PixelY yOfCodingId(AbstractByteArrayView::CodingTypeId codingId) const; 0178 0179 public: // value access 0180 PixelX byteWidth() const; 0181 PixelX digitWidth() const; 0182 PixelX groupSpacingWidth() const; 0183 PixelX byteSpacingWidth() const; 0184 Size noOfGroupedBytes() const; 0185 PixelY digitHeight() const; 0186 PixelY rowHeight() const; 0187 0188 PixelX binaryGapWidth() const; 0189 0190 /** returns true if "unprintable" chars (>32) are displayed in the char column 0191 * with their corresponding character, default is false 0192 */ 0193 bool isShowingNonprinting() const; 0194 /** returns the actually used substitute character for "unprintable" chars, default is '.' */ 0195 QChar substituteChar() const; 0196 /** returns the actually used undefined character for "undefined" chars, default is '?' */ 0197 QChar undefinedChar() const; 0198 0199 LinePosition firstLinePos() const; 0200 LinePosition lastLinePos() const; 0201 LinePositionRange visibleLinePositions() const; 0202 const ByteArrayTableLayout* layout() const; 0203 bool isByteTypeColored() const; 0204 0205 AbstractByteArrayView::CodingTypes visibleCodings() const; 0206 0207 private: 0208 Q_DECLARE_PRIVATE(ByteArrayRowColumnRenderer) 0209 }; 0210 0211 } 0212 0213 #endif