Qwt User's Guide 6.1.0

- Main Page
- Related Pages
- Classes

All Classes Functions Variables Typedefs Enumerations Enumerator Pages
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:
44 enum MousePatternCode
45 {
53 MouseSelect1,
54
62 MouseSelect2,
63
71 MouseSelect3,
72
80 MouseSelect4,
81
89 MouseSelect5,
90
98 MouseSelect6,
99
101 MousePatternCount
102 };
103
111 enum KeyPatternCode
112 {
114 KeySelect1,
115
117 KeySelect2,
118
120 KeyAbort,
121
123 KeyLeft,
124
126 KeyRight,
127
129 KeyUp,
130
132 KeyDown,
133
135 KeyRedo,
136
138 KeyUndo,
139
141 KeyHome,
142
144 KeyPatternCount
145 };
146
148 class MousePattern
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
167 class KeyPattern
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,
228 QwtEventPattern::MousePattern b2 )
229 {
230 return b1.button == b2.button && b1.modifiers == b2.modifiers;
231 }
232
234 inline bool operator==( QwtEventPattern::KeyPattern b1,
235 QwtEventPattern::KeyPattern b2 )
236 {
237 return b1.key == b2.key && b1.modifiers == b2.modifiers;
238 }
239
240 #endif