source: ntrip/branches/BNC_2.11.0/qwt/qwt_event_pattern.h@ 9961

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