summaryrefslogtreecommitdiffstats
path: root/khexedit/lib/controller
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /khexedit/lib/controller
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
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
Diffstat (limited to 'khexedit/lib/controller')
-rw-r--r--khexedit/lib/controller/Makefile.am12
-rw-r--r--khexedit/lib/controller/kchareditor.cpp58
-rw-r--r--khexedit/lib/controller/kchareditor.h43
-rw-r--r--khexedit/lib/controller/kcontroller.cpp34
-rw-r--r--khexedit/lib/controller/kcontroller.h44
-rw-r--r--khexedit/lib/controller/keditor.cpp197
-rw-r--r--khexedit/lib/controller/keditor.h52
-rw-r--r--khexedit/lib/controller/knavigator.cpp142
-rw-r--r--khexedit/lib/controller/knavigator.h46
-rw-r--r--khexedit/lib/controller/ktabcontroller.cpp70
-rw-r--r--khexedit/lib/controller/ktabcontroller.h52
-rw-r--r--khexedit/lib/controller/kvalueeditor.cpp226
-rw-r--r--khexedit/lib/controller/kvalueeditor.h75
13 files changed, 1051 insertions, 0 deletions
diff --git a/khexedit/lib/controller/Makefile.am b/khexedit/lib/controller/Makefile.am
new file mode 100644
index 0000000..5fd894b
--- /dev/null
+++ b/khexedit/lib/controller/Makefile.am
@@ -0,0 +1,12 @@
+INCLUDES = -I$(srcdir)/.. $(all_includes)
+
+METASOURCES = AUTO
+
+#
+noinst_LTLIBRARIES = libkcontroller.la
+libkcontroller_la_SOURCES = kcontroller.cpp ktabcontroller.cpp knavigator.cpp \
+ keditor.cpp kvalueeditor.cpp kchareditor.cpp
+
+# no public API
+noinst_HEADERS = kcontroller.h ktabcontroller.h knavigator.h \
+ keditor.h kvalueeditor.h kchareditor.h
diff --git a/khexedit/lib/controller/kchareditor.cpp b/khexedit/lib/controller/kchareditor.cpp
new file mode 100644
index 0000000..5b48fc6
--- /dev/null
+++ b/khexedit/lib/controller/kchareditor.cpp
@@ -0,0 +1,58 @@
+/***************************************************************************
+ kchareditor.cpp - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+// qt specific
+#include <qevent.h>
+// lib specific
+#include "kcharcolumn.h"
+#include "kcharcodec.h"
+#include "khexedit.h"
+#include "kchareditor.h"
+
+
+using namespace KHE;
+
+
+KCharEditor::KCharEditor( KCharColumn *CC, KBufferCursor *BC, KHexEdit *HE, KController *P )
+ : KEditor( BC, HE, P ),
+ CharColumn( CC )
+{
+}
+
+
+bool KCharEditor::handleKeyPress( QKeyEvent *KeyEvent )
+{
+ bool KeyUsed = false;
+ // some input that should be inserted?
+ if( KeyEvent->text().length() > 0
+ && !(KeyEvent->state()&( Qt::ControlButton | Qt::AltButton | Qt::MetaButton )) )
+ {
+ QChar C = KeyEvent->text()[0];
+ if( C.isPrint() )
+ {
+ QByteArray D( 1 );
+ if( CharColumn->codec()->encode(&D[0],C) )
+ {
+ // clearUndoRedoInfo = false;
+ HexEdit->insert( D );
+ KeyUsed = true;
+ }
+ }
+ }
+
+ return KeyUsed ? true : KEditor::handleKeyPress(KeyEvent);
+}
diff --git a/khexedit/lib/controller/kchareditor.h b/khexedit/lib/controller/kchareditor.h
new file mode 100644
index 0000000..74c3d8d
--- /dev/null
+++ b/khexedit/lib/controller/kchareditor.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ kchareditor.h - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef KHE_KCHAREDITOR_H
+#define KHE_KCHAREDITOR_H
+
+// lib specific
+#include "keditor.h"
+
+namespace KHE
+{
+
+class KCharColumn;
+
+class KCharEditor : public KEditor
+{
+ public:
+ KCharEditor( KCharColumn *CC, KBufferCursor *BC, KHexEdit *HE, KController *P );
+
+ public: // KEditor API
+ virtual bool handleKeyPress( QKeyEvent *KeyEvent );
+
+ protected:
+ KCharColumn *CharColumn;
+};
+
+}
+
+#endif
diff --git a/khexedit/lib/controller/kcontroller.cpp b/khexedit/lib/controller/kcontroller.cpp
new file mode 100644
index 0000000..490da93
--- /dev/null
+++ b/khexedit/lib/controller/kcontroller.cpp
@@ -0,0 +1,34 @@
+/***************************************************************************
+ kcontroller.cpp - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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 "khexedit.h"
+#include "kcontroller.h"
+
+
+using namespace KHE;
+
+KController::KController( KHexEdit* HE, KController *P )
+ : Parent( P ), HexEdit( HE )
+{
+}
+
+bool KController::handleKeyPress( QKeyEvent *KeyEvent )
+{
+ return Parent ? Parent->handleKeyPress( KeyEvent ) : false;
+}
diff --git a/khexedit/lib/controller/kcontroller.h b/khexedit/lib/controller/kcontroller.h
new file mode 100644
index 0000000..daeb0d5
--- /dev/null
+++ b/khexedit/lib/controller/kcontroller.h
@@ -0,0 +1,44 @@
+/***************************************************************************
+ kcontroller.h - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef KHE_KCONTROLLER_H
+#define KHE_KCONTROLLER_H
+
+
+class QKeyEvent;
+
+namespace KHE
+{
+
+class KHexEdit;
+
+class KController
+{
+ protected:
+ KController( KHexEdit *HE, KController *P );
+
+ public: // KController API
+ virtual bool handleKeyPress( QKeyEvent *KeyEvent );
+
+ protected:
+ KController *Parent;
+ KHexEdit *HexEdit;
+};
+
+}
+
+#endif
diff --git a/khexedit/lib/controller/keditor.cpp b/khexedit/lib/controller/keditor.cpp
new file mode 100644
index 0000000..7d4e92f
--- /dev/null
+++ b/khexedit/lib/controller/keditor.cpp
@@ -0,0 +1,197 @@
+/***************************************************************************
+ keditor.cpp - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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 "kdatabuffer.h"
+#include "kbufferranges.h"
+#include "kbufferlayout.h"
+#include "kbuffercursor.h"
+#include "kwordbufferservice.h"
+#include "khexedit.h"
+#include "keditor.h"
+
+
+using namespace KHE;
+
+KEditor::KEditor( KBufferCursor *BC, KHexEdit* HE, KController *P )
+ : KController( HE, P ),
+ BufferCursor( BC )
+{
+}
+
+
+bool KEditor::handleKeyPress( QKeyEvent *KeyEvent )
+{
+ bool clearUndoRedoInfo = true;
+ bool ShiftPressed = KeyEvent->state() & Qt::ShiftButton;
+ bool ControlPressed = KeyEvent->state() & Qt::ControlButton;
+ bool AltPressed = KeyEvent->state() & Qt::AltButton;
+
+ bool KeyUsed = true;
+ // we only care for cursor keys and the like, won't hardcode any other keys
+ // we also don't check whether the commands are allowed
+ // as the commands are also available as API so the check has to be done
+ // in each command anyway
+ switch( KeyEvent->key() )
+ {
+ case Qt::Key_Delete:
+ if( ShiftPressed )
+ HexEdit->cut();
+ else if( HexEdit->BufferRanges->hasSelection() )
+ HexEdit->removeSelectedData();
+ else
+ {
+ doEditAction( ControlPressed ? WordDelete : CharDelete );
+ clearUndoRedoInfo = false;
+ }
+ break;
+
+ case Qt::Key_Insert:
+ if( ShiftPressed )
+ HexEdit->paste();
+ else if( ControlPressed )
+ HexEdit->copy();
+ else
+ HexEdit->setOverwriteMode( !HexEdit->OverWrite );
+ break;
+
+ case Qt::Key_Backspace:
+ if( AltPressed )
+ {
+ if( ControlPressed )
+ break;
+ else if( ShiftPressed )
+ {
+// HexEdit->redo();
+ break;
+ }
+ else
+ {
+// HexEdit->undo();
+ break;
+ }
+ }
+ else if( HexEdit->BufferRanges->hasSelection() )
+ {
+ HexEdit->removeSelectedData();
+ break;
+ }
+
+ doEditAction( ControlPressed ? WordBackspace : CharBackspace );
+ clearUndoRedoInfo = false;
+ break;
+ case Qt::Key_F16: // "Copy" key on Sun keyboards
+ HexEdit->copy();
+ break;
+ case Qt::Key_F18: // "Paste" key on Sun keyboards
+ HexEdit->paste();
+ break;
+ case Qt::Key_F20: // "Cut" key on Sun keyboards
+ HexEdit->cut();
+ break;
+
+ default:
+ KeyUsed = false;
+ }
+
+// if( clearUndoRedoInfo )
+// clearUndoRedo();
+// changeIntervalTimer->start( 100, true );
+
+ return KeyUsed ? true : KController::handleKeyPress(KeyEvent);
+}
+
+
+
+void KEditor::doEditAction( KEditAction Action )
+{
+ KSection ChangedRange;
+
+ HexEdit->pauseCursor( true );
+
+ switch( Action )
+ {
+ case CharDelete:
+ if( !HexEdit->OverWrite )
+ {
+ int Index = BufferCursor->realIndex();
+ if( Index < HexEdit->BufferLayout->length() )
+ {
+ ChangedRange = HexEdit->removeData( KSection(Index,1,false) );
+ if( Index == HexEdit->BufferLayout->length() )
+ BufferCursor->gotoEnd();
+ }
+ }
+ break;
+
+ case WordDelete: // kills data until the start of the next word
+ if( !HexEdit->OverWrite )
+ {
+ int Index = BufferCursor->realIndex();
+ if( Index < HexEdit->BufferLayout->length() )
+ {
+ KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
+ int End = WBS.indexOfBeforeNextWordStart( Index );
+ ChangedRange = HexEdit->removeData( KSection(Index,End) );
+ if( Index == HexEdit->BufferLayout->length() )
+ BufferCursor->gotoEnd();
+ }
+ }
+ break;
+
+ case CharBackspace:
+ if( HexEdit->OverWrite )
+ BufferCursor->gotoPreviousByte();
+ else
+ {
+ int DeleteIndex = BufferCursor->realIndex() - 1;
+ if( DeleteIndex >= 0 )
+ {
+ ChangedRange = HexEdit->removeData( KSection(DeleteIndex,1,false) );
+ if( DeleteIndex == HexEdit->BufferLayout->length() )
+ BufferCursor->gotoEnd();
+ else
+ BufferCursor->gotoPreviousByte();
+ }
+ }
+ break;
+ case WordBackspace:
+ {
+ int LeftIndex = BufferCursor->realIndex() - 1;
+ if( LeftIndex >= 0 )
+ {
+ KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
+ int WordStart = WBS.indexOfPreviousWordStart( LeftIndex );
+ if( !HexEdit->OverWrite )
+ ChangedRange = HexEdit->removeData( KSection(WordStart,LeftIndex) );
+ if( WordStart == HexEdit->BufferLayout->length() )
+ BufferCursor->gotoEnd();
+ else
+ BufferCursor->gotoIndex(WordStart);
+ }
+ }
+ }
+
+ HexEdit->repaintChanged();
+ HexEdit->ensureCursorVisible();
+
+ HexEdit->unpauseCursor();
+
+ emit HexEdit->cursorPositionChanged( BufferCursor->index() );
+ if( ChangedRange.isValid() ) emit HexEdit->bufferChanged( ChangedRange.start(), ChangedRange.end() );
+}
diff --git a/khexedit/lib/controller/keditor.h b/khexedit/lib/controller/keditor.h
new file mode 100644
index 0000000..dc2b0fd
--- /dev/null
+++ b/khexedit/lib/controller/keditor.h
@@ -0,0 +1,52 @@
+/***************************************************************************
+ keditor.h - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef KHE_KEDITOR_H
+#define KHE_KEDITOR_H
+
+
+// lib specific
+#include "kcontroller.h"
+
+
+namespace KHE
+{
+
+class KBufferCursor;
+
+class KEditor : public KController
+{
+ protected:
+ enum KEditAction { CharDelete, WordDelete, CharBackspace, WordBackspace };
+
+ protected:
+ KEditor( KBufferCursor *BC, KHexEdit *HE, KController *P );
+
+ public: // API
+ virtual bool handleKeyPress( QKeyEvent *KeyEvent );
+
+ protected:
+ /** executes keyboard Action \a Action. This is normally called by a key event handler. */
+ void doEditAction( KEditAction Action );
+
+ protected:
+ KBufferCursor *BufferCursor;
+};
+
+}
+
+#endif
diff --git a/khexedit/lib/controller/knavigator.cpp b/khexedit/lib/controller/knavigator.cpp
new file mode 100644
index 0000000..51c8048
--- /dev/null
+++ b/khexedit/lib/controller/knavigator.cpp
@@ -0,0 +1,142 @@
+/***************************************************************************
+ knavigator.cpp - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+
+// qt specific
+#include <qevent.h>
+// lib specific
+#include "kdatabuffer.h"
+#include "kbufferranges.h"
+#include "kbuffercursor.h"
+#include "kwordbufferservice.h"
+#include "khexedit.h"
+#include "knavigator.h"
+
+
+using namespace KHE;
+
+KNavigator::KNavigator( KHexEdit* HE, KController *P )
+ : KController( HE, P )
+{
+}
+
+bool KNavigator::handleKeyPress( QKeyEvent *KeyEvent )
+{
+ bool KeyUsed = true;
+
+ //bool clearUndoRedoInfo = true;
+ bool ShiftPressed = KeyEvent->state() & Qt::ShiftButton;
+ bool ControlPressed = KeyEvent->state() & Qt::ControlButton;
+ //bool AltPressed = KeyEvent->state() & AltButton;
+
+ // we only care for cursor keys and the like, won't hardcode any other keys
+ // we also don't check whether the commands are allowed
+ // as the commands are also available as API so the check has to be done
+ // in each command anyway
+ switch( KeyEvent->key() )
+ {
+ case Qt::Key_Left:
+ moveCursor( ControlPressed ? MoveWordBackward : MoveBackward, ShiftPressed );
+ break;
+ case Qt::Key_Right:
+ moveCursor( ControlPressed ? MoveWordForward : MoveForward, ShiftPressed );
+ break;
+ case Qt::Key_Up:
+ moveCursor( ControlPressed ? MovePgUp : MoveUp, ShiftPressed );
+ break;
+ case Qt::Key_Down:
+ moveCursor( ControlPressed ? MovePgDown : MoveDown, ShiftPressed );
+ break;
+ case Qt::Key_Home:
+ moveCursor( ControlPressed ? MoveHome : MoveLineStart, ShiftPressed );
+ break;
+ case Qt::Key_End:
+ moveCursor( ControlPressed ? MoveEnd : MoveLineEnd, ShiftPressed );
+ break;
+ case Qt::Key_Prior:
+ moveCursor( MovePgUp, ShiftPressed );
+ break;
+ case Qt::Key_Next:
+ moveCursor( MovePgDown, ShiftPressed );
+ break;
+
+ default:
+ KeyUsed = false;
+ }
+
+ return KeyUsed ? true : KController::handleKeyPress(KeyEvent);
+}
+
+
+void KNavigator::moveCursor( KMoveAction Action, bool Select )
+{
+ HexEdit->pauseCursor( true );
+
+ KBufferCursor *BufferCursor = HexEdit->BufferCursor;
+ KBufferRanges *BufferRanges = HexEdit->BufferRanges;
+
+ if( Select )
+ {
+ if( !BufferRanges->selectionStarted() )
+ BufferRanges->setSelectionStart( BufferCursor->realIndex() );
+ }
+ else
+ BufferRanges->removeSelection();
+
+ HexEdit->resetInputContext();
+ switch( Action )
+ {
+ case MoveBackward: BufferCursor->gotoPreviousByte(); break;
+ case MoveWordBackward: {
+ KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
+ int NewIndex = WBS.indexOfPreviousWordStart( BufferCursor->realIndex() );
+ BufferCursor->gotoIndex( NewIndex );
+ }
+ break;
+ case MoveForward: BufferCursor->gotoNextByte(); break;
+ case MoveWordForward: {
+ KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
+ int NewIndex = WBS.indexOfNextWordStart( BufferCursor->realIndex() );
+ BufferCursor->gotoCIndex( NewIndex );
+ }
+ break;
+ case MoveUp: BufferCursor->gotoUp(); break;
+ case MovePgUp: BufferCursor->gotoPageUp(); break;
+ case MoveDown: BufferCursor->gotoDown(); break;
+ case MovePgDown: BufferCursor->gotoPageDown(); break;
+ case MoveLineStart: BufferCursor->gotoLineStart(); break;
+ case MoveHome: BufferCursor->gotoStart(); break;
+ case MoveLineEnd: BufferCursor->gotoLineEnd(); break;
+ case MoveEnd: BufferCursor->gotoEnd(); break;
+ }
+
+ if( Select )
+ BufferRanges->setSelectionEnd( BufferCursor->realIndex() );
+
+ HexEdit->repaintChanged();
+ HexEdit->ensureCursorVisible();
+
+ HexEdit->unpauseCursor();
+
+ if( BufferRanges->isModified() )
+ {
+ if( !HexEdit->isOverwriteMode() ) emit HexEdit->cutAvailable( BufferRanges->hasSelection() );
+ emit HexEdit->copyAvailable( BufferRanges->hasSelection() );
+ KSection Selection = BufferRanges->selection();
+ emit HexEdit->selectionChanged( Selection.start(), Selection.end() );
+ }
+}
diff --git a/khexedit/lib/controller/knavigator.h b/khexedit/lib/controller/knavigator.h
new file mode 100644
index 0000000..4615419
--- /dev/null
+++ b/khexedit/lib/controller/knavigator.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ knavigator.h - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef KHE_KNAVIGATOR_H
+#define KHE_KNAVIGATOR_H
+
+// lib specific
+#include "kcontroller.h"
+
+namespace KHE
+{
+
+class KNavigator : public KController
+{
+ protected:
+ enum KMoveAction { MoveBackward, MoveWordBackward, MoveForward, MoveWordForward,
+ MoveUp, MovePgUp, MoveDown, MovePgDown,
+ MoveLineStart, MoveHome, MoveLineEnd, MoveEnd };
+ public:
+ KNavigator( KHexEdit *HE, KController *P );
+
+ public: // KEditor API
+ virtual bool handleKeyPress( QKeyEvent *KeyEvent );
+
+ protected:
+ /** moves the cursor according to the action, handles all drawing */
+ void moveCursor( KMoveAction Action, bool Select );
+};
+
+}
+
+#endif
diff --git a/khexedit/lib/controller/ktabcontroller.cpp b/khexedit/lib/controller/ktabcontroller.cpp
new file mode 100644
index 0000000..76c3051
--- /dev/null
+++ b/khexedit/lib/controller/ktabcontroller.cpp
@@ -0,0 +1,70 @@
+/***************************************************************************
+ ktabcontroller.cpp - description
+ -------------------
+ begin : So Dez 5 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+// qt specific
+#include <qevent.h>
+// lib specific
+#include "kvaluecolumn.h"
+#include "kcharcolumn.h"
+#include "khexedit.h"
+#include "ktabcontroller.h"
+
+
+using namespace KHE;
+
+KTabController::KTabController( KHexEdit* HE, KController *P )
+ : KController( HE, P ),
+ TabChangesFocus( false )
+{
+}
+
+
+bool KTabController::handleKeyPress( QKeyEvent *KeyEvent )
+{
+ bool KeyUsed = false;
+
+ bool ShiftPressed = KeyEvent->state() & Qt::ShiftButton;
+
+ if( KeyEvent->key() == Qt::Key_Tab )
+ {
+ // are we in the char column?
+ if( HexEdit->cursorColumn() == KHexEdit::CharColumnId )
+ {
+ // in last column we care about tab changes focus
+ if( HexEdit->ValueColumn->isVisible() && (!TabChangesFocus || ShiftPressed) )
+ {
+ HexEdit->setCursorColumn( KHexEdit::ValueColumnId );
+ KeyUsed = true;
+ }
+ }
+ // value column then
+ else
+ {
+ if( HexEdit->CharColumn->isVisible() )
+ {
+ // in last column we care about tab changes focus
+ if( HexEdit->CharColumn->isVisible() && (!TabChangesFocus || !ShiftPressed) )
+ {
+ HexEdit->setCursorColumn( KHexEdit::CharColumnId );
+ KeyUsed = true;
+ }
+ }
+ }
+ }
+
+ return KeyUsed ? true : KController::handleKeyPress(KeyEvent);
+}
diff --git a/khexedit/lib/controller/ktabcontroller.h b/khexedit/lib/controller/ktabcontroller.h
new file mode 100644
index 0000000..e1898b4
--- /dev/null
+++ b/khexedit/lib/controller/ktabcontroller.h
@@ -0,0 +1,52 @@
+/***************************************************************************
+ ktabcontroller.h - description
+ -------------------
+ begin : So Dez 5 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef KHE_KTABCONTROLLER_H
+#define KHE_KTABCONTROLLER_H
+
+
+// lib specific
+#include "kcontroller.h"
+
+
+namespace KHE
+{
+
+class KTabController : public KController
+{
+ public:
+ KTabController( KHexEdit *HE, KController *P );
+
+ public: // API
+ virtual bool handleKeyPress( QKeyEvent *KeyEvent );
+
+ public:
+ bool tabChangesFocus() const;
+ void setTabChangesFocus( bool TCF );
+
+ protected:
+ /** flag if tab key should be ignored */
+ bool TabChangesFocus:1;
+};
+
+
+inline bool KTabController::tabChangesFocus() const { return TabChangesFocus; }
+inline void KTabController::setTabChangesFocus( bool TCF ) { TabChangesFocus = TCF; }
+
+}
+
+#endif
diff --git a/khexedit/lib/controller/kvalueeditor.cpp b/khexedit/lib/controller/kvalueeditor.cpp
new file mode 100644
index 0000000..ebfb589
--- /dev/null
+++ b/khexedit/lib/controller/kvalueeditor.cpp
@@ -0,0 +1,226 @@
+/***************************************************************************
+ kvalueeditor.cpp - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+// qt specific
+#include <qevent.h>
+// lib specific
+#include "kvaluecolumn.h"
+#include "kbufferranges.h"
+#include "kbuffercursor.h"
+#include "khexedit.h"
+#include "kvalueeditor.h"
+
+
+using namespace KHE;
+
+KValueEditor::KValueEditor( KValueColumn *VC, KBufferCursor *BC, KHexEdit* HE, KController *P )
+ : KEditor( BC, HE, P ),
+ ValueColumn( VC ),
+ InEditMode( false ),
+ EditModeByInsert( false )
+{
+}
+
+
+bool KValueEditor::handleKeyPress( QKeyEvent *KeyEvent )
+{
+ bool KeyUsed = true;
+
+ // TODO: for now we don't touch it if there are selections
+ if( !HexEdit->BufferRanges->hasSelection() )
+ {
+ //
+ switch( KeyEvent->key() )
+ {
+ case Qt::Key_Plus:
+ doValueEditAction( IncValue );
+ break;
+ case Qt::Key_Minus:
+ doValueEditAction( DecValue );
+ break;
+ case Qt::Key_Space:
+ if( !InEditMode )
+ {
+ KeyUsed = false;
+ break;
+ }
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ doValueEditAction( InEditMode?LeaveValue:EnterValue );
+ break;
+ case Qt::Key_Escape:
+ if( InEditMode )
+ doValueEditAction( CancelValue );
+ else
+ KeyUsed = false;
+ break;
+ case Qt::Key_Backspace:
+ if( InEditMode )
+ doValueEditAction( ValueBackspace );
+ else
+ KeyUsed = false;
+ break;
+ default:
+ // is plain char?
+ if( KeyEvent->text().length() > 0
+ && ( !(KeyEvent->state()&( Qt::ControlButton | Qt::AltButton | Qt::MetaButton )) ) )
+ {
+ QChar C = KeyEvent->text()[0];
+ // no usable char?
+ if( !C.isLetterOrNumber() )
+ {
+ KeyUsed = false;
+ break;
+ }
+ int Input = C.latin1();
+
+ if( InEditMode )
+ doValueEditAction( ValueAppend, Input );
+ else
+ {
+ unsigned char InputValue = 0;
+ const KByteCodec *ByteCodec = ValueColumn->byteCodec();
+ // valid digit?
+ if( ByteCodec->appendDigit(&InputValue,Input) )
+ {
+ if( HexEdit->OverWrite )
+ doValueEditAction( ValueEdit, InputValue );
+ else
+ {
+ int Index = BufferCursor->realIndex();
+ if( HexEdit->DataBuffer->insert(Index,(char*)&InputValue,1) > 0 )
+ {
+ HexEdit->pauseCursor();
+ HexEdit->updateLength();
+
+ InEditMode = true;
+ EditModeByInsert = true;
+ OldValue = EditValue = InputValue;
+ ByteCodec->encode( ByteBuffer, 0, EditValue );
+
+ BufferCursor->gotoRealIndex();
+ KSection ChangedRange( Index,HexEdit->DataBuffer->size()-1 );
+ HexEdit->BufferRanges->addChangedRange( ChangedRange );
+ HexEdit->repaintChanged();
+ HexEdit->ensureCursorVisible();
+ HexEdit->unpauseCursor();
+ HexEdit->updateCursor();
+ emit HexEdit->bufferChanged( ChangedRange.start(), ChangedRange.end() );
+ }
+ }
+ }
+ }
+ }
+ else
+ KeyUsed = false;
+ }
+ }
+ else
+ KeyUsed = false;
+
+ return KeyUsed ? true : KEditor::handleKeyPress(KeyEvent);
+}
+
+
+void KValueEditor::doValueEditAction( KValueEditAction Action, int Input )
+{
+ // we are not yet in edit mode?
+ if( !InEditMode )
+ {
+ int ValidIndex = BufferCursor->validIndex();
+ // no valid cursor position?
+ if( ValidIndex == -1 || (!HexEdit->OverWrite && Input == -1) || BufferCursor->isBehind() )
+ return;
+
+ InEditMode = true;
+ EditModeByInsert = false; // default, to be overwritten if so
+
+ // save old value
+ OldValue = EditValue = (unsigned char)HexEdit->DataBuffer->datum(ValidIndex);
+ }
+
+ const KByteCodec *ByteCodec = ValueColumn->byteCodec();
+ //
+ unsigned char NewValue = EditValue;
+ bool StayInEditMode = true;
+ bool MoveToNext = false;
+
+ switch( Action )
+ {
+ case ValueEdit:
+ NewValue = Input;
+ EditValue = NewValue^255; // force update
+ EditModeByInsert = true;
+ break;
+ case ValueBackspace:
+ if( NewValue > 0 )
+ ByteCodec->removeLastDigit( &NewValue );
+ break;
+ case EnterValue:
+ EditValue ^= 255; // force update
+ break;
+ case IncValue:
+ if( NewValue < 255 )
+ ++NewValue;
+ break;
+ case DecValue:
+ if( NewValue > 0 )
+ --NewValue;
+ break;
+ case ValueAppend:
+ if( ByteCodec->appendDigit(&NewValue,Input) )
+ if( EditModeByInsert && NewValue >= ByteCodec->digitsFilledLimit() )
+ {
+ StayInEditMode = false;
+ MoveToNext = true;
+ }
+ break;
+ case LeaveValue:
+ StayInEditMode = false;
+ MoveToNext = EditModeByInsert;
+ break;
+ case CancelValue:
+ NewValue = OldValue;
+ StayInEditMode = false;
+ break;
+ }
+
+ bool Changed = (NewValue != EditValue);
+ int Index = BufferCursor->index();
+ if( Changed )
+ {
+ // sync value
+ EditValue = NewValue;
+ ByteCodec->encode( ByteBuffer, 0, EditValue );
+
+ HexEdit->DataBuffer->replace( Index, 1, (char*)&EditValue, 1 );
+ }
+
+ HexEdit->updateCursor();
+
+ if( !StayInEditMode )
+ {
+ HexEdit->pauseCursor();
+ InEditMode = false;
+ if( MoveToNext )
+ BufferCursor->gotoNextByte();
+ HexEdit->unpauseCursor();
+ }
+
+ if( Changed )
+ if( Action != EnterValue ) emit HexEdit->bufferChanged( Index, Index );
+}
diff --git a/khexedit/lib/controller/kvalueeditor.h b/khexedit/lib/controller/kvalueeditor.h
new file mode 100644
index 0000000..496bcde
--- /dev/null
+++ b/khexedit/lib/controller/kvalueeditor.h
@@ -0,0 +1,75 @@
+/***************************************************************************
+ kvalueeditor.h - description
+ -------------------
+ begin : Sa Dez 4 2004
+ copyright : (C) 2004 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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef KHE_KVALUEEDITOR_H
+#define KHE_KVALUEEDITOR_H
+
+
+// lib specific
+#include "keditor.h"
+
+namespace KHE
+{
+
+class KValueColumn;
+
+
+class KValueEditor: public KEditor
+{
+ protected:
+ enum KValueEditAction
+ { EnterValue, IncValue, DecValue, ValueAppend, ValueEdit, LeaveValue, CancelValue, ValueBackspace };
+
+ public:
+ KValueEditor( KValueColumn *VC, KBufferCursor *BC, KHexEdit *HE, KController *P );
+ virtual ~KValueEditor();
+
+ public: // KEditor API
+ virtual bool handleKeyPress( QKeyEvent *KeyEvent );
+
+ public:
+ void reset();
+
+ public:
+ bool isInEditMode() const;
+
+ protected:
+ /** executes keyboard Action \a Action. This is normally called by a key event handler. */
+ void doValueEditAction( KValueEditAction Action, int Input = -1 );
+
+ public://protected:
+ KValueColumn *ValueColumn;
+ /** flag whether we are in editing mode */
+ bool InEditMode:1;
+ /** flag whether byte edit mode was reached by inserting */
+ bool EditModeByInsert:1;
+ /** */
+ unsigned char EditValue;
+ /** stores the old byte value */
+ unsigned char OldValue;
+ /** buffer with the */
+ QString ByteBuffer;
+};
+
+inline KValueEditor::~KValueEditor() {}
+
+inline bool KValueEditor::isInEditMode() const { return InEditMode; }
+inline void KValueEditor::reset() { InEditMode = false; }
+
+}
+
+#endif