From 2bda8f7717adf28da4af0d34fb82f63d2868c31d Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- khexedit/lib/kbytesedit.cpp | 162 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 khexedit/lib/kbytesedit.cpp (limited to 'khexedit/lib/kbytesedit.cpp') diff --git a/khexedit/lib/kbytesedit.cpp b/khexedit/lib/kbytesedit.cpp new file mode 100644 index 0000000..40b57a1 --- /dev/null +++ b/khexedit/lib/kbytesedit.cpp @@ -0,0 +1,162 @@ +/*************************************************************************** + kbytesedit.cpp - description + ------------------- + begin : Die Jul 9 2003 + copyright : (C) 2003 by Friedrich W. H. Kossebau + email : Friedrich.W.H@Kossebau.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License version 2 as published by the Free Software Foundation. * + * * + ***************************************************************************/ + + +// lib specific +#include "kplainbuffer.h" +#include "kbytesedit.h" +#include "kbufferranges.h" +#include "kbuffercursor.h" + +using namespace KHE; + + +KBytesEdit::KBytesEdit( char *D, int DS_, int RS_, bool KM, QWidget *Parent, const char *Name, WFlags F ) + : KHexEdit( 0L, Parent, Name, F ), + AutoDelete( false ) +{ + setData( D, DS_, RS_, KM ); +} + +KBytesEdit::KBytesEdit( char *D, int DS_, QWidget *Parent, const char *Name, WFlags F ) + : KHexEdit( 0L, Parent, Name, F ), + AutoDelete( false ) +{ + setData( D, DS_ ); +} + + +KBytesEdit::KBytesEdit( QWidget *Parent, const char *Name, WFlags F ) + : KHexEdit( 0L, Parent, Name, F ), + AutoDelete( false ) +{ + setDataBuffer( new KPlainBuffer() ); +} + +KBytesEdit::~KBytesEdit() +{ + clean(); +} + +void KBytesEdit::setReadOnly( bool RO ) +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + if( Buffer ) + Buffer->setReadOnly( RO ); + KHexEdit::setReadOnly( RO ); +} + + +void KBytesEdit::setAutoDelete( bool AD ) +{ + AutoDelete = AD; +} + + +char *KBytesEdit::data() const +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + return Buffer ? Buffer->data() : 0L; +} + + +void KBytesEdit::setData( char *D, int S, int RS_, bool KM ) +{ + KPlainBuffer *NewBuffer = new KPlainBuffer( D, S, RS_, KM ); + if( DataBuffer ) + { + // take the settings + NewBuffer->setReadOnly( DataBuffer->isReadOnly() ); + clean(); + } + else + NewBuffer->setReadOnly( isReadOnly() ); + + setDataBuffer( NewBuffer ); +} + + +int KBytesEdit::dataSize() const +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + return Buffer ? Buffer->size() : -1; +} + + +int KBytesEdit::maxDataSize() const +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + return Buffer ? Buffer->maxSize() : -1; +} + + +void KBytesEdit::setMaxDataSize( int MS ) +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + if( Buffer ) + Buffer->setMaxSize( MS ); +} + + +bool KBytesEdit::keepsMemory() const +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + return Buffer ? Buffer->keepsMemory() : false; +} + + +void KBytesEdit::setKeepsMemory( bool KM ) +{ + KPlainBuffer *Buffer = dynamic_cast(DataBuffer); + if( Buffer ) + Buffer->setKeepsMemory( KM ); +} + + +bool KBytesEdit::isAutoDelete() const { return AutoDelete; } + + +void KBytesEdit::repaintRange( int i1, int i2 ) +{ + bool ChangeCursor = !(CursorPaused) && KSection(i1,i2).includes( BufferCursor->index() ); + if( ChangeCursor ) + pauseCursor(); + + BufferRanges->addChangedRange( i1, i2 ); + + repaintChanged(); + + if( ChangeCursor ) + unpauseCursor(); +} + + +void KBytesEdit::clean() +{ + if( DataBuffer ) + { + if( AutoDelete ) + { + char *D = data(); + if( D ) + delete [] D; + } + delete DataBuffer; + } +} + + +#include "kbytesedit.moc" -- cgit v1.2.1