qwt_event_pattern.h 5.15 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 13 14 15 16 17 18 19 20 21 22
 * 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

#include <qnamespace.h>
#include "qwt_array.h"

class QMouseEvent;
class QKeyEvent;

/*!
  \brief A collection of event patterns

  QwtEventPattern introduces an level of indirection for mouse and
23
  keyboard inputs. Those are represented by symbolic names, so
pixhawk's avatar
pixhawk committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  the application code can be configured by individual mappings.

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

      The default initialization for 3 button mice is:
      - MouseSelect1\n
        Qt::LeftButton
      - MouseSelect2\n
        Qt::RightButton
      - MouseSelect3\n
        Qt::MidButton
      - MouseSelect4\n
        Qt::LeftButton + Qt::ShiftButton
      - MouseSelect5\n
        Qt::RightButton + Qt::ShiftButton
      - MouseSelect6\n
        Qt::MidButton + Qt::ShiftButton

      The default initialization for 2 button mice is:
      - MouseSelect1\n
        Qt::LeftButton
      - MouseSelect2\n
        Qt::RightButton
      - MouseSelect3\n
        Qt::LeftButton + Qt::AltButton
      - MouseSelect4\n
        Qt::LeftButton + Qt::ShiftButton
      - MouseSelect5\n
        Qt::RightButton + Qt::ShiftButton
      - MouseSelect6\n
        Qt::LeftButton + Qt::AltButton + Qt::ShiftButton

      The default initialization for 1 button mice is:
      - MouseSelect1\n
        Qt::LeftButton
      - MouseSelect2\n
        Qt::LeftButton + Qt::ControlButton
      - MouseSelect3\n
        Qt::LeftButton + Qt::AltButton
      - MouseSelect4\n
        Qt::LeftButton + Qt::ShiftButton
      - MouseSelect5\n
        Qt::LeftButton + Qt::ControlButton + Qt::ShiftButton
      - MouseSelect6\n
        Qt::LeftButton + Qt::AltButton + Qt::ShiftButton

      \sa initMousePattern()
    */

79
    enum MousePatternCode {
pixhawk's avatar
pixhawk committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        MouseSelect1,
        MouseSelect2,
        MouseSelect3,
        MouseSelect4,
        MouseSelect5,
        MouseSelect6,

        MousePatternCount
    };

    /*!
      \brief Symbolic keyboard input codes

      Default initialization:
      - KeySelect1\n
        Qt::Key_Return
      - KeySelect2\n
        Qt::Key_Space
      - KeyAbort\n
        Qt::Key_Escape

      - KeyLeft\n
        Qt::Key_Left
      - KeyRight\n
        Qt::Key_Right
      - KeyUp\n
        Qt::Key_Up
      - KeyDown\n
        Qt::Key_Down

      - KeyUndo\n
        Qt::Key_Minus
      - KeyRedo\n
        Qt::Key_Plus
      - KeyHome\n
        Qt::Key_Escape
    */
117
    enum KeyPatternCode {
pixhawk's avatar
pixhawk committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        KeySelect1,
        KeySelect2,
        KeyAbort,

        KeyLeft,
        KeyRight,
        KeyUp,
        KeyDown,

        KeyRedo,
        KeyUndo,
        KeyHome,

        KeyPatternCount
    };

    //! A pattern for mouse events
    class MousePattern
    {
    public:
138
        MousePattern(int btn = Qt::NoButton, int st = Qt::NoButton) {
pixhawk's avatar
pixhawk committed
139 140 141 142 143 144 145 146 147 148 149 150
            button = btn;
            state = st;
        }

        int button;
        int state;
    };

    //! A pattern for key events
    class KeyPattern
    {
    public:
151 152
        KeyPattern(int k = 0, int st = Qt::NoButton) {
            key = k;
pixhawk's avatar
pixhawk committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
            state = st;
        }

        int key;
        int state;
    };

    QwtEventPattern();
    virtual ~QwtEventPattern();

    void initMousePattern(int numButtons);
    void initKeyPattern();

    void setMousePattern(uint pattern, int button, int state = Qt::NoButton);
    void setKeyPattern(uint pattern, int key, int state = Qt::NoButton);

    void setMousePattern(const QwtArray<MousePattern> &);
    void setKeyPattern(const QwtArray<KeyPattern> &);

    const QwtArray<MousePattern> &mousePattern() const;
    const QwtArray<KeyPattern> &keyPattern() const;

    QwtArray<MousePattern> &mousePattern();
    QwtArray<KeyPattern> &keyPattern();

    bool mouseMatch(uint pattern, const QMouseEvent *) const;
    bool keyMatch(uint pattern, const QKeyEvent *) const;

protected:
    virtual bool mouseMatch(const MousePattern &, const QMouseEvent *) const;
    virtual bool keyMatch(const KeyPattern &, const QKeyEvent *) const;
184

pixhawk's avatar
pixhawk committed
185 186 187 188 189 190 191 192 193 194 195 196 197
private:

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
    QwtArray<MousePattern> d_mousePattern;
    QwtArray<KeyPattern> d_keyPattern;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};

198 199 200 201
inline bool operator==(QwtEventPattern::MousePattern b1,
                       QwtEventPattern::MousePattern  b2)
{
    return b1.button == b2.button && b1.state == b2.state;
pixhawk's avatar
pixhawk committed
202 203
}

204 205 206 207
inline bool operator==(QwtEventPattern::KeyPattern b1,
                       QwtEventPattern::KeyPattern  b2)
{
    return b1.key == b2.key && b1.state == b2.state;
pixhawk's avatar
pixhawk committed
208 209 210 211 212 213 214 215 216 217
}

#if defined(QWT_TEMPLATEDLL)
// MOC_SKIP_BEGIN
template class QWT_EXPORT QwtArray<QwtEventPattern::MousePattern>;
template class QWT_EXPORT QwtArray<QwtEventPattern::KeyPattern>;
// MOC_SKIP_END
#endif

#endif