-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 311 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 10 |
2 files changed, 311 insertions, 10 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index d52a55f..4482754 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,408 +1,705 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | 2 | ||
3 | 3 | ||
4 | 4 | ||
5 | 5 | ||
6 | using namespace Opie::Ui; | 6 | using namespace Opie::Ui; |
7 | 7 | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * The default Constructor of a OKeyPair. | 10 | * The default Constructor of a OKeyPair. |
11 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | 11 | * A Key and a Modifier ( Alt/Shift/Ctrl ) |
12 | * needs to be supplied. | 12 | * needs to be supplied. |
13 | * Use Qt::Key for the information. | 13 | * Use Qt::Key for the information. |
14 | * The default arguments create an Empty OKeyPair. If you | 14 | * The default arguments create an Empty OKeyPair. If you |
15 | * want to get an empty OKeyPair use the static method for getting | 15 | * want to get an empty OKeyPair use the static method for getting |
16 | * the emptyKey() | 16 | * the emptyKey() |
17 | * | 17 | * |
18 | * @see OKeyPair OKeyPair::emptyKey() | 18 | * @see OKeyPair OKeyPair::emptyKey() |
19 | */ | 19 | */ |
20 | OKeyPair::OKeyPair( int key, int mod ) | 20 | OKeyPair::OKeyPair( int key, int mod ) |
21 | : m_key( key ), m_mod( mod ) | 21 | : m_key( key ), m_mod( mod ) |
22 | {} | 22 | {} |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The destructor | 25 | * The destructor |
26 | */ | 26 | */ |
27 | OKeyPair::~OKeyPair() {} | 27 | OKeyPair::~OKeyPair() {} |
28 | 28 | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Is this OKeyPair empty/valid? | 31 | * Is this OKeyPair empty/valid? |
32 | */ | 32 | */ |
33 | bool OKeyPair::isEmpty()const { | 33 | bool OKeyPair::isEmpty()const { |
34 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | 34 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); |
35 | } | 35 | } |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | 38 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. |
39 | * | 39 | * |
40 | * @see Qt::Key | 40 | * @see Qt::Key |
41 | * @see setKey | 41 | * @see setKey |
42 | */ | 42 | */ |
43 | int OKeyPair::keycode()const { | 43 | int OKeyPair::keycode()const { |
44 | return m_key; | 44 | return m_key; |
45 | } | 45 | } |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * get the modifier key for this OKeyPair. The Modifier State relates | 48 | * get the modifier key for this OKeyPair. The Modifier State relates |
49 | * to the Qt::Modifier | 49 | * to the Qt::ButtonState |
50 | * | 50 | * |
51 | * @see Qt::Modifier | 51 | * @see Qt::ButtonState |
52 | * @see setModifier | 52 | * @see setModifier |
53 | */ | 53 | */ |
54 | int OKeyPair::modifier()const { | 54 | int OKeyPair::modifier()const { |
55 | return m_mod; | 55 | return m_mod; |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Set the keycode | 60 | * Set the keycode |
61 | * @param key The Keycode to set | 61 | * @param key The Keycode to set |
62 | * | 62 | * |
63 | * @see keycode() | 63 | * @see keycode() |
64 | * @see Qt::Key | 64 | * @see Qt::Key |
65 | */ | 65 | */ |
66 | void OKeyPair::setKeycode( int key ) { | 66 | void OKeyPair::setKeycode( int key ) { |
67 | 67 | ||
68 | } | 68 | } |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Set the modifier key | 71 | * Set the modifier key |
72 | * | 72 | * |
73 | * @param the Modifier key | 73 | * @param the Modifier key |
74 | * @see Qt::Modifier | 74 | * @see Qt::ButtonState |
75 | * @see modifier() | 75 | * @see modifier() |
76 | */ | 76 | */ |
77 | void OKeyPair::setModifier( int mod ) { | 77 | void OKeyPair::setModifier( int mod ) { |
78 | 78 | ||
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Return an OKeyPair for the Return Key without any modifier. | 82 | * Return an OKeyPair for the Return Key without any modifier. |
83 | */ | 83 | */ |
84 | OKeyPair OKeyPair::returnKey() { | 84 | OKeyPair OKeyPair::returnKey() { |
85 | return OKeyPair( Qt::Key_Return, 0 ); | 85 | return OKeyPair( Qt::Key_Return, 0 ); |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Return an OKeyPair for the Left Arrow Key | 89 | * Return an OKeyPair for the Left Arrow Key |
90 | * without any modifier Key | 90 | * without any modifier Key |
91 | */ | 91 | */ |
92 | OKeyPair OKeyPair::leftArrowKey() { | 92 | OKeyPair OKeyPair::leftArrowKey() { |
93 | return OKeyPair( Qt::Key_Left, 0 ); | 93 | return OKeyPair( Qt::Key_Left, 0 ); |
94 | } | 94 | } |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * Return an OKeyPair for the Right Arrow Key | 97 | * Return an OKeyPair for the Right Arrow Key |
98 | * without any modifier Key | 98 | * without any modifier Key |
99 | */ | 99 | */ |
100 | OKeyPair OKeyPair::rightArrowKey() { | 100 | OKeyPair OKeyPair::rightArrowKey() { |
101 | return OKeyPair( Qt::Key_Right, 0 ); | 101 | return OKeyPair( Qt::Key_Right, 0 ); |
102 | } | 102 | } |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Return an OKeyPair for the Up Arrow Key | 105 | * Return an OKeyPair for the Up Arrow Key |
106 | * without any modifier Key | 106 | * without any modifier Key |
107 | */ | 107 | */ |
108 | OKeyPair OKeyPair::upArrowKey() { | 108 | OKeyPair OKeyPair::upArrowKey() { |
109 | return OKeyPair( Qt::Key_Up, 0 ); | 109 | return OKeyPair( Qt::Key_Up, 0 ); |
110 | } | 110 | } |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Return an OKeyPair for the Down Arrow Key | 113 | * Return an OKeyPair for the Down Arrow Key |
114 | * without any modifier Key | 114 | * without any modifier Key |
115 | */ | 115 | */ |
116 | OKeyPair OKeyPair::downArrowKey() { | 116 | OKeyPair OKeyPair::downArrowKey() { |
117 | return OKeyPair( Qt::Key_Down, 0 ); | 117 | return OKeyPair( Qt::Key_Down, 0 ); |
118 | } | 118 | } |
119 | 119 | ||
120 | /** | 120 | /** |
121 | * Return an Empty OKeyPair | 121 | * Return an Empty OKeyPair |
122 | */ | 122 | */ |
123 | OKeyPair OKeyPair::emptyKey() { | 123 | OKeyPair OKeyPair::emptyKey() { |
124 | return OKeyPair; | 124 | return OKeyPair; |
125 | } | 125 | } |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * This functions uses the Opie::Core::ODevice::buttons | 128 | * This functions uses the Opie::Core::ODevice::buttons |
129 | * for OKeyPairList | 129 | * for OKeyPairList |
130 | * | 130 | * |
131 | * @see Opie::Core::ODevice | 131 | * @see Opie::Core::ODevice |
132 | * @see Opie::Core::ODeviceButton | 132 | * @see Opie::Core::ODeviceButton |
133 | * @see Opie::Core::ODevice::button | 133 | * @see Opie::Core::ODevice::button |
134 | */ | 134 | */ |
135 | OKeyPairList OKeyPair::hardwareKeys() { | 135 | OKeyPairList OKeyPair::hardwareKeys() { |
136 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | 136 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); |
137 | OKeyPairList lst; | 137 | OKeyPairList lst; |
138 | 138 | ||
139 | for ( QValueList<Opie::Core::ODeviceButton>::Iterator it = but.begin(); | 139 | for ( QValueList<Opie::Core::ODeviceButton>::Iterator it = but.begin(); |
140 | it != but.end(); ++it ) | 140 | it != but.end(); ++it ) |
141 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | 141 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); |
142 | 142 | ||
143 | 143 | ||
144 | return lst; | 144 | return lst; |
145 | } | 145 | } |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Equals operator. Check if two OKeyPairs have the same key and modifier | ||
149 | * @see operator!= | ||
150 | */ | ||
151 | bool OKeyPair::operator==( const OKeyPair& pair) { | ||
152 | if ( m_key != pair.m_key ) return false; | ||
153 | if ( m_mod != pair.m_mod ) return false; | ||
154 | |||
155 | return true; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * Not equal operator. calls the equal operator internally | ||
160 | */ | ||
161 | bool OKeyPair::operator!=( const OKeyPair& pair) { | ||
162 | return !(*this == pair); | ||
163 | } | ||
164 | |||
165 | |||
166 | /** | ||
148 | * The normal Constructor to create a OKeyConfigItem | 167 | * The normal Constructor to create a OKeyConfigItem |
149 | * | 168 | * |
150 | * You can set the the key paramater of this item but if | 169 | * You can set the the key paramater of this item but if |
151 | * you use this item with the OKeyConfigManager your setting | 170 | * you use this item with the OKeyConfigManager your setting |
152 | * will be overwritten. | 171 | * will be overwritten. |
153 | * | 172 | * |
154 | * @param text The text exposed to the user | 173 | * @param text The text exposed to the user |
155 | * @param config_key The key used in the config | 174 | * @param config_key The key used in the config |
156 | * @param pix A Pixmap associated with this Item | 175 | * @param pix A Pixmap associated with this Item |
157 | * @param key The OKeyPair used | 176 | * @param key The OKeyPair used |
158 | * @param def The OKeyPair used as default | 177 | * @param def The OKeyPair used as default |
159 | * | 178 | * |
160 | */ | 179 | */ |
161 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | 180 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, |
162 | const QPixmap& pix, int id, const OKeyPair& def, | 181 | const QPixmap& pix, int id, const OKeyPair& def, |
163 | const OKeyPair& key) | 182 | const OKeyPair& key) |
164 | : m_text( text ), m_config( config_key ), m_pix( pix ), | 183 | : m_text( text ), m_config( config_key ), m_pix( pix ), |
165 | m_id( id ), m_def( def ), m_key( key ) {} | 184 | m_id( id ), m_def( def ), m_key( key ) {} |
166 | 185 | ||
167 | /** | 186 | /** |
168 | * A special Constructor for converting from an Opie::Core::ODeviceButton | 187 | * A special Constructor for converting from an Opie::Core::ODeviceButton |
169 | * delivered by Opie::Core::ODevice::buttons() | 188 | * delivered by Opie::Core::ODevice::buttons() |
170 | * There is no Config Key set and both default key and key are set | 189 | * There is no Config Key set and both default key and key are set |
171 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | 190 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier |
172 | * | 191 | * |
173 | * @see Opie::Core::ODevice | 192 | * @see Opie::Core::ODevice |
174 | * @see Opie::Core::ODeviceButton | 193 | * @see Opie::Core::ODeviceButton |
175 | * @see Opie::Core::ODevice::buttons() | 194 | * @see Opie::Core::ODevice::buttons() |
176 | */ | 195 | */ |
177 | OKeyConfigItem::OKeyConfigItem( Opie::Core::ODeviceButton& b ) | 196 | OKeyConfigItem::OKeyConfigItem( Opie::Core::ODeviceButton& b ) |
178 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ) | 197 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ) |
179 | m_def( OKeyPair( b.keycode(), 0 ) ), m_key( OKeyPair( b.keycode(), 0 ) ) | 198 | m_def( OKeyPair( b.keycode(), 0 ) ), m_key( OKeyPair( b.keycode(), 0 ) ) |
180 | {} | 199 | {} |
181 | 200 | ||
182 | 201 | ||
183 | /** | 202 | /** |
184 | * Destructor | 203 | * Destructor |
185 | */ | 204 | */ |
186 | OKeyConfigItem::~OKeyConfigItem() {} | 205 | OKeyConfigItem::~OKeyConfigItem() {} |
187 | 206 | ||
188 | 207 | ||
189 | /** | 208 | /** |
190 | * The text exposed to the user | 209 | * The text exposed to the user |
191 | * | 210 | * |
192 | * @see setText | 211 | * @see setText |
193 | */ | 212 | */ |
194 | QString OKeyConfigItem::text()const { | 213 | QString OKeyConfigItem::text()const { |
195 | return m_text; | 214 | return m_text; |
196 | } | 215 | } |
197 | 216 | ||
198 | /** | 217 | /** |
199 | * The pixmap shown to the user for your action/key | 218 | * The pixmap shown to the user for your action/key |
200 | * | 219 | * |
201 | * @see setPixmap | 220 | * @see setPixmap |
202 | */ | 221 | */ |
203 | QPixmap OKeyConfigItem::pixmap()const { | 222 | QPixmap OKeyConfigItem::pixmap()const { |
204 | return m_pix; | 223 | return m_pix; |
205 | } | 224 | } |
206 | 225 | ||
207 | /** | 226 | /** |
208 | * Return the OKeyPair this OKeyConfigItem is configured for. | 227 | * Return the OKeyPair this OKeyConfigItem is configured for. |
209 | * | 228 | * |
210 | * @see setKeyPair | 229 | * @see setKeyPair |
211 | */ | 230 | */ |
212 | OKeyPair OKeyConfigItem::keyPair()const { | 231 | OKeyPair OKeyConfigItem::keyPair()const { |
213 | return m_key; | 232 | return m_key; |
214 | } | 233 | } |
215 | 234 | ||
216 | /** | 235 | /** |
217 | * Return the default OKeyPair | 236 | * Return the default OKeyPair |
218 | * @see setDefaultKeyPair | 237 | * @see setDefaultKeyPair |
219 | */ | 238 | */ |
220 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | 239 | OKeyPair OKeyConfigItem::defaultKeyPair()const { |
221 | return m_def; | 240 | return m_def; |
222 | } | 241 | } |
223 | 242 | ||
224 | 243 | ||
225 | /** | 244 | /** |
226 | * Return the Id you assigned to this item. | 245 | * Return the Id you assigned to this item. |
227 | * setting is only possible by the constructor | 246 | * setting is only possible by the constructor |
228 | */ | 247 | */ |
229 | int OKeyConfigItem::id()const{ | 248 | int OKeyConfigItem::id()const{ |
230 | return m_id; | 249 | return m_id; |
231 | } | 250 | } |
232 | 251 | ||
233 | /** | 252 | /** |
234 | * reutrn the Config Key. Setting it is only possible | 253 | * reutrn the Config Key. Setting it is only possible |
235 | * by the constructor | 254 | * by the constructor |
236 | */ | 255 | */ |
237 | QCString OKeyConfigItem::configKey()const { | 256 | QCString OKeyConfigItem::configKey()const { |
238 | return m_config; | 257 | return m_config; |
239 | } | 258 | } |
240 | 259 | ||
241 | /** | 260 | /** |
242 | * Set the text | 261 | * Set the text |
243 | * | 262 | * |
244 | * @param text Set the Text of this Action to text | 263 | * @param text Set the Text of this Action to text |
245 | * @see text() | 264 | * @see text() |
246 | */ | 265 | */ |
247 | void OKeyConfigItem::setText( const QString& text ) { | 266 | void OKeyConfigItem::setText( const QString& text ) { |
248 | m_text = text; | 267 | m_text = text; |
249 | } | 268 | } |
250 | 269 | ||
251 | /** | 270 | /** |
252 | * Set the pixmap of this action | 271 | * Set the pixmap of this action |
253 | * | 272 | * |
254 | * @param pix The Pixmap to set | 273 | * @param pix The Pixmap to set |
255 | * @see pixmap() | 274 | * @see pixmap() |
256 | */ | 275 | */ |
257 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | 276 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { |
258 | m_pix = pix; | 277 | m_pix = pix; |
259 | } | 278 | } |
260 | 279 | ||
261 | /** | 280 | /** |
262 | * Set the KeyPair the OKeyConfigItem uses. | 281 | * Set the KeyPair the OKeyConfigItem uses. |
263 | * Your set Key could get overwritten if you use | 282 | * Your set Key could get overwritten if you use |
264 | * the manager or GUI to configure the key | 283 | * the manager or GUI to configure the key |
265 | * | 284 | * |
266 | * @param key Set the OKeyPair used | 285 | * @param key Set the OKeyPair used |
267 | * @see keyPair() | 286 | * @see keyPair() |
268 | */ | 287 | */ |
269 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | 288 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { |
270 | m_key = key; | 289 | m_key = key; |
271 | } | 290 | } |
272 | 291 | ||
273 | /** | 292 | /** |
274 | * Set the default KeyPair. | 293 | * Set the default KeyPair. |
275 | * | 294 | * |
276 | * @param key The default keypair | 295 | * @param key The default keypair |
277 | * @see defaultKeyPair() | 296 | * @see defaultKeyPair() |
278 | */ | 297 | */ |
279 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | 298 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { |
280 | m_def = key; | 299 | m_def = key; |
281 | } | 300 | } |
282 | 301 | ||
283 | /** | 302 | /** |
284 | * @internal | 303 | * @internal |
285 | */ | 304 | */ |
286 | void OKeyConfigItem::setConfigKey( const QCString& str) { | 305 | void OKeyConfigItem::setConfigKey( const QCString& str) { |
287 | m_config = str; | 306 | m_config = str; |
288 | m_config.detach(); | 307 | m_config.detach(); |
289 | } | 308 | } |
290 | 309 | ||
291 | /** | 310 | /** |
292 | * @internal | 311 | * @internal |
293 | */ | 312 | */ |
294 | void OKeyConfigItem::setId( int id ) { | 313 | void OKeyConfigItem::setId( int id ) { |
295 | m_id = id; | 314 | m_id = id; |
296 | } | 315 | } |
297 | 316 | ||
298 | /** | 317 | /** |
299 | * If the item is not configured isEmpty() will return true | 318 | * If the item is not configured isEmpty() will return true |
300 | * It is empty if no text is present and no default | 319 | * It is empty if no text is present and no default |
301 | * and no configured key | 320 | * and no configured key |
302 | */ | 321 | */ |
303 | bool OKeyConfigItem::isEmpty()const { | 322 | bool OKeyConfigItem::isEmpty()const { |
304 | if ( !m_def.isEmpty() ) return false; | 323 | if ( !m_def.isEmpty() ) return false; |
305 | if ( !m_key.isEmpty() ) return false; | 324 | if ( !m_key.isEmpty() ) return false; |
306 | if ( !m_text.isEmpty() ) return false; | 325 | if ( !m_text.isEmpty() ) return false; |
307 | 326 | ||
308 | return true; | 327 | return true; |
309 | } | 328 | } |
310 | 329 | ||
311 | /** | 330 | /** |
331 | * Check if the KeyPairs are the same | ||
332 | */ | ||
333 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { | ||
334 | if ( isEmpty() == conf.isEmpty() ) return true; | ||
335 | else if ( isEmpty() != conf.isEmpty() ) return false; | ||
336 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | ||
337 | |||
338 | if ( m_id != conf.m_id ) return false; | ||
339 | if ( m_text != conf.m_text ) return false; | ||
340 | if ( m_pix != conf.m_pix ) return false; | ||
341 | if ( m_key != conf.m_key ) return false; | ||
342 | if ( m_def != conf.m_def ) return false; | ||
343 | |||
344 | return true; | ||
345 | |||
346 | } | ||
347 | |||
348 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | ||
349 | return !( *this == conf ); | ||
350 | } | ||
351 | |||
352 | /** | ||
312 | * \brief c'tor | 353 | * \brief c'tor |
313 | * The Constructor for a OKeyConfigManager | 354 | * The Constructor for a OKeyConfigManager |
314 | * | 355 | * |
315 | * You can use this manager in multiple ways. Either make it handle | 356 | * You can use this manager in multiple ways. Either make it handle |
316 | * QKeyEvents | 357 | * QKeyEvents |
317 | * | 358 | * |
318 | * \code | 359 | * \code |
319 | * Opie::Core::Config conf = oApp->config(); | 360 | * Opie::Core::Config conf = oApp->config(); |
320 | * Opie::Ui::OKeyPairList blackList; | 361 | * Opie::Ui::OKeyPairList blackList; |
321 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | 362 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); |
322 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | 363 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); |
323 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | 364 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, |
324 | * false); | 365 | * false); |
325 | * QListView *view = new QListView(); | 366 | * QListView *view = new QListView(); |
326 | * manager->handleWidget(view); | 367 | * manager->handleWidget(view); |
327 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | 368 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); |
328 | * manager->load(); | 369 | * manager->load(); |
329 | * | 370 | * |
330 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | 371 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), |
331 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | 372 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); |
332 | * | 373 | * |
333 | * .... | 374 | * .... |
334 | * | 375 | * |
335 | * void update(){ | 376 | * void update(){ |
336 | * QDialog diag(true); | 377 | * QDialog diag(true); |
337 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | 378 | * QHBoxLayout *lay = new QHBoxLayout(&diag); |
338 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | 379 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); |
339 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | 380 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); |
340 | * lay->addWidget(wid); | 381 | * lay->addWidget(wid); |
341 | * if(QPEApplication::execDialog( &diag)== QDialog::Accept){ | 382 | * if(QPEApplication::execDialog( &diag)== QDialog::Accept){ |
342 | * wid->save(); | 383 | * wid->save(); |
343 | * } | 384 | * } |
344 | * } | 385 | * } |
345 | * | 386 | * |
346 | * .... | 387 | * .... |
347 | * MyListView::keyPressEvent( QKeyEvent* e ){ | 388 | * MyListView::keyPressEvent( QKeyEvent* e ){ |
348 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | 389 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); |
349 | * if(!item.isEmpty() ){ | 390 | * if(!item.isEmpty() ){ |
350 | * switch(item.id()){ | 391 | * switch(item.id()){ |
351 | * case My_Delete_Key: | 392 | * case My_Delete_Key: |
352 | * break; | 393 | * break; |
353 | * } | 394 | * } |
354 | * } | 395 | * } |
355 | * } | 396 | * } |
356 | * | 397 | * |
357 | * \endcode | 398 | * \endcode |
358 | * | 399 | * |
359 | * @param conf The Config where the KeySetting should be stored | 400 | * @param conf The Config where the KeySetting should be stored |
360 | * @param group The group where the KeySetting will be stored | 401 | * @param group The group where the KeySetting will be stored |
361 | * @param black Which keys shouldn't be allowed to handle | 402 | * @param black Which keys shouldn't be allowed to handle |
362 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | 403 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons |
363 | * @param par The parent/owner of this manager | 404 | * @param par The parent/owner of this manager |
364 | * @param name The name of this object | 405 | * @param name The name of this object |
365 | */ | 406 | */ |
366 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 407 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
367 | const QString& group, | 408 | const QString& group, |
368 | OKeyPairList black, | 409 | OKeyPairList black, |
369 | bool grabkeyboard, QObject* par, | 410 | bool grabkeyboard, QObject* par, |
370 | const char* name) | 411 | const char* name) |
371 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 412 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
372 | m_blackKeys( black ), m_grab( grabkeyboard ) | 413 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ) |
373 | {} | 414 | {} |
374 | 415 | ||
375 | 416 | ||
376 | /** | 417 | /** |
377 | * Destructor | 418 | * Destructor |
378 | */ | 419 | */ |
379 | OKeyConfigWidget::~OKeyConfigWidget() {} | 420 | OKeyConfigManager::~OKeyConfigManager() {} |
380 | 421 | ||
381 | /** | 422 | /** |
382 | * Load the Configuration from the OConfig | 423 | * Load the Configuration from the OConfig |
383 | * If a Key is restricted but was in the config we will | 424 | * If a Key is restricted but was in the config we will |
384 | * make the empty | 425 | * make it be the empty key paur |
385 | * We will change the group of the OConfig Item! | 426 | * We will change the group of the OConfig Item! |
427 | * | ||
428 | * @see OKeyPair::emptyKey | ||
386 | */ | 429 | */ |
387 | void OKeyConfigWidget::load() { | 430 | void OKeyConfigWidget::load() { |
388 | m_conf->setGroup( m_group ); | 431 | m_conf->setGroup( m_group ); |
389 | 432 | ||
390 | /* | 433 | /* |
391 | * Read each item | 434 | * Read each item |
392 | */ | 435 | */ |
393 | int key, mod; | 436 | int key, mod; |
394 | for( OKeyConfigItemList::Iterator it = m_keys.begin(); | 437 | for( OKeyConfigItemList::Iterator it = m_keys.begin(); |
395 | it != m_keys.end(); ++it ) { | 438 | it != m_keys.end(); ++it ) { |
396 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 439 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); |
397 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 440 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); |
398 | (*it).setKeyPair( OKeyPair(key, mod) ); | 441 | OKeyPair okey( key, mod ); |
442 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | ||
443 | (*it).setKeyPair( OKeyPair(key, mod) ); | ||
444 | else | ||
445 | (*it).setKeyPair( OKeyPair::emptyKey() ); | ||
399 | } | 446 | } |
447 | delete m_map; m_map = 0; | ||
400 | } | 448 | } |
401 | 449 | ||
402 | /** | 450 | /** |
403 | * We will save the current configuration | 451 | * We will save the current configuration |
404 | * to the OConfig. We will change the group. | 452 | * to the OConfig. We will change the group. |
405 | */ | 453 | */ |
406 | void OKeyConfigWidget::save() { | 454 | void OKeyConfigWidget::save() { |
455 | m_conf->setGroup( m_group ); | ||
407 | 456 | ||
457 | /* | ||
458 | * Write each item | ||
459 | */ | ||
460 | int key, mod; | ||
461 | for( OKeyConfigItemList::Iterator it = m_keys.begin(); | ||
462 | it != m_keys.end(); ++it ) { | ||
463 | if ( (*it).isEmpty() ) | ||
464 | continue; | ||
465 | OKeyPair pair = (*it).keyPair(); | ||
466 | m_conf->writeEntry(pair.configKey()+"key", pair.keycode() ); | ||
467 | m_conf->writeEntry(pair.configKey()+"mod", pair.modifier() ); | ||
468 | } | ||
408 | } | 469 | } |
470 | |||
471 | /** | ||
472 | * This is function uses a QMap internally but you can have the same keycode | ||
473 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | ||
474 | * with same keycode and modifier key. The GUI takes care that a user can't | ||
475 | * cofigure two keys. | ||
476 | * | ||
477 | * Make sure you call e->ignore if you don't want to handle this event | ||
478 | */ | ||
479 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | ||
480 | OKeyConfigItemList keyList = keyList( e->key() ); | ||
481 | if ( keyList.isEmpty() ) | ||
482 | return OKeyConfigItem(); | ||
483 | |||
484 | OKeyConfigItem item; | ||
485 | for ( OKeyConfigItemList::Iterator it = keyList.begin(); it != keyList.end(); | ||
486 | ++it ) { | ||
487 | if ( (*it).keyPair().modifier() == e->state() ) { | ||
488 | item = *it; | ||
489 | break; | ||
490 | } | ||
491 | |||
492 | } | ||
493 | |||
494 | return item; | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * Return the associated id of the item or -1 if no item | ||
499 | * matched the key | ||
500 | * | ||
501 | * @see handleKeyEvent | ||
502 | */ | ||
503 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | ||
504 | return handleKeyEvent( ev ).id(); | ||
505 | } | ||
506 | |||
507 | /** | ||
508 | * Add Key Config to the List of items | ||
509 | */ | ||
510 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | ||
511 | m_keys.append( item ); | ||
512 | delete m_map; m_map = 0; | ||
513 | } | ||
514 | |||
515 | /** | ||
516 | * Remove the Key from the Config. Internal lists will be destroyed | ||
517 | * and rebuild on demand later | ||
518 | */ | ||
519 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | ||
520 | m_keys.remove( item ); | ||
521 | delete m_map; m_map = 0; | ||
522 | } | ||
523 | |||
524 | /** | ||
525 | * Clears the complete list | ||
526 | */ | ||
527 | void OKeyConfigManager::clearKeyConfig() { | ||
528 | m_keys.clear(); | ||
529 | delete m_map; m_map = 0; | ||
530 | } | ||
531 | |||
532 | |||
533 | /** | ||
534 | * Add this OKeyPair to the blackList. | ||
535 | * Internal lists will be destroyed | ||
536 | */ | ||
537 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | ||
538 | m_blackKeys.append( key ); | ||
539 | delete m_map; m_map = 0; | ||
540 | } | ||
541 | |||
542 | |||
543 | /** | ||
544 | * Remove this OKeyPair from the black List | ||
545 | * Internal lists will be destroyed | ||
546 | */ | ||
547 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | ||
548 | m_blackKeys.remove( key ); | ||
549 | delete m_map; m_map = 0; | ||
550 | } | ||
551 | |||
552 | |||
553 | /** | ||
554 | * Clear the blackList | ||
555 | */ | ||
556 | void OKeyConfigManager::clearBlackList() { | ||
557 | m_blackKeys.clear(); | ||
558 | delete m_map; m_map = 0; | ||
559 | } | ||
560 | |||
561 | |||
562 | /** | ||
563 | * Return a copy of the blackList | ||
564 | */ | ||
565 | OKeyPairList OKeyConfigManager::blackList()const { | ||
566 | return m_blackKeys; | ||
567 | } | ||
568 | |||
569 | |||
570 | /** | ||
571 | * Ask the Manager to handle KeyEvents for you. | ||
572 | * All handled keys will emit a QSignal and return true | ||
573 | * that it handled the keyevent | ||
574 | */ | ||
575 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | ||
576 | wid->installEventFilter( this ); | ||
577 | } | ||
578 | |||
579 | /** | ||
580 | * @internal | ||
581 | */ | ||
582 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | ||
583 | if ( !obj->isWidgetType() ) | ||
584 | return false; | ||
585 | |||
586 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | ||
587 | return false; | ||
588 | |||
589 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | ||
590 | OKeyConfigItem item = handleKeyEvent( key ); | ||
591 | |||
592 | if ( item.isEmpty() ) | ||
593 | return false; | ||
594 | |||
595 | emit actionActivated( static_cast<QWidget*>( obj ), key, item ); | ||
596 | return true; | ||
597 | } | ||
598 | |||
599 | /** | ||
600 | * @internal | ||
601 | */ | ||
602 | OKeyConfigItemList OKeyConfigManager::keyList( int keycode) { | ||
603 | if ( !m_map ) { | ||
604 | m_map = new OKeyMapConfigPrivate; | ||
605 | /* for every key */ | ||
606 | for ( OKeyConfigItemList::Iterator it = m_keys.begin(); | ||
607 | it!= m_keys.end(); ++it ) { | ||
608 | bool add = true; | ||
609 | /* see if this key is blocked */ | ||
610 | for ( OKeyPairList::Iterator pairIt = m_blackKeys.begin(); | ||
611 | pairIt != m_blackKeys.end(); ++pairIt ) { | ||
612 | if ( (*pairIt).keycode() == (*it).keycode() && | ||
613 | (*pairIt).modifier() == (*it).modifier() ) { | ||
614 | add = false; | ||
615 | break; | ||
616 | } | ||
617 | } | ||
618 | /* check if we added it */ | ||
619 | if ( add ) { | ||
620 | if ( m_map->contains( (*it).keycode() ) ) | ||
621 | (m_map[(*it).keycode()]).append( *it ); | ||
622 | else | ||
623 | m_map.insert( (*it).keycode(), OKeyConfigItemList( *it ) ); | ||
624 | } | ||
625 | } | ||
626 | } | ||
627 | return m_map[keycode]; | ||
628 | } | ||
629 | |||
630 | |||
631 | |||
632 | ///////////////////////// | ||
633 | //////// Widget Starts Here | ||
634 | namespace Opie { | ||
635 | namespace Ui { | ||
636 | namespace Private { | ||
637 | static QString keyToString( const OKeyPair& ); | ||
638 | class OItemBox : public QHBox { | ||
639 | Q_OBJECT | ||
640 | public: | ||
641 | OItemBox( const OKeyConfigItem& item, QWidget* parent = 0, const char* name = 0, WFlags fl = 0); | ||
642 | ~OItemBox(); | ||
643 | |||
644 | OKeyConfigItem item()const; | ||
645 | void setItem( const OKeyConfigItem& item ); | ||
646 | private slots: | ||
647 | void slotClicked(); | ||
648 | signals: | ||
649 | void configureBox( OItemBox* ); | ||
650 | private: | ||
651 | QLabel *m_pix; | ||
652 | QLabel *m_text; | ||
653 | QPushButton *m_btn; | ||
654 | OKeyConfigItem m_item; | ||
655 | }; | ||
656 | |||
657 | OItemBox::OItemBox( const OKeyConfigItem& item, QWidget* parent, | ||
658 | const char* name, WFlags fl ) | ||
659 | : QHBox( parent, name, fl ), { | ||
660 | m_pix = new QLabel( this ); | ||
661 | m_text = new QLabel( this ); | ||
662 | m_btn = new QPushButton( this ); | ||
663 | |||
664 | connect(m_btn, SIGNAL(clicked()), | ||
665 | this, SLOT(slotClicked())); | ||
666 | |||
667 | setItem( item ); | ||
668 | } | ||
669 | |||
670 | OItemBox::~OItemBox() {} | ||
671 | OKeyConfigItem OItemBox::item()const{ | ||
672 | return m_item; | ||
673 | } | ||
674 | void OKeyConfigItem::setItem( const OKeyConfigItem& item ) { | ||
675 | m_item = item; | ||
676 | m_pix ->setPixmap( item.pixmap() ); | ||
677 | m_text->setText( item.text() ); | ||
678 | m_btn->setText( keyToString( item.keyPair() ) ); | ||
679 | } | ||
680 | void OKeyConfigItem::slotClicked() { | ||
681 | emit configureBox( this ); | ||
682 | } | ||
683 | |||
684 | QString keyToString( const OKeyPair& pair ) { | ||
685 | QStringList mod; | ||
686 | if ( ( pair.modifier() & Qt::ShiftButton )== Qt::ShiftButton ) | ||
687 | mod.append( QObject::tr( "Shift", "The Keyboard key" ) ); | ||
688 | if ( ( pair.modifier() & Qt::ControlButton )== Qt::ControlButton ) | ||
689 | mod.append( QObject::tr( "Ctrl", "The Ctrl key" ) ); | ||
690 | if ( ( pair.modifier() & Qt::AltButton ) )== Qt::AltButton ) | ||
691 | mod.append( QObject::tr( "Alt", "The keyboard Alt Key" ) ); | ||
692 | |||
693 | |||
694 | } | ||
695 | } | ||
696 | } | ||
697 | } | ||
698 | |||
699 | |||
700 | |||
701 | //////////////////////// | ||
702 | |||
703 | |||
704 | |||
705 | #include "okeyconfigwidget.moc" | ||
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index 0d5d26f..414ee7e 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -1,205 +1,209 @@ | |||
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_CONFIG_WIDGET_H | 7 | #ifndef ODP_KEY_CONFIG_WIDGET_H |
8 | #define ODP_KEY_CONFIG_WIDGET_H | 8 | #define ODP_KEY_CONFIG_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 <qbytearray.h> | 15 | #include <qbytearray.h> |
16 | #include <qhbox.h> | 16 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 17 | #include <qvaluelist.h> |
18 | 18 | ||
19 | class QKeyEvent; | 19 | class QKeyEvent; |
20 | 20 | ||
21 | namespace Opie { | 21 | namespace Opie { |
22 | namespace Ui { | 22 | namespace Ui { |
23 | 23 | ||
24 | 24 | ||
25 | /** | 25 | /** |
26 | * \brief small class representing a Key with possible modifiers | 26 | * \brief small class representing a Key with possible modifiers |
27 | * This class holds information about key code and possible | 27 | * This class holds information about key code and possible |
28 | * modifier state. That is the lowest level of the key input | 28 | * modifier state. That is the lowest level of the key input |
29 | * functions. | 29 | * functions. |
30 | * There are also static methods to get special keys. | 30 | * There are also static methods to get special keys. |
31 | * OKeyPair will be used with \see OKeyConfigItem | 31 | * OKeyPair will be used with \see OKeyConfigItem |
32 | * | 32 | * |
33 | * @since 1.2 | 33 | * @since 1.2 |
34 | */ | 34 | */ |
35 | class OKeyPair { | 35 | class OKeyPair { |
36 | public: | 36 | public: |
37 | typedef QValueList<OKeyPair> OKeyPairList; | 37 | typedef QValueList<OKeyPair> OKeyPairList; |
38 | OKeyPair( int key = -1, int modifier = -1); | 38 | OKeyPair( int key = -1, int modifier = -1); |
39 | ~OKeyPair(); | 39 | ~OKeyPair(); |
40 | 40 | ||
41 | bool operator==( const OKeyPair& ); | 41 | bool operator==( const OKeyPair& ); |
42 | bool operator!=( const OKeyPair& ); | 42 | bool operator!=( const OKeyPair& ); |
43 | 43 | ||
44 | bool isEmpty()const; | 44 | bool isEmpty()const; |
45 | 45 | ||
46 | int keycode()const; | 46 | int keycode()const; |
47 | int modifier()const; | 47 | int modifier()const; |
48 | 48 | ||
49 | void setKeycode( int ); | 49 | void setKeycode( int ); |
50 | void setModifier( int ); | 50 | void setModifier( int ); |
51 | 51 | ||
52 | static OKeyPair returnKey(); | 52 | static OKeyPair returnKey(); |
53 | static OKeyPair leftArrowKey(); | 53 | static OKeyPair leftArrowKey(); |
54 | static OKeyPair rightArrowKey(); | 54 | static OKeyPair rightArrowKey(); |
55 | static OKeyPair upArrowKey(); | 55 | static OKeyPair upArrowKey(); |
56 | static OKeyPair downArrowKey(); | 56 | static OKeyPair downArrowKey(); |
57 | static OKeyPair emptyKey(); | 57 | static OKeyPair emptyKey(); |
58 | static OKeyPairList hardwareKeys(); | 58 | static OKeyPairList hardwareKeys(); |
59 | 59 | ||
60 | private: | 60 | private: |
61 | int m_key = -1; | 61 | int m_key = -1; |
62 | int m_mod = -1; | 62 | int m_mod = -1; |
63 | class Private; | 63 | class Private; |
64 | Private* d; | 64 | Private* d; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * A class to represent an OKeyPair. | 68 | * A class to represent an OKeyPair. |
69 | * It consists out of a Text exposed to the user, Config Key Item, | 69 | * It consists out of a Text exposed to the user, Config Key Item, |
70 | * Pixmap, A default OKeyPair and the set OKeyPair. | 70 | * Pixmap, A default OKeyPair and the set OKeyPair. |
71 | * You can also pass an id to it | 71 | * You can also pass an id to it |
72 | * | 72 | * |
73 | * @since 1.1.2 | 73 | * @since 1.1.2 |
74 | */ | 74 | */ |
75 | class OKeyConfigItem { | 75 | class OKeyConfigItem { |
76 | friend class OKeyConfigManager; | 76 | friend class OKeyConfigManager; |
77 | public: | 77 | public: |
78 | typedef QValueList<OKeyConfigItem> OKeyConfigItemList; | 78 | typedef QValueList<OKeyConfigItem> OKeyConfigItemList; |
79 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 79 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
80 | const QPixmap& symbol = QPixmap(), | 80 | const QPixmap& symbol = QPixmap(), |
81 | int id = -1, | 81 | int id = -1, |
82 | const OKeyPair& set = OKeyPair::emptyKey(), | 82 | const OKeyPair& set = OKeyPair::emptyKey(), |
83 | const OKeyPair& def = OKeyPair::emptyKey() ); | 83 | const OKeyPair& def = OKeyPair::emptyKey() ); |
84 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 84 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
85 | ~OKeyConfigItem(); | 85 | ~OKeyConfigItem(); |
86 | 86 | ||
87 | bool operator==( const OKeyConfigItem& ); | 87 | bool operator==( const OKeyConfigItem& ); |
88 | bool operator!=( const OKeyConfigItem& ); | 88 | bool operator!=( const OKeyConfigItem& ); |
89 | 89 | ||
90 | QString text()const; | 90 | QString text()const; |
91 | QPixmap pixmap()const; | 91 | QPixmap pixmap()const; |
92 | int id()const; | 92 | int id()const; |
93 | 93 | ||
94 | OKeyPair keyPair()const; | 94 | OKeyPair keyPair()const; |
95 | OKeyPair defaultKeyPair()const; | 95 | OKeyPair defaultKeyPair()const; |
96 | QCString configKey()const; | 96 | QCString configKey()const; |
97 | 97 | ||
98 | void setText( const QString& text ); | 98 | void setText( const QString& text ); |
99 | void setPixmap( const QPixmap& ); | 99 | void setPixmap( const QPixmap& ); |
100 | void setKeyPair( const OKeyPair& ); | 100 | void setKeyPair( const OKeyPair& ); |
101 | void setDefaultKeyPair( const OKeyPair& ); | 101 | void setDefaultKeyPair( const OKeyPair& ); |
102 | 102 | ||
103 | bool isEmpty()const; | 103 | bool isEmpty()const; |
104 | 104 | ||
105 | protected: | 105 | protected: |
106 | void setId( int id ); | 106 | void setId( int id ); |
107 | void setConfigKey( const QCString& ); | 107 | void setConfigKey( const QCString& ); |
108 | 108 | ||
109 | private: | 109 | private: |
110 | int m_id; | 110 | int m_id; |
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 | OKeyPair m_key; | 114 | OKeyPair m_key; |
115 | OKeyPair m_def; | 115 | OKeyPair m_def; |
116 | class Private; | 116 | class Private; |
117 | Private *d; | 117 | Private *d; |
118 | }; | 118 | }; |
119 | 119 | ||
120 | 120 | ||
121 | 121 | ||
122 | /** | 122 | /** |
123 | * \brief A manager to load and save Key Actions and get notified | 123 | * \brief A manager to load and save Key Actions and get notified |
124 | * This is the Manager for KeyActions. | 124 | * This is the Manager for KeyActions. |
125 | * You can say from which config and group to read data, to grab the | 125 | * You can say from which config and group to read data, to grab the |
126 | * keyboard to handle hardware keys, you can supply a blacklist of | 126 | * keyboard to handle hardware keys, you can supply a blacklist of |
127 | * keys which should not be used by allowed to be used. | 127 | * keys which should not be used by allowed to be used. |
128 | * You can even pass this manager to a Widget to do the configuration for you. | 128 | * You can even pass this manager to a Widget to do the configuration for you. |
129 | * You need to add OKeyConfigItem for your keys and then issue a load() to | 129 | * You need to add OKeyConfigItem for your keys and then issue a load() to |
130 | * read the Key information. | 130 | * read the Key information. |
131 | * You can either handle the QKeyEvent yourself and ask this class if it is | 131 | * You can either handle the QKeyEvent yourself and ask this class if it is |
132 | * handled by your action and let give you the action. Or you can install | 132 | * handled by your action and let give you the action. Or you can install |
133 | * the event filter and get a signal. | 133 | * the event filter and get a signal. |
134 | * | 134 | * |
135 | * @since 1.1.2 | 135 | * @since 1.1.2 |
136 | */ | 136 | */ |
137 | class OKeyConfigManager : public QObject { | 137 | class OKeyConfigManager : public QObject { |
138 | Q_OBJECT | 138 | Q_OBJECT |
139 | typedef QMap<it, OKeyConfigItemList> OKeyMapConfigPrivate; | ||
139 | public: | 140 | public: |
140 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | 141 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, |
141 | const QString& group = QString::null, | 142 | const QString& group = QString::null, |
142 | OKeyPairList &block = OKeyPairList(), | 143 | OKeyPairList &block = OKeyPairList(), |
143 | bool grabkeyboard = false, QObject *= 0, | 144 | bool grabkeyboard = false, QObject *= 0, |
144 | const char* name = 0 ); | 145 | const char* name = 0 ); |
145 | ~OKeyConfigManager(); | 146 | ~OKeyConfigManager(); |
146 | 147 | ||
147 | void load(); | 148 | void load(); |
148 | void save(); | 149 | void save(); |
149 | 150 | ||
150 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | 151 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); |
151 | QString handleKeyEventString( QKeyEvent* ); | 152 | int handleKeyEventId( QKeyEvent* ); |
152 | 153 | ||
153 | void addKeyConfig( const OKeyConfigItem& ); | 154 | void addKeyConfig( const OKeyConfigItem& ); |
154 | void removeKeyConfig( const OKeyConfigItem& ); | 155 | void removeKeyConfig( const OKeyConfigItem& ); |
156 | void clearKeyConfig(); | ||
155 | 157 | ||
156 | void addBlackList( const OKeyPair& ); | 158 | void addToBlackList( const OKeyPair& ); |
157 | void removeBlackList( const OKeyPair& ); | 159 | void removeFromBlackList( const OKeyPair& ); |
158 | void clearBlackList(); | 160 | void clearBlackList(); |
159 | OKeyPairList blackList()const; | 161 | OKeyPairList blackList()const; |
160 | 162 | ||
161 | void handleWidget( QWidget* ); | 163 | void handleWidget( QWidget* ); |
162 | 164 | ||
163 | bool eventFilter( QObject*, QEvent* ); | 165 | bool eventFilter( QObject*, QEvent* ); |
164 | signals: | 166 | signals: |
165 | void keyConfigChanged( Opie::Ui::OKeyConfigManager* ); | 167 | void keyConfigChanged( Opie::Ui::OKeyConfigManager* ); |
166 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 168 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); |
167 | 169 | ||
168 | private: | 170 | private: |
171 | OKeyConfigItemList keyList( int ); | ||
169 | OKeyPairList m_blackKeys; | 172 | OKeyPairList m_blackKeys; |
170 | OKeyConfigItemList m_keys; | 173 | OKeyConfigItemList m_keys; |
171 | QValueList<QWidget*> m_widgets; | 174 | QValueList<QWidget*> m_widgets; |
172 | Opie::Core::OConfig *m_conf; | 175 | Opie::Core::OConfig *m_conf; |
173 | QString m_group; | 176 | QString m_group; |
174 | bool m_grab : 1; | 177 | bool m_grab : 1; |
178 | OKeyMapConfigPrivate *m_map; | ||
175 | class Private; | 179 | class Private; |
176 | Private *d; | 180 | Private *d; |
177 | }; | 181 | }; |
178 | 182 | ||
179 | 183 | ||
180 | class OKeyConfigWidget : public QHBox { | 184 | class OKeyConfigWidget : public QHBox { |
181 | Q_OBJECT | 185 | Q_OBJECT |
182 | public: | 186 | public: |
183 | enum ChangeMode { Imediate, Queu }; | 187 | enum ChangeMode { Imediate, Queu }; |
184 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 188 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
185 | OKeyConfigWidget( OKeyConfigManager *, QWidget* parent = 0, const char* = 0, WFlags = 0 ); | 189 | OKeyConfigWidget( OKeyConfigManager *, QWidget* parent = 0, const char* = 0, WFlags = 0 ); |
186 | ~OKeyConfigWidget(); | 190 | ~OKeyConfigWidget(); |
187 | 191 | ||
188 | void setChangeMode( enum ChangeMode ); | 192 | void setChangeMode( enum ChangeMode ); |
189 | ChangeMode changeMode()const; | 193 | ChangeMode changeMode()const; |
190 | 194 | ||
191 | void setKeyConfig( OKeyConfigManager* ); | 195 | void setKeyConfig( OKeyConfigManager* ); |
192 | 196 | ||
193 | void reload(); | 197 | void reload(); |
194 | void save(); | 198 | void save(); |
195 | private: | 199 | private: |
196 | OKeyConfigManager* m_manager; | 200 | OKeyConfigManager* m_manager; |
197 | class Private; | 201 | class Private; |
198 | Private *d; | 202 | Private *d; |
199 | }; | 203 | }; |
200 | 204 | ||
201 | } | 205 | } |
202 | } | 206 | } |
203 | 207 | ||
204 | 208 | ||
205 | #endif | 209 | #endif |