source: ntrip/trunk/BNC/qwt/qwt_picker_machine.cpp@ 4544

Last change on this file since 4544 was 4271, checked in by mervart, 13 years ago
File size: 10.9 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#include "qwt_picker_machine.h"
11#include "qwt_event_pattern.h"
12#include <qevent.h>
13
14//! Constructor
15QwtPickerMachine::QwtPickerMachine( SelectionType type ):
16 d_selectionType( type ),
17 d_state( 0 )
18{
19}
20
21//! Destructor
22QwtPickerMachine::~QwtPickerMachine()
23{
24}
25
26//! Return the selection type
27QwtPickerMachine::SelectionType QwtPickerMachine::selectionType() const
28{
29 return d_selectionType;
30}
31
32//! Return the current state
33int QwtPickerMachine::state() const
34{
35 return d_state;
36}
37
38//! Change the current state
39void QwtPickerMachine::setState( int state )
40{
41 d_state = state;
42}
43
44//! Set the current state to 0.
45void QwtPickerMachine::reset()
46{
47 setState( 0 );
48}
49
50//! Constructor
51QwtPickerTrackerMachine::QwtPickerTrackerMachine():
52 QwtPickerMachine( NoSelection )
53{
54}
55
56//! Transition
57QList<QwtPickerMachine::Command> QwtPickerTrackerMachine::transition(
58 const QwtEventPattern &, const QEvent *e )
59{
60 QList<QwtPickerMachine::Command> cmdList;
61
62 switch ( e->type() )
63 {
64 case QEvent::Enter:
65 case QEvent::MouseMove:
66 {
67 if ( state() == 0 )
68 {
69 cmdList += Begin;
70 cmdList += Append;
71 setState( 1 );
72 }
73 else
74 {
75 cmdList += Move;
76 }
77 break;
78 }
79 case QEvent::Leave:
80 {
81 cmdList += Remove;
82 cmdList += End;
83 setState( 0 );
84 }
85 default:
86 break;
87 }
88
89 return cmdList;
90}
91
92//! Constructor
93QwtPickerClickPointMachine::QwtPickerClickPointMachine():
94 QwtPickerMachine( PointSelection )
95{
96}
97
98//! Transition
99QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition(
100 const QwtEventPattern &eventPattern, const QEvent *e )
101{
102 QList<QwtPickerMachine::Command> cmdList;
103
104 switch ( e->type() )
105 {
106 case QEvent::MouseButtonPress:
107 {
108 if ( eventPattern.mouseMatch(
109 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
110 {
111 cmdList += Begin;
112 cmdList += Append;
113 cmdList += End;
114 }
115 break;
116 }
117 case QEvent::KeyPress:
118 {
119 if ( eventPattern.keyMatch(
120 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
121 {
122 cmdList += Begin;
123 cmdList += Append;
124 cmdList += End;
125 }
126 break;
127 }
128 default:
129 break;
130 }
131
132 return cmdList;
133}
134
135//! Constructor
136QwtPickerDragPointMachine::QwtPickerDragPointMachine():
137 QwtPickerMachine( PointSelection )
138{
139}
140
141//! Transition
142QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition(
143 const QwtEventPattern &eventPattern, const QEvent *e )
144{
145 QList<QwtPickerMachine::Command> cmdList;
146
147 switch ( e->type() )
148 {
149 case QEvent::MouseButtonPress:
150 {
151 if ( eventPattern.mouseMatch(
152 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
153 {
154 if ( state() == 0 )
155 {
156 cmdList += Begin;
157 cmdList += Append;
158 setState( 1 );
159 }
160 }
161 break;
162 }
163 case QEvent::MouseMove:
164 case QEvent::Wheel:
165 {
166 if ( state() != 0 )
167 cmdList += Move;
168 break;
169 }
170 case QEvent::MouseButtonRelease:
171 {
172 if ( state() != 0 )
173 {
174 cmdList += End;
175 setState( 0 );
176 }
177 break;
178 }
179 case QEvent::KeyPress:
180 {
181 if ( eventPattern.keyMatch(
182 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
183 {
184 if ( state() == 0 )
185 {
186 cmdList += Begin;
187 cmdList += Append;
188 setState( 1 );
189 }
190 else
191 {
192 cmdList += End;
193 setState( 0 );
194 }
195 }
196 break;
197 }
198 default:
199 break;
200 }
201
202 return cmdList;
203}
204
205//! Constructor
206QwtPickerClickRectMachine::QwtPickerClickRectMachine():
207 QwtPickerMachine( RectSelection )
208{
209}
210
211//! Transition
212QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
213 const QwtEventPattern &eventPattern, const QEvent *e )
214{
215 QList<QwtPickerMachine::Command> cmdList;
216
217 switch ( e->type() )
218 {
219 case QEvent::MouseButtonPress:
220 {
221 if ( eventPattern.mouseMatch(
222 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
223 {
224 switch ( state() )
225 {
226 case 0:
227 {
228 cmdList += Begin;
229 cmdList += Append;
230 setState( 1 );
231 break;
232 }
233 case 1:
234 {
235 // Uh, strange we missed the MouseButtonRelease
236 break;
237 }
238 default:
239 {
240 cmdList += End;
241 setState( 0 );
242 }
243 }
244 }
245 }
246 case QEvent::MouseMove:
247 case QEvent::Wheel:
248 {
249 if ( state() != 0 )
250 cmdList += Move;
251 break;
252 }
253 case QEvent::MouseButtonRelease:
254 {
255 if ( eventPattern.mouseMatch(
256 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
257 {
258 if ( state() == 1 )
259 {
260 cmdList += Append;
261 setState( 2 );
262 }
263 }
264 break;
265 }
266 case QEvent::KeyPress:
267 {
268 if ( eventPattern.keyMatch(
269 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
270 {
271 if ( state() == 0 )
272 {
273 cmdList += Begin;
274 cmdList += Append;
275 setState( 1 );
276 }
277 else
278 {
279 if ( state() == 1 )
280 {
281 cmdList += Append;
282 setState( 2 );
283 }
284 else if ( state() == 2 )
285 {
286 cmdList += End;
287 setState( 0 );
288 }
289 }
290 }
291 break;
292 }
293 default:
294 break;
295 }
296
297 return cmdList;
298}
299
300//! Constructor
301QwtPickerDragRectMachine::QwtPickerDragRectMachine():
302 QwtPickerMachine( RectSelection )
303{
304}
305
306//! Transition
307QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition(
308 const QwtEventPattern &eventPattern, const QEvent *e )
309{
310 QList<QwtPickerMachine::Command> cmdList;
311
312 switch ( e->type() )
313 {
314 case QEvent::MouseButtonPress:
315 {
316 if ( eventPattern.mouseMatch(
317 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
318 {
319 if ( state() == 0 )
320 {
321 cmdList += Begin;
322 cmdList += Append;
323 cmdList += Append;
324 setState( 2 );
325 }
326 }
327 break;
328 }
329 case QEvent::MouseMove:
330 case QEvent::Wheel:
331 {
332 if ( state() != 0 )
333 cmdList += Move;
334 break;
335 }
336 case QEvent::MouseButtonRelease:
337 {
338 if ( state() == 2 )
339 {
340 cmdList += End;
341 setState( 0 );
342 }
343 break;
344 }
345 case QEvent::KeyPress:
346 {
347 if ( eventPattern.keyMatch(
348 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
349 {
350 if ( state() == 0 )
351 {
352 cmdList += Begin;
353 cmdList += Append;
354 cmdList += Append;
355 setState( 2 );
356 }
357 else
358 {
359 cmdList += End;
360 setState( 0 );
361 }
362 }
363 break;
364 }
365 default:
366 break;
367 }
368
369 return cmdList;
370}
371
372//! Constructor
373QwtPickerPolygonMachine::QwtPickerPolygonMachine():
374 QwtPickerMachine( PolygonSelection )
375{
376}
377
378//! Transition
379QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
380 const QwtEventPattern &eventPattern, const QEvent *e )
381{
382 QList<QwtPickerMachine::Command> cmdList;
383
384 switch ( e->type() )
385 {
386 case QEvent::MouseButtonPress:
387 {
388 if ( eventPattern.mouseMatch(
389 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
390 {
391 if ( state() == 0 )
392 {
393 cmdList += Begin;
394 cmdList += Append;
395 cmdList += Append;
396 setState( 1 );
397 }
398 else
399 {
400 cmdList += End;
401 setState( 0 );
402 }
403 }
404 if ( eventPattern.mouseMatch(
405 QwtEventPattern::MouseSelect2, ( const QMouseEvent * )e ) )
406 {
407 if ( state() == 1 )
408 cmdList += Append;
409 }
410 break;
411 }
412 case QEvent::MouseMove:
413 case QEvent::Wheel:
414 {
415 if ( state() != 0 )
416 cmdList += Move;
417 break;
418 }
419 case QEvent::KeyPress:
420 {
421 if ( eventPattern.keyMatch(
422 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
423 {
424 if ( state() == 0 )
425 {
426 cmdList += Begin;
427 cmdList += Append;
428 cmdList += Append;
429 setState( 1 );
430 }
431 else
432 {
433 cmdList += End;
434 setState( 0 );
435 }
436 }
437 else if ( eventPattern.keyMatch(
438 QwtEventPattern::KeySelect2, ( const QKeyEvent * )e ) )
439 {
440 if ( state() == 1 )
441 cmdList += Append;
442 }
443 break;
444 }
445 default:
446 break;
447 }
448
449 return cmdList;
450}
Note: See TracBrowser for help on using the repository browser.