File indexing completed on 2025-01-05 05:23:53

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008 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 KASTEN_BYTEARRAYROWSCOLUMNTEXTRENDERER_HPP
0010 #define KASTEN_BYTEARRAYROWSCOLUMNTEXTRENDERER_HPP
0011 
0012 // lib
0013 #include "abstractcolumntextrenderer.hpp"
0014 // Okteta gui
0015 #include <Okteta/CoordRange>
0016 // Okteta core
0017 #include <Okteta/OktetaCore>
0018 // Qt
0019 #include <QChar>
0020 
0021 namespace Okteta {
0022 class ValueCodec;
0023 class CharCodec;
0024 class AbstractByteArrayModel;
0025 }
0026 
0027 namespace Kasten {
0028 
0029 // TODO: offset should be set in renderFirstLine, calculated using coordRange,
0030 // in constructor instead take startOffset
0031 class ByteArrayRowsColumnTextRenderer : public AbstractColumnTextRenderer
0032 {
0033 private:
0034     static constexpr int DefaultTRByteSpacingWidth = 1;
0035     static constexpr int TRGroupSpacingWidth = 2;
0036 
0037 public:
0038     ByteArrayRowsColumnTextRenderer(const Okteta::AbstractByteArrayModel* byteArrayModel, Okteta::Address offset,
0039                                     const Okteta::CoordRange& coordRange,
0040                                     int noOfBytesPerLine, int byteSpacingWidth, int noOfGroupedBytes,
0041                                     int visibleCodings,
0042                                     Okteta::ValueCoding valueCoding,
0043                                     const QString& charCodecName, QChar substituteChar, QChar undefinedChar);
0044     ~ByteArrayRowsColumnTextRenderer() override;
0045 
0046 public: // AbstractColumnTextRenderer API
0047     void renderFirstLine(QTextStream* stream, int lineIndex) const override;
0048     void renderNextLine(QTextStream* stream, bool isSubline) const override;
0049     int noOfSublinesNeeded() const override;
0050 
0051 private:
0052     void renderLine(QTextStream* stream, bool isSubline) const;
0053 
0054 private:
0055     void setWidths(int byteWidth, int byteSpacingWidth, int noOfGroupedBytes);
0056 
0057 private:
0058     const Okteta::AbstractByteArrayModel* mByteArrayModel;
0059 
0060     const Okteta::CoordRange mCoordRange;
0061 
0062     const int mNoOfBytesPerLine;
0063 
0064     const int mVisibleCodings;
0065     const Okteta::ValueCodec* mValueCodec;
0066     const Okteta::CharCodec* mCharCodec;
0067     const QChar mSubstituteChar;
0068     const QChar mUndefinedChar;
0069 
0070     /** Line to print */
0071     mutable int mRenderLine;
0072     /** Data to print */
0073     mutable Okteta::Address mOffset;
0074 
0075     /** buffered value of how many chars a line needs */
0076     int mNoOfCharsPerLine = 0;
0077     // positions where to paint the
0078     int* const mLinePositions;
0079 };
0080 
0081 }
0082 
0083 #endif