Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

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:
80 enum MousePatternCode
81 {
82 MouseSelect1,
83 MouseSelect2,
84 MouseSelect3,
85 MouseSelect4,
86 MouseSelect5,
87 MouseSelect6,
88
89 MousePatternCount
90 };
91
119 enum KeyPatternCode
120 {
121 KeySelect1,
122 KeySelect2,
123 KeyAbort,
124
125 KeyLeft,
126 KeyRight,
127 KeyUp,
128 KeyDown,
129
130 KeyRedo,
131 KeyUndo,
132 KeyHome,
133
134 KeyPatternCount
135 };
136
138 class MousePattern
139 {
140 public:
142 MousePattern( int btn = Qt::NoButton, int st = Qt::NoButton )
143 {
144 button = btn;
145 state = st;
146 }
147
149 int button;
150
152 int state;
153 };
154
156 class KeyPattern
157 {
158 public:
160 KeyPattern( int k = 0, int st = Qt::NoButton )
161 {
162 key = k;
163 state = st;
164 }
165
167 int key;
168
170 int state;
171 };
172
173 QwtEventPattern();
174 virtual ~QwtEventPattern();
175
176 void initMousePattern( int numButtons );
177 void initKeyPattern();
178
179 void setMousePattern( uint pattern, int button, int state = Qt::NoButton );
180 void setKeyPattern( uint pattern, int key, int state = Qt::NoButton );
181
182 void setMousePattern( const QVector<MousePattern> & );
183 void setKeyPattern( const QVector<KeyPattern> & );
184
185 const QVector<MousePattern> &mousePattern() const;
186 const QVector<KeyPattern> &keyPattern() const;
187
188 QVector<MousePattern> &mousePattern();
189 QVector<KeyPattern> &keyPattern();
190
191 bool mouseMatch( uint pattern, const QMouseEvent * ) const;
192 bool keyMatch( uint pattern, const QKeyEvent * ) const;
193
194 protected:
195 virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
196 virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
197
198 private:
199
200 #if defined(_MSC_VER)
201 #pragma warning(push)
202 #pragma warning(disable: 4251)
203 #endif
204 QVector<MousePattern> d_mousePattern;
205 QVector<KeyPattern> d_keyPattern;
206 #if defined(_MSC_VER)
207 #pragma warning(pop)
208 #endif
209 };
210
212 inline bool operator==( QwtEventPattern::MousePattern b1,
213 QwtEventPattern::MousePattern b2 )
214 {
215 return b1.button == b2.button && b1.state == b2.state;
216 }
217
219 inline bool operator==( QwtEventPattern::KeyPattern b1,
220 QwtEventPattern::KeyPattern b2 )
221 {
222 return b1.key == b2.key && b1.state == b2.state;
223 }
224
225 #endif