author | zecke <zecke> | 2004-05-17 21:21:20 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-05-17 21:21:20 (UTC) |
commit | e0d8fdf2bcf61f8b6793ee757de35b985aef1b8d (patch) (unidiff) | |
tree | fe4d56b46af10508430eda398ec7d57cc4ab6a9e | |
parent | 34f42c17874e84239fc2bff241cecee7ec78d38d (diff) | |
download | opie-e0d8fdf2bcf61f8b6793ee757de35b985aef1b8d.zip opie-e0d8fdf2bcf61f8b6793ee757de35b985aef1b8d.tar.gz opie-e0d8fdf2bcf61f8b6793ee757de35b985aef1b8d.tar.bz2 |
use the config group saver right?!
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp index ad0f7f7..ccb96cc 100644 --- a/libopie2/opiecore/okeyconfigmanager.cpp +++ b/libopie2/opiecore/okeyconfigmanager.cpp | |||
@@ -316,412 +316,412 @@ QCString OKeyConfigItem::slot()const { | |||
316 | /** | 316 | /** |
317 | * Set the text | 317 | * Set the text |
318 | * | 318 | * |
319 | * @param text Set the Text of this Action to text | 319 | * @param text Set the Text of this Action to text |
320 | * @see text() | 320 | * @see text() |
321 | */ | 321 | */ |
322 | void OKeyConfigItem::setText( const QString& text ) { | 322 | void OKeyConfigItem::setText( const QString& text ) { |
323 | m_text = text; | 323 | m_text = text; |
324 | } | 324 | } |
325 | 325 | ||
326 | /** | 326 | /** |
327 | * Set the pixmap of this action | 327 | * Set the pixmap of this action |
328 | * | 328 | * |
329 | * @param pix The Pixmap to set | 329 | * @param pix The Pixmap to set |
330 | * @see pixmap() | 330 | * @see pixmap() |
331 | */ | 331 | */ |
332 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | 332 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { |
333 | m_pix = pix; | 333 | m_pix = pix; |
334 | } | 334 | } |
335 | 335 | ||
336 | /** | 336 | /** |
337 | * Set the KeyPair the OKeyConfigItem uses. | 337 | * Set the KeyPair the OKeyConfigItem uses. |
338 | * Your set Key could get overwritten if you use | 338 | * Your set Key could get overwritten if you use |
339 | * the manager or GUI to configure the key | 339 | * the manager or GUI to configure the key |
340 | * | 340 | * |
341 | * @param key Set the OKeyPair used | 341 | * @param key Set the OKeyPair used |
342 | * @see keyPair() | 342 | * @see keyPair() |
343 | */ | 343 | */ |
344 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | 344 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { |
345 | m_key = key; | 345 | m_key = key; |
346 | } | 346 | } |
347 | 347 | ||
348 | /** | 348 | /** |
349 | * Set the default KeyPair. | 349 | * Set the default KeyPair. |
350 | * | 350 | * |
351 | * @param key The default keypair | 351 | * @param key The default keypair |
352 | * @see defaultKeyPair() | 352 | * @see defaultKeyPair() |
353 | */ | 353 | */ |
354 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | 354 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { |
355 | m_def = key; | 355 | m_def = key; |
356 | } | 356 | } |
357 | 357 | ||
358 | /** | 358 | /** |
359 | * @internal | 359 | * @internal |
360 | */ | 360 | */ |
361 | void OKeyConfigItem::setConfigKey( const QCString& str) { | 361 | void OKeyConfigItem::setConfigKey( const QCString& str) { |
362 | m_config = str; | 362 | m_config = str; |
363 | m_config.detach(); | 363 | m_config.detach(); |
364 | } | 364 | } |
365 | 365 | ||
366 | /** | 366 | /** |
367 | * @internal | 367 | * @internal |
368 | */ | 368 | */ |
369 | void OKeyConfigItem::setId( int id ) { | 369 | void OKeyConfigItem::setId( int id ) { |
370 | m_id = id; | 370 | m_id = id; |
371 | } | 371 | } |
372 | 372 | ||
373 | /** | 373 | /** |
374 | * If the item is not configured isEmpty() will return true | 374 | * If the item is not configured isEmpty() will return true |
375 | * It is empty if no text is present and no default | 375 | * It is empty if no text is present and no default |
376 | * and no configured key | 376 | * and no configured key |
377 | */ | 377 | */ |
378 | bool OKeyConfigItem::isEmpty()const { | 378 | bool OKeyConfigItem::isEmpty()const { |
379 | if ( !m_def.isEmpty() ) return false; | 379 | if ( !m_def.isEmpty() ) return false; |
380 | if ( !m_key.isEmpty() ) return false; | 380 | if ( !m_key.isEmpty() ) return false; |
381 | if ( !m_text.isEmpty() ) return false; | 381 | if ( !m_text.isEmpty() ) return false; |
382 | if ( m_id != -1 ) return false; | 382 | if ( m_id != -1 ) return false; |
383 | 383 | ||
384 | return true; | 384 | return true; |
385 | } | 385 | } |
386 | 386 | ||
387 | /** | 387 | /** |
388 | * Check if the KeyPairs are the same | 388 | * Check if the KeyPairs are the same |
389 | */ | 389 | */ |
390 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | 390 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { |
391 | /* if ( isEmpty() == conf.isEmpty() ) return true; | 391 | /* if ( isEmpty() == conf.isEmpty() ) return true; |
392 | else if ( isEmpty() != conf.isEmpty() ) return false; | 392 | else if ( isEmpty() != conf.isEmpty() ) return false; |
393 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | 393 | else if ( !isEmpty()!= conf.isEmpty() ) return false; |
394 | */ | 394 | */ |
395 | 395 | ||
396 | if ( m_id != conf.m_id ) return false; | 396 | if ( m_id != conf.m_id ) return false; |
397 | if ( m_obj != conf.m_obj ) return false; | 397 | if ( m_obj != conf.m_obj ) return false; |
398 | if ( m_text != conf.m_text ) return false; | 398 | if ( m_text != conf.m_text ) return false; |
399 | if ( m_key != conf.m_key ) return false; | 399 | if ( m_key != conf.m_key ) return false; |
400 | if ( m_def != conf.m_def ) return false; | 400 | if ( m_def != conf.m_def ) return false; |
401 | 401 | ||
402 | 402 | ||
403 | 403 | ||
404 | return true; | 404 | return true; |
405 | 405 | ||
406 | } | 406 | } |
407 | 407 | ||
408 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | 408 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { |
409 | return !( *this == conf ); | 409 | return !( *this == conf ); |
410 | } | 410 | } |
411 | 411 | ||
412 | /*! \enum OKeyConfigManager::EventMask | 412 | /*! \enum OKeyConfigManager::EventMask |
413 | <a name="Eventmask flags"></a> | 413 | <a name="Eventmask flags"></a> |
414 | This enum is used to tell OKeyConfigManager which type of key events should inspected. | 414 | This enum is used to tell OKeyConfigManager which type of key events should inspected. |
415 | 415 | ||
416 | <ul> | 416 | <ul> |
417 | <li>\c MaskPressed When a key is pressed an action performs | 417 | <li>\c MaskPressed When a key is pressed an action performs |
418 | <li>\c MaskReleased When a key is released an action performs | 418 | <li>\c MaskReleased When a key is released an action performs |
419 | </ul> | 419 | </ul> |
420 | */ | 420 | */ |
421 | 421 | ||
422 | /** | 422 | /** |
423 | * \brief c'tor | 423 | * \brief c'tor |
424 | * The Constructor for a OKeyConfigManager | 424 | * The Constructor for a OKeyConfigManager |
425 | * | 425 | * |
426 | * You can use this manager in multiple ways. Either make it handle | 426 | * You can use this manager in multiple ways. Either make it handle |
427 | * QKeyEvents. The EventMask is set to OKeyConfigManager::MaskReleased by default. | 427 | * QKeyEvents. The EventMask is set to OKeyConfigManager::MaskReleased by default. |
428 | * | 428 | * |
429 | * \code | 429 | * \code |
430 | * Opie::Core::Config conf = oApp->config(); | 430 | * Opie::Core::Config conf = oApp->config(); |
431 | * Opie::Core::OKeyPairList blackList; | 431 | * Opie::Core::OKeyPairList blackList; |
432 | * blackList.append(Opie::Core::OKeyPair::leftArrowKey()); | 432 | * blackList.append(Opie::Core::OKeyPair::leftArrowKey()); |
433 | * blackList.append(Opie::Core::OKeyPair::rightArrowKey()); | 433 | * blackList.append(Opie::Core::OKeyPair::rightArrowKey()); |
434 | * Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList, | 434 | * Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList, |
435 | * false); | 435 | * false); |
436 | * QListView *view = new QListView(); | 436 | * QListView *view = new QListView(); |
437 | * manager->handleWidget(view); | 437 | * manager->handleWidget(view); |
438 | * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey()); | 438 | * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey()); |
439 | * manager->load(); | 439 | * manager->load(); |
440 | * | 440 | * |
441 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), | 441 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), |
442 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&))); | 442 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&))); |
443 | * | 443 | * |
444 | * .... | 444 | * .... |
445 | * | 445 | * |
446 | * void update(){ | 446 | * void update(){ |
447 | * QDialog diag(true); | 447 | * QDialog diag(true); |
448 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | 448 | * QHBoxLayout *lay = new QHBoxLayout(&diag); |
449 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | 449 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); |
450 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | 450 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); |
451 | * lay->addWidget(wid); | 451 | * lay->addWidget(wid); |
452 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | 452 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ |
453 | * wid->save(); | 453 | * wid->save(); |
454 | * } | 454 | * } |
455 | * } | 455 | * } |
456 | * | 456 | * |
457 | * .... | 457 | * .... |
458 | * MyListView::keyPressEvent( QKeyEvent* e ){ | 458 | * MyListView::keyPressEvent( QKeyEvent* e ){ |
459 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | 459 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); |
460 | * if(!item.isEmpty() ){ | 460 | * if(!item.isEmpty() ){ |
461 | * switch(item.id()){ | 461 | * switch(item.id()){ |
462 | * case My_Delete_Key: | 462 | * case My_Delete_Key: |
463 | * break; | 463 | * break; |
464 | * } | 464 | * } |
465 | * } | 465 | * } |
466 | * } | 466 | * } |
467 | * | 467 | * |
468 | * \endcode | 468 | * \endcode |
469 | * | 469 | * |
470 | * @param conf The Config where the KeySetting should be stored | 470 | * @param conf The Config where the KeySetting should be stored |
471 | * @param group The group where the KeySetting will be stored | 471 | * @param group The group where the KeySetting will be stored |
472 | * @param black Which keys shouldn't be allowed to handle | 472 | * @param black Which keys shouldn't be allowed to handle |
473 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | 473 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons |
474 | * @param par The parent/owner of this manager | 474 | * @param par The parent/owner of this manager |
475 | * @param name The name of this object | 475 | * @param name The name of this object |
476 | */ | 476 | */ |
477 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 477 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
478 | const QString& group, | 478 | const QString& group, |
479 | const OKeyPair::List& black, | 479 | const OKeyPair::List& black, |
480 | bool grabkeyboard, QObject* par, | 480 | bool grabkeyboard, QObject* par, |
481 | const char* name) | 481 | const char* name) |
482 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 482 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
483 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | 483 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ |
484 | if ( m_grab ) | 484 | if ( m_grab ) |
485 | QPEApplication::grabKeyboard(); | 485 | QPEApplication::grabKeyboard(); |
486 | m_event_mask = OKeyConfigManager::MaskReleased; | 486 | m_event_mask = OKeyConfigManager::MaskReleased; |
487 | } | 487 | } |
488 | 488 | ||
489 | 489 | ||
490 | /** | 490 | /** |
491 | * Destructor | 491 | * Destructor |
492 | */ | 492 | */ |
493 | OKeyConfigManager::~OKeyConfigManager() { | 493 | OKeyConfigManager::~OKeyConfigManager() { |
494 | if ( m_grab ) | 494 | if ( m_grab ) |
495 | QPEApplication::ungrabKeyboard(); | 495 | QPEApplication::ungrabKeyboard(); |
496 | delete m_map; | 496 | delete m_map; |
497 | } | 497 | } |
498 | 498 | ||
499 | /** | 499 | /** |
500 | * Load the Configuration from the OConfig | 500 | * Load the Configuration from the OConfig |
501 | * If a Key is restricted but was in the config we will | 501 | * If a Key is restricted but was in the config we will |
502 | * make it be the empty key paur | 502 | * make it be the empty key paur |
503 | * We will change the group but restore to the previous. | 503 | * We will change the group but restore to the previous. |
504 | * | 504 | * |
505 | * @see OKeyPair::emptyKey | 505 | * @see OKeyPair::emptyKey |
506 | */ | 506 | */ |
507 | void OKeyConfigManager::load() { | 507 | void OKeyConfigManager::load() { |
508 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | 508 | Opie::Core::OConfigGroupSaver grp( m_conf, m_group ); |
509 | 509 | ||
510 | /* | 510 | /* |
511 | * Read each item | 511 | * Read each item |
512 | */ | 512 | */ |
513 | int key, mod; | 513 | int key, mod; |
514 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | 514 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { |
515 | key = m_conf->readNumEntry( (*it).configKey()+"key", | 515 | key = m_conf->readNumEntry( (*it).configKey()+"key", |
516 | (*it).defaultKeyPair().keycode() ); | 516 | (*it).defaultKeyPair().keycode() ); |
517 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", | 517 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", |
518 | (*it).defaultKeyPair().modifier() ); | 518 | (*it).defaultKeyPair().modifier() ); |
519 | OKeyPair okey( key, mod ); | 519 | OKeyPair okey( key, mod ); |
520 | 520 | ||
521 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | 521 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) |
522 | (*it).setKeyPair( okey ); | 522 | (*it).setKeyPair( okey ); |
523 | else | 523 | else |
524 | (*it).setKeyPair( OKeyPair::emptyKey() ); | 524 | (*it).setKeyPair( OKeyPair::emptyKey() ); |
525 | } | 525 | } |
526 | delete m_map; m_map = 0; | 526 | delete m_map; m_map = 0; |
527 | } | 527 | } |
528 | 528 | ||
529 | /** | 529 | /** |
530 | * We will save the current configuration | 530 | * We will save the current configuration |
531 | * to the OConfig. We will change the group but restore | 531 | * to the OConfig. We will change the group but restore |
532 | * to the previous | 532 | * to the previous |
533 | */ | 533 | */ |
534 | void OKeyConfigManager::save() { | 534 | void OKeyConfigManager::save() { |
535 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | 535 | Opie::Core::OConfigGroupSaver grp( m_conf, m_group ); |
536 | 536 | ||
537 | /* | 537 | /* |
538 | * Write each item | 538 | * Write each item |
539 | */ | 539 | */ |
540 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | 540 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { |
541 | /* skip empty items */ | 541 | /* skip empty items */ |
542 | if ( (*it).isEmpty() ) | 542 | if ( (*it).isEmpty() ) |
543 | continue; | 543 | continue; |
544 | OKeyPair pair = (*it).keyPair(); | 544 | OKeyPair pair = (*it).keyPair(); |
545 | OKeyPair deft = (*it).defaultKeyPair(); | 545 | OKeyPair deft = (*it).defaultKeyPair(); |
546 | /* | 546 | /* |
547 | * don't write if it is the default setting | 547 | * don't write if it is the default setting |
548 | * FIXME allow to remove Keys from config | 548 | * FIXME allow to remove Keys from config |
549 | if ( (pair.keycode() == deft.keycode()) && | 549 | if ( (pair.keycode() == deft.keycode()) && |
550 | (pair.modifier()== deft.modifier() ) ) | 550 | (pair.modifier()== deft.modifier() ) ) |
551 | return; | 551 | return; |
552 | */ | 552 | */ |
553 | 553 | ||
554 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | 554 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
555 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | 555 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); |
556 | } | 556 | } |
557 | m_conf->write(); | 557 | m_conf->write(); |
558 | } | 558 | } |
559 | 559 | ||
560 | /** | 560 | /** |
561 | * This is function uses a QMap internally but you can have the same keycode | 561 | * This is function uses a QMap internally but you can have the same keycode |
562 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | 562 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem |
563 | * with same keycode and modifier key. The GUI takes care that a user can't | 563 | * with same keycode and modifier key. The GUI takes care that a user can't |
564 | * cofigure two keys. | 564 | * cofigure two keys. |
565 | * | 565 | * |
566 | * Make sure you call e->ignore if you don't want to handle this event | 566 | * Make sure you call e->ignore if you don't want to handle this event |
567 | */ | 567 | */ |
568 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | 568 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { |
569 | /* | 569 | /* |
570 | * Fix Up issues with Qt/E, my keybard, and virtual input | 570 | * Fix Up issues with Qt/E, my keybard, and virtual input |
571 | * methods | 571 | * methods |
572 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | 572 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state |
573 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | 573 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower |
574 | * case ascii | 574 | * case ascii |
575 | */ | 575 | */ |
576 | int key, mod; | 576 | int key, mod; |
577 | Opie::Core::Internal::fixupKeys( key, mod, e ); | 577 | Opie::Core::Internal::fixupKeys( key, mod, e ); |
578 | 578 | ||
579 | OKeyConfigItem::List _keyList = keyList( key ); | 579 | OKeyConfigItem::List _keyList = keyList( key ); |
580 | if ( _keyList.isEmpty() ) | 580 | if ( _keyList.isEmpty() ) |
581 | return OKeyConfigItem(); | 581 | return OKeyConfigItem(); |
582 | 582 | ||
583 | OKeyConfigItem item; | 583 | OKeyConfigItem item; |
584 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | 584 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); |
585 | ++it ) { | 585 | ++it ) { |
586 | if ( (*it).keyPair().modifier() == mod ) { | 586 | if ( (*it).keyPair().modifier() == mod ) { |
587 | item = *it; | 587 | item = *it; |
588 | break; | 588 | break; |
589 | } | 589 | } |
590 | 590 | ||
591 | } | 591 | } |
592 | 592 | ||
593 | return item; | 593 | return item; |
594 | } | 594 | } |
595 | 595 | ||
596 | /** | 596 | /** |
597 | * Return the associated id of the item or -1 if no item | 597 | * Return the associated id of the item or -1 if no item |
598 | * matched the key | 598 | * matched the key |
599 | * | 599 | * |
600 | * @see handleKeyEvent | 600 | * @see handleKeyEvent |
601 | */ | 601 | */ |
602 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | 602 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { |
603 | return handleKeyEvent( ev ).id(); | 603 | return handleKeyEvent( ev ).id(); |
604 | } | 604 | } |
605 | 605 | ||
606 | /** | 606 | /** |
607 | * Add Key Config to the List of items | 607 | * Add Key Config to the List of items |
608 | */ | 608 | */ |
609 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | 609 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { |
610 | m_keys.append( item ); | 610 | m_keys.append( item ); |
611 | delete m_map; m_map = 0; | 611 | delete m_map; m_map = 0; |
612 | } | 612 | } |
613 | 613 | ||
614 | /** | 614 | /** |
615 | * Remove the Key from the Config. Internal lists will be destroyed | 615 | * Remove the Key from the Config. Internal lists will be destroyed |
616 | * and rebuild on demand later | 616 | * and rebuild on demand later |
617 | */ | 617 | */ |
618 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | 618 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { |
619 | m_keys.remove( item ); | 619 | m_keys.remove( item ); |
620 | delete m_map; m_map = 0; | 620 | delete m_map; m_map = 0; |
621 | } | 621 | } |
622 | 622 | ||
623 | /** | 623 | /** |
624 | * Clears the complete list | 624 | * Clears the complete list |
625 | */ | 625 | */ |
626 | void OKeyConfigManager::clearKeyConfig() { | 626 | void OKeyConfigManager::clearKeyConfig() { |
627 | m_keys.clear(); | 627 | m_keys.clear(); |
628 | delete m_map; m_map = 0; | 628 | delete m_map; m_map = 0; |
629 | } | 629 | } |
630 | 630 | ||
631 | /** | 631 | /** |
632 | * | 632 | * |
633 | */ | 633 | */ |
634 | Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | 634 | Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ |
635 | return m_keys; | 635 | return m_keys; |
636 | } | 636 | } |
637 | 637 | ||
638 | /** | 638 | /** |
639 | * Add this OKeyPair to the blackList. | 639 | * Add this OKeyPair to the blackList. |
640 | * Internal lists will be destroyed | 640 | * Internal lists will be destroyed |
641 | */ | 641 | */ |
642 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | 642 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { |
643 | m_blackKeys.append( key ); | 643 | m_blackKeys.append( key ); |
644 | delete m_map; m_map = 0; | 644 | delete m_map; m_map = 0; |
645 | } | 645 | } |
646 | 646 | ||
647 | 647 | ||
648 | /** | 648 | /** |
649 | * Remove this OKeyPair from the black List | 649 | * Remove this OKeyPair from the black List |
650 | * Internal lists will be destroyed | 650 | * Internal lists will be destroyed |
651 | */ | 651 | */ |
652 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | 652 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { |
653 | m_blackKeys.remove( key ); | 653 | m_blackKeys.remove( key ); |
654 | delete m_map; m_map = 0; | 654 | delete m_map; m_map = 0; |
655 | } | 655 | } |
656 | 656 | ||
657 | 657 | ||
658 | /** | 658 | /** |
659 | * Clear the blackList | 659 | * Clear the blackList |
660 | */ | 660 | */ |
661 | void OKeyConfigManager::clearBlackList() { | 661 | void OKeyConfigManager::clearBlackList() { |
662 | m_blackKeys.clear(); | 662 | m_blackKeys.clear(); |
663 | delete m_map; m_map = 0; | 663 | delete m_map; m_map = 0; |
664 | } | 664 | } |
665 | 665 | ||
666 | 666 | ||
667 | /** | 667 | /** |
668 | * Return a copy of the blackList | 668 | * Return a copy of the blackList |
669 | */ | 669 | */ |
670 | OKeyPair::List OKeyConfigManager::blackList()const { | 670 | OKeyPair::List OKeyConfigManager::blackList()const { |
671 | return m_blackKeys; | 671 | return m_blackKeys; |
672 | } | 672 | } |
673 | 673 | ||
674 | 674 | ||
675 | /** | 675 | /** |
676 | * Ask the Manager to handle KeyEvents for you. | 676 | * Ask the Manager to handle KeyEvents for you. |
677 | * All handled keys will emit a QSignal and return true | 677 | * All handled keys will emit a QSignal and return true |
678 | * that it handled the keyevent | 678 | * that it handled the keyevent |
679 | */ | 679 | */ |
680 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | 680 | void OKeyConfigManager::handleWidget( QWidget* wid ) { |
681 | wid->installEventFilter( this ); | 681 | wid->installEventFilter( this ); |
682 | } | 682 | } |
683 | 683 | ||
684 | /** | 684 | /** |
685 | * @internal | 685 | * @internal |
686 | */ | 686 | */ |
687 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | 687 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { |
688 | if ( !obj->isWidgetType() ) | 688 | if ( !obj->isWidgetType() ) |
689 | return false; | 689 | return false; |
690 | 690 | ||
691 | /* | 691 | /* |
692 | * check if we care for the event | 692 | * check if we care for the event |
693 | */ | 693 | */ |
694 | if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && | 694 | if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && |
695 | (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) | 695 | (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) |
696 | return false; | 696 | return false; |
697 | 697 | ||
698 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | 698 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); |
699 | OKeyConfigItem item = handleKeyEvent( key ); | 699 | OKeyConfigItem item = handleKeyEvent( key ); |
700 | 700 | ||
701 | if ( item.isEmpty() ) | 701 | if ( item.isEmpty() ) |
702 | return false; | 702 | return false; |
703 | 703 | ||
704 | QWidget *wid = static_cast<QWidget*>( obj ); | 704 | QWidget *wid = static_cast<QWidget*>( obj ); |
705 | 705 | ||
706 | if ( item.object() && !item.slot().isEmpty() ) { | 706 | if ( item.object() && !item.slot().isEmpty() ) { |
707 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | 707 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), |
708 | item.object(), item.slot().data() ); | 708 | item.object(), item.slot().data() ); |
709 | emit actionActivated(wid, key); | 709 | emit actionActivated(wid, key); |
710 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | 710 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), |
711 | item.object(), item.slot().data() ); | 711 | item.object(), item.slot().data() ); |
712 | } | 712 | } |
713 | emit actionActivated( wid, key, item ); | 713 | emit actionActivated( wid, key, item ); |
714 | 714 | ||
715 | return true; | 715 | return true; |
716 | } | 716 | } |
717 | 717 | ||
718 | /** | 718 | /** |
719 | * @internal | 719 | * @internal |
720 | */ | 720 | */ |
721 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | 721 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { |
722 | /* | 722 | /* |
723 | * Create the map if not existing anymore | 723 | * Create the map if not existing anymore |
724 | */ | 724 | */ |
725 | if ( !m_map ) { | 725 | if ( !m_map ) { |
726 | m_map = new OKeyMapConfigPrivate; | 726 | m_map = new OKeyMapConfigPrivate; |
727 | /* for every key */ | 727 | /* for every key */ |