-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index b4f1c5e..2ea0bd5 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -411,214 +411,251 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | |||
411 | * .... | 411 | * .... |
412 | * | 412 | * |
413 | * void update(){ | 413 | * void update(){ |
414 | * QDialog diag(true); | 414 | * QDialog diag(true); |
415 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | 415 | * QHBoxLayout *lay = new QHBoxLayout(&diag); |
416 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | 416 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); |
417 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | 417 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); |
418 | * lay->addWidget(wid); | 418 | * lay->addWidget(wid); |
419 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | 419 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ |
420 | * wid->save(); | 420 | * wid->save(); |
421 | * } | 421 | * } |
422 | * } | 422 | * } |
423 | * | 423 | * |
424 | * .... | 424 | * .... |
425 | * MyListView::keyPressEvent( QKeyEvent* e ){ | 425 | * MyListView::keyPressEvent( QKeyEvent* e ){ |
426 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | 426 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); |
427 | * if(!item.isEmpty() ){ | 427 | * if(!item.isEmpty() ){ |
428 | * switch(item.id()){ | 428 | * switch(item.id()){ |
429 | * case My_Delete_Key: | 429 | * case My_Delete_Key: |
430 | * break; | 430 | * break; |
431 | * } | 431 | * } |
432 | * } | 432 | * } |
433 | * } | 433 | * } |
434 | * | 434 | * |
435 | * \endcode | 435 | * \endcode |
436 | * | 436 | * |
437 | * @param conf The Config where the KeySetting should be stored | 437 | * @param conf The Config where the KeySetting should be stored |
438 | * @param group The group where the KeySetting will be stored | 438 | * @param group The group where the KeySetting will be stored |
439 | * @param black Which keys shouldn't be allowed to handle | 439 | * @param black Which keys shouldn't be allowed to handle |
440 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | 440 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons |
441 | * @param par The parent/owner of this manager | 441 | * @param par The parent/owner of this manager |
442 | * @param name The name of this object | 442 | * @param name The name of this object |
443 | */ | 443 | */ |
444 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 444 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
445 | const QString& group, | 445 | const QString& group, |
446 | const OKeyPair::List& black, | 446 | const OKeyPair::List& black, |
447 | bool grabkeyboard, QObject* par, | 447 | bool grabkeyboard, QObject* par, |
448 | const char* name) | 448 | const char* name) |
449 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 449 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
450 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | 450 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ |
451 | if ( m_grab ) | 451 | if ( m_grab ) |
452 | QPEApplication::grabKeyboard(); | 452 | QPEApplication::grabKeyboard(); |
453 | } | 453 | } |
454 | 454 | ||
455 | 455 | ||
456 | /** | 456 | /** |
457 | * Destructor | 457 | * Destructor |
458 | */ | 458 | */ |
459 | OKeyConfigManager::~OKeyConfigManager() { | 459 | OKeyConfigManager::~OKeyConfigManager() { |
460 | if ( m_grab ) | 460 | if ( m_grab ) |
461 | QPEApplication::ungrabKeyboard(); | 461 | QPEApplication::ungrabKeyboard(); |
462 | } | 462 | } |
463 | 463 | ||
464 | /** | 464 | /** |
465 | * Load the Configuration from the OConfig | 465 | * Load the Configuration from the OConfig |
466 | * If a Key is restricted but was in the config we will | 466 | * If a Key is restricted but was in the config we will |
467 | * make it be the empty key paur | 467 | * make it be the empty key paur |
468 | * We will change the group of the OConfig Item! | 468 | * We will change the group of the OConfig Item! |
469 | * | 469 | * |
470 | * @see OKeyPair::emptyKey | 470 | * @see OKeyPair::emptyKey |
471 | */ | 471 | */ |
472 | void OKeyConfigManager::load() { | 472 | void OKeyConfigManager::load() { |
473 | m_conf->setGroup( m_group ); | 473 | m_conf->setGroup( m_group ); |
474 | 474 | ||
475 | /* | 475 | /* |
476 | * Read each item | 476 | * Read each item |
477 | */ | 477 | */ |
478 | int key, mod; | 478 | int key, mod; |
479 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 479 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
480 | it != m_keys.end(); ++it ) { | 480 | it != m_keys.end(); ++it ) { |
481 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 481 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); |
482 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 482 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); |
483 | OKeyPair okey( key, mod ); | 483 | OKeyPair okey( key, mod ); |
484 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | 484 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) |
485 | (*it).setKeyPair( OKeyPair(key, mod) ); | 485 | (*it).setKeyPair( OKeyPair(key, mod) ); |
486 | else | 486 | else |
487 | (*it).setKeyPair( OKeyPair::emptyKey() ); | 487 | (*it).setKeyPair( OKeyPair::emptyKey() ); |
488 | } | 488 | } |
489 | delete m_map; m_map = 0; | 489 | delete m_map; m_map = 0; |
490 | } | 490 | } |
491 | 491 | ||
492 | /** | 492 | /** |
493 | * We will save the current configuration | 493 | * We will save the current configuration |
494 | * to the OConfig. We will change the group. | 494 | * to the OConfig. We will change the group. |
495 | */ | 495 | */ |
496 | void OKeyConfigManager::save() { | 496 | void OKeyConfigManager::save() { |
497 | m_conf->setGroup( m_group ); | 497 | m_conf->setGroup( m_group ); |
498 | 498 | ||
499 | /* | 499 | /* |
500 | * Write each item | 500 | * Write each item |
501 | */ | 501 | */ |
502 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 502 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
503 | it != m_keys.end(); ++it ) { | 503 | it != m_keys.end(); ++it ) { |
504 | if ( (*it).isEmpty() ) | 504 | if ( (*it).isEmpty() ) |
505 | continue; | 505 | continue; |
506 | OKeyPair pair = (*it).keyPair(); | 506 | OKeyPair pair = (*it).keyPair(); |
507 | OKeyPair deft = (*it).defaultKeyPair(); | ||
508 | /* don't write if it is the default setting */ | ||
509 | if ( (pair.keycode() == deft.keycode()) && | ||
510 | (pair.modifier()== deft.modifier() ) ) | ||
511 | return; | ||
512 | |||
507 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | 513 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
508 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | 514 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); |
509 | } | 515 | } |
510 | } | 516 | } |
511 | 517 | ||
512 | /** | 518 | /** |
513 | * This is function uses a QMap internally but you can have the same keycode | 519 | * This is function uses a QMap internally but you can have the same keycode |
514 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | 520 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem |
515 | * with same keycode and modifier key. The GUI takes care that a user can't | 521 | * with same keycode and modifier key. The GUI takes care that a user can't |
516 | * cofigure two keys. | 522 | * cofigure two keys. |
517 | * | 523 | * |
518 | * Make sure you call e->ignore if you don't want to handle this event | 524 | * Make sure you call e->ignore if you don't want to handle this event |
519 | */ | 525 | */ |
520 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | 526 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { |
521 | OKeyConfigItem::List _keyList = keyList( e->key() ); | 527 | /* |
528 | * Fix Up issues with Qt/E, my keybard, and virtual input | ||
529 | * methods | ||
530 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | ||
531 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | ||
532 | * case ascii | ||
533 | */ | ||
534 | int key = e->key(); | ||
535 | int mod = e->state(); | ||
536 | |||
537 | /* | ||
538 | * virtual keyboard | ||
539 | * else change the button mod only | ||
540 | */ | ||
541 | qWarning( "handleKeyEvent...." ); | ||
542 | if ( key == 0 ) { | ||
543 | key = e->ascii(); | ||
544 | if ( key > 96 && key < 123) | ||
545 | key -= 32; | ||
546 | }else{ | ||
547 | int new_mod = 0; | ||
548 | if ( mod & 256 ) | ||
549 | new_mod |= Qt::ShiftButton; | ||
550 | else if ( mod & 512 ) | ||
551 | new_mod |= Qt::AltButton; | ||
552 | else if ( mod & 1024 ) | ||
553 | new_mod |= Qt::ControlButton; | ||
554 | |||
555 | mod = new_mod == 0? mod : new_mod; | ||
556 | } | ||
557 | |||
558 | OKeyConfigItem::List _keyList = keyList( key ); | ||
522 | if ( _keyList.isEmpty() ) | 559 | if ( _keyList.isEmpty() ) |
523 | return OKeyConfigItem(); | 560 | return OKeyConfigItem(); |
524 | 561 | ||
525 | OKeyConfigItem item; | 562 | OKeyConfigItem item; |
526 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | 563 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); |
527 | ++it ) { | 564 | ++it ) { |
528 | if ( (*it).keyPair().modifier() == e->state() ) { | 565 | if ( (*it).keyPair().modifier() == mod ) { |
529 | item = *it; | 566 | item = *it; |
530 | break; | 567 | break; |
531 | } | 568 | } |
532 | 569 | ||
533 | } | 570 | } |
534 | 571 | ||
535 | return item; | 572 | return item; |
536 | } | 573 | } |
537 | 574 | ||
538 | /** | 575 | /** |
539 | * Return the associated id of the item or -1 if no item | 576 | * Return the associated id of the item or -1 if no item |
540 | * matched the key | 577 | * matched the key |
541 | * | 578 | * |
542 | * @see handleKeyEvent | 579 | * @see handleKeyEvent |
543 | */ | 580 | */ |
544 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | 581 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { |
545 | return handleKeyEvent( ev ).id(); | 582 | return handleKeyEvent( ev ).id(); |
546 | } | 583 | } |
547 | 584 | ||
548 | /** | 585 | /** |
549 | * Add Key Config to the List of items | 586 | * Add Key Config to the List of items |
550 | */ | 587 | */ |
551 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | 588 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { |
552 | m_keys.append( item ); | 589 | m_keys.append( item ); |
553 | delete m_map; m_map = 0; | 590 | delete m_map; m_map = 0; |
554 | } | 591 | } |
555 | 592 | ||
556 | /** | 593 | /** |
557 | * Remove the Key from the Config. Internal lists will be destroyed | 594 | * Remove the Key from the Config. Internal lists will be destroyed |
558 | * and rebuild on demand later | 595 | * and rebuild on demand later |
559 | */ | 596 | */ |
560 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | 597 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { |
561 | m_keys.remove( item ); | 598 | m_keys.remove( item ); |
562 | delete m_map; m_map = 0; | 599 | delete m_map; m_map = 0; |
563 | } | 600 | } |
564 | 601 | ||
565 | /** | 602 | /** |
566 | * Clears the complete list | 603 | * Clears the complete list |
567 | */ | 604 | */ |
568 | void OKeyConfigManager::clearKeyConfig() { | 605 | void OKeyConfigManager::clearKeyConfig() { |
569 | m_keys.clear(); | 606 | m_keys.clear(); |
570 | delete m_map; m_map = 0; | 607 | delete m_map; m_map = 0; |
571 | } | 608 | } |
572 | 609 | ||
573 | 610 | ||
574 | /** | 611 | /** |
575 | * Add this OKeyPair to the blackList. | 612 | * Add this OKeyPair to the blackList. |
576 | * Internal lists will be destroyed | 613 | * Internal lists will be destroyed |
577 | */ | 614 | */ |
578 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | 615 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { |
579 | m_blackKeys.append( key ); | 616 | m_blackKeys.append( key ); |
580 | delete m_map; m_map = 0; | 617 | delete m_map; m_map = 0; |
581 | } | 618 | } |
582 | 619 | ||
583 | 620 | ||
584 | /** | 621 | /** |
585 | * Remove this OKeyPair from the black List | 622 | * Remove this OKeyPair from the black List |
586 | * Internal lists will be destroyed | 623 | * Internal lists will be destroyed |
587 | */ | 624 | */ |
588 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | 625 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { |
589 | m_blackKeys.remove( key ); | 626 | m_blackKeys.remove( key ); |
590 | delete m_map; m_map = 0; | 627 | delete m_map; m_map = 0; |
591 | } | 628 | } |
592 | 629 | ||
593 | 630 | ||
594 | /** | 631 | /** |
595 | * Clear the blackList | 632 | * Clear the blackList |
596 | */ | 633 | */ |
597 | void OKeyConfigManager::clearBlackList() { | 634 | void OKeyConfigManager::clearBlackList() { |
598 | m_blackKeys.clear(); | 635 | m_blackKeys.clear(); |
599 | delete m_map; m_map = 0; | 636 | delete m_map; m_map = 0; |
600 | } | 637 | } |
601 | 638 | ||
602 | 639 | ||
603 | /** | 640 | /** |
604 | * Return a copy of the blackList | 641 | * Return a copy of the blackList |
605 | */ | 642 | */ |
606 | OKeyPair::List OKeyConfigManager::blackList()const { | 643 | OKeyPair::List OKeyConfigManager::blackList()const { |
607 | return m_blackKeys; | 644 | return m_blackKeys; |
608 | } | 645 | } |
609 | 646 | ||
610 | 647 | ||
611 | /** | 648 | /** |
612 | * Ask the Manager to handle KeyEvents for you. | 649 | * Ask the Manager to handle KeyEvents for you. |
613 | * All handled keys will emit a QSignal and return true | 650 | * All handled keys will emit a QSignal and return true |
614 | * that it handled the keyevent | 651 | * that it handled the keyevent |
615 | */ | 652 | */ |
616 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | 653 | void OKeyConfigManager::handleWidget( QWidget* wid ) { |
617 | wid->installEventFilter( this ); | 654 | wid->installEventFilter( this ); |
618 | } | 655 | } |
619 | 656 | ||
620 | /** | 657 | /** |
621 | * @internal | 658 | * @internal |
622 | */ | 659 | */ |
623 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | 660 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { |
624 | if ( !obj->isWidgetType() ) | 661 | if ( !obj->isWidgetType() ) |