Пример #1
0
bool MouseNavigator::handleMouseDoubleClickEvent( QMouseEvent* mouseEvent )
{
    bool eventUsed = false;

    if( mouseEvent->button() == Qt::LeftButton )
    {
        ByteArrayTableCursor* tableCursor = mView->tableCursor();

        mDoubleClickLine = tableCursor->line();

        const Address index = tableCursor->validIndex();

        if( mView->activeCoding() == AbstractByteArrayView::CharCodingId )
        {
            mView->selectWord( index );

            // as we already have a doubleclick maybe it is a tripple click
            mTrippleClickTimer->start( qApp->doubleClickInterval() );
            mDoubleClickPoint = mouseEvent->globalPos();
        }
        //  else
        //    mValueEditor->goInsideByte(); TODO: make this possible again

        mInLMBDoubleClick = true; //
        mLMBPressed = true;

        emit mView->doubleClicked( index );
        eventUsed = true;
    }

    return eventUsed ? true : AbstractMouseController::handleMouseDoubleClickEvent( mouseEvent );
}
Пример #2
0
void Dropper::handleInternalDrag( QDropEvent* dropEvent, AbstractByteArrayView* sourceByteArrayView )
{
    // get drag origin
    AddressRange selection = sourceByteArrayView->tableRanges()->removeSelection();

    ByteArrayTableCursor* tableCursor = mByteArrayView->tableCursor();
    AbstractByteArrayModel* byteArrayModel = mByteArrayView->byteArrayModel();

    Address insertIndex = tableCursor->realIndex();

    // is this a move?
    if( dropEvent->proposedAction() == Qt::MoveAction )
    {
        // ignore the copy hold in the event but only move
        Address newCursorIndex;
        // need to swap?
        if( selection.end() < insertIndex )
        {
            newCursorIndex = insertIndex;
            const Address firstIndex = selection.start();
            selection.set( selection.nextBehindEnd(), insertIndex-1 );
            insertIndex = firstIndex;
        }
        else
            newCursorIndex = insertIndex + selection.width();

        const bool success = byteArrayModel->swap( insertIndex, selection );
        if( success )
        {
            tableCursor->gotoCIndex( newCursorIndex );
            emit mByteArrayView->cursorPositionChanged( tableCursor->realIndex() );
        }
    }
    // is a copy
    else
    {
        // TODO: should this be a method of AbstractByteArrayModel, to reuse piece data?

        // get data
        const QByteArray data =
            dropEvent->mimeData()->data( QLatin1String(DropperOctetStreamFormatName) );

        if( !data.isEmpty() )
        {
            if( mByteArrayView->isOverwriteMode() )
            {
                const Size length = mByteArrayView->layout()->length();
                if( !tableCursor->isBehind() && length > 0 )
                {
                    AddressRange overwriteRange = AddressRange::fromWidth( insertIndex, data.size() );
                    overwriteRange.restrictEndTo( length-1 );
                    if( overwriteRange.isValid() )
                        byteArrayModel->replace( overwriteRange, reinterpret_cast<const Byte*>(data.constData()), overwriteRange.width() );
                }
            }
            else
                byteArrayModel->insert( insertIndex, reinterpret_cast<const Byte*>(data.constData()), data.size() );
        }
    }
}
Пример #3
0
bool Dropper::handleDragLeaveEvent( QDragLeaveEvent* dragLeaveEvent )
{
Q_UNUSED( dragLeaveEvent )

    const bool eventUsed = true;
    // bye... and thanks for all the cursor movement...
    mIsActive = false;
    if( mCursorIsMovedByDrag )
    {
        mByteArrayView->pauseCursor();
        // TODO: get back to value edit mode if we were in
        ByteArrayTableCursor* tableCursor = mByteArrayView->tableCursor();
        tableCursor->gotoIndex( mBeforeDragCursorPos );
        if( mBeforeDragCursorIsBehind )
            tableCursor->stepBehind();
        mByteArrayView->unpauseCursor();
    }

    return eventUsed;
}
Пример #4
0
void KNavigator::moveCursor( KMoveAction action, bool select )
{
    mView->pauseCursor();
    mView->finishByteEdit();

    ByteArrayTableCursor* tableCursor = mView->tableCursor();
    ByteArrayTableRanges* tableRanges = mView->tableRanges();

    if( select )
    {
        if( !tableRanges->selectionStarted() )
            tableRanges->setSelectionStart( tableCursor->realIndex() );
    }
    else
        tableRanges->removeSelection();

    switch( action )
    {
    case MoveBackward:     tableCursor->gotoPreviousByte(); break;
    case MoveWordBackward: {
            const Okteta::WordByteArrayService WBS( mView->byteArrayModel(), mView->charCodec() );
            const int newIndex = WBS.indexOfPreviousWordStart( tableCursor->realIndex() );
            tableCursor->gotoIndex( newIndex );
        }
        break;
    case MoveForward:      tableCursor->gotoNextByte();     break;
    case MoveWordForward:  {
            const Okteta::WordByteArrayService WBS( mView->byteArrayModel(), mView->charCodec() );
            const int newIndex = WBS.indexOfNextWordStart( tableCursor->realIndex() );
            tableCursor->gotoCIndex( newIndex );
        }
        break;
    case MoveUp:           tableCursor->gotoUp();             break;
    case MovePgUp:         tableCursor->gotoPageUp();         break;
    case MoveDown:         tableCursor->gotoDown();           break;
    case MovePgDown:       tableCursor->gotoPageDown();       break;
    case MoveLineStart:    tableCursor->gotoLineStart();      break;
    case MoveHome:         tableCursor->gotoStart();          break;
    case MoveLineEnd:      tableCursor->gotoLineEnd();        break;
    case MoveEnd:          tableCursor->gotoEnd();            break;
    }

    if( select )
        tableRanges->setSelectionEnd( tableCursor->realIndex() );

    if( tableRanges->isModified() )
        mView->emitSelectionSignals(); // TODO: can this be moved somewhere
    emit mView->cursorPositionChanged( tableCursor->realIndex() );
    mView->updateChanged();
    mView->ensureCursorVisible();

    mView->unpauseCursor();
}
Пример #5
0
bool MouseNavigator::handleMousePressEvent( QMouseEvent* mouseEvent )
{
    bool eventUsed = false;

    if( mouseEvent->button() == Qt::LeftButton )
    {
        ByteArrayTableCursor* tableCursor = mView->tableCursor();
        ByteArrayTableRanges* tableRanges = mView->tableRanges();
        ByteArrayTableLayout* tableLayout = mView->layout();

        const bool oldHasSelection = tableRanges->hasSelection();

        mView->pauseCursor();
        mView->finishByteEdit();

        mLMBPressed = true;

        // select whole line?
        if( mTrippleClickTimer->isActive()
            && (mouseEvent->globalPos()-mDoubleClickPoint).manhattanLength() < QApplication::startDragDistance() )
        {
            mTrippleClickTimer->stop();
            const Address indexAtFirstDoubleClickLinePosition = tableLayout->indexAtFirstLinePosition( mDoubleClickLine );
            tableRanges->setSelectionStart( indexAtFirstDoubleClickLinePosition );
            tableCursor->gotoIndex( indexAtFirstDoubleClickLinePosition );
            tableCursor->gotoLineEnd();
            tableRanges->setSelectionEnd( mView->cursorPosition() );
            mView->updateChanged();

            mView->unpauseCursor();

            const bool newHasSelection = tableRanges->hasSelection();
            emit mView->cursorPositionChanged( mView->cursorPosition() );
            emit mView->selectionChanged( tableRanges->selection() );
            if( oldHasSelection != newHasSelection )
            {
                if( ! mView->isOverwriteMode() ) emit mView->cutAvailable( newHasSelection );
                emit mView->copyAvailable( newHasSelection );
                emit mView->hasSelectedDataChanged( newHasSelection );
            }
        }
        else
        {
            // TODO: pos() is now, not at the moment of the event, use globalPos() for that,.says dox
            const QPoint mousePoint = mView->viewportToColumns( mouseEvent->pos() );

            // start of a drag perhaps?
            if( tableRanges->hasSelection() && tableRanges->selectionIncludes(mView->indexByPoint( mousePoint )) )
            {
                mDragStartPossible = true;
                mDragStartTimer->start( QApplication::startDragTime() );
                mDragStartPoint = mousePoint;
            }
            else
            {
                mView->placeCursor( mousePoint );
                mView->ensureCursorVisible();

                const Address realIndex = tableCursor->realIndex();
                if( tableRanges->selectionStarted() )
                {
                    if( mouseEvent->modifiers() & Qt::SHIFT )
                        tableRanges->setSelectionEnd( realIndex );
                    else
                    {
                        tableRanges->removeSelection();
                        tableRanges->setSelectionStart( realIndex );
                    }
                }
                else // start of a new selection possible
                {
                    tableRanges->setSelectionStart( realIndex );

                    if( !mView->isReadOnly() && (mouseEvent->modifiers()&Qt::SHIFT) ) // TODO: why only for readwrite?
                        tableRanges->setSelectionEnd( realIndex );
                }

                tableRanges->removeFurtherSelections();
            }

            if( tableRanges->isModified() )
            {
                mView->updateChanged();
                mView->viewport()->setCursor( mView->isReadOnly() ? Qt::ArrowCursor : Qt::IBeamCursor );
            }

            mView->unpauseCursor();

            const bool newHasSelection = tableRanges->hasSelection();
            emit mView->selectionChanged( tableRanges->selection() );
            if( oldHasSelection != newHasSelection )
            {
                if( ! mView->isOverwriteMode() ) emit mView->cutAvailable( newHasSelection );
                emit mView->copyAvailable( newHasSelection );
                emit mView->hasSelectedDataChanged( newHasSelection );
            }
        }
        eventUsed = true;
    }

    return eventUsed ? true : AbstractMouseController::handleMousePressEvent( mouseEvent );
}
Пример #6
0
void MouseNavigator::handleMouseMove( const QPoint& point ) // handles the move of the mouse with pressed buttons
{
    ByteArrayTableCursor* tableCursor = mView->tableCursor();
    ByteArrayTableRanges* tableRanges = mView->tableRanges();

    const bool oldHasSelection = tableRanges->hasSelection();
    const int yOffset = mView->yOffset();
    const int behindLastYOffset = yOffset + mView->visibleHeight();
    // scrolltimer but inside of viewport?
    if( mScrollTimer->isActive() )
    {
        if( yOffset <= point.y() && point.y() < behindLastYOffset )
            mScrollTimer->stop();
    }
    // no scrolltimer and outside of viewport?
    else
    {
        if( point.y() < yOffset || behindLastYOffset <= point.y() )
            mScrollTimer->start( DefaultScrollTimerPeriod );
    }
    mView->pauseCursor();

    mView->placeCursor( point );
    mView->ensureCursorVisible();

    // do wordwise selection?
    if( mInLMBDoubleClick && tableRanges->hasFirstWordSelection() )
    {
        Address newIndex = tableCursor->realIndex();
        const AddressRange firstWordSelection = tableRanges->firstWordSelection();
        const WordByteArrayService WBS( mView->byteArrayModel(), mView->charCodec() );
        // are we before the selection?
        if( firstWordSelection.startsBehind(newIndex) )
        {
            tableRanges->ensureWordSelectionForward( false );
            newIndex = WBS.indexOfLeftWordSelect( newIndex );
        }
        // or behind?
        else if( firstWordSelection.endsBefore(newIndex) )
        {
            tableRanges->ensureWordSelectionForward( true );
            newIndex = WBS.indexOfRightWordSelect( newIndex );
        }
        // or inside?
        else
        {
            tableRanges->ensureWordSelectionForward( true );
            newIndex = firstWordSelection.nextBehindEnd();
        }

        tableCursor->gotoIndex( newIndex );
    }

    if( tableRanges->selectionStarted() )
        tableRanges->setSelectionEnd( mView->cursorPosition() );

    mView->updateChanged();

    mView->unpauseCursor();

    const bool newHasSelection = tableRanges->hasSelection();
    emit mView->cursorPositionChanged( mView->cursorPosition() );
    emit mView->selectionChanged( tableRanges->selection() );
    if( oldHasSelection != newHasSelection )
    {
        if( ! mView->isOverwriteMode() ) emit mView->cutAvailable( newHasSelection );
        emit mView->copyAvailable( newHasSelection );
        emit mView->hasSelectedDataChanged( newHasSelection );
    }
}