qwt_picker.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.h"
#include "qwt_picker_machine.h"
#include "qwt_painter.h"
#include "qwt_math.h"
#include "qwt_widget_overlay.h"
#include "qwt_text.h"
#include <qevent.h>
#include <qpainter.h>
#include <qpainterpath.h>
#include <qcursor.h>
#include <qpointer.h>
static inline QRegion qwtMaskRegion( const QRect& r, int penWidth )
{
const int pw = qMax( penWidth, 1 );
const int pw2 = penWidth / 2;
int x1 = r.left() - pw2;
int x2 = r.right() + 1 + pw2 + ( pw % 2 );
int y1 = r.top() - pw2;
int y2 = r.bottom() + 1 + pw2 + ( pw % 2 );
QRegion region;
region += QRect( x1, y1, x2 - x1, pw );
region += QRect( x1, y1, pw, y2 - y1 );
region += QRect( x1, y2 - pw, x2 - x1, pw );
region += QRect( x2 - pw, y1, pw, y2 - y1 );
return region;
}
static inline QRegion qwtMaskRegion( const QLine& l, int penWidth )
{
const int pw = qMax( penWidth, 1 );
const int pw2 = penWidth / 2;
QRegion region;
if ( l.x1() == l.x2() )
{
region += QRect( l.x1() - pw2, l.y1(),
pw, l.y2() ).normalized();
}
else if ( l.y1() == l.y2() )
{
region += QRect( l.x1(), l.y1() - pw2,
l.x2(), pw ).normalized();
}
return region;
}
namespace
{
class Rubberband QWT_FINAL : public QwtWidgetOverlay
{
public:
Rubberband( QwtPicker* picker, QWidget* parent )
: QwtWidgetOverlay( parent )
, m_picker( picker )
{
setMaskMode( QwtWidgetOverlay::MaskHint );
}
protected:
virtual void drawOverlay( QPainter* painter ) const QWT_OVERRIDE
{
painter->setPen( m_picker->rubberBandPen() );
m_picker->drawRubberBand( painter );
}
virtual QRegion maskHint() const QWT_OVERRIDE
{
return m_picker->rubberBandMask();
}
QwtPicker* m_picker;
};
class Tracker QWT_FINAL : public QwtWidgetOverlay
{
public:
Tracker( QwtPicker* picker, QWidget* parent )
: QwtWidgetOverlay( parent )
, m_picker( picker )
{
setMaskMode( QwtWidgetOverlay::MaskHint );
}
protected:
virtual void drawOverlay( QPainter* painter ) const QWT_OVERRIDE
{
painter->setPen( m_picker->trackerPen() );
m_picker->drawTracker( painter );
}
virtual QRegion maskHint() const QWT_OVERRIDE
{
return m_picker->trackerMask();
}
QwtPicker* m_picker;
};
}
class QwtPicker::PrivateData
{
public:
PrivateData():
enabled( false ),
stateMachine( NULL ),
resizeMode( QwtPicker::Stretch ),
rubberBand( QwtPicker::NoRubberBand ),
trackerMode( QwtPicker::AlwaysOff ),
isActive( false ),
trackerPosition( -1, -1 ),
mouseTracking( false ),
openGL( false )
{
}
bool enabled;
QwtPickerMachine* stateMachine;
QwtPicker::ResizeMode resizeMode;
QwtPicker::RubberBand rubberBand;
QPen rubberBandPen;
QwtPicker::DisplayMode trackerMode;
QPen trackerPen;
QFont trackerFont;
QPolygon pickedPoints;
bool isActive;
QPoint trackerPosition;
bool mouseTracking; // used to save previous value
QPointer< Rubberband > rubberBandOverlay;
QPointer< Tracker > trackerOverlay;
bool openGL;
};
QwtPicker::QwtPicker( QWidget* parent ):
QObject( parent )
{
init( parent, NoRubberBand, AlwaysOff );
}
QwtPicker::QwtPicker( RubberBand rubberBand,
DisplayMode trackerMode, QWidget* parent ):
QObject( parent )
{
init( parent, rubberBand, trackerMode );
}
QwtPicker::~QwtPicker()
{
setMouseTracking( false );
delete m_data->stateMachine;
delete m_data->rubberBandOverlay;
delete m_data->trackerOverlay;
delete m_data;
}
void QwtPicker::init( QWidget* parent,
RubberBand rubberBand, DisplayMode trackerMode )
{
m_data = new PrivateData;
m_data->rubberBand = rubberBand;
if ( parent )
{
if ( parent->focusPolicy() == Qt::NoFocus )
parent->setFocusPolicy( Qt::WheelFocus );
m_data->openGL = parent->inherits( "QGLWidget" );
m_data->trackerFont = parent->font();
m_data->mouseTracking = parent->hasMouseTracking();
setEnabled( true );
}
setTrackerMode( trackerMode );
}
void QwtPicker::setStateMachine( QwtPickerMachine* stateMachine )
{
if ( m_data->stateMachine != stateMachine )
{
reset();
delete m_data->stateMachine;
m_data->stateMachine = stateMachine;
if ( m_data->stateMachine )
m_data->stateMachine->reset();
}
}
QwtPickerMachine* QwtPicker::stateMachine()
{
return m_data->stateMachine;
}
const QwtPickerMachine* QwtPicker::stateMachine() const
{
return m_data->stateMachine;
}
QWidget* QwtPicker::parentWidget()
{
QObject* obj = parent();
if ( obj && obj->isWidgetType() )
return static_cast< QWidget* >( obj );
return NULL;
}
const QWidget* QwtPicker::parentWidget() const
{
QObject* obj = parent();
if ( obj && obj->isWidgetType() )
return static_cast< const QWidget* >( obj );
return NULL;
}
void QwtPicker::setRubberBand( RubberBand rubberBand )
{
m_data->rubberBand = rubberBand;
}
QwtPicker::RubberBand QwtPicker::rubberBand() const
{
return m_data->rubberBand;
}
void QwtPicker::setTrackerMode( DisplayMode mode )
{
if ( m_data->trackerMode != mode )
{
m_data->trackerMode = mode;
setMouseTracking( m_data->trackerMode == AlwaysOn );
}
}
QwtPicker::DisplayMode QwtPicker::trackerMode() const
{
return m_data->trackerMode;
}
void QwtPicker::setResizeMode( ResizeMode mode )
{
m_data->resizeMode = mode;
}
QwtPicker::ResizeMode QwtPicker::resizeMode() const
{
return m_data->resizeMode;
}
void QwtPicker::setEnabled( bool enabled )
{
if ( m_data->enabled != enabled )
{
m_data->enabled = enabled;
QWidget* w = parentWidget();
if ( w )
{
if ( enabled )
w->installEventFilter( this );
else
w->removeEventFilter( this );
}
updateDisplay();
}
}
bool QwtPicker::isEnabled() const
{
return m_data->enabled;
}
void QwtPicker::setTrackerFont( const QFont& font )
{
if ( font != m_data->trackerFont )
{
m_data->trackerFont = font;
updateDisplay();
}
}
QFont QwtPicker::trackerFont() const
{
return m_data->trackerFont;
}
void QwtPicker::setTrackerPen( const QPen& pen )
{
if ( pen != m_data->trackerPen )
{
m_data->trackerPen = pen;
updateDisplay();
}
}
QPen QwtPicker::trackerPen() const
{
return m_data->trackerPen;
}
void QwtPicker::setRubberBandPen( const QPen& pen )
{
if ( pen != m_data->rubberBandPen )
{
m_data->rubberBandPen = pen;
updateDisplay();
}
}
QPen QwtPicker::rubberBandPen() const
{
return m_data->rubberBandPen;
}
QwtText QwtPicker::trackerText( const QPoint& pos ) const
{
QString label;
switch ( rubberBand() )
{
case HLineRubberBand:
label = QString::number( pos.y() );
break;
case VLineRubberBand:
label = QString::number( pos.x() );
break;
default:
label = QString::number( pos.x() ) + ", " + QString::number( pos.y() );
}
return label;
}
QRegion QwtPicker::trackerMask() const
{
return trackerRect( m_data->trackerFont );
}
QRegion QwtPicker::rubberBandMask() const
{
QRegion mask;
if ( !isActive() || rubberBand() == NoRubberBand ||
rubberBandPen().style() == Qt::NoPen )
{
return mask;
}
const QPolygon pa = adjustedPoints( m_data->pickedPoints );
QwtPickerMachine::SelectionType selectionType =
QwtPickerMachine::NoSelection;
if ( m_data->stateMachine )
selectionType = m_data->stateMachine->selectionType();
switch ( selectionType )
{
case QwtPickerMachine::NoSelection:
case QwtPickerMachine::PointSelection:
{
if ( pa.count() < 1 )
return mask;
const QPoint pos = pa[0];
const int pw = rubberBandPen().width();
const QRect pRect = pickArea().boundingRect().toRect();
switch ( rubberBand() )
{
case VLineRubberBand:
{
mask += qwtMaskRegion( QLine( pos.x(), pRect.top(),
pos.x(), pRect.bottom() ), pw );
break;
}
case HLineRubberBand:
{
mask += qwtMaskRegion( QLine( pRect.left(), pos.y(),
pRect.right(), pos.y() ), pw );
break;
}
case CrossRubberBand:
{
mask += qwtMaskRegion( QLine( pos.x(), pRect.top(),
pos.x(), pRect.bottom() ), pw );
mask += qwtMaskRegion( QLine( pRect.left(), pos.y(),
pRect.right(), pos.y() ), pw );
break;
}
default:
break;
}
break;
}
case QwtPickerMachine::RectSelection:
{
if ( pa.count() < 2 )
return mask;
const int pw = rubberBandPen().width();
switch ( rubberBand() )
{
case RectRubberBand:
{
const QRect r = QRect( pa.first(), pa.last() );
mask = qwtMaskRegion( r.normalized(), pw );
break;
}
case EllipseRubberBand:
{
const QRect r = QRect( pa.first(), pa.last() );
mask += r.adjusted( -pw, -pw, pw, pw );
break;
}
default:
break;
}
break;
}
case QwtPickerMachine::PolygonSelection:
{
const int pw = rubberBandPen().width();
if ( pw <= 1 )
{
// because of the join style we better
// return a mask for a pen width <= 1 only
const int off = 2 * pw;
const QRect r = pa.boundingRect();
mask += r.adjusted( -off, -off, off, off );
}
break;
}
default:
break;
}
return mask;
}
void QwtPicker::drawRubberBand( QPainter* painter ) const
{
if ( !isActive() || rubberBand() == NoRubberBand ||
rubberBandPen().style() == Qt::NoPen )
{
return;
}
const QPolygon pa = adjustedPoints( m_data->pickedPoints );
QwtPickerMachine::SelectionType selectionType =
QwtPickerMachine::NoSelection;
if ( m_data->stateMachine )
selectionType = m_data->stateMachine->selectionType();
switch ( selectionType )
{
case QwtPickerMachine::NoSelection:
case QwtPickerMachine::PointSelection:
{
if ( pa.count() < 1 )
return;
const QPoint pos = pa[0];
const QRect pRect = pickArea().boundingRect().toRect();
switch ( rubberBand() )
{
case VLineRubberBand:
{
QwtPainter::drawLine( painter, pos.x(),
pRect.top(), pos.x(), pRect.bottom() );
break;
}
case HLineRubberBand:
{
QwtPainter::drawLine( painter, pRect.left(),
pos.y(), pRect.right(), pos.y() );
break;
}
case CrossRubberBand:
{
QwtPainter::drawLine( painter, pos.x(),
pRect.top(), pos.x(), pRect.bottom() );
QwtPainter::drawLine( painter, pRect.left(),
pos.y(), pRect.right(), pos.y() );
break;
}
default:
break;
}
break;
}
case QwtPickerMachine::RectSelection:
{
if ( pa.count() < 2 )
return;
const QRect rect = QRect( pa.first(), pa.last() ).normalized();
switch ( rubberBand() )
{
case EllipseRubberBand:
{
QwtPainter::drawEllipse( painter, rect );
break;
}
case RectRubberBand:
{
QwtPainter::drawRect( painter, rect );
break;
}
default:
break;
}
break;
}
case QwtPickerMachine::PolygonSelection:
{
if ( rubberBand() == PolygonRubberBand )
painter->drawPolyline( pa );
break;
}
default:
break;
}
}
void QwtPicker::drawTracker( QPainter* painter ) const
{
const QRect textRect = trackerRect( painter->font() );
if ( !textRect.isEmpty() )
{
const QwtText label = trackerText( m_data->trackerPosition );
if ( !label.isEmpty() )
label.draw( painter, textRect );
}
}
QPolygon QwtPicker::adjustedPoints( const QPolygon& points ) const
{
return points;
}
QPolygon QwtPicker::selection() const
{
return adjustedPoints( m_data->pickedPoints );
}
QPoint QwtPicker::trackerPosition() const
{
return m_data->trackerPosition;
}
QRect QwtPicker::trackerRect( const QFont& font ) const
{
if ( trackerMode() == AlwaysOff ||
( trackerMode() == ActiveOnly && !isActive() ) )
{
return QRect();
}
if ( m_data->trackerPosition.x() < 0 || m_data->trackerPosition.y() < 0 )
return QRect();
QwtText text = trackerText( m_data->trackerPosition );
if ( text.isEmpty() )
return QRect();
const QSizeF textSize = text.textSize( font );
QRect textRect( 0, 0, qwtCeil( textSize.width() ), qwtCeil( textSize.height() ) );
const QPoint& pos = m_data->trackerPosition;
int alignment = 0;
if ( isActive() && m_data->pickedPoints.count() > 1
&& rubberBand() != NoRubberBand )
{
const QPoint last =
m_data->pickedPoints[ m_data->pickedPoints.count() - 2 ];
alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft;
alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop;
}
else
alignment = Qt::AlignTop | Qt::AlignRight;
const int margin = 5;
int x = pos.x();
if ( alignment & Qt::AlignLeft )
x -= textRect.width() + margin;
else if ( alignment & Qt::AlignRight )
x += margin;
int y = pos.y();
if ( alignment & Qt::AlignBottom )
y += margin;
else if ( alignment & Qt::AlignTop )
y -= textRect.height() + margin;
textRect.moveTopLeft( QPoint( x, y ) );
const QRect pickRect = pickArea().boundingRect().toRect();
int right = qMin( textRect.right(), pickRect.right() - margin );
int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin );
textRect.moveBottomRight( QPoint( right, bottom ) );
int left = qMax( textRect.left(), pickRect.left() + margin );
int top = qMax( textRect.top(), pickRect.top() + margin );
textRect.moveTopLeft( QPoint( left, top ) );
return textRect;
}
bool QwtPicker::eventFilter( QObject* object, QEvent* event )
{
if ( object && object == parentWidget() )
{
switch ( event->type() )
{
case QEvent::Resize:
{
const QResizeEvent* re = static_cast< QResizeEvent* >( event );
/*
Adding/deleting additional event filters inside of an event filter
is not safe dues to the implementation in Qt ( changing a list while iterating ).
So we create the overlays in a way, that they don't install en event filter
( parent set to NULL ) and do the resizing here.
*/
if ( m_data->trackerOverlay )
m_data->trackerOverlay->resize( re->size() );
if ( m_data->rubberBandOverlay )
m_data->rubberBandOverlay->resize( re->size() );
if ( m_data->resizeMode == Stretch )
stretchSelection( re->oldSize(), re->size() );
updateDisplay();
break;
}
case QEvent::Enter:
{
widgetEnterEvent( event );
break;
}
case QEvent::Leave:
{
widgetLeaveEvent( event );
break;
}
case QEvent::MouseButtonPress:
{
widgetMousePressEvent( static_cast< QMouseEvent* >( event ) );
break;
}
case QEvent::MouseButtonRelease:
{
widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) );
break;
}
case QEvent::MouseButtonDblClick:
{
widgetMouseDoubleClickEvent( static_cast< QMouseEvent* >( event ) );
break;
}
case QEvent::MouseMove:
{
widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) );
break;
}
case QEvent::KeyPress:
{
widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) );
break;
}
case QEvent::KeyRelease:
{
widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) );
break;
}
case QEvent::Wheel:
{
widgetWheelEvent( static_cast< QWheelEvent* >( event ) );
break;
}
default:
break;
}
}
return false;
}
void QwtPicker::widgetMousePressEvent( QMouseEvent* mouseEvent )
{
transition( mouseEvent );
}
void QwtPicker::widgetMouseMoveEvent( QMouseEvent* mouseEvent )
{
if ( pickArea().contains( mouseEvent->pos() ) )
m_data->trackerPosition = mouseEvent->pos();
else
m_data->trackerPosition = QPoint( -1, -1 );
if ( !isActive() )
updateDisplay();
transition( mouseEvent );
}
void QwtPicker::widgetEnterEvent( QEvent* event )
{
transition( event );
}
void QwtPicker::widgetLeaveEvent( QEvent* event )
{
transition( event );
m_data->trackerPosition = QPoint( -1, -1 );
if ( !isActive() )
updateDisplay();
}
void QwtPicker::widgetMouseReleaseEvent( QMouseEvent* mouseEvent )
{
transition( mouseEvent );
}
void QwtPicker::widgetMouseDoubleClickEvent( QMouseEvent* mouseEvent )
{
transition( mouseEvent );
}
void QwtPicker::widgetWheelEvent( QWheelEvent* wheelEvent )
{
#if QT_VERSION < 0x050e00
const QPoint wheelPos = wheelEvent->pos();
#else
const QPoint wheelPos = wheelEvent->position().toPoint();
#endif
if ( pickArea().contains( wheelPos ) )
m_data->trackerPosition = wheelPos;
else
m_data->trackerPosition = QPoint( -1, -1 );
updateDisplay();
transition( wheelEvent );
}
void QwtPicker::widgetKeyPressEvent( QKeyEvent* keyEvent )
{
int dx = 0;
int dy = 0;
int offset = 1;
if ( keyEvent->isAutoRepeat() )
offset = 5;
if ( keyMatch( KeyLeft, keyEvent ) )
dx = -offset;
else if ( keyMatch( KeyRight, keyEvent ) )
dx = offset;
else if ( keyMatch( KeyUp, keyEvent ) )
dy = -offset;
else if ( keyMatch( KeyDown, keyEvent ) )
dy = offset;
else if ( keyMatch( KeyAbort, keyEvent ) )
{
reset();
}
else
transition( keyEvent );
if ( dx != 0 || dy != 0 )
{
const QRect rect = pickArea().boundingRect().toRect();
const QPoint pos = parentWidget()->mapFromGlobal( QCursor::pos() );
int x = pos.x() + dx;
x = qMax( rect.left(), x );
x = qMin( rect.right(), x );
int y = pos.y() + dy;
y = qMax( rect.top(), y );
y = qMin( rect.bottom(), y );
QCursor::setPos( parentWidget()->mapToGlobal( QPoint( x, y ) ) );
}
}
void QwtPicker::widgetKeyReleaseEvent( QKeyEvent* keyEvent )
{
transition( keyEvent );
}
void QwtPicker::transition( const QEvent* event )
{
if ( !m_data->stateMachine )
return;
const QList< QwtPickerMachine::Command > commandList =
m_data->stateMachine->transition( *this, event );
QPoint pos;
switch ( event->type() )
{
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
{
const QMouseEvent* me =
static_cast< const QMouseEvent* >( event );
pos = me->pos();
break;
}
default:
pos = parentWidget()->mapFromGlobal( QCursor::pos() );
}
for ( int i = 0; i < commandList.count(); i++ )
{
switch ( commandList[i] )
{
case QwtPickerMachine::Begin:
{
begin();
break;
}
case QwtPickerMachine::Append:
{
append( pos );
break;
}
case QwtPickerMachine::Move:
{
move( pos );
break;
}
case QwtPickerMachine::Remove:
{
remove();
break;
}
case QwtPickerMachine::End:
{
end();
break;
}
}
}
}
void QwtPicker::begin()
{
if ( m_data->isActive )
return;
m_data->pickedPoints.clear();
m_data->isActive = true;
Q_EMIT activated( true );
if ( trackerMode() != AlwaysOff )
{
if ( m_data->trackerPosition.x() < 0 || m_data->trackerPosition.y() < 0 )
{
QWidget* w = parentWidget();
if ( w )
m_data->trackerPosition = w->mapFromGlobal( QCursor::pos() );
}
}
updateDisplay();
setMouseTracking( true );
}
bool QwtPicker::end( bool ok )
{
if ( m_data->isActive )
{
setMouseTracking( false );
m_data->isActive = false;
Q_EMIT activated( false );
if ( trackerMode() == ActiveOnly )
m_data->trackerPosition = QPoint( -1, -1 );
if ( ok )
ok = accept( m_data->pickedPoints );
if ( ok )
Q_EMIT selected( m_data->pickedPoints );
else
m_data->pickedPoints.clear();
updateDisplay();
}
else
ok = false;
return ok;
}
void QwtPicker::reset()
{
if ( m_data->stateMachine )
m_data->stateMachine->reset();
if ( isActive() )
end( false );
}
void QwtPicker::append( const QPoint& pos )
{
if ( m_data->isActive )
{
m_data->pickedPoints += pos;
updateDisplay();
Q_EMIT appended( pos );
}
}
void QwtPicker::move( const QPoint& pos )
{
if ( m_data->isActive && !m_data->pickedPoints.isEmpty() )
{
QPoint& point = m_data->pickedPoints.last();
if ( point != pos )
{
point = pos;
updateDisplay();
Q_EMIT moved( pos );
}
}
}
void QwtPicker::remove()
{
if ( m_data->isActive && !m_data->pickedPoints.isEmpty() )
{
#if QT_VERSION >= 0x050100
const QPoint pos = m_data->pickedPoints.takeLast();
#else
const QPoint pos = m_data->pickedPoints.last();
m_data->pickedPoints.resize( m_data->pickedPoints.count() - 1 );
#endif
updateDisplay();
Q_EMIT removed( pos );
}
}
bool QwtPicker::accept( QPolygon& selection ) const
{
Q_UNUSED( selection );
return true;
}
bool QwtPicker::isActive() const
{
return m_data->isActive;
}
const QPolygon& QwtPicker::pickedPoints() const
{
return m_data->pickedPoints;
}
void QwtPicker::stretchSelection( const QSize& oldSize, const QSize& newSize )
{
if ( oldSize.isEmpty() )
{
// avoid division by zero. But scaling for small sizes also
// doesn't make much sense, because of rounding losses. TODO ...
return;
}
const double xRatio = double( newSize.width() ) / double( oldSize.width() );
const double yRatio = double( newSize.height() ) / double( oldSize.height() );
for ( int i = 0; i < m_data->pickedPoints.count(); i++ )
{
QPoint& p = m_data->pickedPoints[i];
p.setX( qRound( p.x() * xRatio ) );
p.setY( qRound( p.y() * yRatio ) );
Q_EMIT changed( m_data->pickedPoints );
}
}
void QwtPicker::setMouseTracking( bool enable )
{
QWidget* widget = parentWidget();
if ( !widget )
return;
if ( enable )
{
m_data->mouseTracking = widget->hasMouseTracking();
widget->setMouseTracking( true );
}
else
{
widget->setMouseTracking( m_data->mouseTracking );
}
}
QPainterPath QwtPicker::pickArea() const
{
QPainterPath path;
const QWidget* widget = parentWidget();
if ( widget )
path.addRect( widget->contentsRect() );
return path;
}
void QwtPicker::updateDisplay()
{
QWidget* w = parentWidget();
bool showRubberband = false;
bool showTracker = false;
if ( w && w->isVisible() && m_data->enabled )
{
if ( rubberBand() != NoRubberBand && isActive() &&
rubberBandPen().style() != Qt::NoPen )
{
showRubberband = true;
}
if ( trackerMode() == AlwaysOn ||
( trackerMode() == ActiveOnly && isActive() ) )
{
if ( trackerPen() != Qt::NoPen
&& !trackerRect( QFont() ).isEmpty() )
{
showTracker = true;
}
}
}
QPointer< Rubberband >& rw = m_data->rubberBandOverlay;
if ( showRubberband )
{
if ( rw.isNull() )
{
rw = new Rubberband( this, NULL ); // NULL -> no extra event filter
rw->setObjectName( "PickerRubberBand" );
rw->setParent( w );
rw->resize( w->size() );
}
if ( m_data->rubberBand <= RectRubberBand )
rw->setMaskMode( QwtWidgetOverlay::MaskHint );
else
rw->setMaskMode( QwtWidgetOverlay::AlphaMask );
rw->updateOverlay();
}
else
{
if ( m_data->openGL )
{
// Qt 4.8 crashes for a delete
if ( !rw.isNull() )
{
rw->hide();
rw->deleteLater();
rw = NULL;
}
}
else
{
delete rw;
}
}
QPointer< Tracker >& tw = m_data->trackerOverlay;
if ( showTracker )
{
if ( tw.isNull() )
{
tw = new Tracker( this, NULL ); // NULL -> no extra event filter
tw->setObjectName( "PickerTracker" );
tw->setParent( w );
tw->resize( w->size() );
}
tw->setFont( m_data->trackerFont );
tw->updateOverlay();
}
else
{
if ( m_data->openGL )
{
// Qt 4.8 crashes for a delete
if ( !tw.isNull() )
{
tw->hide();
tw->deleteLater();
tw = NULL;
}
}
else
{
delete tw;
}
}
}
const QwtWidgetOverlay* QwtPicker::rubberBandOverlay() const
{
return m_data->rubberBandOverlay;
}
const QwtWidgetOverlay* QwtPicker::trackerOverlay() const
{
return m_data->trackerOverlay;
}
#if QWT_MOC_INCLUDE
#include "moc_qwt_picker.cpp"
#endif
QList
Definition: qwt_abstract_legend.h:17
QwtEventPattern::keyMatch
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
Definition: qwt_event_pattern.cpp:234
QwtEventPattern::KeyDown
@ KeyDown
Qt::Key_Down.
Definition: qwt_event_pattern.h:133
QwtEventPattern::KeyUp
@ KeyUp
Qt::Key_Up.
Definition: qwt_event_pattern.h:130
QwtEventPattern::KeyAbort
@ KeyAbort
Qt::Key_Escape.
Definition: qwt_event_pattern.h:121
QwtEventPattern::KeyRight
@ KeyRight
Qt::Key_Right.
Definition: qwt_event_pattern.h:127
QwtEventPattern::KeyLeft
@ KeyLeft
Qt::Key_Left.
Definition: qwt_event_pattern.h:124
QwtPainter::drawEllipse
static void drawEllipse(QPainter *, const QRectF &)
Wrapper for QPainter::drawEllipse()
Definition: qwt_painter.cpp:426
QwtPainter::drawRect
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
Definition: qwt_painter.cpp:347
QwtPainter::drawLine
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
Definition: qwt_painter.h:154
QwtPicker
QwtPicker provides selections on a widget.
Definition: qwt_picker.h:104
QwtPicker::DisplayMode
DisplayMode
Display mode.
Definition: qwt_picker.h:162
QwtPicker::AlwaysOn
@ AlwaysOn
Display always.
Definition: qwt_picker.h:167
QwtPicker::AlwaysOff
@ AlwaysOff
Display never.
Definition: qwt_picker.h:164
QwtPicker::ActiveOnly
@ ActiveOnly
Display only when the selection is active.
Definition: qwt_picker.h:170
QwtPicker::updateDisplay
virtual void updateDisplay()
Update the state of rubber band and tracker label.
Definition: qwt_picker.cpp:1486
QwtPicker::trackerFont
QFont trackerFont() const
Definition: qwt_picker.cpp:424
QwtPicker::resizeMode
ResizeMode resizeMode() const
Definition: qwt_picker.cpp:361
QwtPicker::reset
virtual void reset()
Definition: qwt_picker.cpp:1303
QwtPicker::drawRubberBand
virtual void drawRubberBand(QPainter *) const
Definition: qwt_picker.cpp:637
QwtPicker::rubberBand
RubberBand rubberBand() const
Definition: qwt_picker.cpp:298
QwtPicker::setRubberBandPen
void setRubberBandPen(const QPen &)
Definition: qwt_picker.cpp:459
QwtPicker::trackerMask
virtual QRegion trackerMask() const
Definition: qwt_picker.cpp:514
QwtPicker::remove
virtual void remove()
Definition: qwt_picker.cpp:1359
QwtPicker::stretchSelection
virtual void stretchSelection(const QSize &oldSize, const QSize &newSize)
Definition: qwt_picker.cpp:1417
QwtPicker::eventFilter
virtual bool eventFilter(QObject *, QEvent *) override
Event filter.
Definition: qwt_picker.cpp:893
QwtPicker::selected
void selected(const QPolygon &polygon)
QwtPicker::rubberBandPen
QPen rubberBandPen() const
Definition: qwt_picker.cpp:472
QwtPicker::rubberBandOverlay
const QwtWidgetOverlay * rubberBandOverlay() const
Definition: qwt_picker.cpp:1581
QwtPicker::begin
virtual void begin()
Definition: qwt_picker.cpp:1239
QwtPicker::widgetMousePressEvent
virtual void widgetMousePressEvent(QMouseEvent *)
Definition: qwt_picker.cpp:982
QwtPicker::move
virtual void move(const QPoint &)
Definition: qwt_picker.cpp:1338
QwtPicker::~QwtPicker
virtual ~QwtPicker()
Destructor.
Definition: qwt_picker.cpp:189
QwtPicker::append
virtual void append(const QPoint &)
Definition: qwt_picker.cpp:1320
QwtPicker::setStateMachine
void setStateMachine(QwtPickerMachine *)
Definition: qwt_picker.cpp:229
QwtPicker::drawTracker
virtual void drawTracker(QPainter *) const
Definition: qwt_picker.cpp:732
QwtPicker::trackerPen
QPen trackerPen() const
Definition: qwt_picker.cpp:448
QwtPicker::rubberBandMask
virtual QRegion rubberBandMask() const
Definition: qwt_picker.cpp:525
QwtPicker::trackerPosition
QPoint trackerPosition() const
Definition: qwt_picker.cpp:798
QwtPicker::widgetEnterEvent
virtual void widgetEnterEvent(QEvent *)
Definition: qwt_picker.cpp:1018
QwtPicker::setRubberBand
void setRubberBand(RubberBand)
Definition: qwt_picker.cpp:289
QwtPicker::trackerOverlay
const QwtWidgetOverlay * trackerOverlay() const
Definition: qwt_picker.cpp:1587
QwtPicker::widgetMouseMoveEvent
virtual void widgetMouseMoveEvent(QMouseEvent *)
Definition: qwt_picker.cpp:996
QwtPicker::activated
void activated(bool on)
QwtPicker::widgetLeaveEvent
virtual void widgetLeaveEvent(QEvent *)
Definition: qwt_picker.cpp:1032
QwtPicker::transition
virtual void transition(const QEvent *)
Definition: qwt_picker.cpp:1176
QwtPicker::accept
virtual bool accept(QPolygon &) const
Validate and fix up the selection.
Definition: qwt_picker.cpp:1383
QwtPicker::setTrackerMode
void setTrackerMode(DisplayMode)
Set the display mode of the tracker.
Definition: qwt_picker.cpp:319
QwtPicker::pickArea
virtual QPainterPath pickArea() const
Definition: qwt_picker.cpp:1474
QwtPicker::isActive
bool isActive() const
Definition: qwt_picker.cpp:1393
QwtPicker::widgetKeyReleaseEvent
virtual void widgetKeyReleaseEvent(QKeyEvent *)
Definition: qwt_picker.cpp:1164
QwtPicker::setTrackerFont
void setTrackerFont(const QFont &)
Definition: qwt_picker.cpp:410
QwtPicker::setEnabled
void setEnabled(bool)
En/disable the picker.
Definition: qwt_picker.cpp:375
QwtPicker::isEnabled
bool isEnabled() const
Definition: qwt_picker.cpp:399
QwtPicker::trackerMode
DisplayMode trackerMode() const
Definition: qwt_picker.cpp:332
QwtPicker::adjustedPoints
virtual QPolygon adjustedPoints(const QPolygon &) const
Map the pickedPoints() into a selection()
Definition: qwt_picker.cpp:783
QwtPicker::RubberBand
RubberBand
Definition: qwt_picker.h:128
QwtPicker::VLineRubberBand
@ VLineRubberBand
A vertical line ( only for QwtPickerMachine::PointSelection )
Definition: qwt_picker.h:136
QwtPicker::CrossRubberBand
@ CrossRubberBand
A crosshair ( only for QwtPickerMachine::PointSelection )
Definition: qwt_picker.h:139
QwtPicker::EllipseRubberBand
@ EllipseRubberBand
An ellipse ( only for QwtPickerMachine::RectSelection )
Definition: qwt_picker.h:145
QwtPicker::PolygonRubberBand
@ PolygonRubberBand
A polygon ( only for QwtPickerMachine::PolygonSelection )
Definition: qwt_picker.h:148
QwtPicker::HLineRubberBand
@ HLineRubberBand
A horizontal line ( only for QwtPickerMachine::PointSelection )
Definition: qwt_picker.h:133
QwtPicker::NoRubberBand
@ NoRubberBand
No rubberband.
Definition: qwt_picker.h:130
QwtPicker::RectRubberBand
@ RectRubberBand
A rectangle ( only for QwtPickerMachine::RectSelection )
Definition: qwt_picker.h:142
QwtPicker::ResizeMode
ResizeMode
Definition: qwt_picker.h:182
QwtPicker::Stretch
@ Stretch
All points are scaled according to the new size,.
Definition: qwt_picker.h:184
QwtPicker::trackerText
virtual QwtText trackerText(const QPoint &pos) const
Return the label for a position.
Definition: qwt_picker.cpp:490
QwtPicker::widgetMouseReleaseEvent
virtual void widgetMouseReleaseEvent(QMouseEvent *)
Definition: qwt_picker.cpp:1050
QwtPicker::end
virtual bool end(bool ok=true)
Close a selection setting the state to inactive.
Definition: qwt_picker.cpp:1272
QwtPicker::appended
void appended(const QPoint &pos)
QwtPicker::parentWidget
QWidget * parentWidget()
Return the parent widget, where the selection happens.
Definition: qwt_picker.cpp:262
QwtPicker::moved
void moved(const QPoint &pos)
QwtPicker::pickedPoints
const QPolygon & pickedPoints() const
Definition: qwt_picker.cpp:1403
QwtPicker::stateMachine
const QwtPickerMachine * stateMachine() const
Definition: qwt_picker.cpp:256
QwtPicker::removed
void removed(const QPoint &pos)
QwtPicker::changed
void changed(const QPolygon &selection)
QwtPicker::trackerRect
virtual QRect trackerRect(const QFont &) const
Definition: qwt_picker.cpp:812
QwtPicker::widgetMouseDoubleClickEvent
virtual void widgetMouseDoubleClickEvent(QMouseEvent *)
Definition: qwt_picker.cpp:1064
QwtPicker::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *)
Definition: qwt_picker.cpp:1112
QwtPicker::setTrackerPen
void setTrackerPen(const QPen &)
Definition: qwt_picker.cpp:435
QwtPicker::setResizeMode
void setResizeMode(ResizeMode)
Set the resize mode.
Definition: qwt_picker.cpp:351
QwtPicker::widgetWheelEvent
virtual void widgetWheelEvent(QWheelEvent *)
Definition: qwt_picker.cpp:1081
QwtPicker::QwtPicker
QwtPicker(QWidget *parent)
Definition: qwt_picker.cpp:168
QwtPicker::selection
QPolygon selection() const
Definition: qwt_picker.cpp:792
QwtPickerMachine
A state machine for QwtPicker selections.
Definition: qwt_picker_machine.h:29
QwtPickerMachine::SelectionType
SelectionType
Definition: qwt_picker_machine.h:36
QwtPickerMachine::NoSelection
@ NoSelection
The state machine not usable for any type of selection.
Definition: qwt_picker_machine.h:38
QwtPickerMachine::RectSelection
@ RectSelection
The state machine is for selecting a rectangle (2 points).
Definition: qwt_picker_machine.h:44
QwtPickerMachine::PolygonSelection
@ PolygonSelection
The state machine is for selecting a polygon (many points).
Definition: qwt_picker_machine.h:47
QwtPickerMachine::PointSelection
@ PointSelection
The state machine is for selecting a single point.
Definition: qwt_picker_machine.h:41
QwtText
A class representing a text.
Definition: qwt_text.h:52
QwtText::textSize
QSizeF textSize() const
Definition: qwt_text.cpp:570
QwtText::isEmpty
bool isEmpty() const
Definition: qwt_text.cpp:739
QwtText::draw
void draw(QPainter *painter, const QRectF &rect) const
Definition: qwt_text.cpp:615
QwtWidgetOverlay
An overlay for a widget.
Definition: qwt_widget_overlay.h:41
QwtWidgetOverlay::AlphaMask
@ AlphaMask
Calculate a mask by checking the alpha values.
Definition: qwt_widget_overlay.h:84
QwtWidgetOverlay::MaskHint
@ MaskHint
Use maskHint() as mask.
Definition: qwt_widget_overlay.h:72
QwtWidgetOverlay::setMaskMode
void setMaskMode(MaskMode)
Specify how to find the mask for the overlay.
Definition: qwt_widget_overlay.cpp:154
QwtWidgetOverlay::drawOverlay
virtual void drawOverlay(QPainter *painter) const =0
QwtWidgetOverlay::maskHint
virtual QRegion maskHint() const
Calculate an approximation for the mask.
Definition: qwt_widget_overlay.cpp:373