Example #1
0
bool MouseNavigator::handleMouseMoveEvent( QMouseEvent* mouseEvent )
{
    bool eventUsed = false;

    if( mouseEvent->buttons() == Qt::LeftButton )
    {
        const QPoint movePoint = mView->viewportToColumns( mouseEvent->pos() );

        if( mLMBPressed )
        {
            if( mDragStartPossible )
            {
                mDragStartTimer->stop();
                // moved enough for a drag?
                if( (movePoint-mDragStartPoint).manhattanLength() > QApplication::startDragDistance() )
                    startDrag();
                if( ! mView->isReadOnly() )
                    mView->viewport()->setCursor( Qt::IBeamCursor );
            }
            else
                // selecting
                handleMouseMove( movePoint );
        }
        else if( ! mView->isReadOnly() )
        {
            ByteArrayTableRanges* tableRanges = mView->tableRanges();

            // visual feedback for possible dragging
            const bool InSelection =
                tableRanges->hasSelection() && tableRanges->selectionIncludes( mView->indexByPoint(movePoint) );
            mView->viewport()->setCursor( InSelection ? Qt::ArrowCursor : Qt::IBeamCursor );
        }
        eventUsed = true;
    }

    return eventUsed ? true : AbstractMouseController::handleMouseMoveEvent( mouseEvent );
}
Example #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 );
}