~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.1/src/qwt_event_pattern.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-05-26 10:26:31 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526102631-bp95mfccnrb957nx
Tags: 5.1.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 * 
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the Qwt License, Version 1.0
 
8
 *****************************************************************************/
 
9
 
 
10
#ifndef QWT_EVENT_PATTERN
 
11
#define QWT_EVENT_PATTERN 1
 
12
 
 
13
#include <qnamespace.h>
 
14
#include "qwt_array.h"
 
15
 
 
16
class QMouseEvent;
 
17
class QKeyEvent;
 
18
 
 
19
/*!
 
20
  \brief A collection of event patterns
 
21
 
 
22
  QwtEventPattern introduces an level of indirection for mouse and
 
23
  keyboard inputs. Those are represented by symbolic names, so 
 
24
  the application code can be configured by individual mappings.
 
25
 
 
26
  \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer
 
27
*/
 
28
class QWT_EXPORT QwtEventPattern
 
29
{
 
30
public:
 
31
    /*!
 
32
      \brief Symbolic mouse input codes
 
33
 
 
34
      The default initialization for 3 button mice is:
 
35
      - MouseSelect1\n
 
36
        Qt::LeftButton
 
37
      - MouseSelect2\n
 
38
        Qt::RightButton
 
39
      - MouseSelect3\n
 
40
        Qt::MidButton
 
41
      - MouseSelect4\n
 
42
        Qt::LeftButton + Qt::ShiftButton
 
43
      - MouseSelect5\n
 
44
        Qt::RightButton + Qt::ShiftButton
 
45
      - MouseSelect6\n
 
46
        Qt::MidButton + Qt::ShiftButton
 
47
 
 
48
      The default initialization for 2 button mice is:
 
49
      - MouseSelect1\n
 
50
        Qt::LeftButton
 
51
      - MouseSelect2\n
 
52
        Qt::RightButton
 
53
      - MouseSelect3\n
 
54
        Qt::LeftButton + Qt::AltButton
 
55
      - MouseSelect4\n
 
56
        Qt::LeftButton + Qt::ShiftButton
 
57
      - MouseSelect5\n
 
58
        Qt::RightButton + Qt::ShiftButton
 
59
      - MouseSelect6\n
 
60
        Qt::LeftButton + Qt::AltButton + Qt::ShiftButton
 
61
 
 
62
      The default initialization for 1 button mice is:
 
63
      - MouseSelect1\n
 
64
        Qt::LeftButton
 
65
      - MouseSelect2\n
 
66
        Qt::LeftButton + Qt::ControlButton
 
67
      - MouseSelect3\n
 
68
        Qt::LeftButton + Qt::AltButton
 
69
      - MouseSelect4\n
 
70
        Qt::LeftButton + Qt::ShiftButton
 
71
      - MouseSelect5\n
 
72
        Qt::LeftButton + Qt::ControlButton + Qt::ShiftButton
 
73
      - MouseSelect6\n
 
74
        Qt::LeftButton + Qt::AltButton + Qt::ShiftButton
 
75
 
 
76
      \sa initMousePattern()
 
77
    */
 
78
 
 
79
    enum MousePatternCode
 
80
    {
 
81
        MouseSelect1,
 
82
        MouseSelect2,
 
83
        MouseSelect3,
 
84
        MouseSelect4,
 
85
        MouseSelect5,
 
86
        MouseSelect6,
 
87
 
 
88
        MousePatternCount
 
89
    };
 
90
 
 
91
    /*!
 
92
      \brief Symbolic keyboard input codes
 
93
 
 
94
      Default initialization:
 
95
      - KeySelect1\n
 
96
        Qt::Key_Return
 
97
      - KeySelect2\n
 
98
        Qt::Key_Space
 
99
      - KeyAbort\n
 
100
        Qt::Key_Escape
 
101
 
 
102
      - KeyLeft\n
 
103
        Qt::Key_Left
 
104
      - KeyRight\n
 
105
        Qt::Key_Right
 
106
      - KeyUp\n
 
107
        Qt::Key_Up
 
108
      - KeyDown\n
 
109
        Qt::Key_Down
 
110
 
 
111
      - KeyUndo\n
 
112
        Qt::Key_Minus
 
113
      - KeyRedo\n
 
114
        Qt::Key_Plus
 
115
      - KeyHome\n
 
116
        Qt::Key_Escape
 
117
    */
 
118
    enum KeyPatternCode
 
119
    {
 
120
        KeySelect1,
 
121
        KeySelect2,
 
122
        KeyAbort,
 
123
 
 
124
        KeyLeft,
 
125
        KeyRight,
 
126
        KeyUp,
 
127
        KeyDown,
 
128
 
 
129
        KeyRedo,
 
130
        KeyUndo,
 
131
        KeyHome,
 
132
 
 
133
        KeyPatternCount
 
134
    };
 
135
 
 
136
    //! A pattern for mouse events
 
137
    class MousePattern
 
138
    {
 
139
    public:
 
140
        MousePattern(int btn = Qt::NoButton, int st = Qt::NoButton) 
 
141
        { 
 
142
            button = btn;
 
143
            state = st;
 
144
        }
 
145
 
 
146
        int button;
 
147
        int state;
 
148
    };
 
149
 
 
150
    //! A pattern for key events
 
151
    class KeyPattern
 
152
    {
 
153
    public:
 
154
        KeyPattern(int k = 0, int st = Qt::NoButton)    
 
155
        { 
 
156
            key = k; 
 
157
            state = st;
 
158
        }
 
159
 
 
160
        int key;
 
161
        int state;
 
162
    };
 
163
 
 
164
    QwtEventPattern();
 
165
    virtual ~QwtEventPattern();
 
166
 
 
167
    void initMousePattern(int numButtons);
 
168
    void initKeyPattern();
 
169
 
 
170
    void setMousePattern(uint pattern, int button, int state = Qt::NoButton);
 
171
    void setKeyPattern(uint pattern, int key, int state = Qt::NoButton);
 
172
 
 
173
    void setMousePattern(const QwtArray<MousePattern> &);
 
174
    void setKeyPattern(const QwtArray<KeyPattern> &);
 
175
 
 
176
    const QwtArray<MousePattern> &mousePattern() const;
 
177
    const QwtArray<KeyPattern> &keyPattern() const;
 
178
 
 
179
    QwtArray<MousePattern> &mousePattern();
 
180
    QwtArray<KeyPattern> &keyPattern();
 
181
 
 
182
    bool mouseMatch(uint pattern, const QMouseEvent *) const;
 
183
    bool keyMatch(uint pattern, const QKeyEvent *) const;
 
184
 
 
185
protected:
 
186
    virtual bool mouseMatch(const MousePattern &, const QMouseEvent *) const;
 
187
    virtual bool keyMatch(const KeyPattern &, const QKeyEvent *) const;
 
188
    
 
189
private:
 
190
 
 
191
#if defined(_MSC_VER)
 
192
#pragma warning(push)
 
193
#pragma warning(disable: 4251)
 
194
#endif
 
195
    QwtArray<MousePattern> d_mousePattern;
 
196
    QwtArray<KeyPattern> d_keyPattern;
 
197
#if defined(_MSC_VER)
 
198
#pragma warning(pop)
 
199
#endif
 
200
};
 
201
 
 
202
inline bool operator==(QwtEventPattern::MousePattern b1, 
 
203
   QwtEventPattern::MousePattern  b2)
 
204
 
205
    return b1.button == b2.button && b1.state == b2.state; 
 
206
}
 
207
 
 
208
inline bool operator==(QwtEventPattern::KeyPattern b1, 
 
209
   QwtEventPattern::KeyPattern  b2)
 
210
 
211
    return b1.key == b2.key && b1.state == b2.state; 
 
212
}
 
213
 
 
214
#if defined(QWT_TEMPLATEDLL)
 
215
// MOC_SKIP_BEGIN
 
216
template class QWT_EXPORT QwtArray<QwtEventPattern::MousePattern>;
 
217
template class QWT_EXPORT QwtArray<QwtEventPattern::KeyPattern>;
 
218
// MOC_SKIP_END
 
219
#endif
 
220
 
 
221
#endif