15 #include <qapplication.h> 22 #include <qpaintengine.h> 27 const int pw = qMax( penWidth, 1 );
28 const int pw2 = penWidth / 2;
30 int x1 = r.left() - pw2;
31 int x2 = r.right() + 1 + pw2 + ( pw % 2 );
33 int y1 = r.top() - pw2;
34 int y2 = r.bottom() + 1 + pw2 + ( pw % 2 );
38 region += QRect( x1, y1, x2 - x1, pw );
39 region += QRect( x1, y1, pw, y2 - y1 );
40 region += QRect( x1, y2 - pw, x2 - x1, pw );
41 region += QRect( x2 - pw, y1, pw, y2 - y1 );
48 const int pw = qMax( penWidth, 1 );
49 const int pw2 = penWidth / 2;
53 if ( l.x1() == l.x2() )
55 region += QRect( l.x1() - pw2, l.y1(),
58 else if ( l.y1() == l.y2() )
60 region += QRect( l.x1(), l.y1() - pw2,
102 trackerPosition( -1, -1 ),
103 mouseTracking( false ),
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.sprintf(
"%d", pos.y() );
512 label.sprintf(
"%d", pos.x() );
515 label.sprintf(
"%d, %d", pos.x(), 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 );
836 const QSizeF textSize = text.
textSize( font );
837 QRect textRect( 0, 0, qCeil( textSize.width() ), qCeil( textSize.height() ) );
848 alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft;
849 alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop;
852 alignment = Qt::AlignTop | Qt::AlignRight;
854 const int margin = 5;
857 if ( alignment & Qt::AlignLeft )
858 x -= textRect.width() + margin;
859 else if ( alignment & Qt::AlignRight )
863 if ( alignment & Qt::AlignBottom )
865 else if ( alignment & Qt::AlignTop )
866 y -= textRect.height() + margin;
868 textRect.moveTopLeft( QPoint( x, y ) );
870 const QRect pickRect =
pickArea().boundingRect().toRect();
872 int right = qMin( textRect.right(), pickRect.right() - margin );
873 int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin );
874 textRect.moveBottomRight( QPoint( right, bottom ) );
876 int left = qMax( textRect.left(), pickRect.left() + margin );
877 int top = qMax( textRect.top(), pickRect.top() + margin );
878 textRect.moveTopLeft( QPoint( left, top ) );
906 switch ( event->type() )
910 const QResizeEvent *re =
static_cast<QResizeEvent *
>( event );
940 case QEvent::MouseButtonPress:
945 case QEvent::MouseButtonRelease:
950 case QEvent::MouseButtonDblClick:
955 case QEvent::MouseMove:
960 case QEvent::KeyPress:
965 case QEvent::KeyRelease:
1007 if (
pickArea().contains( mouseEvent->pos() ) )
1092 if (
pickArea().contains( wheelEvent->pos() ) )
1122 if ( keyEvent->isAutoRepeat() )
1140 if ( dx != 0 || dy != 0 )
1142 const QRect rect =
pickArea().boundingRect().toRect();
1143 const QPoint pos =
parentWidget()->mapFromGlobal( QCursor::pos() );
1145 int x = pos.x() + dx;
1146 x = qMax( rect.left(), x );
1147 x = qMin( rect.right(), x );
1149 int y = pos.y() + dy;
1150 y = qMax( rect.top(), y );
1151 y = qMin( rect.bottom(), y );
1153 QCursor::setPos(
parentWidget()->mapToGlobal( QPoint( x, y ) ) );
1185 const QList<QwtPickerMachine::Command> commandList =
1189 switch ( event->type() )
1191 case QEvent::MouseButtonDblClick:
1192 case QEvent::MouseButtonPress:
1193 case QEvent::MouseButtonRelease:
1194 case QEvent::MouseMove:
1196 const QMouseEvent *me =
1197 static_cast< const QMouseEvent *
>( event );
1205 for (
int i = 0;
i < commandList.count();
i++ )
1207 switch ( commandList[
i] )
1356 Q_EMIT
moved( pos );
1396 Q_UNUSED( selection );
1430 if ( oldSize.isEmpty() )
1437 const double xRatio =
1438 double( newSize.width() ) /
double( oldSize.width() );
1439 const double yRatio =
1440 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 )
1531 rw->setObjectName(
"PickerRubberBand" );
1533 rw->resize( w->size() );
1541 rw->updateOverlay();
1567 tw->setObjectName(
"PickerTracker" );
1569 tw->resize( w->size() );
1572 tw->updateOverlay();
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)
static void drawLine(QPainter *, double x1, double y1, double x2, double y2)
Wrapper for QPainter::drawLine()
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)
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
QwtPickerTracker(QwtPicker *, QWidget *)
void reset()
Set the current state to 0.
QPoint trackerPosition() const
QPointer< QwtPickerTracker > trackerOverlay
void draw(QPainter *painter, const QRectF &rect) const
QPen rubberBandPen() const
const QPolygon & pickedPoints() const
QFont trackerFont() const
QPolygon selection() const
virtual bool eventFilter(QObject *, QEvent *)
Event filter.
virtual bool accept(QPolygon &) const
Validate and fix up the selection.
TFSIMD_FORCE_INLINE const tfScalar & y() const
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)
TFSIMD_FORCE_INLINE Vector3 normalized() const
QSizeF textSize(const QFont &=QFont()) const
virtual void drawOverlay(QPainter *) const
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.
GraphId path[kMaxDeadlockPathLen]
static void drawRect(QPainter *, double x, double y, double w, double h)
Wrapper for QPainter::drawRect()
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 &)
TFSIMD_FORCE_INLINE const tfScalar & x() const
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.
TFSIMD_FORCE_INLINE const tfScalar & w() const
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 *)
virtual QRegion maskHint() const
Calculate an approximation for the mask.
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.
virtual void drawOverlay(QPainter *) const
virtual QwtText trackerText(const QPoint &pos) const
Return the label for a position.
void setRubberBandPen(const QPen &)
virtual QRegion maskHint() const
Calculate an approximation for the mask.
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.
QwtPickerRubberband(QwtPicker *, QWidget *)
The state machine is for selecting a rectangle (2 points).
QwtPickerMachine * stateMachine
virtual void append(const QPoint &)
Display only when the selection is active.