Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / libs / qwt / src / qwt_picker.h
blob87d6805e9e91797fd82915bbd07c2674959c4f1e
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
10 #ifndef QWT_PICKER
11 #define QWT_PICKER 1
13 #include "qwt_global.h"
14 #include "qwt_text.h"
15 #include "qwt_event_pattern.h"
16 #include <qobject.h>
17 #include <qpen.h>
18 #include <qfont.h>
19 #include <qrect.h>
20 #include <qpainterpath.h>
22 class QWidget;
23 class QMouseEvent;
24 class QWheelEvent;
25 class QKeyEvent;
26 class QwtPickerMachine;
27 class QwtWidgetOverlay;
29 /*!
30 \brief QwtPicker provides selections on a widget
32 QwtPicker filters all enter, leave, mouse and keyboard events of a widget
33 and translates them into an array of selected points.
35 The way how the points are collected depends on type of state machine
36 that is connected to the picker. Qwt offers a couple of predefined
37 state machines for selecting:
39 - Nothing\n
40 QwtPickerTrackerMachine
41 - Single points\n
42 QwtPickerClickPointMachine, QwtPickerDragPointMachine
43 - Rectangles\n
44 QwtPickerClickRectMachine, QwtPickerDragRectMachine
45 - Polygons\n
46 QwtPickerPolygonMachine
48 While these state machines cover the most common ways to collect points
49 it is also possible to implement individual machines as well.
51 QwtPicker translates the picked points into a selection using the
52 adjustedPoints() method. adjustedPoints() is intended to be reimplemented
53 to fix up the selection according to application specific requirements.
54 (F.e. when an application accepts rectangles of a fixed aspect ratio only.)
56 Optionally QwtPicker support the process of collecting points by a
57 rubber band and tracker displaying a text for the current mouse
58 position.
60 \par Example
61 \verbatim #include <qwt_picker.h>
62 #include <qwt_picker_machine.h>
64 QwtPicker *picker = new QwtPicker(widget);
65 picker->setStateMachine(new QwtPickerDragRectMachine);
66 picker->setTrackerMode(QwtPicker::ActiveOnly);
67 picker->setRubberBand(QwtPicker::RectRubberBand); \endverbatim\n
69 The state machine triggers the following commands:
71 - begin()\n
72 Activate/Initialize the selection.
73 - append()\n
74 Add a new point
75 - move() \n
76 Change the position of the last point.
77 - remove()\n
78 Remove the last point.
79 - end()\n
80 Terminate the selection and call accept to validate the picked points.
82 The picker is active (isActive()), between begin() and end().
83 In active state the rubber band is displayed, and the tracker is visible
84 in case of trackerMode is ActiveOnly or AlwaysOn.
86 The cursor can be moved using the arrow keys. All selections can be aborted
87 using the abort key. (QwtEventPattern::KeyPatternCode)
89 \warning In case of QWidget::NoFocus the focus policy of the observed
90 widget is set to QWidget::WheelFocus and mouse tracking
91 will be manipulated while the picker is active,
92 or if trackerMode() is AlwayOn.
95 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
97 Q_OBJECT
99 Q_ENUMS( RubberBand DisplayMode ResizeMode )
101 Q_PROPERTY( bool isEnabled READ isEnabled WRITE setEnabled )
102 Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
104 Q_PROPERTY( DisplayMode trackerMode READ trackerMode WRITE setTrackerMode )
105 Q_PROPERTY( QPen trackerPen READ trackerPen WRITE setTrackerPen )
106 Q_PROPERTY( QFont trackerFont READ trackerFont WRITE setTrackerFont )
108 Q_PROPERTY( RubberBand rubberBand READ rubberBand WRITE setRubberBand )
109 Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen )
111 public:
113 Rubber band style
115 The default value is QwtPicker::NoRubberBand.
116 \sa setRubberBand(), rubberBand()
119 enum RubberBand
121 //! No rubberband.
122 NoRubberBand = 0,
124 //! A horizontal line ( only for QwtPickerMachine::PointSelection )
125 HLineRubberBand,
127 //! A vertical line ( only for QwtPickerMachine::PointSelection )
128 VLineRubberBand,
130 //! A crosshair ( only for QwtPickerMachine::PointSelection )
131 CrossRubberBand,
133 //! A rectangle ( only for QwtPickerMachine::RectSelection )
134 RectRubberBand,
136 //! An ellipse ( only for QwtPickerMachine::RectSelection )
137 EllipseRubberBand,
139 //! A polygon ( only for QwtPickerMachine::PolygonSelection )
140 PolygonRubberBand,
143 Values >= UserRubberBand can be used to define additional
144 rubber bands.
146 UserRubberBand = 100
150 \brief Display mode
151 \sa setTrackerMode(), trackerMode(), isActive()
153 enum DisplayMode
155 //! Display never
156 AlwaysOff,
158 //! Display always
159 AlwaysOn,
161 //! Display only when the selection is active
162 ActiveOnly
166 Controls what to do with the selected points of an active
167 selection when the observed widget is resized.
169 The default value is QwtPicker::Stretch.
170 \sa setResizeMode()
173 enum ResizeMode
175 //! All points are scaled according to the new size,
176 Stretch,
178 //! All points remain unchanged.
179 KeepSize
182 explicit QwtPicker( QWidget *parent );
183 explicit QwtPicker( RubberBand rubberBand,
184 DisplayMode trackerMode, QWidget * );
186 virtual ~QwtPicker();
188 void setStateMachine( QwtPickerMachine * );
189 const QwtPickerMachine *stateMachine() const;
190 QwtPickerMachine *stateMachine();
192 void setRubberBand( RubberBand );
193 RubberBand rubberBand() const;
195 void setTrackerMode( DisplayMode );
196 DisplayMode trackerMode() const;
198 void setResizeMode( ResizeMode );
199 ResizeMode resizeMode() const;
201 void setRubberBandPen( const QPen & );
202 QPen rubberBandPen() const;
204 void setTrackerPen( const QPen & );
205 QPen trackerPen() const;
207 void setTrackerFont( const QFont & );
208 QFont trackerFont() const;
210 bool isEnabled() const;
211 bool isActive() const;
213 virtual bool eventFilter( QObject *, QEvent * );
215 QWidget *parentWidget();
216 const QWidget *parentWidget() const;
218 virtual QPainterPath pickArea() const;
220 virtual void drawRubberBand( QPainter * ) const;
221 virtual void drawTracker( QPainter * ) const;
223 virtual QRegion rubberBandMask() const;
225 virtual QwtText trackerText( const QPoint &pos ) const;
226 QPoint trackerPosition() const;
227 virtual QRect trackerRect( const QFont & ) const;
229 QPolygon selection() const;
231 public Q_SLOTS:
232 void setEnabled( bool );
234 Q_SIGNALS:
236 A signal indicating, when the picker has been activated.
237 Together with setEnabled() it can be used to implement
238 selections with more than one picker.
240 \param on True, when the picker has been activated
242 void activated( bool on );
245 A signal emitting the selected points,
246 at the end of a selection.
248 \param polygon Selected points
250 void selected( const QPolygon &polygon );
253 A signal emitted when a point has been appended to the selection
255 \param pos Position of the appended point.
256 \sa append(). moved()
258 void appended( const QPoint &pos );
261 A signal emitted whenever the last appended point of the
262 selection has been moved.
264 \param pos Position of the moved last point of the selection.
265 \sa move(), appended()
267 void moved( const QPoint &pos );
270 A signal emitted whenever the last appended point of the
271 selection has been removed.
273 \param pos Position of the point, that has been removed
274 \sa remove(), appended()
276 void removed( const QPoint &pos );
278 A signal emitted when the active selection has been changed.
279 This might happen when the observed widget is resized.
281 \param selection Changed selection
282 \sa stretchSelection()
284 void changed( const QPolygon &selection );
286 protected:
287 virtual QPolygon adjustedPoints( const QPolygon & ) const;
289 virtual void transition( const QEvent * );
291 virtual void begin();
292 virtual void append( const QPoint & );
293 virtual void move( const QPoint & );
294 virtual void remove();
295 virtual bool end( bool ok = true );
297 virtual bool accept( QPolygon & ) const;
298 virtual void reset();
300 virtual void widgetMousePressEvent( QMouseEvent * );
301 virtual void widgetMouseReleaseEvent( QMouseEvent * );
302 virtual void widgetMouseDoubleClickEvent( QMouseEvent * );
303 virtual void widgetMouseMoveEvent( QMouseEvent * );
304 virtual void widgetWheelEvent( QWheelEvent * );
305 virtual void widgetKeyPressEvent( QKeyEvent * );
306 virtual void widgetKeyReleaseEvent( QKeyEvent * );
307 virtual void widgetEnterEvent( QEvent * );
308 virtual void widgetLeaveEvent( QEvent * );
310 virtual void stretchSelection( const QSize &oldSize,
311 const QSize &newSize );
313 virtual void updateDisplay();
315 const QwtWidgetOverlay *rubberBandOverlay() const;
316 const QwtWidgetOverlay *trackerOverlay() const;
318 const QPolygon &pickedPoints() const;
320 private:
321 void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode );
323 void setMouseTracking( bool );
325 class PrivateData;
326 PrivateData *d_data;
329 #endif