00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_EVENT_PATTERN
00011 #define QWT_EVENT_PATTERN 1
00012
00013 #include "qwt_global.h"
00014 #include <qnamespace.h>
00015 #include <qvector.h>
00016
00017 class QMouseEvent;
00018 class QKeyEvent;
00019
00029 class QWT_EXPORT QwtEventPattern
00030 {
00031 public:
00080 enum MousePatternCode
00081 {
00082 MouseSelect1,
00083 MouseSelect2,
00084 MouseSelect3,
00085 MouseSelect4,
00086 MouseSelect5,
00087 MouseSelect6,
00088
00089 MousePatternCount
00090 };
00091
00119 enum KeyPatternCode
00120 {
00121 KeySelect1,
00122 KeySelect2,
00123 KeyAbort,
00124
00125 KeyLeft,
00126 KeyRight,
00127 KeyUp,
00128 KeyDown,
00129
00130 KeyRedo,
00131 KeyUndo,
00132 KeyHome,
00133
00134 KeyPatternCount
00135 };
00136
00138 class MousePattern
00139 {
00140 public:
00141 MousePattern(int btn = Qt::NoButton, int st = Qt::NoButton)
00142 {
00143 button = btn;
00144 state = st;
00145 }
00146
00147 int button;
00148 int state;
00149 };
00150
00152 class KeyPattern
00153 {
00154 public:
00155 KeyPattern(int k = 0, int st = Qt::NoButton)
00156 {
00157 key = k;
00158 state = st;
00159 }
00160
00161 int key;
00162 int state;
00163 };
00164
00165 QwtEventPattern();
00166 virtual ~QwtEventPattern();
00167
00168 void initMousePattern(int numButtons);
00169 void initKeyPattern();
00170
00171 void setMousePattern(uint pattern, int button, int state = Qt::NoButton);
00172 void setKeyPattern(uint pattern, int key, int state = Qt::NoButton);
00173
00174 void setMousePattern(const QVector<MousePattern> &);
00175 void setKeyPattern(const QVector<KeyPattern> &);
00176
00177 const QVector<MousePattern> &mousePattern() const;
00178 const QVector<KeyPattern> &keyPattern() const;
00179
00180 QVector<MousePattern> &mousePattern();
00181 QVector<KeyPattern> &keyPattern();
00182
00183 bool mouseMatch(uint pattern, const QMouseEvent *) const;
00184 bool keyMatch(uint pattern, const QKeyEvent *) const;
00185
00186 protected:
00187 virtual bool mouseMatch(const MousePattern &, const QMouseEvent *) const;
00188 virtual bool keyMatch(const KeyPattern &, const QKeyEvent *) const;
00189
00190 private:
00191
00192 #if defined(_MSC_VER)
00193 #pragma warning(push)
00194 #pragma warning(disable: 4251)
00195 #endif
00196 QVector<MousePattern> d_mousePattern;
00197 QVector<KeyPattern> d_keyPattern;
00198 #if defined(_MSC_VER)
00199 #pragma warning(pop)
00200 #endif
00201 };
00202
00203 inline bool operator==(QwtEventPattern::MousePattern b1,
00204 QwtEventPattern::MousePattern b2)
00205 {
00206 return b1.button == b2.button && b1.state == b2.state;
00207 }
00208
00209 inline bool operator==(QwtEventPattern::KeyPattern b1,
00210 QwtEventPattern::KeyPattern b2)
00211 {
00212 return b1.key == b2.key && b1.state == b2.state;
00213 }
00214
00215 #endif