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/controller/knavigator.cpp | 142 +++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 khexedit/lib/controller/knavigator.cpp (limited to 'khexedit/lib/controller/knavigator.cpp') 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 +// 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() ); + } +} -- cgit v1.2.3