qwt_picker_machine.cpp
Go to the documentation of this file.
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 
13 #include <qevent.h>
14 
17  d_selectionType( type ),
18  d_state( 0 )
19 {
20 }
21 
24 {
25 }
26 
29 {
30  return d_selectionType;
31 }
32 
35 {
36  return d_state;
37 }
38 
41 {
42  d_state = state;
43 }
44 
47 {
48  setState( 0 );
49 }
50 
54 {
55 }
56 
59  const QwtEventPattern &, const QEvent *e )
60 {
62 
63  switch ( e->type() )
64  {
65  case QEvent::Enter:
66  case QEvent::MouseMove:
67  {
68  if ( state() == 0 )
69  {
70  cmdList += Begin;
71  cmdList += Append;
72  setState( 1 );
73  }
74  else
75  {
76  cmdList += Move;
77  }
78  break;
79  }
80  case QEvent::Leave:
81  {
82  cmdList += Remove;
83  cmdList += End;
84  setState( 0 );
85  }
86  default:
87  break;
88  }
89 
90  return cmdList;
91 }
92 
96 {
97 }
98 
101  const QwtEventPattern &eventPattern, const QEvent *event )
102 {
104 
105  switch ( event->type() )
106  {
107  case QEvent::MouseButtonPress:
108  {
109  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
110  static_cast<const QMouseEvent *>( event ) ) )
111  {
112  cmdList += Begin;
113  cmdList += Append;
114  cmdList += End;
115  }
116  break;
117  }
118  case QEvent::KeyPress:
119  {
120  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
121  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
122  {
123  if ( !keyEvent->isAutoRepeat() )
124  {
125  cmdList += Begin;
126  cmdList += Append;
127  cmdList += End;
128  }
129  }
130  break;
131  }
132  default:
133  break;
134  }
135 
136  return cmdList;
137 }
138 
142 {
143 }
144 
147  const QwtEventPattern &eventPattern, const QEvent *event )
148 {
150 
151  switch ( event->type() )
152  {
153  case QEvent::MouseButtonPress:
154  {
155  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
156  static_cast<const QMouseEvent *>( event ) ) )
157  {
158  if ( state() == 0 )
159  {
160  cmdList += Begin;
161  cmdList += Append;
162  setState( 1 );
163  }
164  }
165  break;
166  }
167  case QEvent::MouseMove:
168  case QEvent::Wheel:
169  {
170  if ( state() != 0 )
171  cmdList += Move;
172  break;
173  }
174  case QEvent::MouseButtonRelease:
175  {
176  if ( state() != 0 )
177  {
178  cmdList += End;
179  setState( 0 );
180  }
181  break;
182  }
183  case QEvent::KeyPress:
184  {
185  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
186  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
187  {
188  if ( !keyEvent->isAutoRepeat() )
189  {
190  if ( state() == 0 )
191  {
192  cmdList += Begin;
193  cmdList += Append;
194  setState( 1 );
195  }
196  else
197  {
198  cmdList += End;
199  setState( 0 );
200  }
201  }
202  }
203  break;
204  }
205  default:
206  break;
207  }
208 
209  return cmdList;
210 }
211 
215 {
216 }
217 
220  const QwtEventPattern &eventPattern, const QEvent *event )
221 {
223 
224  switch ( event->type() )
225  {
226  case QEvent::MouseButtonPress:
227  {
228  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
229  static_cast<const QMouseEvent *>( event ) ) )
230  {
231  switch ( state() )
232  {
233  case 0:
234  {
235  cmdList += Begin;
236  cmdList += Append;
237  setState( 1 );
238  break;
239  }
240  case 1:
241  {
242  // Uh, strange we missed the MouseButtonRelease
243  break;
244  }
245  default:
246  {
247  cmdList += End;
248  setState( 0 );
249  }
250  }
251  }
252  break;
253  }
254  case QEvent::MouseMove:
255  case QEvent::Wheel:
256  {
257  if ( state() != 0 )
258  cmdList += Move;
259  break;
260  }
261  case QEvent::MouseButtonRelease:
262  {
263  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
264  static_cast<const QMouseEvent *>( event ) ) )
265  {
266  if ( state() == 1 )
267  {
268  cmdList += Append;
269  setState( 2 );
270  }
271  }
272  break;
273  }
274  case QEvent::KeyPress:
275  {
276  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
277  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
278  {
279  if ( !keyEvent->isAutoRepeat() )
280  {
281  if ( state() == 0 )
282  {
283  cmdList += Begin;
284  cmdList += Append;
285  setState( 1 );
286  }
287  else
288  {
289  if ( state() == 1 )
290  {
291  cmdList += Append;
292  setState( 2 );
293  }
294  else if ( state() == 2 )
295  {
296  cmdList += End;
297  setState( 0 );
298  }
299  }
300  }
301  }
302  break;
303  }
304  default:
305  break;
306  }
307 
308  return cmdList;
309 }
310 
314 {
315 }
316 
319  const QwtEventPattern &eventPattern, const QEvent *event )
320 {
322 
323  switch ( event->type() )
324  {
325  case QEvent::MouseButtonPress:
326  {
327  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
328  static_cast<const QMouseEvent *>( event ) ) )
329  {
330  if ( state() == 0 )
331  {
332  cmdList += Begin;
333  cmdList += Append;
334  cmdList += Append;
335  setState( 2 );
336  }
337  }
338  break;
339  }
340  case QEvent::MouseMove:
341  case QEvent::Wheel:
342  {
343  if ( state() != 0 )
344  cmdList += Move;
345  break;
346  }
347  case QEvent::MouseButtonRelease:
348  {
349  if ( state() == 2 )
350  {
351  cmdList += End;
352  setState( 0 );
353  }
354  break;
355  }
356  case QEvent::KeyPress:
357  {
358  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
359  static_cast<const QKeyEvent *> ( event ) ) )
360  {
361  if ( state() == 0 )
362  {
363  cmdList += Begin;
364  cmdList += Append;
365  cmdList += Append;
366  setState( 2 );
367  }
368  else
369  {
370  cmdList += End;
371  setState( 0 );
372  }
373  }
374  break;
375  }
376  default:
377  break;
378  }
379 
380  return cmdList;
381 }
382 
386 {
387 }
388 
391  const QwtEventPattern &eventPattern, const QEvent *event )
392 {
394 
395  switch ( event->type() )
396  {
397  case QEvent::MouseButtonPress:
398  {
399  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
400  static_cast<const QMouseEvent *>( event ) ) )
401  {
402  if ( state() == 0 )
403  {
404  cmdList += Begin;
405  cmdList += Append;
406  cmdList += Append;
407  setState( 1 );
408  }
409  else
410  {
411  cmdList += Append;
412  }
413  }
414  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2,
415  static_cast<const QMouseEvent *>( event ) ) )
416  {
417  if ( state() == 1 )
418  {
419  cmdList += End;
420  setState( 0 );
421  }
422  }
423  break;
424  }
425  case QEvent::MouseMove:
426  case QEvent::Wheel:
427  {
428  if ( state() != 0 )
429  cmdList += Move;
430  break;
431  }
432  case QEvent::KeyPress:
433  {
434  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
435  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
436  {
437  if ( !keyEvent->isAutoRepeat() )
438  {
439  if ( state() == 0 )
440  {
441  cmdList += Begin;
442  cmdList += Append;
443  cmdList += Append;
444  setState( 1 );
445  }
446  else
447  {
448  cmdList += Append;
449  }
450  }
451  }
452  else if ( eventPattern.keyMatch( QwtEventPattern::KeySelect2, keyEvent ) )
453  {
454  if ( !keyEvent->isAutoRepeat() )
455  {
456  if ( state() == 1 )
457  {
458  cmdList += End;
459  setState( 0 );
460  }
461  }
462  }
463  break;
464  }
465  default:
466  break;
467  }
468 
469  return cmdList;
470 }
471 
475 {
476 }
477 
480  const QwtEventPattern &eventPattern, const QEvent *event )
481 {
483 
484  switch( event->type() )
485  {
486  case QEvent::MouseButtonPress:
487  {
488  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
489  static_cast<const QMouseEvent *>( event ) ) )
490  {
491  if ( state() == 0 )
492  {
493  cmdList += Begin;
494  cmdList += Append;
495  cmdList += Append;
496  setState( 1 );
497  }
498  }
499  break;
500  }
501  case QEvent::KeyPress:
502  {
503  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
504  static_cast<const QKeyEvent *> ( event ) ) )
505  {
506  if ( state() == 0 )
507  {
508  cmdList += Begin;
509  cmdList += Append;
510  cmdList += Append;
511  setState( 1 );
512  }
513  else
514  {
515  cmdList += End;
516  setState( 0 );
517  }
518  }
519  break;
520  }
521  case QEvent::MouseMove:
522  case QEvent::Wheel:
523  {
524  if ( state() != 0 )
525  cmdList += Move;
526 
527  break;
528  }
529  case QEvent::MouseButtonRelease:
530  {
531  if ( state() != 0 )
532  {
533  cmdList += End;
534  setState( 0 );
535  }
536  }
537  default:
538  break;
539  }
540 
541  return cmdList;
542 }
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
QwtPickerDragLineMachine()
Constructor.
QwtPickerClickRectMachine()
Constructor.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
The state machine not usable for any type of selection.
QwtPickerMachine(SelectionType)
Constructor.
void reset()
Set the current state to 0.
void setState(int)
Change the current state.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
The state machine is for selecting a polygon (many points).
The state machine is for selecting a single point.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
A state machine for QwtPicker selections.
virtual ~QwtPickerMachine()
Destructor.
bool mouseMatch(MousePatternCode, const QMouseEvent *) const
Compare a mouse event with an event pattern.
QwtPickerDragPointMachine()
Constructor.
A collection of event patterns.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
SelectionType selectionType() const
Return the selection type.
const SelectionType d_selectionType
QwtPickerClickPointMachine()
Constructor.
QwtPickerTrackerMachine()
Constructor.
int state() const
Return the current state.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *) QWT_OVERRIDE
Transition.
QwtPickerDragRectMachine()
Constructor.
QwtPickerPolygonMachine()
Constructor.
The state machine is for selecting a rectangle (2 points).


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10