Loading...
Searching...
No Matches
qwt_picker_machine.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_picker_machine.h"
#include "qwt_event_pattern.h"
#include <qevent.h>
QwtPickerMachine::QwtPickerMachine( SelectionType type )
: m_selectionType( type )
, m_state( 0 )
{
}
QwtPickerMachine::~QwtPickerMachine()
{
}
QwtPickerMachine::SelectionType QwtPickerMachine::selectionType() const
{
return m_selectionType;
}
int QwtPickerMachine::state() const
{
return m_state;
}
void QwtPickerMachine::setState( int state )
{
m_state = state;
}
void QwtPickerMachine::reset()
{
setState( 0 );
}
QwtPickerTrackerMachine::QwtPickerTrackerMachine():
QwtPickerMachine( NoSelection )
{
}
QList< QwtPickerMachine::Command > QwtPickerTrackerMachine::transition(
const QwtEventPattern&, const QEvent* e )
{
QList< QwtPickerMachine::Command > cmdList;
switch ( e->type() )
{
case QEvent::Enter:
case QEvent::MouseMove:
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
setState( 1 );
}
else
{
cmdList += Move;
}
break;
}
case QEvent::Leave:
{
cmdList += Remove;
cmdList += End;
setState( 0 );
}
default:
break;
}
return cmdList;
}
QwtPickerClickPointMachine::QwtPickerClickPointMachine():
QwtPickerMachine( PointSelection )
{
}
QList< QwtPickerMachine::Command > QwtPickerClickPointMachine::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 ) ) )
{
cmdList += Begin;
cmdList += Append;
cmdList += End;
}
break;
}
case QEvent::KeyPress:
{
const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
{
if ( !keyEvent->isAutoRepeat() )
{
cmdList += Begin;
cmdList += Append;
cmdList += End;
}
}
break;
}
default:
break;
}
return cmdList;
}
QwtPickerDragPointMachine::QwtPickerDragPointMachine():
QwtPickerMachine( PointSelection )
{
}
QList< QwtPickerMachine::Command > QwtPickerDragPointMachine::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;
setState( 1 );
}
}
break;
}
case QEvent::MouseMove:
case QEvent::Wheel:
{
if ( state() != 0 )
cmdList += Move;
break;
}
case QEvent::MouseButtonRelease:
{
if ( state() != 0 )
{
cmdList += End;
setState( 0 );
}
break;
}
case QEvent::KeyPress:
{
const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
{
if ( !keyEvent->isAutoRepeat() )
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
setState( 1 );
}
else
{
cmdList += End;
setState( 0 );
}
}
}
break;
}
default:
break;
}
return cmdList;
}
QwtPickerClickRectMachine::QwtPickerClickRectMachine():
QwtPickerMachine( RectSelection )
{
}
QList< QwtPickerMachine::Command > QwtPickerClickRectMachine::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 ) ) )
{
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 );
}
}
}
break;
}
case QEvent::MouseMove:
case QEvent::Wheel:
{
if ( state() != 0 )
cmdList += Move;
break;
}
case QEvent::MouseButtonRelease:
{
if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
static_cast< const QMouseEvent* >( event ) ) )
{
if ( state() == 1 )
{
cmdList += Append;
setState( 2 );
}
}
break;
}
case QEvent::KeyPress:
{
const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
{
if ( !keyEvent->isAutoRepeat() )
{
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;
}
QwtPickerDragRectMachine::QwtPickerDragRectMachine():
QwtPickerMachine( RectSelection )
{
}
QList< QwtPickerMachine::Command > QwtPickerDragRectMachine::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( 2 );
}
}
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,
static_cast< const QKeyEvent* > ( event ) ) )
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
cmdList += Append;
setState( 2 );
}
else
{
cmdList += End;
setState( 0 );
}
}
break;
}
default:
break;
}
return cmdList;
}
QwtPickerPolygonMachine::QwtPickerPolygonMachine():
QwtPickerMachine( PolygonSelection )
{
}
QList< QwtPickerMachine::Command > QwtPickerPolygonMachine::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 );
}
else
{
cmdList += Append;
}
}
if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2,
static_cast< const QMouseEvent* >( event ) ) )
{
if ( state() == 1 )
{
cmdList += End;
setState( 0 );
}
}
break;
}
case QEvent::MouseMove:
case QEvent::Wheel:
{
if ( state() != 0 )
cmdList += Move;
break;
}
case QEvent::KeyPress:
{
const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
{
if ( !keyEvent->isAutoRepeat() )
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
cmdList += Append;
setState( 1 );
}
else
{
cmdList += Append;
}
}
}
else if ( eventPattern.keyMatch( QwtEventPattern::KeySelect2, keyEvent ) )
{
if ( !keyEvent->isAutoRepeat() )
{
if ( state() == 1 )
{
cmdList += End;
setState( 0 );
}
}
}
break;
}
default:
break;
}
return cmdList;
}
QwtPickerDragLineMachine::QwtPickerDragLineMachine():
QwtPickerMachine( PolygonSelection )
{
}
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;
}
QList
Definition qwt_abstract_legend.h:17
QwtEventPattern
A collection of event patterns.
Definition qwt_event_pattern.h:31
QwtEventPattern::mouseMatch
bool mouseMatch(MousePatternCode, const QMouseEvent *) const
Compare a mouse event with an event pattern.
Definition qwt_event_pattern.cpp:188
QwtEventPattern::keyMatch
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
Definition qwt_event_pattern.cpp:234
QwtEventPattern::KeySelect1
@ KeySelect1
Qt::Key_Return.
Definition qwt_event_pattern.h:115
QwtEventPattern::KeySelect2
@ KeySelect2
Qt::Key_Space.
Definition qwt_event_pattern.h:118
QwtEventPattern::MouseSelect1
@ MouseSelect1
Definition qwt_event_pattern.h:54
QwtEventPattern::MouseSelect2
@ MouseSelect2
Definition qwt_event_pattern.h:63
QwtPickerClickPointMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:100
QwtPickerClickPointMachine::QwtPickerClickPointMachine
QwtPickerClickPointMachine()
Constructor.
Definition qwt_picker_machine.cpp:94
QwtPickerClickRectMachine::QwtPickerClickRectMachine
QwtPickerClickRectMachine()
Constructor.
Definition qwt_picker_machine.cpp:213
QwtPickerClickRectMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:219
QwtPickerDragLineMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:479
QwtPickerDragLineMachine::QwtPickerDragLineMachine
QwtPickerDragLineMachine()
Constructor.
Definition qwt_picker_machine.cpp:473
QwtPickerDragPointMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:146
QwtPickerDragPointMachine::QwtPickerDragPointMachine
QwtPickerDragPointMachine()
Constructor.
Definition qwt_picker_machine.cpp:140
QwtPickerDragRectMachine::QwtPickerDragRectMachine
QwtPickerDragRectMachine()
Constructor.
Definition qwt_picker_machine.cpp:312
QwtPickerDragRectMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:318
QwtPickerMachine
A state machine for QwtPicker selections.
Definition qwt_picker_machine.h:29
QwtPickerMachine::SelectionType
SelectionType
Definition qwt_picker_machine.h:36
QwtPickerMachine::state
int state() const
Return the current state.
Definition qwt_picker_machine.cpp:34
QwtPickerMachine::setState
void setState(int)
Change the current state.
Definition qwt_picker_machine.cpp:40
QwtPickerMachine::selectionType
SelectionType selectionType() const
Return the selection type.
Definition qwt_picker_machine.cpp:28
QwtPickerMachine::~QwtPickerMachine
virtual ~QwtPickerMachine()
Destructor.
Definition qwt_picker_machine.cpp:23
QwtPickerMachine::QwtPickerMachine
QwtPickerMachine(SelectionType)
Constructor.
Definition qwt_picker_machine.cpp:16
QwtPickerMachine::reset
void reset()
Set the current state to 0.
Definition qwt_picker_machine.cpp:46
QwtPickerPolygonMachine::QwtPickerPolygonMachine
QwtPickerPolygonMachine()
Constructor.
Definition qwt_picker_machine.cpp:384
QwtPickerPolygonMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:390
QwtPickerTrackerMachine::QwtPickerTrackerMachine
QwtPickerTrackerMachine()
Constructor.
Definition qwt_picker_machine.cpp:52
QwtPickerTrackerMachine::transition
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) override
Transition.
Definition qwt_picker_machine.cpp:58