-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.h b/libopie2/opiecore/okeyconfigmanager.h index b861675..d0a6247 100644 --- a/libopie2/opiecore/okeyconfigmanager.h +++ b/libopie2/opiecore/okeyconfigmanager.h | |||
@@ -1,277 +1,280 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004 | 2 | * Copyright (C) 2004 |
3 | * LGPL v2 zecke@handhelds.org | 3 | * LGPL v2 zecke@handhelds.org |
4 | */ | 4 | */ |
5 | 5 | ||
6 | 6 | ||
7 | #ifndef ODP_KEY_MANAGER_WIDGET_H | 7 | #ifndef ODP_KEY_MANAGER_WIDGET_H |
8 | #define ODP_KEY_MANAGER_WIDGET_H | 8 | #define ODP_KEY_MANAGER_WIDGET_H |
9 | 9 | ||
10 | #include <opie2/oconfig.h> | 10 | #include <opie2/oconfig.h> |
11 | #include <opie2/odevice.h> | 11 | #include <opie2/odevice.h> |
12 | 12 | ||
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qpixmap.h> | 14 | #include <qpixmap.h> |
15 | #include <qcstring.h> | 15 | #include <qcstring.h> |
16 | #include <qvaluelist.h> | 16 | #include <qvaluelist.h> |
17 | 17 | ||
18 | namespace Opie { | 18 | namespace Opie { |
19 | namespace Core { | 19 | namespace Core { |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * \brief small class representing a Key with possible modifiers | 22 | * \brief small class representing a Key with possible modifiers |
23 | * This class holds information about key code and possible | 23 | * This class holds information about key code and possible |
24 | * modifier state. That is the lowest level of the key input | 24 | * modifier state. That is the lowest level of the key input |
25 | * functions. | 25 | * functions. |
26 | * There are also static methods to get special keys. | 26 | * There are also static methods to get special keys. |
27 | * OKeyPair will be used with \see OKeyConfigItem | 27 | * OKeyPair will be used with \see OKeyConfigItem |
28 | * | 28 | * |
29 | * @since 1.2 | 29 | * @since 1.2 |
30 | */ | 30 | */ |
31 | class OKeyPair { | 31 | class OKeyPair { |
32 | public: | 32 | public: |
33 | typedef QValueList<OKeyPair> List; | 33 | typedef QValueList<OKeyPair> List; |
34 | OKeyPair( int key = -1, int modifier = -1); | 34 | OKeyPair( int key = -1, int modifier = -1); |
35 | ~OKeyPair(); | 35 | ~OKeyPair(); |
36 | 36 | ||
37 | bool operator==( const OKeyPair& )const; | 37 | bool operator==( const OKeyPair& )const; |
38 | bool operator!=( const OKeyPair& )const; | 38 | bool operator!=( const OKeyPair& )const; |
39 | 39 | ||
40 | bool isEmpty()const; | 40 | bool isEmpty()const; |
41 | 41 | ||
42 | int keycode()const; | 42 | int keycode()const; |
43 | int modifier()const; | 43 | int modifier()const; |
44 | 44 | ||
45 | void setKeycode( int ); | 45 | void setKeycode( int ); |
46 | void setModifier( int ); | 46 | void setModifier( int ); |
47 | 47 | ||
48 | static OKeyPair returnKey(); | 48 | static OKeyPair returnKey(); |
49 | static OKeyPair leftArrowKey(); | 49 | static OKeyPair leftArrowKey(); |
50 | static OKeyPair rightArrowKey(); | 50 | static OKeyPair rightArrowKey(); |
51 | static OKeyPair upArrowKey(); | 51 | static OKeyPair upArrowKey(); |
52 | static OKeyPair downArrowKey(); | 52 | static OKeyPair downArrowKey(); |
53 | static OKeyPair emptyKey(); | 53 | static OKeyPair emptyKey(); |
54 | static OKeyPair::List hardwareKeys(); | 54 | static OKeyPair::List hardwareKeys(); |
55 | 55 | ||
56 | private: | 56 | private: |
57 | int m_key; | 57 | int m_key; |
58 | int m_mod; | 58 | int m_mod; |
59 | class Private; | 59 | class Private; |
60 | Private* d; | 60 | Private* d; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * A class to represent an OKeyPair. | 64 | * A class to represent an OKeyPair. |
65 | * It consists out of a Text exposed to the user, Config Key Item, | 65 | * It consists out of a Text exposed to the user, Config Key Item, |
66 | * Pixmap, A default OKeyPair and the set OKeyPair. | 66 | * Pixmap, A default OKeyPair and the set OKeyPair. |
67 | * You can also pass an id to it | 67 | * You can also pass an id to it |
68 | * | 68 | * |
69 | * @since 1.1.2 | 69 | * @since 1.1.2 |
70 | */ | 70 | */ |
71 | class OKeyConfigItem { | 71 | class OKeyConfigItem { |
72 | friend class OKeyConfigManager; | 72 | friend class OKeyConfigManager; |
73 | public: | 73 | public: |
74 | typedef QValueList<OKeyConfigItem> List; | 74 | typedef QValueList<OKeyConfigItem> List; |
75 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 75 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
76 | const QPixmap& symbol = QPixmap(), | 76 | const QPixmap& symbol = QPixmap(), |
77 | int id = -1, | 77 | int id = -1, |
78 | const OKeyPair& def = OKeyPair::emptyKey(), | 78 | const OKeyPair& def = OKeyPair::emptyKey(), |
79 | QObject *caller = 0, const char* slot = 0); | 79 | QObject *caller = 0, const char* slot = 0); |
80 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 80 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
81 | ~OKeyConfigItem(); | 81 | ~OKeyConfigItem(); |
82 | 82 | ||
83 | bool operator==( const OKeyConfigItem& )const; | 83 | bool operator==( const OKeyConfigItem& )const; |
84 | bool operator!=( const OKeyConfigItem& )const; | 84 | bool operator!=( const OKeyConfigItem& )const; |
85 | 85 | ||
86 | QString text()const; | 86 | QString text()const; |
87 | QPixmap pixmap()const; | 87 | QPixmap pixmap()const; |
88 | int id()const; | 88 | int id()const; |
89 | 89 | ||
90 | 90 | ||
91 | 91 | ||
92 | OKeyPair keyPair()const; | 92 | OKeyPair keyPair()const; |
93 | OKeyPair defaultKeyPair()const; | 93 | OKeyPair defaultKeyPair()const; |
94 | QCString configKey()const; | 94 | QCString configKey()const; |
95 | 95 | ||
96 | 96 | ||
97 | void setText( const QString& text ); | 97 | void setText( const QString& text ); |
98 | void setPixmap( const QPixmap& ); | 98 | void setPixmap( const QPixmap& ); |
99 | void setKeyPair( const OKeyPair& ); | 99 | void setKeyPair( const OKeyPair& ); |
100 | void setDefaultKeyPair( const OKeyPair& ); | 100 | void setDefaultKeyPair( const OKeyPair& ); |
101 | 101 | ||
102 | bool isEmpty()const; | 102 | bool isEmpty()const; |
103 | 103 | ||
104 | protected: | 104 | protected: |
105 | QObject *object()const; | 105 | QObject *object()const; |
106 | QCString slot()const; | 106 | QCString slot()const; |
107 | void setId( int id ); | 107 | void setId( int id ); |
108 | void setConfigKey( const QCString& ); | 108 | void setConfigKey( const QCString& ); |
109 | 109 | ||
110 | private: | 110 | private: |
111 | QString m_text; | 111 | QString m_text; |
112 | QCString m_config; | 112 | QCString m_config; |
113 | QPixmap m_pix; | 113 | QPixmap m_pix; |
114 | int m_id; | 114 | int m_id; |
115 | OKeyPair m_key; | 115 | OKeyPair m_key; |
116 | OKeyPair m_def; | 116 | OKeyPair m_def; |
117 | QObject *m_obj; | 117 | QObject *m_obj; |
118 | QCString m_str; | 118 | QCString m_str; |
119 | class Private; | 119 | class Private; |
120 | Private *d; | 120 | Private *d; |
121 | }; | 121 | }; |
122 | 122 | ||
123 | 123 | ||
124 | 124 | ||
125 | /** | 125 | /** |
126 | * \brief A manager to load and save Key Actions and get notified | 126 | * \brief A manager to load and save Key Actions and get notified |
127 | * This is the Manager for KeyActions. | 127 | * This is the Manager for KeyActions. |
128 | * You can say from which config and group to read data, to grab the | 128 | * You can say from which config and group to read data, to grab the |
129 | * keyboard to handle hardware keys, you can supply a blacklist of | 129 | * keyboard to handle hardware keys, you can supply a blacklist of |
130 | * keys which should not be used by allowed to be used. | 130 | * keys which should not be used by allowed to be used. |
131 | * You can even pass this manager to a Widget to do the configuration for you. | 131 | * You can even pass this manager to a Widget to do the configuration for you. |
132 | * You need to add OKeyConfigItem for your keys and then issue a load() to | 132 | * You need to add OKeyConfigItem for your keys and then issue a load() to |
133 | * read the Key information. | 133 | * read the Key information. |
134 | * You can either handle the QKeyEvent yourself and ask this class if it is | 134 | * You can either handle the QKeyEvent yourself and ask this class if it is |
135 | * handled by your action and let give you the action. Or you can install | 135 | * handled by your action and let give you the action. Or you can install |
136 | * the event filter and get a signal. | 136 | * the event filter and get a signal. |
137 | * You need to load and save yourself! | 137 | * You need to load and save yourself! |
138 | * | 138 | * |
139 | * Again if you want to extend it and I missed a virtual, tell me so I can improve (zecke@handhelds.org) | ||
140 | * | ||
139 | * @since 1.1.2 | 141 | * @since 1.1.2 |
140 | */ | 142 | */ |
141 | class OKeyConfigManager : public QObject { | 143 | class OKeyConfigManager : public QObject { |
142 | Q_OBJECT | 144 | Q_OBJECT |
143 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | 145 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; |
144 | public: | 146 | public: |
147 | enum EventMask { | ||
148 | MaskPressed = 0x1, | ||
149 | MaskReleased = 0x2, | ||
150 | }; | ||
151 | |||
145 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | 152 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, |
146 | const QString& group = QString::null, | 153 | const QString& group = QString::null, |
147 | const OKeyPair::List &block = OKeyPair::List(), | 154 | const OKeyPair::List &block = OKeyPair::List(), |
148 | bool grabkeyboard = false, QObject * par = 0, | 155 | bool grabkeyboard = false, QObject * par = 0, |
149 | const char* name = 0 ); | 156 | const char* name = 0 ); |
150 | ~OKeyConfigManager(); | 157 | virtual ~OKeyConfigManager(); |
151 | 158 | ||
152 | void load(); | 159 | virtual void load(); |
153 | void save(); | 160 | virtual void save(); |
154 | 161 | ||
155 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | 162 | virtual OKeyConfigItem handleKeyEvent( QKeyEvent* ); |
156 | int handleKeyEventId( QKeyEvent* ); | 163 | int handleKeyEventId( QKeyEvent* ); |
157 | 164 | ||
158 | void addKeyConfig( const OKeyConfigItem& ); | 165 | void addKeyConfig( const OKeyConfigItem& ); |
159 | void removeKeyConfig( const OKeyConfigItem& ); | 166 | void removeKeyConfig( const OKeyConfigItem& ); |
160 | void clearKeyConfig(); | 167 | void clearKeyConfig(); |
161 | 168 | ||
162 | void addToBlackList( const OKeyPair& ); | 169 | void addToBlackList( const OKeyPair& ); |
163 | void removeFromBlackList( const OKeyPair& ); | 170 | void removeFromBlackList( const OKeyPair& ); |
164 | void clearBlackList(); | 171 | void clearBlackList(); |
165 | OKeyPair::List blackList()const; | 172 | OKeyPair::List blackList()const; |
166 | 173 | ||
167 | void handleWidget( QWidget* ); | 174 | void handleWidget( QWidget* ); |
168 | 175 | ||
169 | bool eventFilter( QObject*, QEvent* ); | 176 | bool eventFilter( QObject*, QEvent* ); |
170 | 177 | ||
171 | /** | 178 | /** |
172 | * Sets the event mask flags aMask. | 179 | * Sets the event mask flags aMask. |
173 | * | 180 | * |
174 | * aMask is a combination of OKeyConfigManager::EventMask | 181 | * aMask is a combination of OKeyConfigManager::EventMask |
175 | * | 182 | * |
176 | * @see eventMask(), testEventMask(), addEventMask(), clearEventMask() | 183 | * @see eventMask(), testEventMask(), addEventMask(), clearEventMask() |
177 | */ | 184 | */ |
178 | void setEventMask(uint aMask); | 185 | void setEventMask(uint aMask); |
179 | /** | 186 | /** |
180 | * Returns the event mask flags set. | 187 | * Returns the event mask flags set. |
181 | * | 188 | * |
182 | * aMask is a combination of OKeyConfigManager::EventMask | 189 | * aMask is a combination of OKeyConfigManager::EventMask |
183 | * | 190 | * |
184 | * @see setEventMask(), testEventMask(), addEventMask(), clearEventMask() | 191 | * @see setEventMask(), testEventMask(), addEventMask(), clearEventMask() |
185 | */ | 192 | */ |
186 | uint eventMask()const; | 193 | uint eventMask()const; |
187 | /** | 194 | /** |
188 | * Test if the event mask flag aMask is set. | 195 | * Test if the event mask flag aMask is set. |
189 | * | 196 | * |
190 | * @param aMask one of OKeyConfigManager::EventMask | 197 | * @param aMask one of OKeyConfigManager::EventMask |
191 | * | 198 | * |
192 | * @see eventMask(), setEventMask(), addEventMask(), clearEventMask() | 199 | * @see eventMask(), setEventMask(), addEventMask(), clearEventMask() |
193 | */ | 200 | */ |
194 | bool testEventMask(uint aMask); | 201 | bool testEventMask(uint aMask); |
195 | /** | 202 | /** |
196 | * Add the event mask flag aMask. | 203 | * Add the event mask flag aMask. |
197 | * | 204 | * |
198 | * @param aMask one of OKeyConfigManager::EventMask | 205 | * @param aMask one of OKeyConfigManager::EventMask |
199 | * | 206 | * |
200 | * @see eventMask(), setEventMask(), addEventMask(), clearEventMask() | 207 | * @see eventMask(), setEventMask(), addEventMask(), clearEventMask() |
201 | */ | 208 | */ |
202 | void addEventMask(uint aMask); | 209 | void addEventMask(uint aMask); |
203 | /** | 210 | /** |
204 | * Clears the event mask flag aMask. | 211 | * Clears the event mask flag aMask. |
205 | * | 212 | * |
206 | * @param aMask is one of OKeyConfigManager::EventMask | 213 | * @param aMask is one of OKeyConfigManager::EventMask |
207 | * | 214 | * |
208 | * @see eventMask(), testEventMask(), addEventMask(), setEventMask() | 215 | * @see eventMask(), testEventMask(), addEventMask(), setEventMask() |
209 | */ | 216 | */ |
210 | void clearEventMask(uint aMask); | 217 | void clearEventMask(uint aMask); |
211 | 218 | ||
212 | OKeyConfigItem::List keyConfigList()const; | 219 | OKeyConfigItem::List keyConfigList()const; |
213 | 220 | ||
214 | enum EventMask { | ||
215 | MaskPressed = 0x1, | ||
216 | MaskReleased = 0x2, | ||
217 | }; | ||
218 | signals: | 221 | signals: |
219 | /** | 222 | /** |
220 | * The Signals are triggered on KeyPress and KeyRelease! | 223 | * The Signals are triggered on KeyPress and KeyRelease! |
221 | * You can check the isDown of the QKeyEvent | 224 | * You can check the isDown of the QKeyEvent |
222 | * @see QKeyEvent | 225 | * @see QKeyEvent |
223 | */ | 226 | */ |
224 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); | 227 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); |
225 | 228 | ||
226 | /** | 229 | /** |
227 | * This Signal correspondents to the OKeyConfigItem slot | 230 | * This Signal correspondents to the OKeyConfigItem slot |
228 | * and object | 231 | * and object |
229 | * | 232 | * |
230 | * @see OKeyConfigItem::slot | 233 | * @see OKeyConfigItem::slot |
231 | * @see OKeyConfigItem::object | 234 | * @see OKeyConfigItem::object |
232 | */ | 235 | */ |
233 | void actionActivated( QWidget* par, QKeyEvent* key); | 236 | void actionActivated( QWidget* par, QKeyEvent* key); |
234 | 237 | ||
235 | private: | 238 | private: |
236 | OKeyConfigItem::List keyList( int ); | 239 | OKeyConfigItem::List keyList( int ); |
237 | OKeyConfigItem::List m_keys; | 240 | OKeyConfigItem::List m_keys; |
238 | QValueList<QWidget*> m_widgets; | 241 | QValueList<QWidget*> m_widgets; |
239 | Opie::Core::OConfig *m_conf; | 242 | Opie::Core::OConfig *m_conf; |
240 | QString m_group; | 243 | QString m_group; |
241 | OKeyPair::List m_blackKeys; | 244 | OKeyPair::List m_blackKeys; |
242 | bool m_grab : 1; | 245 | bool m_grab : 1; |
243 | OKeyMapConfigPrivate *m_map; | 246 | OKeyMapConfigPrivate *m_map; |
244 | class Private; | 247 | class Private; |
245 | Private *d; | 248 | Private *d; |
246 | uint m_event_mask; | 249 | uint m_event_mask; |
247 | }; | 250 | }; |
248 | 251 | ||
249 | inline bool OKeyConfigManager::testEventMask(uint aMask) | 252 | inline bool OKeyConfigManager::testEventMask(uint aMask) |
250 | { | 253 | { |
251 | return (m_event_mask&aMask)!=0; | 254 | return (m_event_mask&aMask)!=0; |
252 | } | 255 | } |
253 | 256 | ||
254 | inline void OKeyConfigManager::addEventMask(uint aMask) | 257 | inline void OKeyConfigManager::addEventMask(uint aMask) |
255 | { | 258 | { |
256 | m_event_mask |= aMask; | 259 | m_event_mask |= aMask; |
257 | } | 260 | } |
258 | 261 | ||
259 | inline void OKeyConfigManager::clearEventMask(uint aMask) | 262 | inline void OKeyConfigManager::clearEventMask(uint aMask) |
260 | { | 263 | { |
261 | m_event_mask &= ~aMask; | 264 | m_event_mask &= ~aMask; |
262 | } | 265 | } |
263 | 266 | ||
264 | inline void OKeyConfigManager::setEventMask(uint aMask) | 267 | inline void OKeyConfigManager::setEventMask(uint aMask) |
265 | { | 268 | { |
266 | m_event_mask = aMask; | 269 | m_event_mask = aMask; |
267 | } | 270 | } |
268 | 271 | ||
269 | inline uint OKeyConfigManager::eventMask()const | 272 | inline uint OKeyConfigManager::eventMask()const |
270 | { | 273 | { |
271 | return m_event_mask; | 274 | return m_event_mask; |
272 | } | 275 | } |
273 | 276 | ||
274 | } | 277 | } |
275 | } | 278 | } |
276 | 279 | ||
277 | #endif | 280 | #endif |