19 #include <qpainterpath.h> 25 const int pw = qMax( penWidth, 1 );
26 const int pw2 = penWidth / 2;
28 int x1 = r.left() - pw2;
29 int x2 = r.right() + 1 + pw2 + ( pw % 2 );
31 int y1 = r.top() - pw2;
32 int y2 = r.bottom() + 1 + pw2 + ( pw % 2 );
36 region += QRect( x1, y1, x2 - x1, pw );
37 region += QRect( x1, y1, pw, y2 - y1 );
38 region += QRect( x1, y2 - pw, x2 - x1, pw );
39 region += QRect( x2 - pw, y1, pw, y2 - y1 );
46 const int pw = qMax( penWidth, 1 );
47 const int pw2 = penWidth / 2;
51 if ( l.x1() == l.x2() )
53 region += QRect( l.x1() - pw2, l.y1(),
54 pw, l.y2() ).normalized();
56 else if ( l.y1() == l.y2() )
58 region += QRect( l.x1(), l.y1() - pw2,
59 l.x2(), pw ).normalized();
70 QwtPickerRubberband(
QwtPicker *, QWidget * );
82 QwtPickerTracker(
QwtPicker *, QWidget * );
85 virtual void drawOverlay( QPainter * )
const QWT_OVERRIDE;
102 trackerPosition( -1, -1 ),
103 mouseTracking( false ),
133 QwtPickerRubberband::QwtPickerRubberband(
141 QRegion QwtPickerRubberband::maskHint()
const 143 return d_picker->rubberBandMask();
146 void QwtPickerRubberband::drawOverlay( QPainter *painter )
const 148 painter->setPen( d_picker->rubberBandPen() );
149 d_picker->drawRubberBand( painter );
152 QwtPickerTracker::QwtPickerTracker(
160 QRegion QwtPickerTracker::maskHint()
const 162 return d_picker->trackerMask();
165 void QwtPickerTracker::drawOverlay( QPainter *painter )
const 167 painter->setPen( d_picker->trackerPen() );
168 d_picker->drawTracker( painter );
197 init( parent, rubberBand, trackerMode );
222 if ( parent->focusPolicy() == Qt::NoFocus )
223 parent->setFocusPolicy( Qt::WheelFocus );
276 QObject *obj = parent();
277 if ( obj && obj->isWidgetType() )
278 return static_cast<QWidget *>( obj );
286 QObject *obj = parent();
287 if ( obj && obj->isWidgetType() )
288 return static_cast< const QWidget *>( obj );
397 w->installEventFilter(
this );
399 w->removeEventFilter(
this );
509 label = QString::number( pos.y() );
512 label = QString::number( pos.x() );
515 label = QString::number( pos.x() ) +
", " + QString::number( pos.y() );
555 switch ( selectionType )
560 if ( pa.count() < 1 )
563 const QPoint pos = pa[0];
566 const QRect pRect =
pickArea().boundingRect().toRect();
572 pos.x(), pRect.bottom() ), pw );
578 pRect.right(), pos.y() ), pw );
584 pos.x(), pRect.bottom() ), pw );
586 pRect.right(), pos.y() ), pw );
596 if ( pa.count() < 2 )
605 const QRect r = QRect( pa.first(), pa.last() );
611 const QRect r = QRect( pa.first(), pa.last() );
612 mask += r.adjusted( -pw, -pw, pw, pw );
628 const int off = 2 * pw;
629 const QRect r = pa.boundingRect();
630 mask += r.adjusted( -off, -off, off, off );
665 switch ( selectionType )
670 if ( pa.count() < 1 )
673 const QPoint pos = pa[0];
675 const QRect pRect =
pickArea().boundingRect().toRect();
681 pRect.top(), pos.x(), pRect.bottom() );
687 pos.y(), pRect.right(), pos.y() );
693 pRect.top(), pos.x(), pRect.bottom() );
695 pos.y(), pRect.right(), pos.y() );
705 if ( pa.count() < 2 )
708 const QRect rect = QRect( pa.first(), pa.last() ).normalized();
729 painter->drawPolyline( pa );
746 const QRect textRect =
trackerRect( painter->font() );
747 if ( !textRect.isEmpty() )
751 label.
draw( painter, textRect );
840 const QSizeF textSize = text.
textSize( font );
841 QRect textRect( 0, 0,
qwtCeil( textSize.width() ),
qwtCeil( textSize.height() ) );
852 alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft;
853 alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop;
856 alignment = Qt::AlignTop | Qt::AlignRight;
858 const int margin = 5;
861 if ( alignment & Qt::AlignLeft )
862 x -= textRect.width() + margin;
863 else if ( alignment & Qt::AlignRight )
867 if ( alignment & Qt::AlignBottom )
869 else if ( alignment & Qt::AlignTop )
870 y -= textRect.height() + margin;
872 textRect.moveTopLeft( QPoint( x, y ) );
874 const QRect pickRect =
pickArea().boundingRect().toRect();
876 int right = qMin( textRect.right(), pickRect.right() - margin );
877 int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin );
878 textRect.moveBottomRight( QPoint( right, bottom ) );
880 int left = qMax( textRect.left(), pickRect.left() + margin );
881 int top = qMax( textRect.top(), pickRect.top() + margin );
882 textRect.moveTopLeft( QPoint( left, top ) );
910 switch ( event->type() )
914 const QResizeEvent *re =
static_cast<QResizeEvent *
>( event );
944 case QEvent::MouseButtonPress:
949 case QEvent::MouseButtonRelease:
954 case QEvent::MouseButtonDblClick:
959 case QEvent::MouseMove:
964 case QEvent::KeyPress:
969 case QEvent::KeyRelease:
1011 if (
pickArea().contains( mouseEvent->pos() ) )
1096 #if QT_VERSION < 0x050e00 1097 const QPoint wheelPos = wheelEvent->pos();
1099 const QPoint wheelPos = wheelEvent->position().toPoint();
1101 if (
pickArea().contains( wheelPos ) )
1131 if ( keyEvent->isAutoRepeat() )
1149 if ( dx != 0 || dy != 0 )
1151 const QRect rect =
pickArea().boundingRect().toRect();
1152 const QPoint pos =
parentWidget()->mapFromGlobal( QCursor::pos() );
1154 int x = pos.x() + dx;
1155 x = qMax( rect.left(), x );
1156 x = qMin( rect.right(), x );
1158 int y = pos.y() + dy;
1159 y = qMax( rect.top(), y );
1160 y = qMin( rect.bottom(), y );
1162 QCursor::setPos(
parentWidget()->mapToGlobal( QPoint( x, y ) ) );
1198 switch ( event->type() )
1200 case QEvent::MouseButtonDblClick:
1201 case QEvent::MouseButtonPress:
1202 case QEvent::MouseButtonRelease:
1203 case QEvent::MouseMove:
1205 const QMouseEvent *me =
1206 static_cast< const QMouseEvent *
>( event );
1214 for (
int i = 0; i < commandList.count(); i++ )
1216 switch ( commandList[i] )
1361 Q_EMIT
moved( pos );
1376 #if QT_VERSION >= 0x050100 1398 Q_UNUSED( selection );
1432 if ( oldSize.isEmpty() )
1439 const double xRatio = double( newSize.width() ) /
double( oldSize.width() );
1440 const double yRatio = double( newSize.height() ) /
double( oldSize.height() );
1445 p.setX( qRound( p.x() * xRatio ) );
1446 p.setY( qRound( p.y() * yRatio ) );
1474 widget->setMouseTracking(
true );
1493 path.addRect( widget->contentsRect() );
1503 bool showRubberband =
false;
1504 bool showTracker =
false;
1511 showRubberband =
true;
1526 if ( showRubberband )
1530 rw =
new QwtPickerRubberband(
this, NULL );
1531 rw->setObjectName(
"PickerRubberBand" );
1533 rw->resize( w->size() );
1541 rw->updateOverlay();
1566 tw =
new QwtPickerTracker(
this, NULL );
1567 tw->setObjectName(
"PickerTracker" );
1569 tw->resize( w->size() );
1572 tw->updateOverlay();
1606 #include "moc_qwt_picker.cpp"
virtual QRegion trackerMask() const
virtual bool end(bool ok=true)
Close a selection setting the state to inactive.
virtual void widgetKeyPressEvent(QKeyEvent *)
virtual void stretchSelection(const QSize &oldSize, const QSize &newSize)
void setRubberBand(RubberBand)
DisplayMode trackerMode() const
const QwtWidgetOverlay * rubberBandOverlay() const
void setTrackerFont(const QFont &)
virtual void widgetEnterEvent(QEvent *)
virtual void widgetKeyReleaseEvent(QKeyEvent *)
A crosshair ( only for QwtPickerMachine::PointSelection )
static QRegion qwtMaskRegion(const QRect &r, int penWidth)
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
The state machine not usable for any type of selection.
virtual QRegion rubberBandMask() const
QWidget * parentWidget()
Return the parent widget, where the selection happens.
void setTrackerMode(DisplayMode)
Set the display mode of the tracker.
QPointer< QwtPickerRubberband > rubberBandOverlay
void reset()
Set the current state to 0.
QPoint trackerPosition() const
QPointer< QwtPickerTracker > trackerOverlay
void draw(QPainter *painter, const QRectF &rect) const
virtual bool eventFilter(QObject *, QEvent *) QWT_OVERRIDE
Event filter.
QPen rubberBandPen() const
const QPolygon & pickedPoints() const
QFont trackerFont() const
QPolygon selection() const
virtual bool accept(QPolygon &) const
Validate and fix up the selection.
void selected(const QPolygon &polygon)
virtual void widgetLeaveEvent(QEvent *)
void changed(const QPolygon &selection)
All points are scaled according to the new size,.
void moved(const QPoint &pos)
The state machine is for selecting a polygon (many points).
void setMouseTracking(bool)
virtual QPainterPath pickArea() const
const QwtPickerMachine * stateMachine() const
virtual void drawRubberBand(QPainter *) const
QwtPicker::ResizeMode resizeMode
The state machine is for selecting a single point.
A polygon ( only for QwtPickerMachine::PolygonSelection )
void setStateMachine(QwtPickerMachine *)
virtual QRect trackerRect(const QFont &) const
virtual void widgetMouseMoveEvent(QMouseEvent *)
virtual void transition(const QEvent *)
An ellipse ( only for QwtPickerMachine::RectSelection )
virtual void widgetMouseDoubleClickEvent(QMouseEvent *)
RubberBand rubberBand() const
QwtPicker::DisplayMode trackerMode
A class representing a text.
A state machine for QwtPicker selections.
virtual void move(const QPoint &)
A horizontal line ( only for QwtPickerMachine::PointSelection )
virtual void widgetWheelEvent(QWheelEvent *)
QwtPicker::RubberBand rubberBand
virtual void updateDisplay()
Update the state of rubber band and tracker label.
static void drawEllipse(QPainter *, const QRectF &)
Wrapper for QPainter::drawEllipse()
void setEnabled(bool)
En/disable the picker.
void appended(const QPoint &pos)
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)=0
Transition.
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
virtual void drawTracker(QPainter *) const
const QwtWidgetOverlay * trackerOverlay() const
A rectangle ( only for QwtPickerMachine::RectSelection )
virtual QPolygon adjustedPoints(const QPolygon &) const
Map the pickedPoints() into a selection()
virtual void widgetMouseReleaseEvent(QMouseEvent *)
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
void setResizeMode(ResizeMode)
Set the resize mode.
SelectionType selectionType() const
Return the selection type.
A vertical line ( only for QwtPickerMachine::PointSelection )
void removed(const QPoint &pos)
QwtPicker(QWidget *parent)
virtual ~QwtPicker()
Destructor.
qreal penWidth(const QPainter *painter, const QwtScaleDraw *scaleDraw)
virtual QwtText trackerText(const QPoint &pos) const
Return the label for a position.
void setRubberBandPen(const QPen &)
ResizeMode resizeMode() const
virtual void widgetMousePressEvent(QMouseEvent *)
void init(QWidget *, RubberBand rubberBand, DisplayMode trackerMode)
Initialize the picker - used by the constructors.
void setTrackerPen(const QPen &)
QwtPicker provides selections on a widget.
The state machine is for selecting a rectangle (2 points).
QwtPickerMachine * stateMachine
virtual void append(const QPoint &)
Display only when the selection is active.