qwt_event_pattern.h

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_EVENT_PATTERN
00011 #define QWT_EVENT_PATTERN 1
00012 
00013 #include <qnamespace.h>
00014 #include "qwt_array.h"
00015 
00016 class QMouseEvent;
00017 class QKeyEvent;
00018 
00028 class QWT_EXPORT QwtEventPattern
00029 {
00030 public:
00079     enum MousePatternCode
00080     {
00081         MouseSelect1,
00082         MouseSelect2,
00083         MouseSelect3,
00084         MouseSelect4,
00085         MouseSelect5,
00086         MouseSelect6,
00087 
00088         MousePatternCount
00089     };
00090 
00118     enum KeyPatternCode
00119     {
00120         KeySelect1,
00121         KeySelect2,
00122         KeyAbort,
00123 
00124         KeyLeft,
00125         KeyRight,
00126         KeyUp,
00127         KeyDown,
00128 
00129         KeyRedo,
00130         KeyUndo,
00131         KeyHome,
00132 
00133         KeyPatternCount
00134     };
00135 
00137     class MousePattern
00138     {
00139     public:
00140         MousePattern(int btn = Qt::NoButton, int st = Qt::NoButton) 
00141         { 
00142             button = btn;
00143             state = st;
00144         }
00145 
00146         int button;
00147         int state;
00148     };
00149 
00151     class KeyPattern
00152     {
00153     public:
00154         KeyPattern(int k = 0, int st = Qt::NoButton)    
00155         { 
00156             key = k; 
00157             state = st;
00158         }
00159 
00160         int key;
00161         int state;
00162     };
00163 
00164     QwtEventPattern();
00165     virtual ~QwtEventPattern();
00166 
00167     void initMousePattern(int numButtons);
00168     void initKeyPattern();
00169 
00170     void setMousePattern(uint pattern, int button, int state = Qt::NoButton);
00171     void setKeyPattern(uint pattern, int key, int state = Qt::NoButton);
00172 
00173     void setMousePattern(const QwtArray<MousePattern> &);
00174     void setKeyPattern(const QwtArray<KeyPattern> &);
00175 
00176     const QwtArray<MousePattern> &mousePattern() const;
00177     const QwtArray<KeyPattern> &keyPattern() const;
00178 
00179     QwtArray<MousePattern> &mousePattern();
00180     QwtArray<KeyPattern> &keyPattern();
00181 
00182     bool mouseMatch(uint pattern, const QMouseEvent *) const;
00183     bool keyMatch(uint pattern, const QKeyEvent *) const;
00184 
00185 protected:
00186     virtual bool mouseMatch(const MousePattern &, const QMouseEvent *) const;
00187     virtual bool keyMatch(const KeyPattern &, const QKeyEvent *) const;
00188     
00189 private:
00190 
00191 #if defined(_MSC_VER)
00192 #pragma warning(push)
00193 #pragma warning(disable: 4251)
00194 #endif
00195     QwtArray<MousePattern> d_mousePattern;
00196     QwtArray<KeyPattern> d_keyPattern;
00197 #if defined(_MSC_VER)
00198 #pragma warning(pop)
00199 #endif
00200 };
00201 
00202 inline bool operator==(QwtEventPattern::MousePattern b1, 
00203    QwtEventPattern::MousePattern  b2)
00204 { 
00205     return b1.button == b2.button && b1.state == b2.state; 
00206 }
00207 
00208 inline bool operator==(QwtEventPattern::KeyPattern b1, 
00209    QwtEventPattern::KeyPattern  b2)
00210 { 
00211     return b1.key == b2.key && b1.state == b2.state; 
00212 }
00213 
00214 #if defined(QWT_TEMPLATEDLL)
00215 // MOC_SKIP_BEGIN
00216 template class QWT_EXPORT QwtArray<QwtEventPattern::MousePattern>;
00217 template class QWT_EXPORT QwtArray<QwtEventPattern::KeyPattern>;
00218 // MOC_SKIP_END
00219 #endif
00220 
00221 #endif

Generated on Mon Feb 26 21:22:36 2007 for Qwt User's Guide by  doxygen 1.4.6