• 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
keditor.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 "keditor.h"
24 
25 // lib
26 #include <bytearraytablelayout.h>
27 #include <bytearraytablecursor.h>
28 #include <abstractbytearrayview.h>
29 // Okteta core
30 #include <abstractbytearraymodel.h>
31 #include <wordbytearrayservice.h>
32 // Qt
33 #include <QtGui/QKeyEvent>
34 
35 
36 namespace Okteta
37 {
38 
39 KEditor::KEditor( ByteArrayTableCursor* cursor, AbstractByteArrayView* view, KController *parent )
40  : KController( parent ),
41  mCursor( cursor ),
42  mView( view )
43 {
44 }
45 
46 
47 bool KEditor::handleKeyPress( QKeyEvent* keyEvent )
48 {
49  const bool shiftPressed = keyEvent->modifiers() & Qt::SHIFT;
50  const bool controlPressed = keyEvent->modifiers() & Qt::CTRL;
51  const bool altPressed = keyEvent->modifiers() & Qt::ALT;
52 
53  bool keyUsed = true;
54  // we only care for cursor keys and the like, won't hardcode any other keys
55  // we also don't check whether the commands are allowed
56  // as the commands are also available as API so the check has to be done
57  // in each command anyway
58  switch( keyEvent->key() )
59  {
60  case Qt::Key_Delete:
61  if( shiftPressed )
62  mView->cut();
63  else if( mView->hasSelectedData() )
64  mView->removeSelectedData();
65  else
66  doEditAction( controlPressed ? WordDelete : CharDelete );
67  break;
68  case Qt::Key_Insert:
69  if( shiftPressed )
70  mView->paste();
71  else if( controlPressed )
72  mView->copy();
73  else
74  mView->setOverwriteMode( !mView->isOverwriteMode() );
75  break;
76  case Qt::Key_Backspace:
77  if( altPressed )
78  break;
79  else if( mView->hasSelectedData() )
80  {
81  mView->removeSelectedData();
82  break;
83  }
84 
85  doEditAction( controlPressed ? WordBackspace : CharBackspace );
86  break;
87  case Qt::Key_F16: // "Copy" key on Sun keyboards
88  mView->copy();
89  break;
90  case Qt::Key_F18: // "Paste" key on Sun keyboards
91  mView->paste();
92  break;
93  case Qt::Key_F20: // "Cut" key on Sun keyboards
94  mView->cut();
95  break;
96  default:
97  keyUsed = false;
98  }
99 
100  return keyUsed ? true : KController::handleKeyPress(keyEvent);
101 }
102 
103 
104 
105 void KEditor::doEditAction( KEditAction action )
106 {
107  Okteta::AbstractByteArrayModel* byteArrayModel = mView->byteArrayModel();
108  switch( action )
109  {
110  case CharDelete:
111  if( !mView->isOverwriteMode() )
112  {
113  const Address index = mCursor->realIndex();
114  if( index < mView->layout()->length() )
115  byteArrayModel->remove( AddressRange::fromWidth(index,1) );
116  }
117  break;
118  case WordDelete: // kills data until the start of the next word
119  if( !mView->isOverwriteMode() )
120  {
121  const Address index = mCursor->realIndex();
122  if( index < mView->layout()->length() )
123  {
124  const WordByteArrayService WBS( byteArrayModel, mView->charCodec() );
125  const Address end = WBS.indexOfBeforeNextWordStart( index );
126  byteArrayModel->remove( AddressRange(index,end) );
127  }
128  }
129  break;
130  case CharBackspace:
131  if( mView->isOverwriteMode() )
132  {
133  mView->pauseCursor();
134  mCursor->gotoPreviousByte();
135  mView->ensureCursorVisible();
136  mView->unpauseCursor();
137  }
138  else
139  {
140  const Address deleteIndex = mCursor->realIndex() - 1;
141  if( deleteIndex >= 0 )
142  byteArrayModel->remove( AddressRange::fromWidth(deleteIndex,1) );
143  }
144  break;
145  case WordBackspace:
146  {
147  const int leftIndex = mCursor->realIndex() - 1;
148  if( leftIndex >= 0 )
149  {
150  const WordByteArrayService WBS( byteArrayModel, mView->charCodec() );
151  const Address wordStart = WBS.indexOfPreviousWordStart( leftIndex );
152  if( !mView->isOverwriteMode() )
153  byteArrayModel->remove( AddressRange(wordStart,leftIndex) );
154  }
155  }
156  }
157 }
158 
159 KEditor::~KEditor() {}
160 
161 }
wordbytearrayservice.h
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
Okteta::AbstractByteArrayView::removeSelectedData
void removeSelectedData()
removes the selected data, takes care of the cursor
Definition: abstractbytearrayview.cpp:226
abstractbytearraymodel.h
Okteta::AbstractByteArrayView::paste
virtual void paste()
Definition: abstractbytearrayview.cpp:214
Okteta::AbstractByteArrayView::setOverwriteMode
void setOverwriteMode(bool overwriteMode)
sets whether the widget is in overwrite mode or not.
Definition: abstractbytearrayview.cpp:244
Okteta::KEditor::mCursor
ByteArrayTableCursor * mCursor
Definition: keditor.h:54
Okteta::KEditor::mView
AbstractByteArrayView * mView
Definition: keditor.h:55
KDE::NumberRange< Address, Size >
Okteta::AbstractByteArrayView::hasSelectedData
bool hasSelectedData() const
returns true if there is a selected range in the array
Definition: abstractbytearrayview.cpp:166
abstractbytearrayview.h
Okteta::KEditor::KEditor
KEditor(ByteArrayTableCursor *cursor, AbstractByteArrayView *view, KController *parent)
Definition: keditor.cpp:39
Okteta::AbstractByteArrayView
Definition: abstractbytearrayview.h:55
Okteta::AbstractByteArrayView::isOverwriteMode
bool isOverwriteMode() const
Definition: abstractbytearrayview.cpp:49
Okteta::ByteArrayTableCursor::gotoPreviousByte
void gotoPreviousByte()
Definition: bytearraytablecursor.cpp:70
bytearraytablelayout.h
Okteta::KEditor::WordDelete
Definition: keditor.h:39
Okteta::KEditor::doEditAction
void doEditAction(KEditAction Action)
executes keyboard Action Action.
Definition: keditor.cpp:105
Okteta::WordByteArrayService::indexOfBeforeNextWordStart
Address indexOfBeforeNextWordStart(Address index) const
searches for the start of the next word not including the given index.
Definition: wordbytearrayservice.cpp:100
KDE::NumberRange< Address, Size >::fromWidth
static NumberRange fromWidth(AddressstartIndex, Sizewidth)
constructs a range by width
Okteta::AbstractByteArrayView::byteArrayModel
Okteta::AbstractByteArrayModel * byteArrayModel() const
Definition: abstractbytearrayview.cpp:44
keditor.h
Okteta::AbstractByteArrayView::pauseCursor
void pauseCursor()
simply pauses any blinking, i.e.
Definition: abstractbytearrayview.cpp:421
Okteta::WordByteArrayService
Definition: wordbytearrayservice.h:44
Okteta::ByteArrayTableCursor
navigates through the buffer in an abstract way, based on the layout
Definition: bytearraytablecursor.h:60
Okteta::AddressRange
KDE::NumberRange< Address, Size > AddressRange
Definition: addressrange.h:35
Okteta::KEditor::CharBackspace
Definition: keditor.h:39
Okteta::KEditor::WordBackspace
Definition: keditor.h:39
Okteta::KController::handleKeyPress
virtual bool handleKeyPress(QKeyEvent *keyEvent)
Definition: kcontroller.cpp:34
Okteta::KEditor::KEditAction
KEditAction
Definition: keditor.h:39
Okteta::AbstractByteArrayView::unpauseCursor
void unpauseCursor()
undoes pauseCursor
Definition: abstractbytearrayview.cpp:409
Okteta::ByteArrayTableCursor::realIndex
Address realIndex() const
returns the real index.
Definition: bytearraytablecursor.h:175
Okteta::KEditor::CharDelete
Definition: keditor.h:39
Okteta::AbstractByteArrayView::charCodec
const Okteta::CharCodec * charCodec() const
Definition: abstractbytearrayview.cpp:100
Okteta::KEditor::~KEditor
virtual ~KEditor()
Definition: keditor.cpp:159
Okteta::AbstractByteArrayView::copy
virtual void copy()
Definition: abstractbytearrayview.cpp:208
Okteta::AbstractByteArrayView::ensureCursorVisible
void ensureCursorVisible()
scrolls the view as much as needed to have the cursor fully visible
Definition: abstractbytearrayview.cpp:390
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::AbstractByteArrayView::cut
virtual void cut()
Definition: abstractbytearrayview.cpp:202
Okteta::KEditor::handleKeyPress
virtual bool handleKeyPress(QKeyEvent *keyEvent)
Definition: keditor.cpp:47
Okteta::KController
Definition: kcontroller.h:32
Okteta::AbstractByteArrayModel::remove
virtual Size remove(const AddressRange &removeRange)
removes beginning with position as much as possible
Definition: abstractbytearraymodel.cpp:53
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