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

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

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 13.7 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 *event )
101{
102 QList<QwtPickerMachine::Command> cmdList;
103
104 switch ( event->type() )
105 {
106 case QEvent::MouseButtonPress:
107 {
108 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
109 static_cast<const QMouseEvent *>( event ) ) )
110 {
111 cmdList += Begin;
112 cmdList += Append;
113 cmdList += End;
114 }
115 break;
116 }
117 case QEvent::KeyPress:
118 {
119 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
120 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
121 {
122 if ( !keyEvent->isAutoRepeat() )
123 {
124 cmdList += Begin;
125 cmdList += Append;
126 cmdList += End;
127 }
128 }
129 break;
130 }
131 default:
132 break;
133 }
134
135 return cmdList;
136}
137
138//! Constructor
139QwtPickerDragPointMachine::QwtPickerDragPointMachine():
140 QwtPickerMachine( PointSelection )
141{
142}
143
144//! Transition
145QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition(
146 const QwtEventPattern &eventPattern, const QEvent *event )
147{
148 QList<QwtPickerMachine::Command> cmdList;
149
150 switch ( event->type() )
151 {
152 case QEvent::MouseButtonPress:
153 {
154 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
155 static_cast<const QMouseEvent *>( event ) ) )
156 {
157 if ( state() == 0 )
158 {
159 cmdList += Begin;
160 cmdList += Append;
161 setState( 1 );
162 }
163 }
164 break;
165 }
166 case QEvent::MouseMove:
167 case QEvent::Wheel:
168 {
169 if ( state() != 0 )
170 cmdList += Move;
171 break;
172 }
173 case QEvent::MouseButtonRelease:
174 {
175 if ( state() != 0 )
176 {
177 cmdList += End;
178 setState( 0 );
179 }
180 break;
181 }
182 case QEvent::KeyPress:
183 {
184 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
185 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
186 {
187 if ( !keyEvent->isAutoRepeat() )
188 {
189 if ( state() == 0 )
190 {
191 cmdList += Begin;
192 cmdList += Append;
193 setState( 1 );
194 }
195 else
196 {
197 cmdList += End;
198 setState( 0 );
199 }
200 }
201 }
202 break;
203 }
204 default:
205 break;
206 }
207
208 return cmdList;
209}
210
211//! Constructor
212QwtPickerClickRectMachine::QwtPickerClickRectMachine():
213 QwtPickerMachine( RectSelection )
214{
215}
216
217//! Transition
218QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
219 const QwtEventPattern &eventPattern, const QEvent *event )
220{
221 QList<QwtPickerMachine::Command> cmdList;
222
223 switch ( event->type() )
224 {
225 case QEvent::MouseButtonPress:
226 {
227 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
228 static_cast<const QMouseEvent *>( event ) ) )
229 {
230 switch ( state() )
231 {
232 case 0:
233 {
234 cmdList += Begin;
235 cmdList += Append;
236 setState( 1 );
237 break;
238 }
239 case 1:
240 {
241 // Uh, strange we missed the MouseButtonRelease
242 break;
243 }
244 default:
245 {
246 cmdList += End;
247 setState( 0 );
248 }
249 }
250 }
251 break;
252 }
253 case QEvent::MouseMove:
254 case QEvent::Wheel:
255 {
256 if ( state() != 0 )
257 cmdList += Move;
258 break;
259 }
260 case QEvent::MouseButtonRelease:
261 {
262 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
263 static_cast<const QMouseEvent *>( event ) ) )
264 {
265 if ( state() == 1 )
266 {
267 cmdList += Append;
268 setState( 2 );
269 }
270 }
271 break;
272 }
273 case QEvent::KeyPress:
274 {
275 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
276 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
277 {
278 if ( !keyEvent->isAutoRepeat() )
279 {
280 if ( state() == 0 )
281 {
282 cmdList += Begin;
283 cmdList += Append;
284 setState( 1 );
285 }
286 else
287 {
288 if ( state() == 1 )
289 {
290 cmdList += Append;
291 setState( 2 );
292 }
293 else if ( state() == 2 )
294 {
295 cmdList += End;
296 setState( 0 );
297 }
298 }
299 }
300 }
301 break;
302 }
303 default:
304 break;
305 }
306
307 return cmdList;
308}
309
310//! Constructor
311QwtPickerDragRectMachine::QwtPickerDragRectMachine():
312 QwtPickerMachine( RectSelection )
313{
314}
315
316//! Transition
317QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition(
318 const QwtEventPattern &eventPattern, const QEvent *event )
319{
320 QList<QwtPickerMachine::Command> cmdList;
321
322 switch ( event->type() )
323 {
324 case QEvent::MouseButtonPress:
325 {
326 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
327 static_cast<const QMouseEvent *>( event ) ) )
328 {
329 if ( state() == 0 )
330 {
331 cmdList += Begin;
332 cmdList += Append;
333 cmdList += Append;
334 setState( 2 );
335 }
336 }
337 break;
338 }
339 case QEvent::MouseMove:
340 case QEvent::Wheel:
341 {
342 if ( state() != 0 )
343 cmdList += Move;
344 break;
345 }
346 case QEvent::MouseButtonRelease:
347 {
348 if ( state() == 2 )
349 {
350 cmdList += End;
351 setState( 0 );
352 }
353 break;
354 }
355 case QEvent::KeyPress:
356 {
357 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
358 static_cast<const QKeyEvent *> ( event ) ) )
359 {
360 if ( state() == 0 )
361 {
362 cmdList += Begin;
363 cmdList += Append;
364 cmdList += Append;
365 setState( 2 );
366 }
367 else
368 {
369 cmdList += End;
370 setState( 0 );
371 }
372 }
373 break;
374 }
375 default:
376 break;
377 }
378
379 return cmdList;
380}
381
382//! Constructor
383QwtPickerPolygonMachine::QwtPickerPolygonMachine():
384 QwtPickerMachine( PolygonSelection )
385{
386}
387
388//! Transition
389QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
390 const QwtEventPattern &eventPattern, const QEvent *event )
391{
392 QList<QwtPickerMachine::Command> cmdList;
393
394 switch ( event->type() )
395 {
396 case QEvent::MouseButtonPress:
397 {
398 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
399 static_cast<const QMouseEvent *>( event ) ) )
400 {
401 if ( state() == 0 )
402 {
403 cmdList += Begin;
404 cmdList += Append;
405 cmdList += Append;
406 setState( 1 );
407 }
408 else
409 {
410 cmdList += Append;
411 }
412 }
413 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2,
414 static_cast<const QMouseEvent *>( event ) ) )
415 {
416 if ( state() == 1 )
417 {
418 cmdList += End;
419 setState( 0 );
420 }
421 }
422 break;
423 }
424 case QEvent::MouseMove:
425 case QEvent::Wheel:
426 {
427 if ( state() != 0 )
428 cmdList += Move;
429 break;
430 }
431 case QEvent::KeyPress:
432 {
433 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
434 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
435 {
436 if ( !keyEvent->isAutoRepeat() )
437 {
438 if ( state() == 0 )
439 {
440 cmdList += Begin;
441 cmdList += Append;
442 cmdList += Append;
443 setState( 1 );
444 }
445 else
446 {
447 cmdList += Append;
448 }
449 }
450 }
451 else if ( eventPattern.keyMatch( QwtEventPattern::KeySelect2, keyEvent ) )
452 {
453 if ( !keyEvent->isAutoRepeat() )
454 {
455 if ( state() == 1 )
456 {
457 cmdList += End;
458 setState( 0 );
459 }
460 }
461 }
462 break;
463 }
464 default:
465 break;
466 }
467
468 return cmdList;
469}
470
471//! Constructor
472QwtPickerDragLineMachine::QwtPickerDragLineMachine():
473 QwtPickerMachine( PolygonSelection )
474{
475}
476
477//! Transition
478QList<QwtPickerMachine::Command> QwtPickerDragLineMachine::transition(
479 const QwtEventPattern &eventPattern, const QEvent *event )
480{
481 QList<QwtPickerMachine::Command> cmdList;
482
483 switch( event->type() )
484 {
485 case QEvent::MouseButtonPress:
486 {
487 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
488 static_cast<const QMouseEvent *>( event ) ) )
489 {
490 if ( state() == 0 )
491 {
492 cmdList += Begin;
493 cmdList += Append;
494 cmdList += Append;
495 setState( 1 );
496 }
497 }
498 break;
499 }
500 case QEvent::KeyPress:
501 {
502 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
503 static_cast<const QKeyEvent *> ( event ) ) )
504 {
505 if ( state() == 0 )
506 {
507 cmdList += Begin;
508 cmdList += Append;
509 cmdList += Append;
510 setState( 1 );
511 }
512 else
513 {
514 cmdList += End;
515 setState( 0 );
516 }
517 }
518 break;
519 }
520 case QEvent::MouseMove:
521 case QEvent::Wheel:
522 {
523 if ( state() != 0 )
524 cmdList += Move;
525
526 break;
527 }
528 case QEvent::MouseButtonRelease:
529 {
530 if ( state() != 0 )
531 {
532 cmdList += End;
533 setState( 0 );
534 }
535 }
536 default:
537 break;
538 }
539
540 return cmdList;
541}
Note: See TracBrowser for help on using the repository browser.