source: ntrip/trunk/BNC/qwt/qwt_picker.h@ 10309

Last change on this file since 10309 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

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