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