//! Transition
QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition(
    const QwtEventPattern &eventPattern, const QEvent *e )
{
    QList<QwtPickerMachine::Command> cmdList;

    switch ( e->type() )
    {
        case QEvent::MouseButtonPress:
        {
            if ( eventPattern.mouseMatch(
                QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
            {
                cmdList += Begin;
                cmdList += Append;
                cmdList += End;
            }
            break;
        }
        case QEvent::KeyPress:
        {
            if ( eventPattern.keyMatch(
                QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
            {
                cmdList += Begin;
                cmdList += Append;
                cmdList += End;
            }
            break;
        }
        default:
            break;
    }

    return cmdList;
}
//! Transition
QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
    const QwtEventPattern &eventPattern, const QEvent *e )
{
    QList<QwtPickerMachine::Command> cmdList;

    switch ( e->type() )
    {
        case QEvent::MouseButtonPress:
        {
            if ( eventPattern.mouseMatch(
                QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
            {
                if ( state() == 0 )
                {
                    cmdList += Begin;
                    cmdList += Append;
                    cmdList += Append;
                    setState( 1 );
                }
                else
                {
                    cmdList += End;
                    setState( 0 );
                }
            }
            if ( eventPattern.mouseMatch(
                QwtEventPattern::MouseSelect2, ( const QMouseEvent * )e ) )
            {
                if ( state() == 1 )
                    cmdList += Append;
            }
            break;
        }
        case QEvent::MouseMove:
        case QEvent::Wheel:
        {
            if ( state() != 0 )
                cmdList += Move;
            break;
        }
        case QEvent::KeyPress:
        {
            if ( eventPattern.keyMatch(
                QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
            {
                if ( state() == 0 )
                {
                    cmdList += Begin;
                    cmdList += Append;
                    cmdList += Append;
                    setState( 1 );
                }
                else
                {
                    cmdList += End;
                    setState( 0 );
                }
            }
            else if ( eventPattern.keyMatch(
                QwtEventPattern::KeySelect2, ( const QKeyEvent * )e ) )
            {
                if ( state() == 1 )
                    cmdList += Append;
            }
            break;
        }
        default:
            break;
    }

    return cmdList;
}
Exemplo n.º 3
0
  virtual QList<Command> transition(const QwtEventPattern& eventPattern, const QEvent* e)
	{
		QList<Command> cmdList;

		switch(e->type())
		{
			case QEvent::MouseButtonPress:
			{
				const QMouseEvent *mouseEvent = (QMouseEvent*)e;

				if(eventPattern.mouseMatch(QwtEventPattern::MouseSelect1, mouseEvent)
						|| (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier)
						|| (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ShiftModifier))
				{
					if(state() == 0)
					{
						cmdList += Begin;
						cmdList += Append;
						cmdList += Append;
						setState(2);
					}

					if(mouseEvent->modifiers() == Qt::ControlModifier || mouseEvent->modifiers() == Qt::ShiftModifier)
						m_bAddToSelection = true;
					else 
						m_bAddToSelection = false;
				}
				break;
			}

			case QEvent::MouseMove:
			case QEvent::Wheel:
			{
				if ( state() != 0 )
					cmdList += Move;
				break;
			}

			case QEvent::MouseButtonRelease:
			{
				if ( state() == 2 )
				{
					cmdList += End;
					setState(0);
				}
				break;
			}

			case QEvent::KeyPress:
			{
				if(eventPattern.keyMatch(QwtEventPattern::KeySelect1, (const QKeyEvent *)e))
				{
					if ( state() == 0 )
					{
						cmdList += Begin;
						cmdList += Append;
						cmdList += Append;
						setState(2);
					}
					else
					{
						cmdList += End;
						setState(0);
					}
				}
				break;
			}

			default:
			break;
		}

		return cmdList;
	}
//! Transition
QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
    const QwtEventPattern &eventPattern, const QEvent *e )
{
    QList<QwtPickerMachine::Command> cmdList;

    switch ( e->type() )
    {
        case QEvent::MouseButtonPress:
        {
            if ( eventPattern.mouseMatch(
                QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
            {
                switch ( state() )
                {
                    case 0:
                    {
                        cmdList += Begin;
                        cmdList += Append;
                        setState( 1 );
                        break;
                    }
                    case 1:
                    {
                        // Uh, strange we missed the MouseButtonRelease
                        break;
                    }
                    default:
                    {
                        cmdList += End;
                        setState( 0 );
                    }
                }
            }
        }
        case QEvent::MouseMove:
        case QEvent::Wheel:
        {
            if ( state() != 0 )
                cmdList += Move;
            break;
        }
        case QEvent::MouseButtonRelease:
        {
            if ( eventPattern.mouseMatch(
                QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
            {
                if ( state() == 1 )
                {
                    cmdList += Append;
                    setState( 2 );
                }
            }
            break;
        }
        case QEvent::KeyPress:
        {
            if ( eventPattern.keyMatch(
                QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
            {
                if ( state() == 0 )
                {
                    cmdList += Begin;
                    cmdList += Append;
                    setState( 1 );
                }
                else
                {
                    if ( state() == 1 )
                    {
                        cmdList += Append;
                        setState( 2 );
                    }
                    else if ( state() == 2 )
                    {
                        cmdList += End;
                        setState( 0 );
                    }
                }
            }
            break;
        }
        default:
            break;
    }

    return cmdList;
}
//! Transition
QList<QwtPickerMachine::Command> QwtPickerDragLineMachine::transition(
    const QwtEventPattern &eventPattern, const QEvent *event )
{
    QList<QwtPickerMachine::Command> cmdList;

    switch( event->type() )
    {
        case QEvent::MouseButtonPress:
        {
            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
                static_cast<const QMouseEvent *>( event ) ) )
            {
                if ( state() == 0 )
                {
                    cmdList += Begin;
                    cmdList += Append;
                    cmdList += Append;
                    setState( 1 );
                }
            }
            break;
        }
        case QEvent::KeyPress:
        {
            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
                static_cast<const QKeyEvent *> ( event ) ) )
            {
                if ( state() == 0 )
                {
                    cmdList += Begin;
                    cmdList += Append;
                    cmdList += Append;
                    setState( 1 );
                }
                else
                {
                    cmdList += End;
                    setState( 0 );
                }
            }
            break;
        }
        case QEvent::MouseMove:
        case QEvent::Wheel:
        {
            if ( state() != 0 )
                cmdList += Move;

            break;
        }
        case QEvent::MouseButtonRelease:
        {
            if ( state() != 0 )
            {
                cmdList += End;
                setState( 0 );
            }
        }
        default:
            break;
    }

    return cmdList;
}