qwt_event_pattern.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_EVENT_PATTERN
  10. #define QWT_EVENT_PATTERN 1
  11. #include "qwt_global.h"
  12. #include <qnamespace.h>
  13. #include <qvector.h>
  14. class QMouseEvent;
  15. class QKeyEvent;
  16. /*!
  17. \brief A collection of event patterns
  18. QwtEventPattern introduces an level of indirection for mouse and
  19. keyboard inputs. Those are represented by symbolic names, so
  20. the application code can be configured by individual mappings.
  21. \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer
  22. */
  23. class QWT_EXPORT QwtEventPattern
  24. {
  25. public:
  26. /*!
  27. \brief Symbolic mouse input codes
  28. QwtEventPattern implements 3 different settings for
  29. mice with 1, 2, or 3 buttons that can be activated
  30. using initMousePattern(). The default setting is for
  31. 3 button mice.
  32. Individual settings can be configured using setMousePattern().
  33. \sa initMousePattern(), setMousePattern(), setKeyPattern()
  34. */
  35. enum MousePatternCode
  36. {
  37. /*!
  38. The default setting for 1, 2 and 3 button mice is:
  39. - Qt::LeftButton
  40. - Qt::LeftButton
  41. - Qt::LeftButton
  42. */
  43. MouseSelect1,
  44. /*!
  45. The default setting for 1, 2 and 3 button mice is:
  46. - Qt::LeftButton + Qt::ControlModifier
  47. - Qt::RightButton
  48. - Qt::RightButton
  49. */
  50. MouseSelect2,
  51. /*!
  52. The default setting for 1, 2 and 3 button mice is:
  53. - Qt::LeftButton + Qt::AltModifier
  54. - Qt::LeftButton + Qt::AltModifier
  55. - Qt::MidButton
  56. */
  57. MouseSelect3,
  58. /*!
  59. The default setting for 1, 2 and 3 button mice is:
  60. - Qt::LeftButton + Qt::ShiftModifier
  61. - Qt::LeftButton + Qt::ShiftModifier
  62. - Qt::LeftButton + Qt::ShiftModifier
  63. */
  64. MouseSelect4,
  65. /*!
  66. The default setting for 1, 2 and 3 button mice is:
  67. - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier
  68. - Qt::RightButton + Qt::ShiftModifier
  69. - Qt::RightButton + Qt::ShiftModifier
  70. */
  71. MouseSelect5,
  72. /*!
  73. The default setting for 1, 2 and 3 button mice is:
  74. - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier
  75. - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier
  76. - Qt::MidButton + Qt::ShiftModifier
  77. */
  78. MouseSelect6,
  79. //! Number of mouse patterns
  80. MousePatternCount
  81. };
  82. /*!
  83. \brief Symbolic keyboard input codes
  84. Individual settings can be configured using setKeyPattern()
  85. \sa setKeyPattern(), setMousePattern()
  86. */
  87. enum KeyPatternCode
  88. {
  89. //! Qt::Key_Return
  90. KeySelect1,
  91. //! Qt::Key_Space
  92. KeySelect2,
  93. //! Qt::Key_Escape
  94. KeyAbort,
  95. //! Qt::Key_Left
  96. KeyLeft,
  97. //! Qt::Key_Right
  98. KeyRight,
  99. //! Qt::Key_Up
  100. KeyUp,
  101. //! Qt::Key_Down
  102. KeyDown,
  103. //! Qt::Key_Plus
  104. KeyRedo,
  105. //! Qt::Key_Minus
  106. KeyUndo,
  107. //! Qt::Key_Escape
  108. KeyHome,
  109. //! Number of key patterns
  110. KeyPatternCount
  111. };
  112. //! A pattern for mouse events
  113. class MousePattern
  114. {
  115. public:
  116. //! Constructor
  117. MousePattern( Qt::MouseButton btn = Qt::NoButton,
  118. Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
  119. button( btn ),
  120. modifiers( modifierCodes )
  121. {
  122. }
  123. //! Button
  124. Qt::MouseButton button;
  125. //! Keyboard modifier
  126. Qt::KeyboardModifiers modifiers;
  127. };
  128. //! A pattern for key events
  129. class KeyPattern
  130. {
  131. public:
  132. //! Constructor
  133. KeyPattern( int keyCode = Qt::Key_unknown,
  134. Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
  135. key( keyCode ),
  136. modifiers( modifierCodes )
  137. {
  138. }
  139. //! Key code
  140. int key;
  141. //! Modifiers
  142. Qt::KeyboardModifiers modifiers;
  143. };
  144. QwtEventPattern();
  145. virtual ~QwtEventPattern();
  146. void initMousePattern( int numButtons );
  147. void initKeyPattern();
  148. void setMousePattern( MousePatternCode, Qt::MouseButton button,
  149. Qt::KeyboardModifiers = Qt::NoModifier );
  150. void setKeyPattern( KeyPatternCode, int key,
  151. Qt::KeyboardModifiers modifiers = Qt::NoModifier );
  152. void setMousePattern( const QVector<MousePattern> & );
  153. void setKeyPattern( const QVector<KeyPattern> & );
  154. const QVector<MousePattern> &mousePattern() const;
  155. const QVector<KeyPattern> &keyPattern() const;
  156. QVector<MousePattern> &mousePattern();
  157. QVector<KeyPattern> &keyPattern();
  158. bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;
  159. bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;
  160. protected:
  161. virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
  162. virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
  163. private:
  164. #if defined(_MSC_VER)
  165. #pragma warning(push)
  166. #pragma warning(disable: 4251)
  167. #endif
  168. QVector<MousePattern> d_mousePattern;
  169. QVector<KeyPattern> d_keyPattern;
  170. #if defined(_MSC_VER)
  171. #pragma warning(pop)
  172. #endif
  173. };
  174. //! Compare operator
  175. inline bool operator==( QwtEventPattern::MousePattern b1,
  176. QwtEventPattern::MousePattern b2 )
  177. {
  178. return b1.button == b2.button && b1.modifiers == b2.modifiers;
  179. }
  180. //! Compare operator
  181. inline bool operator==( QwtEventPattern::KeyPattern b1,
  182. QwtEventPattern::KeyPattern b2 )
  183. {
  184. return b1.key == b2.key && b1.modifiers == b2.modifiers;
  185. }
  186. #endif