Qwt User's Guide svn
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 "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:
00142         MousePattern( int btn = Qt::NoButton, int st = Qt::NoButton )
00143         {
00144             button = btn;
00145             state = st;
00146         }
00147 
00149         int button;
00150 
00152         int state;
00153     };
00154 
00156     class KeyPattern
00157     {
00158     public:
00160         KeyPattern( int k = 0, int st = Qt::NoButton )
00161         {
00162             key = k;
00163             state = st;
00164         }
00165 
00167         int key;
00168 
00170         int state;
00171     };
00172 
00173     QwtEventPattern();
00174     virtual ~QwtEventPattern();
00175 
00176     void initMousePattern( int numButtons );
00177     void initKeyPattern();
00178 
00179     void setMousePattern( uint pattern, int button, int state = Qt::NoButton );
00180     void setKeyPattern( uint pattern, int key, int state = Qt::NoButton );
00181 
00182     void setMousePattern( const QVector<MousePattern> & );
00183     void setKeyPattern( const QVector<KeyPattern> & );
00184 
00185     const QVector<MousePattern> &mousePattern() const;
00186     const QVector<KeyPattern> &keyPattern() const;
00187 
00188     QVector<MousePattern> &mousePattern();
00189     QVector<KeyPattern> &keyPattern();
00190 
00191     bool mouseMatch( uint pattern, const QMouseEvent * ) const;
00192     bool keyMatch( uint pattern, const QKeyEvent * ) const;
00193 
00194 protected:
00195     virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
00196     virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
00197 
00198 private:
00199 
00200 #if defined(_MSC_VER)
00201 #pragma warning(push)
00202 #pragma warning(disable: 4251)
00203 #endif
00204     QVector<MousePattern> d_mousePattern;
00205     QVector<KeyPattern> d_keyPattern;
00206 #if defined(_MSC_VER)
00207 #pragma warning(pop)
00208 #endif
00209 };
00210 
00212 inline bool operator==( QwtEventPattern::MousePattern b1,
00213     QwtEventPattern::MousePattern  b2 )
00214 {
00215     return b1.button == b2.button && b1.state == b2.state;
00216 }
00217 
00219 inline bool operator==( QwtEventPattern::KeyPattern b1,
00220    QwtEventPattern::KeyPattern  b2 )
00221 {
00222     return b1.key == b2.key && b1.state == b2.state;
00223 }
00224 
00225 #endif
qmi style