{
public:
PickerDragLineMachine():
{
}
virtual QList<Command> transition(
{
QList<QwtPickerMachine::Command> cmdList;
if ( event
->type
() == QEvent::MouseButtonPress ) {
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
cmdList += Append;
setState( 1 );
}
}
}
else if ( event
->type
() == QEvent::MouseMove ) {
if ( state() != 0 )
cmdList += Move;
}
else if ( event
->type
() == QEvent::MouseButtonRelease ) {
if ( state() != 0 )
{
cmdList += End;
setState( 0 );
}
}
return cmdList;
}
};
class PickerDragLineMachine: public QwtPickerMachine
{
public:
PickerDragLineMachine():
QwtPickerMachine( PolygonSelection )
{
}
virtual QList<Command> transition(
const QwtEventPattern &eventPattern, const QEvent *event )
{
QList<QwtPickerMachine::Command> cmdList;
if ( event->type() == QEvent::MouseButtonPress )
{
if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
static_cast<const QMouseEvent *>( event ) ) )
{
if ( state() == 0 )
{
cmdList += Begin;
cmdList += Append;
cmdList += Append;
setState( 1 );
}
}
}
else if ( event->type() == QEvent::MouseMove )
{
if ( state() != 0 )
cmdList += Move;
}
else if ( event->type() == QEvent::MouseButtonRelease )
{
if ( state() != 0 )
{
cmdList += End;
setState( 0 );
}
}
return cmdList;
}
};
To copy to clipboard, switch view to plain text mode
{
public:
{
setStateMachine( new PickerDragLineMachine() );
}
{
if ( !points.isEmpty() )
{
num.
setNum( QLineF( pos, invTransform
( points
[0] ) ).
length() );
bg.setAlpha( 200 );
text.
setBackgroundBrush( QBrush( bg
) );
text.setText( num );
}
return text;
}
};
class DistancePicker: public QwtPlotPicker
{
public:
DistancePicker( QWidget *canvas ):
QwtPlotPicker( canvas )
{
setTrackerMode( QwtPicker::ActiveOnly );
setStateMachine( new PickerDragLineMachine() );
setMousePattern( QwtEventPattern::MouseSelect1, Qt::LeftButton );
setRubberBand( QwtPlotPicker::PolygonRubberBand );
}
virtual QwtText trackerTextF( const QPointF &pos ) const
{
QwtText text;
const QPolygon points = selection();
if ( !points.isEmpty() )
{
QString num;
num.setNum( QLineF( pos, invTransform( points[0] ) ).length() );
QColor bg( Qt::white );
bg.setAlpha( 200 );
text.setBackgroundBrush( QBrush( bg ) );
text.setText( num );
}
return text;
}
};
To copy to clipboard, switch view to plain text mode
HTH,
Uwe
Bookmarks