• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • gui
valuebytearraycolumnrenderer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Gui library, made within the KDE community.
3 
4  Copyright 2003,2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "valuebytearraycolumnrenderer.h"
24 
25 // lib
26 #include "helper.h"
27 #include "oktetagui.h"
28 // lib
29 #include <abstractcolumnstylist.h>
30 // Okteta core
31 #include <valuecodec.h>
32 #include <charcodec.h>
33 // KDE
34 #include <KColorScheme>
35 // Qt
36 #include <QtGui/QPainter>
37 
38 
39 namespace Okteta
40 {
41 
42 
43 ValueByteArrayColumnRenderer::ValueByteArrayColumnRenderer( AbstractColumnStylist* stylist,
44  AbstractByteArrayModel* byteArrayModel, ByteArrayTableLayout* layout, ByteArrayTableRanges* ranges )
45  : AbstractByteArrayColumnRenderer( stylist, byteArrayModel, layout, ranges ),
46  mValueCodec( 0 ),
47  mBinaryGapWidth( DefaultBinaryGapWidth )
48 {
49 }
50 
51 void ValueByteArrayColumnRenderer::setValueCodec( ValueCoding valueCoding, const ValueCodec* valueCodec )
52 {
53  mValueCoding = valueCoding;
54  mValueCodec = valueCodec;
55  mDecodedByteText.resize( mValueCodec->encodingWidth() );
56 
57  // recalculate depend sizes
58  recalcByteWidth();
59 
60  if( mLinePosLeftPixelX )
61  recalcX();
62 }
63 
64 
65 bool ValueByteArrayColumnRenderer::setBinaryGapWidth( PixelX binaryGapWidth )
66 {
67  // no changes?
68  if( mBinaryGapWidth == binaryGapWidth )
69  return false;
70 
71  mBinaryGapWidth = binaryGapWidth;
72 
73  // recalculate depend sizes
74  recalcByteWidth();
75 
76  if( mLinePosLeftPixelX )
77  recalcX();
78  return true;
79 }
80 
81 
82 void ValueByteArrayColumnRenderer::recalcByteWidth()
83 {
84  // use 0 as reference, using a fixed font should always yield same width
85  mValueCodec->encode( mDecodedByteText, 0, Byte(0) );
86  if( mValueCoding == BinaryCoding )
87  {
88  const int binaryHalfWidth = mFontMetrics.width( mDecodedByteText.left(4) );
89  mBinaryHalfOffset = binaryHalfWidth + mBinaryGapWidth;
90  setByteWidth( mBinaryHalfOffset + binaryHalfWidth );
91  }
92  else
93  setByteWidth( mFontMetrics.width(mDecodedByteText) );
94 }
95 
96 
97 // perhaps sometimes there will be a grammar
98 void ValueByteArrayColumnRenderer::renderEditedByte( QPainter* painter, Byte byte, const QString& editBuffer )
99 {
100  const Character byteChar = mCharCodec->decode( byte );
101 
102  const QPalette& palette = stylist()->palette();
103  KColorScheme colorScheme( palette.currentColorGroup(), KColorScheme::View );
104  const KColorScheme::ForegroundRole foregroundRole =
105  mByteTypeColored ? foregroundRoleForChar(byteChar): KColorScheme::NormalText;
106  const QBrush brush = colorScheme.foreground( foregroundRole );
107  painter->fillRect( 0,0, byteWidth(),lineHeight(), brush );
108 
109  const QBrush backgroundBrush = colorScheme.background();
110  const QColor &charColor = backgroundBrush.color();
111  renderCode( painter, editBuffer, charColor );
112 }
113 
114 
115 void ValueByteArrayColumnRenderer::renderByteText( QPainter* painter,
116  Byte byte, Character byteChar, const QColor& color ) const
117 {
118 Q_UNUSED( byteChar )
119 
120  mValueCodec->encode( mDecodedByteText, 0, byte );
121  renderCode( painter, mDecodedByteText, color );
122 }
123 
124 
125 void ValueByteArrayColumnRenderer::renderCode( QPainter *painter, const QString &code, const QColor &color ) const
126 {
127  painter->setPen( color );
128  if( mValueCoding == Okteta::BinaryCoding )
129  {
130  // leave a gap in the middle
131  painter->drawText( 0, mDigitBaseLine, code.left(4) );
132  painter->drawText( mBinaryHalfOffset, mDigitBaseLine, code.right(4) );
133  }
134  else
135  painter->drawText( 0, mDigitBaseLine, code );
136 }
137 
138 
139 ValueByteArrayColumnRenderer::~ValueByteArrayColumnRenderer()
140 {
141 }
142 
143 }
Okteta::ValueByteArrayColumnRenderer::renderByteText
virtual void renderByteText(QPainter *painter, Byte byte, Character byteChar, const QColor &color) const
Definition: valuebytearraycolumnrenderer.cpp:115
Okteta::AbstractByteArrayColumnRenderer::mByteTypeColored
bool mByteTypeColored
Definition: abstractbytearraycolumnrenderer.h:237
Okteta::AbstractByteArrayColumnRenderer::mLinePosLeftPixelX
PixelX * mLinePosLeftPixelX
pointer to array with buffered linePositions (relative to column position) a spacing gets assigned to...
Definition: abstractbytearraycolumnrenderer.h:231
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
Okteta::ByteArrayTableRanges
a class to control all the ranges like marking and selections holds also all modified ranges and merg...
Definition: bytearraytableranges.h:45
Okteta::ValueByteArrayColumnRenderer::mBinaryGapWidth
PixelX mBinaryGapWidth
Definition: valuebytearraycolumnrenderer.h:74
abstractcolumnstylist.h
Okteta::ValueByteArrayColumnRenderer::setBinaryGapWidth
bool setBinaryGapWidth(PixelX binaryGapWidth)
sets the spacing in the middle of a binary byte in the value column
Definition: valuebytearraycolumnrenderer.cpp:65
Okteta::DefaultBinaryGapWidth
static const int DefaultBinaryGapWidth
Definition: oktetagui.h:52
Okteta::ValueByteArrayColumnRenderer::renderEditedByte
void renderEditedByte(QPainter *painter, Byte byte, const QString &editBuffer)
Definition: valuebytearraycolumnrenderer.cpp:98
oktetagui.h
Okteta::AbstractByteArrayColumnRenderer::mCharCodec
const CharCodec * mCharCodec
Definition: abstractbytearraycolumnrenderer.h:206
Okteta::Byte
unsigned char Byte
Definition: byte.h:29
Okteta::ValueByteArrayColumnRenderer::renderCode
void renderCode(QPainter *painter, const QString &code, const QColor &color) const
Definition: valuebytearraycolumnrenderer.cpp:125
Okteta::CharCodec::decode
virtual Character decode(Byte byte) const =0
valuebytearraycolumnrenderer.h
Okteta::ValueByteArrayColumnRenderer::mBinaryHalfOffset
PixelX mBinaryHalfOffset
calculated: Offset in pixels of the second half of the binary
Definition: valuebytearraycolumnrenderer.h:80
Okteta::AbstractByteArrayColumnRenderer::mFontMetrics
QFontMetrics mFontMetrics
Definition: abstractbytearraycolumnrenderer.h:213
Okteta::AbstractColumnStylist
Definition: abstractcolumnstylist.h:38
Okteta::ByteArrayTableLayout
the logical layout of a byte array table for a view
Definition: bytearraytablelayout.h:61
Okteta::ValueByteArrayColumnRenderer::setValueCodec
void setValueCodec(ValueCoding valueCoding, const ValueCodec *valueCodec)
Definition: valuebytearraycolumnrenderer.cpp:51
Okteta::PixelX
int PixelX
Definition: kadds.h:34
Okteta::AbstractByteArrayColumnRenderer::setByteWidth
void setByteWidth(int byteWidth)
Definition: abstractbytearraycolumnrenderer.h:273
Okteta::AbstractByteArrayColumnRenderer::byteWidth
PixelX byteWidth() const
Definition: abstractbytearraycolumnrenderer.h:249
Okteta::AbstractByteArrayColumnRenderer::recalcX
void recalcX()
Definition: abstractbytearraycolumnrenderer.cpp:176
Okteta::ValueCodec
Class that is able to convert codings to and from hexadecimal, decimal, octal, and binary...
Definition: valuecodec.h:45
Okteta::ValueByteArrayColumnRenderer::mValueCodec
const ValueCodec * mValueCodec
Definition: valuebytearraycolumnrenderer.h:72
Okteta::ValueByteArrayColumnRenderer::mDecodedByteText
QString mDecodedByteText
buffer to hold the formatted valueCoding
Definition: valuebytearraycolumnrenderer.h:78
Okteta::ValueByteArrayColumnRenderer::~ValueByteArrayColumnRenderer
virtual ~ValueByteArrayColumnRenderer()
Definition: valuebytearraycolumnrenderer.cpp:139
valuecodec.h
Okteta::BinaryCoding
Definition: oktetacore.h:34
Okteta::AbstractByteArrayColumnRenderer
base class of all buffer column displayers holds all information about the vertical layout of a buffe...
Definition: abstractbytearraycolumnrenderer.h:60
Okteta::ValueByteArrayColumnRenderer::recalcByteWidth
virtual void recalcByteWidth()
default implementation sets byte width to one digit width
Definition: valuebytearraycolumnrenderer.cpp:82
charcodec.h
Okteta::ValueByteArrayColumnRenderer::binaryGapWidth
PixelX binaryGapWidth() const
Definition: valuebytearraycolumnrenderer.h:84
foregroundRoleForChar
static KColorScheme::ForegroundRole foregroundRoleForChar(const Okteta::Character byteChar)
Definition: helper.h:46
Okteta::AbstractColumnRenderer::stylist
AbstractColumnStylist * stylist() const
Definition: abstractcolumnrenderer.cpp:40
Okteta::ValueByteArrayColumnRenderer::ValueByteArrayColumnRenderer
ValueByteArrayColumnRenderer(AbstractColumnStylist *stylist, AbstractByteArrayModel *byteArrayModel, ByteArrayTableLayout *layout, ByteArrayTableRanges *ranges)
Definition: valuebytearraycolumnrenderer.cpp:43
Okteta::ValueCoding
ValueCoding
Definition: oktetacore.h:34
Okteta::ValueByteArrayColumnRenderer::mValueCoding
ValueCoding mValueCoding
Definition: valuebytearraycolumnrenderer.h:70
Okteta::AbstractColumnRenderer::lineHeight
PixelY lineHeight() const
Definition: abstractcolumnrenderer.cpp:47
Okteta::AbstractColumnStylist::palette
virtual const QPalette & palette() const =0
Okteta::ValueCodec::encodingWidth
virtual unsigned int encodingWidth() const =0
Okteta::Character
Definition: character.h:35
Okteta::AbstractByteArrayColumnRenderer::mDigitBaseLine
PixelY mDigitBaseLine
Definition: abstractbytearraycolumnrenderer.h:211
helper.h
Okteta::ValueCodec::encode
virtual void encode(QString &digits, unsigned int pos, Byte byte) const =0
Encodes the byte using full coding width, prefixing with 0s if needed, and writes the result to digit...
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal