• 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
dropper.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 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 "dropper.h"
24 
25 // lib
26 #include <bytearraytableranges.h>
27 #include <bytearraytablecursor.h>
28 #include <bytearraytablelayout.h>
29 #include <abstractbytearrayview.h>
30 // Okteta core
31 #include <abstractbytearraymodel.h>
32 // Qt
33 #include <QtGui/QApplication>
34 #include <QtGui/QDragEnterEvent>
35 #include <QtGui/QDragMoveEvent>
36 #include <QtGui/QDragLeaveEvent>
37 #include <QtGui/QDropEvent>
38 
39 
40 namespace Okteta
41 {
42 
43 static const char DropperOctetStreamFormatName[] = "application/octet-stream";
44 
45 
46 Dropper::Dropper( AbstractByteArrayView* view )
47  : mByteArrayView( view ),
48  mIsActive( false )
49 {
50 }
51 
52 bool Dropper::isActive() const { return mIsActive; }
53 
54 bool Dropper::handleDragEnterEvent( QDragEnterEvent* dragEnterEvent )
55 {
56  bool eventUsed = false;
57 
58  if( !mByteArrayView->isReadOnly()
59  && mByteArrayView->canReadData(dragEnterEvent->mimeData()) )
60  {
61  mIsActive = true;
62  // TODO: store value edit data
63  ByteArrayTableCursor* tableCursor = mByteArrayView->tableCursor();
64  // TODO: behind state should not be controllable, add cursorData for (re)storingdragEnterEvent
65  mBeforeDragCursorPos = tableCursor->index();
66  mBeforeDragCursorIsBehind = tableCursor->isBehind();
67  mCursorIsMovedByDrag = false;
68 
69  eventUsed = true;
70  }
71 
72  return eventUsed;
73 }
74 
75 
76 bool Dropper::handleDragMoveEvent( QDragMoveEvent* dragMoveEvent )
77 {
78  bool eventUsed = false;
79 
80  if( !mByteArrayView->isReadOnly()
81  && mByteArrayView->canReadData(dragMoveEvent->mimeData()) )
82  {
83  mCursorIsMovedByDrag = true;
84 
85  // let text cursor follow mouse
86  mByteArrayView->pauseCursor();
87  //TODO: just for following skip the value edit, remember we are and get back
88  mByteArrayView->finishByteEdit();
89  mByteArrayView->placeCursor( dragMoveEvent->pos() );
90  mByteArrayView->unpauseCursor();
91 
92  eventUsed = true;
93  }
94 
95  return eventUsed;
96 }
97 
98 
99 bool Dropper::handleDragLeaveEvent( QDragLeaveEvent* dragLeaveEvent )
100 {
101 Q_UNUSED( dragLeaveEvent )
102 
103  const bool eventUsed = true;
104  // bye... and thanks for all the cursor movement...
105  mIsActive = false;
106  if( mCursorIsMovedByDrag )
107  {
108  mByteArrayView->pauseCursor();
109  // TODO: get back to value edit mode if we were in
110  ByteArrayTableCursor* tableCursor = mByteArrayView->tableCursor();
111  tableCursor->gotoIndex( mBeforeDragCursorPos );
112  if( mBeforeDragCursorIsBehind )
113  tableCursor->stepBehind();
114  mByteArrayView->unpauseCursor();
115  }
116 
117  return eventUsed;
118 }
119 
120 
121 bool Dropper::handleDropEvent( QDropEvent* dropEvent )
122 {
123  bool eventUsed = false;
124 
125  if( !mByteArrayView->isReadOnly()
126  && mByteArrayView->canReadData(dropEvent->mimeData()) )
127  {
128  // leave state
129  mIsActive = false;
130 
131  // is this an internal dnd?
132  AbstractByteArrayView* sourceByteArrayView = qobject_cast<AbstractByteArrayView*>( dropEvent->source() );
133  if( sourceByteArrayView
134  && sourceByteArrayView->byteArrayModel() == mByteArrayView->byteArrayModel() )
135  handleInternalDrag( dropEvent, sourceByteArrayView );
136  else
137  {
138  //mByteArrayView->tableRanges()->removeSelection();
139  mByteArrayView->pasteData( dropEvent->mimeData() );
140  }
141  }
142 
143  return eventUsed;
144 }
145 
146 
147 void Dropper::handleInternalDrag( QDropEvent* dropEvent, AbstractByteArrayView* sourceByteArrayView )
148 {
149  // get drag origin
150  AddressRange selection = sourceByteArrayView->tableRanges()->removeSelection();
151 
152  ByteArrayTableCursor* tableCursor = mByteArrayView->tableCursor();
153  AbstractByteArrayModel* byteArrayModel = mByteArrayView->byteArrayModel();
154 
155  Address insertIndex = tableCursor->realIndex();
156 
157  // is this a move?
158  if( dropEvent->proposedAction() == Qt::MoveAction )
159  {
160  // ignore the copy hold in the event but only move
161  Address newCursorIndex;
162  // need to swap?
163  if( selection.end() < insertIndex )
164  {
165  newCursorIndex = insertIndex;
166  const Address firstIndex = selection.start();
167  selection.set( selection.nextBehindEnd(), insertIndex-1 );
168  insertIndex = firstIndex;
169  }
170  else
171  newCursorIndex = insertIndex + selection.width();
172 
173  const bool success = byteArrayModel->swap( insertIndex, selection );
174  if( success )
175  {
176  tableCursor->gotoCIndex( newCursorIndex );
177  emit mByteArrayView->cursorPositionChanged( tableCursor->realIndex() );
178  }
179  }
180  // is a copy
181  else
182  {
183  // TODO: should this be a method of AbstractByteArrayModel, to reuse piece data?
184 
185  // get data
186  const QByteArray data =
187  dropEvent->mimeData()->data( QLatin1String(DropperOctetStreamFormatName) );
188 
189  if( !data.isEmpty() )
190  {
191  if( mByteArrayView->isOverwriteMode() )
192  {
193  const Size length = mByteArrayView->layout()->length();
194  if( !tableCursor->isBehind() && length > 0 )
195  {
196  AddressRange overwriteRange = AddressRange::fromWidth( insertIndex, data.size() );
197  overwriteRange.restrictEndTo( length-1 );
198  if( overwriteRange.isValid() )
199  byteArrayModel->replace( overwriteRange, reinterpret_cast<const Byte*>(data.constData()), overwriteRange.width() );
200  }
201  }
202  else
203  byteArrayModel->insert( insertIndex, reinterpret_cast<const Byte*>(data.constData()), data.size() );
204  }
205  }
206 }
207 
208 Dropper::~Dropper() {}
209 
210 }
Okteta::AbstractByteArrayModel::replace
virtual Size replace(const AddressRange &removeRange, const Byte *insertData, int insertLength)=0
replaces as much as possible
Okteta::AbstractByteArrayView::tableCursor
ByteArrayTableCursor * tableCursor() const
Definition: abstractbytearrayview.cpp:106
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::ByteArrayTableCursor::index
Address index() const
the index that is drawn at the actual coord
Definition: bytearraytablecursor.h:170
Okteta::AbstractByteArrayModel::swap
virtual bool swap(Address firstStart, const AddressRange &secondRange)=0
moves the second section before the start of the first which is the same as moving the first behind t...
abstractbytearraymodel.h
Okteta::Dropper::mByteArrayView
AbstractByteArrayView * mByteArrayView
Definition: dropper.h:61
KDE::NumberRange::nextBehindEnd
N nextBehindEnd() const
Definition: numberrange.h:145
Okteta::AbstractByteArrayModel::insert
virtual Size insert(Address offset, const Byte *insertData, int insertLength)
inserts bytes copied from the given source at Position.
Definition: abstractbytearraymodel.cpp:47
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
abstractbytearrayview.h
Okteta::Dropper::handleDropEvent
bool handleDropEvent(QDropEvent *dropEvent)
Definition: dropper.cpp:121
Okteta::Dropper::mCursorIsMovedByDrag
bool mCursorIsMovedByDrag
Definition: dropper.h:65
Okteta::AbstractByteArrayView::isReadOnly
bool isReadOnly() const
Definition: abstractbytearrayview.cpp:59
Okteta::AbstractByteArrayView
Definition: abstractbytearrayview.h:55
Okteta::AbstractByteArrayView::isOverwriteMode
bool isOverwriteMode() const
Definition: abstractbytearrayview.cpp:49
KDE::NumberRange::width
S width() const
Definition: numberrange.h:141
bytearraytablelayout.h
Okteta::Dropper::mBeforeDragCursorPos
Address mBeforeDragCursorPos
Definition: dropper.h:63
Okteta::ByteArrayTableCursor::gotoIndex
void gotoIndex(Address index)
Definition: bytearraytablecursor.cpp:260
Okteta::AbstractByteArrayView::pasteData
void pasteData(const QMimeData *data)
Definition: abstractbytearrayview.cpp:190
Okteta::Dropper::~Dropper
~Dropper()
Definition: dropper.cpp:208
KDE::Range::restrictEndTo
void restrictEndTo(T Limit)
restricts the end to Limit.
Definition: range.h:69
KDE::Range::end
T end() const
Definition: range.h:88
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
Okteta::Dropper::handleDragEnterEvent
bool handleDragEnterEvent(QDragEnterEvent *dragEnterEvent)
Definition: dropper.cpp:54
Okteta::Dropper::isActive
bool isActive() const
Definition: dropper.cpp:52
Okteta::AbstractByteArrayView::pauseCursor
void pauseCursor()
simply pauses any blinking, i.e.
Definition: abstractbytearrayview.cpp:421
Okteta::AbstractByteArrayView::cursorPositionChanged
void cursorPositionChanged(Okteta::Address index)
Okteta::Dropper::handleInternalDrag
void handleInternalDrag(QDropEvent *dropEvent, AbstractByteArrayView *sourceByteArrayView)
Definition: dropper.cpp:147
Okteta::AbstractByteArrayView::canReadData
bool canReadData(const QMimeData *data) const
Definition: abstractbytearrayview.cpp:196
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::Dropper::Dropper
Dropper(AbstractByteArrayView *view)
Definition: dropper.cpp:46
Okteta::AbstractByteArrayView::layout
ByteArrayTableLayout * layout() const
Definition: abstractbytearrayview.cpp:75
Okteta::ByteArrayTableCursor::gotoCIndex
void gotoCIndex(Address index)
Definition: bytearraytablecursor.cpp:218
Okteta::Dropper::mBeforeDragCursorIsBehind
bool mBeforeDragCursorIsBehind
Definition: dropper.h:64
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
bytearraytableranges.h
Okteta::Dropper::handleDragMoveEvent
bool handleDragMoveEvent(QDragMoveEvent *dragMoveEvent)
Definition: dropper.cpp:76
Okteta::Size
qint32 Size
Definition: size.h:33
Okteta::ByteArrayTableRanges::removeSelection
AddressRange removeSelection(int id=0)
removes selection with id and returns it
Definition: bytearraytableranges.cpp:156
Okteta::DropperOctetStreamFormatName
static const char DropperOctetStreamFormatName[]
Definition: dropper.cpp:43
Okteta::ByteArrayTableCursor::isBehind
bool isBehind() const
true if the cursor is located to the right of the actual coord but still shown at the coord ...
Definition: bytearraytablecursor.h:174
Okteta::AbstractByteArrayView::placeCursor
void placeCursor(const QPoint &point)
puts the cursor in the column at the pos of Point (in absolute coord), does not handle the drawing ...
Definition: abstractbytearrayview.cpp:396
bytearraytablecursor.h
dropper.h
KDE::Range::isValid
bool isValid() const
returns true if the range covers at least one index
Definition: range.h:122
KDE::Range::set
void set(T S, T E)
sets the first and the last index of the range
Definition: range.h:54
Okteta::ByteArrayTableLayout::length
Size length() const
returns the length of the displayed byte array section
Definition: bytearraytablelayout.h:211
Okteta::Dropper::mIsActive
bool mIsActive
Definition: dropper.h:67
Okteta::Dropper::handleDragLeaveEvent
bool handleDragLeaveEvent(QDragLeaveEvent *dragLeaveEvent)
Definition: dropper.cpp:99
Okteta::ByteArrayTableCursor::stepBehind
void stepBehind()
puts the cursor behind the actual position if it isn't already
Definition: bytearraytablecursor.h:178
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