source: ntrip/trunk/GnssCenter/qwt/qwt_picker.h@ 10196

Last change on this file since 10196 was 4839, checked in by mervart, 12 years ago
File size: 9.1 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
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 *****************************************************************************/
9
10#ifndef QWT_PICKER
11#define QWT_PICKER 1
12
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
21class QWidget;
22class QMouseEvent;
23class QWheelEvent;
24class QKeyEvent;
25class QwtPickerMachine;
26
27/*!
28 \brief QwtPicker provides selections on a widget
29
30 QwtPicker filters all enter, leave, mouse and keyboard events of a widget
31 and translates them into an array of selected points.
32
33 The way how the points are collected depends on type of state machine
34 that is connected to the picker. Qwt offers a couple of predefined
35 state machines for selecting:
36
37 - Nothing\n
38 QwtPickerTrackerMachine
39 - Single points\n
40 QwtPickerClickPointMachine, QwtPickerDragPointMachine
41 - Rectangles\n
42 QwtPickerClickRectMachine, QwtPickerDragRectMachine
43 - Polygons\n
44 QwtPickerPolygonMachine
45
46 While these state machines cover the most common ways to collect points
47 it is also possible to implement individual machines as well.
48
49 QwtPicker translates the picked points into a selection using the
50 adjustedPoints method. adjustedPoints is intended to be reimplemented
51 to fixup the selection according to application specific requirements.
52 (F.e. when an application accepts rectangles of a fixed aspect ratio only.)
53
54 Optionally QwtPicker support the process of collecting points by a
55 rubberband and tracker displaying a text for the current mouse
56 position.
57
58 \par Example
59 \verbatim #include <qwt_picker.h>
60#include <qwt_picker_machine.h>
61
62QwtPicker *picker = new QwtPicker(widget);
63picker->setStateMachine(new QwtPickerDragRectMachine);
64picker->setTrackerMode(QwtPicker::ActiveOnly);
65picker->setRubberBand(QwtPicker::RectRubberBand); \endverbatim\n
66
67 The state machine triggers the following commands:
68
69 - begin()\n
70 Activate/Initialize the selection.
71 - append()\n
72 Add a new point
73 - move() \n
74 Change the position of the last point.
75 - remove()\n
76 Remove the last point.
77 - end()\n
78 Terminate the selection and call accept to validate the picked points.
79
80 The picker is active (isActive()), between begin() and end().
81 In active state the rubberband is displayed, and the tracker is visible
82 in case of trackerMode is ActiveOnly or AlwaysOn.
83
84 The cursor can be moved using the arrow keys. All selections can be aborted
85 using the abort key. (QwtEventPattern::KeyPatternCode)
86
87 \warning In case of QWidget::NoFocus the focus policy of the observed
88 widget is set to QWidget::WheelFocus and mouse tracking
89 will be manipulated while the picker is active,
90 or if trackerMode() is AlwayOn.
91*/
92
93class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
94{
95 Q_OBJECT
96
97 Q_ENUMS( RubberBand )
98 Q_ENUMS( DisplayMode )
99 Q_ENUMS( ResizeMode )
100
101 Q_PROPERTY( bool isEnabled READ isEnabled WRITE setEnabled )
102 Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
103
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 )
107
108 Q_PROPERTY( RubberBand rubberBand READ rubberBand WRITE setRubberBand )
109 Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen )
110
111public:
112 /*!
113 Rubberband style
114
115 The default value is QwtPicker::NoRubberBand.
116 \sa setRubberBand(), rubberBand()
117 */
118
119 enum RubberBand
120 {
121 //! No rubberband.
122 NoRubberBand = 0,
123
124 //! A horizontal line ( only for QwtPicker::PointSelection )
125 HLineRubberBand,
126
127 //! A vertical line ( only for QwtPicker::PointSelection )
128 VLineRubberBand,
129
130 //! A crosshair ( only for QwtPicker::PointSelection )
131 CrossRubberBand,
132
133 //! A rectangle ( only for QwtPicker::RectSelection )
134 RectRubberBand,
135
136 //! An ellipse ( only for QwtPicker::RectSelection )
137 EllipseRubberBand,
138
139 //! A polygon ( only for QwtPicker::&PolygonSelection )
140 PolygonRubberBand,
141
142 /*!
143 Values >= UserRubberBand can be used to define additional
144 rubber bands.
145 */
146 UserRubberBand = 100
147 };
148
149 /*!
150 \brief Display mode
151 \sa setTrackerMode(), trackerMode(), isActive()
152 */
153 enum DisplayMode
154 {
155 //! Display never
156 AlwaysOff,
157
158 //! Display always
159 AlwaysOn,
160
161 //! Display only when the selection is active
162 ActiveOnly
163 };
164
165 /*!
166 Controls what to do with the selected points of an active
167 selection when the observed widget is resized.
168
169 The default value is QwtPicker::Stretch.
170 \sa setResizeMode()
171 */
172
173 enum ResizeMode
174 {
175 //! All points are scaled according to the new size,
176 Stretch,
177
178 //! All points remain unchanged.
179 KeepSize
180 };
181
182 explicit QwtPicker( QWidget *parent );
183 explicit QwtPicker( RubberBand rubberBand,
184 DisplayMode trackerMode, QWidget * );
185
186 virtual ~QwtPicker();
187
188 void setStateMachine( QwtPickerMachine * );
189 const QwtPickerMachine *stateMachine() const;
190 QwtPickerMachine *stateMachine();
191
192 void setRubberBand( RubberBand );
193 RubberBand rubberBand() const;
194
195 void setTrackerMode( DisplayMode );
196 DisplayMode trackerMode() const;
197
198 void setResizeMode( ResizeMode );
199 ResizeMode resizeMode() const;
200
201 void setRubberBandPen( const QPen & );
202 QPen rubberBandPen() const;
203
204 void setTrackerPen( const QPen & );
205 QPen trackerPen() const;
206
207 void setTrackerFont( const QFont & );
208 QFont trackerFont() const;
209
210 bool isEnabled() const;
211 bool isActive() const;
212
213 virtual bool eventFilter( QObject *, QEvent * );
214
215 QWidget *parentWidget();
216 const QWidget *parentWidget() const;
217
218 virtual QRect pickRect() const;
219
220 virtual void drawRubberBand( QPainter * ) const;
221 virtual void drawTracker( QPainter * ) const;
222
223 virtual QwtText trackerText( const QPoint &pos ) const;
224 QPoint trackerPosition() const;
225 virtual QRect trackerRect( const QFont & ) const;
226
227 QPolygon selection() const;
228
229public Q_SLOTS:
230 void setEnabled( bool );
231
232Q_SIGNALS:
233 /*!
234 A signal indicating, when the picker has been activated.
235 Together with setEnabled() it can be used to implement
236 selections with more than one picker.
237
238 \param on True, when the picker has been activated
239 */
240 void activated( bool on );
241
242 /*!
243 A signal emitting the selected points,
244 at the end of a selection.
245
246 \param polygon Selected points
247 */
248 void selected( const QPolygon &polygon );
249
250 /*!
251 A signal emitted when a point has been appended to the selection
252
253 \param pos Position of the appended point.
254 \sa append(). moved()
255 */
256 void appended( const QPoint &pos );
257
258 /*!
259 A signal emitted whenever the last appended point of the
260 selection has been moved.
261
262 \param pos Position of the moved last point of the selection.
263 \sa move(), appended()
264 */
265 void moved( const QPoint &pos );
266
267 /*!
268 A signal emitted whenever the last appended point of the
269 selection has been removed.
270
271 \sa remove(), appended()
272 */
273 void removed( const QPoint &pos );
274 /*!
275 A signal emitted when the active selection has been changed.
276 This might happen when the observed widget is resized.
277
278 \param selection Changed selection
279 \sa stretchSelection()
280 */
281 void changed( const QPolygon &selection );
282
283protected:
284 virtual QPolygon adjustedPoints( const QPolygon & ) const;
285
286 virtual void transition( const QEvent * );
287
288 virtual void begin();
289 virtual void append( const QPoint & );
290 virtual void move( const QPoint & );
291 virtual void remove();
292 virtual bool end( bool ok = true );
293
294 virtual bool accept( QPolygon & ) const;
295 virtual void reset();
296
297 virtual void widgetMousePressEvent( QMouseEvent * );
298 virtual void widgetMouseReleaseEvent( QMouseEvent * );
299 virtual void widgetMouseDoubleClickEvent( QMouseEvent * );
300 virtual void widgetMouseMoveEvent( QMouseEvent * );
301 virtual void widgetWheelEvent( QWheelEvent * );
302 virtual void widgetKeyPressEvent( QKeyEvent * );
303 virtual void widgetKeyReleaseEvent( QKeyEvent * );
304 virtual void widgetEnterEvent( QEvent * );
305 virtual void widgetLeaveEvent( QEvent * );
306
307 virtual void stretchSelection( const QSize &oldSize,
308 const QSize &newSize );
309
310 virtual void updateDisplay();
311
312 const QWidget *rubberBandWidget() const;
313 const QWidget *trackerWidget() const;
314
315 const QPolygon &pickedPoints() const;
316
317private:
318 void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode );
319
320 void setMouseTracking( bool );
321
322 class PickerWidget;
323 class PrivateData;
324 PrivateData *d_data;
325};
326
327#endif
Note: See TracBrowser for help on using the repository browser.