19 #include <qpainterpath.h>
29 int x1 = r.left() - pw2;
30 int x2 = r.right() + 1 + pw2 + ( pw % 2 );
32 int y1 = r.top() - pw2;
33 int y2 = r.bottom() + 1 + pw2 + ( pw % 2 );
37 region += QRect( x1, y1, x2 - x1, pw );
38 region += QRect( x1, y1, pw, y2 - y1 );
39 region += QRect( x1, y2 - pw, x2 - x1, pw );
40 region += QRect( x2 - pw, y1, pw, y2 - y1 );
52 if ( l.x1() == l.x2() )
54 region += QRect( l.x1() - pw2, l.y1(),
55 pw, l.y2() ).normalized();
57 else if ( l.y1() == l.y2() )
59 region += QRect( l.x1(), l.y1() - pw2,
60 l.x2(), pw ).normalized();
71 Rubberband(
QwtPicker* picker, QWidget* parent )
81 painter->setPen( m_picker->rubberBandPen() );
82 m_picker->drawRubberBand( painter );
87 return m_picker->rubberBandMask();
96 Tracker(
QwtPicker* picker, QWidget* parent )
106 painter->setPen( m_picker->trackerPen() );
107 m_picker->drawTracker( painter );
112 return m_picker->trackerMask();
211 if ( parent->focusPolicy() == Qt::NoFocus )
212 parent->setFocusPolicy( Qt::WheelFocus );
265 QObject* obj = parent();
266 if ( obj && obj->isWidgetType() )
267 return static_cast< QWidget*
>( obj );
275 QObject* obj = parent();
276 if ( obj && obj->isWidgetType() )
277 return static_cast< const QWidget*
>( obj );
386 w->installEventFilter(
this );
388 w->removeEventFilter(
this );
498 label = QString::number( pos.y() );
501 label = QString::number( pos.x() );
504 label = QString::number( pos.x() ) +
", " + QString::number( pos.y() );
547 switch ( selectionType )
552 if ( pa.count() < 1 )
555 const QPoint pos = pa[0];
557 const QRect pRect =
pickArea().boundingRect().toRect();
563 pos.x(), pRect.bottom() ), pw );
569 pRect.right(), pos.y() ), pw );
575 pos.x(), pRect.bottom() ), pw );
577 pRect.right(), pos.y() ), pw );
587 if ( pa.count() < 2 )
594 const QRect r = QRect( pa.first(), pa.last() );
600 const QRect r = QRect( pa.first(), pa.last() );
601 mask += r.adjusted( -pw, -pw, pw, pw );
616 const int off = 2 * pw;
617 const QRect r = pa.boundingRect();
618 mask += r.adjusted( -off, -off, off, off );
653 switch ( selectionType )
658 if ( pa.count() < 1 )
661 const QPoint pos = pa[0];
663 const QRect pRect =
pickArea().boundingRect().toRect();
669 pRect.top(), pos.x(), pRect.bottom() );
675 pos.y(), pRect.right(), pos.y() );
681 pRect.top(), pos.x(), pRect.bottom() );
683 pos.y(), pRect.right(), pos.y() );
693 if ( pa.count() < 2 )
696 const QRect rect = QRect( pa.first(), pa.last() ).normalized();
717 painter->drawPolyline( pa );
734 const QRect textRect =
trackerRect( painter->font() );
735 if ( !textRect.isEmpty() )
739 label.
draw( painter, textRect );
824 if ( text.isEmpty() )
827 const QSizeF textSize = text.textSize( font );
829 const int w =
qwtCeil( textSize.width() );
830 const int h =
qwtCeil( textSize.height() );
847 QRect infoRect( 0, 0,
size.width(),
size.height() );
856 alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft;
857 alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop;
861 alignment = Qt::AlignTop | Qt::AlignRight;
864 const int margin = 5;
867 if ( alignment & Qt::AlignLeft )
868 x -= infoRect.width() + margin;
869 else if ( alignment & Qt::AlignRight )
873 if ( alignment & Qt::AlignBottom )
875 else if ( alignment & Qt::AlignTop )
876 y -= infoRect.height() + margin;
878 infoRect.moveTopLeft( QPoint(
x,
y ) );
880 const QRect pickRect =
pickArea().boundingRect().toRect();
882 int right = qMin( infoRect.right(), pickRect.right() - margin );
883 int bottom = qMin( infoRect.bottom(), pickRect.bottom() - margin );
884 infoRect.moveBottomRight( QPoint(
right, bottom ) );
886 int left = qMax( infoRect.left(), pickRect.left() + margin );
887 int top = qMax( infoRect.top(), pickRect.top() + margin );
888 infoRect.moveTopLeft( QPoint(
left,
top ) );
916 switch ( event->type() )
920 const QResizeEvent* re =
static_cast< QResizeEvent*
>( event );
950 case QEvent::MouseButtonPress:
955 case QEvent::MouseButtonRelease:
960 case QEvent::MouseButtonDblClick:
965 case QEvent::MouseMove:
970 case QEvent::KeyPress:
975 case QEvent::KeyRelease:
1017 if (
pickArea().contains( mouseEvent->pos() ) )
1102 #if QT_VERSION < 0x050e00
1103 const QPoint wheelPos = wheelEvent->pos();
1105 const QPoint wheelPos = wheelEvent->position().toPoint();
1107 if (
pickArea().contains( wheelPos ) )
1137 if ( keyEvent->isAutoRepeat() )
1155 if ( dx != 0 || dy != 0 )
1157 const QRect rect =
pickArea().boundingRect().toRect();
1158 const QPoint pos =
parentWidget()->mapFromGlobal( QCursor::pos() );
1160 int x = pos.x() + dx;
1161 x = qMax( rect.left(),
x );
1162 x = qMin( rect.right(),
x );
1164 int y = pos.y() + dy;
1165 y = qMax( rect.top(),
y );
1166 y = qMin( rect.bottom(),
y );
1168 QCursor::setPos(
parentWidget()->mapToGlobal( QPoint(
x,
y ) ) );
1204 switch ( event->type() )
1206 case QEvent::MouseButtonDblClick:
1207 case QEvent::MouseButtonPress:
1208 case QEvent::MouseButtonRelease:
1209 case QEvent::MouseMove:
1211 const QMouseEvent* me =
1212 static_cast< const QMouseEvent*
>( event );
1220 for (
int i = 0; i < commandList.count(); i++ )
1222 switch ( commandList[i] )
1367 Q_EMIT
moved( pos );
1382 #if QT_VERSION >= 0x050100
1438 if ( oldSize.isEmpty() )
1445 const double xRatio = double( newSize.width() ) / double( oldSize.width() );
1446 const double yRatio = double( newSize.height() ) / double( oldSize.height() );
1451 p.setX( qRound( p.x() * xRatio ) );
1452 p.setY( qRound( p.y() * yRatio ) );
1480 widget->setMouseTracking(
true );
1499 path.addRect( widget->contentsRect() );
1509 bool showRubberband =
false;
1510 bool showTracker =
false;
1517 showRubberband =
true;
1532 if ( showRubberband )
1536 rw =
new Rubberband(
this, NULL );
1537 rw->setObjectName(
"PickerRubberBand" );
1539 rw->resize( w->size() );
1547 rw->updateOverlay();
1572 tw =
new Tracker(
this, NULL );
1573 tw->setObjectName(
"PickerTracker" );
1575 tw->resize( w->size() );
1578 tw->updateOverlay();
1612 #include "moc_qwt_picker.cpp"