qwt_event_pattern.h 5.83 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_EVENT_PATTERN
#define QWT_EVENT_PATTERN 1

Bryant's avatar
Bryant committed
13
#include "qwt_global.h"
pixhawk's avatar
pixhawk committed
14
#include <qnamespace.h>
Bryant's avatar
Bryant committed
15
#include <qvector.h>
pixhawk's avatar
pixhawk committed
16 17 18 19 20 21 22 23

class QMouseEvent;
class QKeyEvent;

/*!
  \brief A collection of event patterns

  QwtEventPattern introduces an level of indirection for mouse and
24
  keyboard inputs. Those are represented by symbolic names, so
pixhawk's avatar
pixhawk committed
25 26 27 28 29 30 31 32 33 34
  the application code can be configured by individual mappings.

  \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer
*/
class QWT_EXPORT QwtEventPattern
{
public:
    /*!
      \brief Symbolic mouse input codes

Bryant's avatar
Bryant committed
35 36 37 38 39 40 41 42
      QwtEventPattern implements 3 different settings for
      mice with 1, 2, or 3 buttons that can be activated
      using initMousePattern(). The default setting is for
      3 button mice.

      Individual settings can be configured using setMousePattern().

      \sa initMousePattern(), setMousePattern(), setKeyPattern()
pixhawk's avatar
pixhawk committed
43
    */
Bryant's avatar
Bryant committed
44 45 46 47
    enum MousePatternCode
    {
        /*! 
          The default setting for 1, 2 and 3 button mice is:
pixhawk's avatar
pixhawk committed
48

Bryant's avatar
Bryant committed
49 50 51 52
          - Qt::LeftButton 
          - Qt::LeftButton 
          - Qt::LeftButton 
         */
pixhawk's avatar
pixhawk committed
53
        MouseSelect1,
Bryant's avatar
Bryant committed
54 55 56 57 58 59 60 61

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::ControlModifier
          - Qt::RightButton
          - Qt::RightButton
         */
pixhawk's avatar
pixhawk committed
62
        MouseSelect2,
Bryant's avatar
Bryant committed
63 64 65 66 67 68 69 70

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::AltModifier
          - Qt::LeftButton + Qt::AltModifier
          - Qt::MidButton
         */
pixhawk's avatar
pixhawk committed
71
        MouseSelect3,
Bryant's avatar
Bryant committed
72 73 74 75 76 77 78 79

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::ShiftModifier
          - Qt::LeftButton + Qt::ShiftModifier
          - Qt::LeftButton + Qt::ShiftModifier
         */
pixhawk's avatar
pixhawk committed
80
        MouseSelect4,
Bryant's avatar
Bryant committed
81 82 83 84 85 86 87 88

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier
          - Qt::RightButton + Qt::ShiftModifier
          - Qt::RightButton + Qt::ShiftModifier
         */
pixhawk's avatar
pixhawk committed
89
        MouseSelect5,
Bryant's avatar
Bryant committed
90 91 92 93 94 95 96 97

        /*!
          The default setting for 1, 2 and 3 button mice is:

          - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier
          - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier
          - Qt::MidButton + Qt::ShiftModifier
         */
pixhawk's avatar
pixhawk committed
98 99
        MouseSelect6,

Bryant's avatar
Bryant committed
100
        //! Number of mouse patterns
pixhawk's avatar
pixhawk committed
101 102 103 104 105 106
        MousePatternCount
    };

    /*!
      \brief Symbolic keyboard input codes

Bryant's avatar
Bryant committed
107 108 109
      Individual settings can be configured using setKeyPattern()

      \sa setKeyPattern(), setMousePattern()
pixhawk's avatar
pixhawk committed
110
    */
Bryant's avatar
Bryant committed
111 112 113
    enum KeyPatternCode
    {
        //! Qt::Key_Return
pixhawk's avatar
pixhawk committed
114
        KeySelect1,
Bryant's avatar
Bryant committed
115 116

        //! Qt::Key_Space
pixhawk's avatar
pixhawk committed
117
        KeySelect2,
Bryant's avatar
Bryant committed
118 119

        //! Qt::Key_Escape
pixhawk's avatar
pixhawk committed
120 121
        KeyAbort,

Bryant's avatar
Bryant committed
122
        //! Qt::Key_Left
pixhawk's avatar
pixhawk committed
123
        KeyLeft,
Bryant's avatar
Bryant committed
124 125

        //! Qt::Key_Right
pixhawk's avatar
pixhawk committed
126
        KeyRight,
Bryant's avatar
Bryant committed
127 128

        //! Qt::Key_Up
pixhawk's avatar
pixhawk committed
129
        KeyUp,
Bryant's avatar
Bryant committed
130 131

        //! Qt::Key_Down
pixhawk's avatar
pixhawk committed
132 133
        KeyDown,

Bryant's avatar
Bryant committed
134
        //! Qt::Key_Plus
pixhawk's avatar
pixhawk committed
135
        KeyRedo,
Bryant's avatar
Bryant committed
136 137

        //! Qt::Key_Minus
pixhawk's avatar
pixhawk committed
138
        KeyUndo,
Bryant's avatar
Bryant committed
139 140

        //! Qt::Key_Escape
pixhawk's avatar
pixhawk committed
141 142
        KeyHome,

Bryant's avatar
Bryant committed
143
        //! Number of key patterns
pixhawk's avatar
pixhawk committed
144 145 146 147 148 149 150
        KeyPatternCount
    };

    //! A pattern for mouse events
    class MousePattern
    {
    public:
Bryant's avatar
Bryant committed
151 152 153 154 155 156
        //! Constructor
        MousePattern( Qt::MouseButton btn = Qt::NoButton, 
                Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
            button( btn ),
            modifiers( modifierCodes )
        {
pixhawk's avatar
pixhawk committed
157 158
        }

Bryant's avatar
Bryant committed
159 160 161 162 163
        //! Button 
        Qt::MouseButton button;

        //! Keyboard modifier
        Qt::KeyboardModifiers modifiers;
pixhawk's avatar
pixhawk committed
164 165 166 167 168 169
    };

    //! A pattern for key events
    class KeyPattern
    {
    public:
Bryant's avatar
Bryant committed
170 171 172 173 174 175
        //! Constructor
        KeyPattern( int keyCode = Qt::Key_unknown, 
                Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
            key( keyCode ),
            modifiers( modifierCodes )
        {
pixhawk's avatar
pixhawk committed
176 177
        }

Bryant's avatar
Bryant committed
178
        //! Key code
pixhawk's avatar
pixhawk committed
179
        int key;
Bryant's avatar
Bryant committed
180 181 182

        //! Modifiers
        Qt::KeyboardModifiers modifiers;
pixhawk's avatar
pixhawk committed
183 184 185 186 187
    };

    QwtEventPattern();
    virtual ~QwtEventPattern();

Bryant's avatar
Bryant committed
188
    void initMousePattern( int numButtons );
pixhawk's avatar
pixhawk committed
189 190
    void initKeyPattern();

Bryant's avatar
Bryant committed
191 192
    void setMousePattern( MousePatternCode, Qt::MouseButton button, 
        Qt::KeyboardModifiers = Qt::NoModifier );
pixhawk's avatar
pixhawk committed
193

Bryant's avatar
Bryant committed
194 195
    void setKeyPattern( KeyPatternCode, int keyCode, 
        Qt::KeyboardModifiers modifierCodes = Qt::NoModifier );
pixhawk's avatar
pixhawk committed
196

Bryant's avatar
Bryant committed
197 198
    void setMousePattern( const QVector<MousePattern> & );
    void setKeyPattern( const QVector<KeyPattern> & );
pixhawk's avatar
pixhawk committed
199

Bryant's avatar
Bryant committed
200 201
    const QVector<MousePattern> &mousePattern() const;
    const QVector<KeyPattern> &keyPattern() const;
pixhawk's avatar
pixhawk committed
202

Bryant's avatar
Bryant committed
203 204 205 206 207
    QVector<MousePattern> &mousePattern();
    QVector<KeyPattern> &keyPattern();

    bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;
    bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;
pixhawk's avatar
pixhawk committed
208 209

protected:
Bryant's avatar
Bryant committed
210 211
    virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
    virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
212

pixhawk's avatar
pixhawk committed
213 214 215 216 217 218
private:

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
Bryant's avatar
Bryant committed
219 220
    QVector<MousePattern> d_mousePattern;
    QVector<KeyPattern> d_keyPattern;
pixhawk's avatar
pixhawk committed
221 222 223 224 225
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};

Bryant's avatar
Bryant committed
226 227 228
//! Compare operator
inline bool operator==( QwtEventPattern::MousePattern b1,
    QwtEventPattern::MousePattern  b2 )
229
{
Bryant's avatar
Bryant committed
230
    return b1.button == b2.button && b1.modifiers == b2.modifiers;
pixhawk's avatar
pixhawk committed
231 232
}

Bryant's avatar
Bryant committed
233 234 235
//! Compare operator
inline bool operator==( QwtEventPattern::KeyPattern b1,
   QwtEventPattern::KeyPattern  b2 )
236
{
Bryant's avatar
Bryant committed
237
    return b1.key == b2.key && b1.modifiers == b2.modifiers;
pixhawk's avatar
pixhawk committed
238 239 240
}

#endif