• 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
  • controller
knavigator.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 2004,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 "knavigator.h"
24 
25 // lib
26 #include <bytearraytableranges.h>
27 #include <bytearraytablecursor.h>
28 #include <abstractbytearrayview.h>
29 // lib
30 #include <wordbytearrayservice.h>
31 // Qt
32 #include <QtGui/QKeyEvent>
33 
34 
35 namespace Okteta
36 {
37 
38 KNavigator::KNavigator( AbstractByteArrayView* view, KController* parent )
39  : KController( parent ),
40  mView( view )
41 {
42 }
43 
44 bool KNavigator::handleKeyPress( QKeyEvent *keyEvent )
45 {
46  bool keyUsed;
47 
48  const bool altPressed = keyEvent->modifiers() & Qt::ALT;
49  if( altPressed )
50  // currently there is no input with the Alt modifier used, so ignore them all
51  keyUsed = false;
52  else
53  {
54  keyUsed = true;
55 
56  const bool shiftPressed = keyEvent->modifiers() & Qt::SHIFT;
57  const bool controlPressed = keyEvent->modifiers() & Qt::CTRL;
58 
59  // we only care for cursor keys and the like, won't hardcode any other keys
60  // we also don't check whether the commands are allowed
61  // as the commands are also available as API so the check has to be done
62  // in each command anyway
63  switch( keyEvent->key() )
64  {
65  case Qt::Key_Left:
66  moveCursor( controlPressed ? MoveWordBackward : MoveBackward, shiftPressed );
67  break;
68  case Qt::Key_Right:
69  moveCursor( controlPressed ? MoveWordForward : MoveForward, shiftPressed );
70  break;
71  case Qt::Key_Up:
72  moveCursor( controlPressed ? MovePgUp : MoveUp, shiftPressed );
73  break;
74  case Qt::Key_Down:
75  moveCursor( controlPressed ? MovePgDown : MoveDown, shiftPressed );
76  break;
77  case Qt::Key_Home:
78  moveCursor( controlPressed ? MoveHome : MoveLineStart, shiftPressed );
79  break;
80  case Qt::Key_End:
81  moveCursor( controlPressed ? MoveEnd : MoveLineEnd, shiftPressed );
82  break;
83  case Qt::Key_PageUp:
84  moveCursor( MovePgUp, shiftPressed );
85  break;
86  case Qt::Key_PageDown:
87  moveCursor( MovePgDown, shiftPressed );
88  break;
89  default:
90  keyUsed = false;
91  }
92  }
93 
94  return keyUsed ? true : KController::handleKeyPress(keyEvent);
95 }
96 
97 
98 void KNavigator::moveCursor( KMoveAction action, bool select )
99 {
100  mView->pauseCursor();
101  mView->finishByteEdit();
102 
103  ByteArrayTableCursor* tableCursor = mView->tableCursor();
104  ByteArrayTableRanges* tableRanges = mView->tableRanges();
105 
106  if( select )
107  {
108  if( !tableRanges->selectionStarted() )
109  tableRanges->setSelectionStart( tableCursor->realIndex() );
110  }
111  else
112  tableRanges->removeSelection();
113 
114  switch( action )
115  {
116  case MoveBackward: tableCursor->gotoPreviousByte(); break;
117  case MoveWordBackward: {
118  const Okteta::WordByteArrayService WBS( mView->byteArrayModel(), mView->charCodec() );
119  const int newIndex = WBS.indexOfPreviousWordStart( tableCursor->realIndex() );
120  tableCursor->gotoIndex( newIndex );
121  }
122  break;
123  case MoveForward: tableCursor->gotoNextByte(); break;
124  case MoveWordForward: {
125  const Okteta::WordByteArrayService WBS( mView->byteArrayModel(), mView->charCodec() );
126  const int newIndex = WBS.indexOfNextWordStart( tableCursor->realIndex() );
127  tableCursor->gotoCIndex( newIndex );
128  }
129  break;
130  case MoveUp: tableCursor->gotoUp(); break;
131  case MovePgUp: tableCursor->gotoPageUp(); break;
132  case MoveDown: tableCursor->gotoDown(); break;
133  case MovePgDown: tableCursor->gotoPageDown(); break;
134  case MoveLineStart: tableCursor->gotoLineStart(); break;
135  case MoveHome: tableCursor->gotoStart(); break;
136  case MoveLineEnd: tableCursor->gotoLineEnd(); break;
137  case MoveEnd: tableCursor->gotoEnd(); break;
138  }
139 
140  if( select )
141  tableRanges->setSelectionEnd( tableCursor->realIndex() );
142 
143  if( tableRanges->isModified() )
144  mView->emitSelectionSignals(); // TODO: can this be moved somewhere
145  emit mView->cursorPositionChanged( tableCursor->realIndex() );
146  mView->updateChanged();
147  mView->ensureCursorVisible();
148 
149  mView->unpauseCursor();
150 }
151 
152 }
Okteta::KNavigator::MoveEnd
Definition: knavigator.h:41
wordbytearrayservice.h
Okteta::AbstractByteArrayView::tableCursor
ByteArrayTableCursor * tableCursor() const
Definition: abstractbytearrayview.cpp:106
Okteta::KNavigator::MoveBackward
Definition: knavigator.h:39
Okteta::KNavigator::KNavigator
KNavigator(AbstractByteArrayView *view, KController *parent)
Definition: knavigator.cpp:38
Okteta::KNavigator::MovePgDown
Definition: knavigator.h:40
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::ByteArrayTableCursor::gotoLineEnd
void gotoLineEnd()
Definition: bytearraytablecursor.cpp:182
Okteta::KNavigator::MovePgUp
Definition: knavigator.h:40
Okteta::AbstractByteArrayView::updateChanged
void updateChanged()
Definition: abstractbytearrayview.cpp:505
Okteta::WordByteArrayService::indexOfNextWordStart
Address indexOfNextWordStart(Address index) const
searches for the start of the next word not including the given index.
Definition: wordbytearrayservice.cpp:80
Okteta::KNavigator::moveCursor
void moveCursor(KMoveAction Action, bool Select)
moves the cursor according to the action, handles all drawing
Definition: knavigator.cpp:98
Okteta::AbstractByteArrayView::emitSelectionSignals
void emitSelectionSignals()
Definition: abstractbytearrayview.cpp:494
Okteta::KNavigator::MoveHome
Definition: knavigator.h:41
abstractbytearrayview.h
Okteta::KNavigator::mView
AbstractByteArrayView * mView
Definition: knavigator.h:53
Okteta::AbstractByteArrayView
Definition: abstractbytearrayview.h:55
Okteta::ByteArrayTableCursor::gotoPreviousByte
void gotoPreviousByte()
Definition: bytearraytablecursor.cpp:70
Okteta::ByteArrayTableCursor::gotoIndex
void gotoIndex(Address index)
Definition: bytearraytablecursor.cpp:260
Okteta::KNavigator::MoveLineEnd
Definition: knavigator.h:41
Okteta::ByteArrayTableCursor::gotoNextByte
void gotoNextByte()
Definition: bytearraytablecursor.cpp:102
Okteta::ByteArrayTableCursor::gotoPageDown
void gotoPageDown()
Definition: bytearraytablecursor.cpp:315
Okteta::ByteArrayTableCursor::gotoUp
void gotoUp()
Definition: bytearraytablecursor.cpp:133
Okteta::ByteArrayTableCursor::gotoDown
void gotoDown()
Definition: bytearraytablecursor.cpp:159
Okteta::KNavigator::handleKeyPress
virtual bool handleKeyPress(QKeyEvent *keyEvent)
Definition: knavigator.cpp:44
Okteta::KNavigator::MoveDown
Definition: knavigator.h:40
Okteta::AbstractByteArrayView::byteArrayModel
Okteta::AbstractByteArrayModel * byteArrayModel() const
Definition: abstractbytearrayview.cpp:44
Okteta::ByteArrayTableRanges::setSelectionStart
void setSelectionStart(Address startIndex)
Definition: bytearraytableranges.cpp:83
Okteta::AbstractByteArrayView::pauseCursor
void pauseCursor()
simply pauses any blinking, i.e.
Definition: abstractbytearrayview.cpp:421
Okteta::AbstractByteArrayView::cursorPositionChanged
void cursorPositionChanged(Okteta::Address index)
Okteta::KNavigator::MoveWordBackward
Definition: knavigator.h:39
knavigator.h
Okteta::KNavigator::MoveLineStart
Definition: knavigator.h:41
Okteta::WordByteArrayService
Definition: wordbytearrayservice.h:44
Okteta::AbstractByteArrayView::finishByteEdit
void finishByteEdit()
Definition: abstractbytearrayview.cpp:487
Okteta::ByteArrayTableCursor
navigates through the buffer in an abstract way, based on the layout
Definition: bytearraytablecursor.h:60
Okteta::ByteArrayTableCursor::gotoCIndex
void gotoCIndex(Address index)
Definition: bytearraytablecursor.cpp:218
Okteta::ByteArrayTableCursor::gotoLineStart
void gotoLineStart()
Definition: bytearraytablecursor.cpp:173
Okteta::KController::handleKeyPress
virtual bool handleKeyPress(QKeyEvent *keyEvent)
Definition: kcontroller.cpp:34
Okteta::AbstractByteArrayView::unpauseCursor
void unpauseCursor()
undoes pauseCursor
Definition: abstractbytearrayview.cpp:409
Okteta::AbstractByteArrayView::tableRanges
ByteArrayTableRanges * tableRanges() const
Definition: abstractbytearrayview.cpp:111
Okteta::ByteArrayTableCursor::realIndex
Address realIndex() const
returns the real index.
Definition: bytearraytablecursor.h:175
Okteta::KNavigator::MoveWordForward
Definition: knavigator.h:39
Okteta::KNavigator::KMoveAction
KMoveAction
Definition: knavigator.h:39
bytearraytableranges.h
Okteta::AbstractByteArrayView::charCodec
const Okteta::CharCodec * charCodec() const
Definition: abstractbytearrayview.cpp:100
Okteta::ByteArrayTableCursor::gotoStart
void gotoStart()
Definition: bytearraytablecursor.cpp:195
Okteta::ByteArrayTableRanges::selectionStarted
bool selectionStarted() const
Definition: bytearraytableranges.h:137
Okteta::ByteArrayTableRanges::setSelectionEnd
void setSelectionEnd(Address startIndex)
Definition: bytearraytableranges.cpp:93
Okteta::ByteArrayTableRanges::removeSelection
AddressRange removeSelection(int id=0)
removes selection with id and returns it
Definition: bytearraytableranges.cpp:156
Okteta::KNavigator::MoveUp
Definition: knavigator.h:40
Okteta::AbstractByteArrayView::ensureCursorVisible
void ensureCursorVisible()
scrolls the view as much as needed to have the cursor fully visible
Definition: abstractbytearrayview.cpp:390
Okteta::KNavigator::MoveForward
Definition: knavigator.h:39
bytearraytablecursor.h
Okteta::WordByteArrayService::indexOfPreviousWordStart
Address indexOfPreviousWordStart(Address index) const
searches for the first char after the end of the word including the given index.
Definition: wordbytearrayservice.cpp:54
Okteta::ByteArrayTableRanges::isModified
bool isModified() const
Definition: bytearraytableranges.h:133
Okteta::ByteArrayTableCursor::gotoEnd
void gotoEnd()
sets the index behind the last index.
Definition: bytearraytablecursor.cpp:203
Okteta::ByteArrayTableCursor::gotoPageUp
void gotoPageUp()
Definition: bytearraytablecursor.cpp:295
Okteta::KController
Definition: kcontroller.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 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