909
void ByteArrayRowViewPrivate::clipboardChanged()
911
Q_Q( ByteArrayRowView );
913
// don't listen to selection changes
914
q->disconnect( QApplication::clipboard(), SIGNAL(selectionChanged()) );
919
void ByteArrayRowViewPrivate::mousePressEvent( QMouseEvent* mouseEvent )
921
Q_Q( ByteArrayRowView );
923
const bool oldHasSelection = mTableRanges->hasSelection();
926
mValueEditor->finishEdit();
928
// care about a left button press?
929
if( mouseEvent->button() == Qt::LeftButton )
931
mMousePressed = true;
933
// select whole line?
934
if( mTrippleClickTimer->isActive()
935
&& (mouseEvent->globalPos()-mDoubleClickPoint).manhattanLength() < QApplication::startDragDistance() )
937
mTrippleClickTimer->stop();
938
const Address indexAtFirstDoubleClickLinePosition = mTableLayout->indexAtFirstLinePosition( mDoubleClickLine );
939
mTableRanges->setSelectionStart( indexAtFirstDoubleClickLinePosition );
940
mTableCursor->gotoIndex( indexAtFirstDoubleClickLinePosition );
941
mTableCursor->gotoLineEnd();
942
mTableRanges->setSelectionEnd( cursorPosition() );
947
const bool newHasSelection = mTableRanges->hasSelection();
948
emit q->cursorPositionChanged( cursorPosition() );
949
emit q->selectionChanged( mTableRanges->selection() );
950
if( oldHasSelection != newHasSelection )
952
if( !mOverWrite ) emit q->cutAvailable( newHasSelection );
953
emit q->copyAvailable( newHasSelection );
954
emit q->hasSelectedDataChanged( newHasSelection );
959
const QPoint mousePoint = q->viewportToColumns( mouseEvent->pos() );
961
// start of a drag perhaps?
962
if( mTableRanges->hasSelection() && mTableRanges->selectionIncludes(indexByPoint( mousePoint )) )
964
mDragStartPossible = true;
965
mDragStartTimer->start( QApplication::startDragTime() );
966
mDragStartPoint = mousePoint;
970
placeCursor( mousePoint );
971
ensureCursorVisible();
973
const Address realIndex = mTableCursor->realIndex();
974
if( mTableRanges->selectionStarted() )
976
if( mouseEvent->modifiers() & Qt::SHIFT )
977
mTableRanges->setSelectionEnd( realIndex );
980
mTableRanges->removeSelection();
981
mTableRanges->setSelectionStart( realIndex );
984
else // start of a new selection possible
986
mTableRanges->setSelectionStart( realIndex );
988
if( !isEffectiveReadOnly() && (mouseEvent->modifiers()&Qt::SHIFT) ) // TODO: why only for readwrite?
989
mTableRanges->setSelectionEnd( realIndex );
992
mTableRanges->removeFurtherSelections();
995
else if( mouseEvent->button() == Qt::MidButton )
996
mTableRanges->removeSelection();
998
if( mTableRanges->isModified() )
1001
q->viewport()->setCursor( isEffectiveReadOnly() ? Qt::ArrowCursor : Qt::IBeamCursor );
1006
const bool newHasSelection = mTableRanges->hasSelection();
1007
emit q->selectionChanged( mTableRanges->selection() );
1008
if( oldHasSelection != newHasSelection )
1010
if( !mOverWrite ) emit q->cutAvailable( newHasSelection );
1011
emit q->copyAvailable( newHasSelection );
1012
emit q->hasSelectedDataChanged( newHasSelection );
1017
void ByteArrayRowViewPrivate::mouseMoveEvent( QMouseEvent *mouseEvent )
1019
Q_Q( ByteArrayRowView );
1021
const QPoint movePoint = q->viewportToColumns( mouseEvent->pos() );
1025
if( mDragStartPossible )
1027
mDragStartTimer->stop();
1028
// moved enough for a drag?
1029
if( (movePoint-mDragStartPoint).manhattanLength() > QApplication::startDragDistance() )
1031
if( !isEffectiveReadOnly() )
1032
q->viewport()->setCursor( Qt::IBeamCursor );
1036
handleMouseMove( movePoint );
1038
else if( !isEffectiveReadOnly() )
1040
// visual feedback for possible dragging
1041
const bool InSelection =
1042
mTableRanges->hasSelection() && mTableRanges->selectionIncludes( indexByPoint(movePoint) );
1043
q->viewport()->setCursor( InSelection?Qt::ArrowCursor:Qt::IBeamCursor );
1048
void ByteArrayRowViewPrivate::mouseReleaseEvent( QMouseEvent* mouseEvent )
1050
Q_Q( ByteArrayRowView );
1052
const bool oldHasSelection = mTableRanges->hasSelection();
1053
const QPoint releasePoint = q->viewportToColumns( mouseEvent->pos() );
1055
// this is not the release of a doubleclick so we need to process it?
1056
if( !mInDoubleClick )
1058
const int line = q->lineAt( releasePoint.y() );
1059
const int pos = mByteArrayColumn->linePositionOfX( releasePoint.x() ); // TODO: can we be sure here about the active column?
1060
const Address index = mTableLayout->indexAtCCoord( Coord(pos,line) ); // TODO: can this be another index than the one of the cursor???
1061
emit q->clicked( index );
1066
mMousePressed = false;
1068
if( mScrollTimer->isActive() )
1069
mScrollTimer->stop();
1071
// was only click inside selection, nothing dragged?
1072
if( mDragStartPossible )
1075
mDragStartTimer->stop();
1076
mDragStartPossible = false;
1078
placeCursor( mDragStartPoint );
1079
ensureCursorVisible();
1083
// was end of selection operation?
1084
else if( mTableRanges->hasSelection() )
1086
if( QApplication::clipboard()->supportsSelection() )
1088
mClipboardMode = QClipboard::Selection;
1089
q->disconnect( QApplication::clipboard(), SIGNAL(selectionChanged()) );
1093
//TODO: why did we do this? And why does the disconnect above not work?
1094
// got connected multiple times after a few selections by mouse
1095
// connect( QApplication::clipboard(), SIGNAL(selectionChanged()), SLOT(clipboardChanged()) );
1096
mClipboardMode = QClipboard::Clipboard;
1100
// middle mouse button paste?
1101
else if( mouseEvent->button() == Qt::MidButton && !isEffectiveReadOnly() )
1104
mValueEditor->finishEdit();
1106
placeCursor( releasePoint );
1108
// replace no selection?
1109
if( mTableRanges->hasSelection() && !mTableRanges->selectionIncludes(mTableCursor->index()) )
1110
mTableRanges->removeSelection();
1112
mClipboardMode = QClipboard::Selection;
1114
mClipboardMode = QClipboard::Clipboard;
1116
// ensure selection changes to be drawn TODO: create a insert/pasteAtCursor that leaves out drawing
1119
ensureCursorVisible();
1123
emit q->cursorPositionChanged( cursorPosition() );
1125
mInDoubleClick = false;
1127
if( mTableRanges->selectionJustStarted() )
1128
mTableRanges->removeSelection();
1130
const bool newHasSelection = mTableRanges->hasSelection();
1131
emit q->selectionChanged( mTableRanges->selection() );
1132
if( oldHasSelection != newHasSelection )
1134
if( !mOverWrite ) emit q->cutAvailable( newHasSelection );
1135
emit q->copyAvailable( newHasSelection );
1136
emit q->hasSelectedDataChanged( newHasSelection );
1141
// gets called after press and release instead of a plain press event (?)
1142
void ByteArrayRowViewPrivate::mouseDoubleClickEvent( QMouseEvent* mouseEvent )
1144
Q_Q( ByteArrayRowView );
1146
// we are only interested in LMB doubleclicks
1147
if( mouseEvent->button() != Qt::LeftButton )
1149
mouseEvent->ignore();
1153
mDoubleClickLine = mTableCursor->line();
1155
const Address index = mTableCursor->validIndex();
1157
if( mActiveCoding == AbstractByteArrayView::CharCodingId )
1159
selectWord( index );
1161
// as we already have a doubleclick maybe it is a tripple click
1162
mTrippleClickTimer->start( qApp->doubleClickInterval() );
1163
mDoubleClickPoint = mouseEvent->globalPos();
1166
// mValueEditor->goInsideByte(); TODO: make this possible again
1168
mInDoubleClick = true; //
1169
mMousePressed = true;
1171
emit q->doubleClicked( index );
1175
void ByteArrayRowViewPrivate::autoScrollTimerDone()
1177
Q_Q( ByteArrayRowView );
1180
handleMouseMove( q->viewportToColumns(q->viewport()->mapFromGlobal( QCursor::pos() )) );
1184
void ByteArrayRowViewPrivate::handleMouseMove( const QPoint& point ) // handles the move of the mouse with pressed buttons
1186
Q_Q( ByteArrayRowView );
1188
const bool oldHasSelection = mTableRanges->hasSelection();
1189
const int yOffset = q->yOffset();
1190
const int behindLastYOffset = yOffset + q->visibleHeight();
1191
// scrolltimer but inside of viewport?
1192
if( mScrollTimer->isActive() )
1194
if( yOffset <= point.y() && point.y() < behindLastYOffset )
1195
mScrollTimer->stop();
1197
// no scrolltimer and outside of viewport?
1200
if( point.y() < yOffset || behindLastYOffset <= point.y() )
1201
mScrollTimer->start( DefaultScrollTimerPeriod );
1205
placeCursor( point );
1206
ensureCursorVisible();
1208
// do wordwise selection?
1209
if( mInDoubleClick && mTableRanges->hasFirstWordSelection() )
1211
Address newIndex = mTableCursor->realIndex();
1212
const AddressRange firstWordSelection = mTableRanges->firstWordSelection();
1213
const WordByteArrayService WBS( mByteArrayModel, charCodec() );
1214
// are we before the selection?
1215
if( firstWordSelection.startsBehind(newIndex) )
1217
mTableRanges->ensureWordSelectionForward( false );
1218
newIndex = WBS.indexOfLeftWordSelect( newIndex );
1221
else if( firstWordSelection.endsBefore(newIndex) )
1223
mTableRanges->ensureWordSelectionForward( true );
1224
newIndex = WBS.indexOfRightWordSelect( newIndex );
1229
mTableRanges->ensureWordSelectionForward( true );
1230
newIndex = firstWordSelection.nextBehindEnd();
1233
mTableCursor->gotoIndex( newIndex );
1236
if( mTableRanges->selectionStarted() )
1237
mTableRanges->setSelectionEnd( cursorPosition() );
1243
const bool newHasSelection = mTableRanges->hasSelection();
1244
emit q->cursorPositionChanged( cursorPosition() );
1245
emit q->selectionChanged( mTableRanges->selection() );
1246
if( oldHasSelection != newHasSelection )
1248
if( !mOverWrite ) emit q->cutAvailable( newHasSelection );
1249
emit q->copyAvailable( newHasSelection );
1250
emit q->hasSelectedDataChanged( newHasSelection );
1255
void ByteArrayRowViewPrivate::startDrag()
1257
Q_Q( ByteArrayRowView );
1260
mMousePressed = false;
1261
mInDoubleClick = false;
1262
mDragStartPossible = false;
1265
QMimeData *dragData = selectionAsMimeData();
1269
QDrag *drag = new QDrag( q );
1270
drag->setMimeData( dragData );
1272
Qt::DropActions request = (isEffectiveReadOnly()||mOverWrite) ? Qt::CopyAction : Qt::CopyAction|Qt::MoveAction;
1273
Qt::DropAction dropAction = drag->exec( request );
1275
if( dropAction == Qt::MoveAction )
1277
AbstractByteArrayView* targetByteArrayView = qobject_cast<AbstractByteArrayView*>( drag->target() );
1278
// Not inside this widget itself?
1279
if( ! targetByteArrayView
1280
|| targetByteArrayView->byteArrayModel() != q->byteArrayModel() )
1281
removeSelectedData();
1285
831
ByteArrayRowViewPrivate::~ByteArrayRowViewPrivate()
1287
delete mCursorPixmaps;