Beispiel #1
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();
}
Beispiel #2
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 );
}
Beispiel #3
0
bool MouseNavigator::handleMouseReleaseEvent( QMouseEvent* mouseEvent )
{
    bool eventUsed = false;

    if( mouseEvent->button() == Qt::LeftButton )
    {
        ByteArrayTableRanges* tableRanges = mView->tableRanges();

        const bool oldHasSelection = tableRanges->hasSelection();
//         const QPoint releasePoint = mView->viewportToColumns( mouseEvent->pos() );

        // this is not the release of a doubleclick so we need to process it?
        if( ! mInLMBDoubleClick )
        {
//             const int line = mView->lineAt( releasePoint.y() );
//             const int pos = mActiveColumn->linePositionOfX( releasePoint.x() ); // TODO: can we be sure here about the active column?
//             const Address index = tableLayout->indexAtCCoord( Coord(pos,line) ); // TODO: can this be another index than the one of the cursor???
//             emit mView->clicked( index ); // TODO: who needs this?
        }

        if( mLMBPressed )
        {
            mLMBPressed = false;

            if( mScrollTimer->isActive() )
                mScrollTimer->stop();

            // was only click inside selection, nothing dragged?
            if( mDragStartPossible )
            {
                mView->selectAll( false );
                mDragStartTimer->stop();
                mDragStartPossible = false;

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

                mView->unpauseCursor();
            }
            // was end of selection operation?
            else if( tableRanges->hasSelection() )
            {
                if( QApplication::clipboard()->supportsSelection() )
                    mView->copyToClipboard( QClipboard::Selection );
            }
        }

        emit mView->cursorPositionChanged( mView->cursorPosition() );

        mInLMBDoubleClick = false;

        if( tableRanges->selectionJustStarted() )
            tableRanges->removeSelection();

        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::handleMouseReleaseEvent( mouseEvent );
}