okteta
abstractbytearraycolumntextrenderer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "abstractbytearraycolumntextrenderer.h"
00024
00025
00026 #include <QtCore/QTextStream>
00027
00028 #include <string.h>
00029
00030
00031 static const int DefaultTRByteSpacingWidth = 1;
00032 static const int TRGroupSpacingWidth = 2;
00033
00034 QString AbstractByteArrayColumnTextRenderer::whiteSpace( uint s )
00035 {
00036 return QString().fill( ' ', s );
00037 }
00038
00039 AbstractByteArrayColumnTextRenderer::AbstractByteArrayColumnTextRenderer( const KHECore::KAbstractByteArrayModel *byteArrayModel, int offset, const KHEUI::CoordRange &coordRange,
00040 int noOfBytesPerLine )
00041 : mByteArrayModel( byteArrayModel ),
00042 mCoordRange( coordRange ),
00043 mNoOfBytesPerLine( noOfBytesPerLine ),
00044 mOffset( offset )
00045 {
00046 mLinePositions = new int[mNoOfBytesPerLine];
00047 mNoOfCharsPerLine = 0;
00048 }
00049
00050 void AbstractByteArrayColumnTextRenderer::setWidths( int byteWidth, int byteSpacingWidth, int noOfGroupedBytes )
00051 {
00052
00053 if( byteSpacingWidth > 0 )
00054 byteSpacingWidth = DefaultTRByteSpacingWidth;
00055
00056 int spacingTrigger = noOfGroupedBytes-1;
00057 if( spacingTrigger < 0 )
00058 spacingTrigger = mNoOfBytesPerLine;
00059
00060 int N = 0;
00061 int p = 0;
00062 int gs = 0;
00063 int *P = mLinePositions;
00064 for( ; P<&mLinePositions[mNoOfBytesPerLine]; ++P, ++p, ++gs )
00065 {
00066 *P = N;
00067 N += byteWidth;
00068
00069
00070 if( gs == spacingTrigger )
00071 {
00072 N += TRGroupSpacingWidth;
00073 gs = -1;
00074 }
00075 else
00076 N += byteSpacingWidth;
00077 }
00078 N -= (gs==0)?TRGroupSpacingWidth:byteSpacingWidth;
00079
00080 mNoOfCharsPerLine = N;
00081 }
00082
00083
00084 void AbstractByteArrayColumnTextRenderer::renderFirstLine( QTextStream *stream, int lineIndex ) const
00085 {
00086 mRenderLine = lineIndex;
00087 renderLine( stream );
00088 }
00089
00090
00091 void AbstractByteArrayColumnTextRenderer::renderNextLine( QTextStream *stream ) const
00092 {
00093 renderLine( stream );
00094 }
00095
00096 AbstractByteArrayColumnTextRenderer::~AbstractByteArrayColumnTextRenderer()
00097 {
00098 delete [] mLinePositions;
00099 }