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: 2003, 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 #include "offsetcolumntextrenderer.hpp"
0010 
0011 // Qt
0012 #include <QString>
0013 #include <QTextStream>
0014 
0015 namespace Kasten {
0016 
0017 OffsetColumnTextRenderer::OffsetColumnTextRenderer(int offsetFormat, int firstLineOffset, int delta)
0018     : mFirstLineOffset(firstLineOffset)
0019     , mDelta(delta)
0020     , printFunction(Okteta::OffsetFormat::printFunction(offsetFormat))
0021     , mCodingWidth(Okteta::OffsetFormat::codingWidth(offsetFormat))
0022 {
0023     mEncodedOffsetBuffer = new char[mCodingWidth + 1];
0024 }
0025 
0026 OffsetColumnTextRenderer::~OffsetColumnTextRenderer()
0027 {
0028     delete [] mEncodedOffsetBuffer;
0029 }
0030 
0031 void OffsetColumnTextRenderer::renderFirstLine(QTextStream* stream, int lineIndex) const
0032 {
0033     mRenderLine = lineIndex;
0034     renderLine(stream, false);
0035 }
0036 
0037 void OffsetColumnTextRenderer::renderNextLine(QTextStream* stream, bool isSubline) const
0038 {
0039     renderLine(stream, isSubline);
0040 }
0041 
0042 void OffsetColumnTextRenderer::renderLine(QTextStream* stream, bool isSubline) const
0043 {
0044     if (isSubline) {
0045         *stream << whiteSpace(mCodingWidth);
0046     } else {
0047         // TODO: fix me (no more printFunction)
0048         printFunction(mEncodedOffsetBuffer, mFirstLineOffset + mDelta * mRenderLine);
0049         *stream << mEncodedOffsetBuffer;
0050 
0051         ++mRenderLine;
0052     }
0053 }
0054 
0055 }