• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

okteta

abstractbytearraycolumntextrenderer.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of the Okteta Kakao module, part of the KDE project.
00003 
00004     Copyright 2003,2008 Friedrich W. H. Kossebau <kossebau@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) version 3, or any
00010     later version accepted by the membership of KDE e.V. (or its
00011     successor approved by the membership of KDE e.V.), which shall
00012     act as a proxy defined in Section 6 of version 3 of the license.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public
00020     License along with this library. If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 #include "abstractbytearraycolumntextrenderer.h"
00024 
00025 // Qt
00026 #include <QtCore/QTextStream>
00027 // C
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     // TODO: remove this hack and make it more general
00053     if( byteSpacingWidth > 0 )
00054         byteSpacingWidth = DefaultTRByteSpacingWidth;
00055 
00056     int spacingTrigger = noOfGroupedBytes-1;
00057     if( spacingTrigger < 0 )
00058         spacingTrigger = mNoOfBytesPerLine; // ensures to never trigger the group spacing
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         // is there a space behind the actual byte (if it is not the last)?
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 }

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal