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

Last change on this file since 9407 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
RevLine 
[4271]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(
[8127]100 const QwtEventPattern &eventPattern, const QEvent *event )
[4271]101{
102 QList<QwtPickerMachine::Command> cmdList;
103
[8127]104 switch ( event->type() )
[4271]105 {
106 case QEvent::MouseButtonPress:
107 {
[9383]108 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
[8127]109 static_cast<const QMouseEvent *>( event ) ) )
[4271]110 {
111 cmdList += Begin;
112 cmdList += Append;
113 cmdList += End;
114 }
115 break;
116 }
117 case QEvent::KeyPress:
118 {
[8127]119 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
120 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
[4271]121 {
[8127]122 if ( !keyEvent->isAutoRepeat() )
123 {
124 cmdList += Begin;
125 cmdList += Append;
126 cmdList += End;
127 }
[4271]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(
[8127]146 const QwtEventPattern &eventPattern, const QEvent *event )
[4271]147{
148 QList<QwtPickerMachine::Command> cmdList;
149
[8127]150 switch ( event->type() )
[4271]151 {
152 case QEvent::MouseButtonPress:
153 {
[9383]154 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
[8127]155 static_cast<const QMouseEvent *>( event ) ) )
[4271]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 {
[8127]184 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
185 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
[4271]186 {
[8127]187 if ( !keyEvent->isAutoRepeat() )
[4271]188 {
[8127]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 }
[4271]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(
[8127]219 const QwtEventPattern &eventPattern, const QEvent *event )
[4271]220{
221 QList<QwtPickerMachine::Command> cmdList;
222
[8127]223 switch ( event->type() )
[4271]224 {
225 case QEvent::MouseButtonPress:
226 {
[9383]227 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
[8127]228 static_cast<const QMouseEvent *>( event ) ) )
[4271]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 }
[8127]251 break;
[4271]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 {
[9383]262 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
[8127]263 static_cast<const QMouseEvent *>( event ) ) )
[4271]264 {
265 if ( state() == 1 )
266 {
267 cmdList += Append;
268 setState( 2 );
269 }
270 }
271 break;
272 }
273 case QEvent::KeyPress:
274 {
[8127]275 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
276 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
[4271]277 {
[8127]278 if ( !keyEvent->isAutoRepeat() )
[4271]279 {
[8127]280 if ( state() == 0 )
[4271]281 {
[8127]282 cmdList += Begin;
[4271]283 cmdList += Append;
[8127]284 setState( 1 );
[4271]285 }
[8127]286 else
[4271]287 {
[8127]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 }
[4271]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(
[8127]318 const QwtEventPattern &eventPattern, const QEvent *event )
[4271]319{
320 QList<QwtPickerMachine::Command> cmdList;
321
[8127]322 switch ( event->type() )
[4271]323 {
324 case QEvent::MouseButtonPress:
325 {
[9383]326 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
[8127]327 static_cast<const QMouseEvent *>( event ) ) )
[4271]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 {
[9383]357 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
[8127]358 static_cast<const QKeyEvent *> ( event ) ) )
[4271]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(
[8127]390 const QwtEventPattern &eventPattern, const QEvent *event )
[4271]391{
392 QList<QwtPickerMachine::Command> cmdList;
393
[8127]394 switch ( event->type() )
[4271]395 {
396 case QEvent::MouseButtonPress:
397 {
[9383]398 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
[8127]399 static_cast<const QMouseEvent *>( event ) ) )
[4271]400 {
401 if ( state() == 0 )
402 {
403 cmdList += Begin;
404 cmdList += Append;
405 cmdList += Append;
406 setState( 1 );
407 }
408 else
409 {
[8127]410 cmdList += Append;
[4271]411 }
412 }
[9383]413 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2,
[8127]414 static_cast<const QMouseEvent *>( event ) ) )
[4271]415 {
416 if ( state() == 1 )
[8127]417 {
418 cmdList += End;
419 setState( 0 );
420 }
[4271]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 {
[8127]433 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
434 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
[4271]435 {
[8127]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 {
[4271]490 if ( state() == 0 )
491 {
492 cmdList += Begin;
493 cmdList += Append;
494 cmdList += Append;
495 setState( 1 );
496 }
[8127]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 }
[4271]512 else
513 {
514 cmdList += End;
515 setState( 0 );
516 }
517 }
[8127]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 )
[4271]531 {
[8127]532 cmdList += End;
533 setState( 0 );
[4271]534 }
535 }
536 default:
537 break;
538 }
539
540 return cmdList;
541}
Note: See TracBrowser for help on using the repository browser.