Qwt User's Guide: qwt_event_pattern.h Source File

Qwt User's Guide 5.2.3

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