Qwt User's Guide  6.1.3
qwt_event_pattern.h
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 #ifndef QWT_EVENT_PATTERN
11 #define QWT_EVENT_PATTERN 1
12 
13 #include "qwt_global.h"
14 #include <qnamespace.h>
15 #include <qvector.h>
16 
17 class QMouseEvent;
18 class QKeyEvent;
19 
29 class QWT_EXPORT QwtEventPattern
30 {
31 public:
45  {
54 
63 
72 
81 
90 
99 
101  MousePatternCount
102  };
103 
112  {
115 
118 
121 
124 
127 
130 
133 
136 
139 
142 
144  KeyPatternCount
145  };
146 
149  {
150  public:
152  MousePattern( Qt::MouseButton btn = Qt::NoButton,
153  Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
154  button( btn ),
155  modifiers( modifierCodes )
156  {
157  }
158 
160  Qt::MouseButton button;
161 
163  Qt::KeyboardModifiers modifiers;
164  };
165 
168  {
169  public:
171  KeyPattern( int keyCode = Qt::Key_unknown,
172  Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
173  key( keyCode ),
174  modifiers( modifierCodes )
175  {
176  }
177 
179  int key;
180 
182  Qt::KeyboardModifiers modifiers;
183  };
184 
185  QwtEventPattern();
186  virtual ~QwtEventPattern();
187 
188  void initMousePattern( int numButtons );
189  void initKeyPattern();
190 
191  void setMousePattern( MousePatternCode, Qt::MouseButton button,
192  Qt::KeyboardModifiers = Qt::NoModifier );
193 
194  void setKeyPattern( KeyPatternCode, int keyCode,
195  Qt::KeyboardModifiers modifierCodes = Qt::NoModifier );
196 
197  void setMousePattern( const QVector<MousePattern> & );
198  void setKeyPattern( const QVector<KeyPattern> & );
199 
200  const QVector<MousePattern> &mousePattern() const;
201  const QVector<KeyPattern> &keyPattern() const;
202 
203  QVector<MousePattern> &mousePattern();
204  QVector<KeyPattern> &keyPattern();
205 
206  bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;
207  bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;
208 
209 protected:
210  virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
211  virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
212 
213 private:
214 
215 #if defined(_MSC_VER)
216 #pragma warning(push)
217 #pragma warning(disable: 4251)
218 #endif
219  QVector<MousePattern> d_mousePattern;
220  QVector<KeyPattern> d_keyPattern;
221 #if defined(_MSC_VER)
222 #pragma warning(pop)
223 #endif
224 };
225 
227 inline bool operator==( QwtEventPattern::MousePattern b1,
229 {
230  return b1.button == b2.button && b1.modifiers == b2.modifiers;
231 }
232 
234 inline bool operator==( QwtEventPattern::KeyPattern b1,
236 {
237  return b1.key == b2.key && b1.modifiers == b2.modifiers;
238 }
239 
240 #endif
Definition: qwt_event_pattern.h:53
A pattern for key events.
Definition: qwt_event_pattern.h:167
MousePattern(Qt::MouseButton btn=Qt::NoButton, Qt::KeyboardModifiers modifierCodes=Qt::NoModifier)
Constructor.
Definition: qwt_event_pattern.h:152
Qt::Key_Return.
Definition: qwt_event_pattern.h:114
Qt::Key_Down.
Definition: qwt_event_pattern.h:132
Qt::Key_Space.
Definition: qwt_event_pattern.h:117
MousePatternCode
Symbolic mouse input codes.
Definition: qwt_event_pattern.h:44
Definition: qwt_event_pattern.h:62
Qt::Key_Escape.
Definition: qwt_event_pattern.h:141
Qt::KeyboardModifiers modifiers
Keyboard modifier.
Definition: qwt_event_pattern.h:163
A collection of event patterns.
Definition: qwt_event_pattern.h:29
Qt::Key_Escape.
Definition: qwt_event_pattern.h:120
Qt::KeyboardModifiers modifiers
Modifiers.
Definition: qwt_event_pattern.h:182
Qt::Key_Up.
Definition: qwt_event_pattern.h:129
Qt::Key_Left.
Definition: qwt_event_pattern.h:123
Qt::Key_Minus.
Definition: qwt_event_pattern.h:138
Qt::Key_Right.
Definition: qwt_event_pattern.h:126
Definition: qwt_event_pattern.h:80
Qt::Key_Plus.
Definition: qwt_event_pattern.h:135
KeyPatternCode
Symbolic keyboard input codes.
Definition: qwt_event_pattern.h:111
A pattern for mouse events.
Definition: qwt_event_pattern.h:148
Qt::MouseButton button
Button.
Definition: qwt_event_pattern.h:160
KeyPattern(int keyCode=Qt::Key_unknown, Qt::KeyboardModifiers modifierCodes=Qt::NoModifier)
Constructor.
Definition: qwt_event_pattern.h:171
Definition: qwt_event_pattern.h:71
Definition: qwt_event_pattern.h:89
Definition: qwt_event_pattern.h:98
int key
Key code.
Definition: qwt_event_pattern.h:179