qwt_picker_machine.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #ifndef QWT_PICKER_MACHINE
  10. #define QWT_PICKER_MACHINE 1
  11. #include "qwt_global.h"
  12. #include <qlist.h>
  13. class QEvent;
  14. class QwtEventPattern;
  15. /*!
  16. \brief A state machine for QwtPicker selections
  17. QwtPickerMachine accepts key and mouse events and translates them
  18. into selection commands.
  19. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
  20. */
  21. class QWT_EXPORT QwtPickerMachine
  22. {
  23. public:
  24. /*!
  25. Type of a selection.
  26. \sa selectionType()
  27. */
  28. enum SelectionType
  29. {
  30. //! The state machine not usable for any type of selection.
  31. NoSelection = -1,
  32. //! The state machine is for selecting a single point.
  33. PointSelection,
  34. //! The state machine is for selecting a rectangle (2 points).
  35. RectSelection,
  36. //! The state machine is for selecting a polygon (many points).
  37. PolygonSelection
  38. };
  39. //! Commands - the output of a state machine
  40. enum Command
  41. {
  42. Begin,
  43. Append,
  44. Move,
  45. Remove,
  46. End
  47. };
  48. QwtPickerMachine( SelectionType );
  49. virtual ~QwtPickerMachine();
  50. //! Transition
  51. virtual QList<Command> transition(
  52. const QwtEventPattern &, const QEvent * ) = 0;
  53. void reset();
  54. int state() const;
  55. void setState( int );
  56. SelectionType selectionType() const;
  57. private:
  58. const SelectionType d_selectionType;
  59. int d_state;
  60. };
  61. /*!
  62. \brief A state machine for indicating mouse movements
  63. QwtPickerTrackerMachine supports displaying information
  64. corresponding to mouse movements, but is not intended for
  65. selecting anything. Begin/End are related to Enter/Leave events.
  66. */
  67. class QWT_EXPORT QwtPickerTrackerMachine: public QwtPickerMachine
  68. {
  69. public:
  70. QwtPickerTrackerMachine();
  71. virtual QList<Command> transition(
  72. const QwtEventPattern &, const QEvent * );
  73. };
  74. /*!
  75. \brief A state machine for point selections
  76. Pressing QwtEventPattern::MouseSelect1 or
  77. QwtEventPattern::KeySelect1 selects a point.
  78. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
  79. */
  80. class QWT_EXPORT QwtPickerClickPointMachine: public QwtPickerMachine
  81. {
  82. public:
  83. QwtPickerClickPointMachine();
  84. virtual QList<Command> transition(
  85. const QwtEventPattern &, const QEvent * );
  86. };
  87. /*!
  88. \brief A state machine for point selections
  89. Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1
  90. starts the selection, releasing QwtEventPattern::MouseSelect1 or
  91. a second press of QwtEventPattern::KeySelect1 terminates it.
  92. */
  93. class QWT_EXPORT QwtPickerDragPointMachine: public QwtPickerMachine
  94. {
  95. public:
  96. QwtPickerDragPointMachine();
  97. virtual QList<Command> transition(
  98. const QwtEventPattern &, const QEvent * );
  99. };
  100. /*!
  101. \brief A state machine for rectangle selections
  102. Pressing QwtEventPattern::MouseSelect1 starts
  103. the selection, releasing it selects the first point. Pressing it
  104. again selects the second point and terminates the selection.
  105. Pressing QwtEventPattern::KeySelect1 also starts the
  106. selection, a second press selects the first point. A third one selects
  107. the second point and terminates the selection.
  108. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
  109. */
  110. class QWT_EXPORT QwtPickerClickRectMachine: public QwtPickerMachine
  111. {
  112. public:
  113. QwtPickerClickRectMachine();
  114. virtual QList<Command> transition(
  115. const QwtEventPattern &, const QEvent * );
  116. };
  117. /*!
  118. \brief A state machine for rectangle selections
  119. Pressing QwtEventPattern::MouseSelect1 selects
  120. the first point, releasing it the second point.
  121. Pressing QwtEventPattern::KeySelect1 also selects the
  122. first point, a second press selects the second point and terminates
  123. the selection.
  124. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
  125. */
  126. class QWT_EXPORT QwtPickerDragRectMachine: public QwtPickerMachine
  127. {
  128. public:
  129. QwtPickerDragRectMachine();
  130. virtual QList<Command> transition(
  131. const QwtEventPattern &, const QEvent * );
  132. };
  133. /*!
  134. \brief A state machine for line selections
  135. Pressing QwtEventPattern::MouseSelect1 selects
  136. the first point, releasing it the second point.
  137. Pressing QwtEventPattern::KeySelect1 also selects the
  138. first point, a second press selects the second point and terminates
  139. the selection.
  140. A common use case of QwtPickerDragLineMachine are pickers for
  141. distance measurements.
  142. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
  143. */
  144. class QWT_EXPORT QwtPickerDragLineMachine: public QwtPickerMachine
  145. {
  146. public:
  147. QwtPickerDragLineMachine();
  148. virtual QList<Command> transition(
  149. const QwtEventPattern &, const QEvent * );
  150. };
  151. /*!
  152. \brief A state machine for polygon selections
  153. Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1
  154. starts the selection and selects the first point, or appends a point.
  155. Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2
  156. appends the last point and terminates the selection.
  157. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
  158. */
  159. class QWT_EXPORT QwtPickerPolygonMachine: public QwtPickerMachine
  160. {
  161. public:
  162. QwtPickerPolygonMachine();
  163. virtual QList<Command> transition(
  164. const QwtEventPattern &, const QEvent * );
  165. };
  166. #endif