Diffstat (limited to 'libopie2/opiecore/okeyconfigmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp index ccb96cc..891cda7 100644 --- a/libopie2/opiecore/okeyconfigmanager.cpp +++ b/libopie2/opiecore/okeyconfigmanager.cpp | |||
@@ -545,207 +545,217 @@ void OKeyConfigManager::save() { | |||
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 | * | ||
642 | * @see clearBlackList | ||
643 | * @see removeFromBlackList | ||
641 | */ | 644 | */ |
642 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | 645 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { |
643 | m_blackKeys.append( key ); | 646 | m_blackKeys.append( key ); |
644 | delete m_map; m_map = 0; | 647 | delete m_map; m_map = 0; |
645 | } | 648 | } |
646 | 649 | ||
647 | 650 | ||
648 | /** | 651 | /** |
649 | * Remove this OKeyPair from the black List | 652 | * Remove this OKeyPair from the black List |
650 | * Internal lists will be destroyed | 653 | * Internal lists will be destroyed |
654 | * | ||
655 | * @see addToBlackList | ||
656 | * @see clearBlackList | ||
651 | */ | 657 | */ |
652 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | 658 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { |
653 | m_blackKeys.remove( key ); | 659 | m_blackKeys.remove( key ); |
654 | delete m_map; m_map = 0; | 660 | delete m_map; m_map = 0; |
655 | } | 661 | } |
656 | 662 | ||
657 | 663 | ||
658 | /** | 664 | /** |
659 | * Clear the blackList | 665 | * Clear the blackList |
660 | */ | 666 | */ |
661 | void OKeyConfigManager::clearBlackList() { | 667 | void OKeyConfigManager::clearBlackList() { |
662 | m_blackKeys.clear(); | 668 | m_blackKeys.clear(); |
663 | delete m_map; m_map = 0; | 669 | delete m_map; m_map = 0; |
664 | } | 670 | } |
665 | 671 | ||
666 | 672 | ||
667 | /** | 673 | /** |
668 | * Return a copy of the blackList | 674 | * Return a copy of the blackList |
675 | * | ||
676 | * @see addToBlackList | ||
677 | * @see clearBlackList | ||
678 | * @see removeFromBlackList | ||
669 | */ | 679 | */ |
670 | OKeyPair::List OKeyConfigManager::blackList()const { | 680 | OKeyPair::List OKeyConfigManager::blackList()const { |
671 | return m_blackKeys; | 681 | return m_blackKeys; |
672 | } | 682 | } |
673 | 683 | ||
674 | 684 | ||
675 | /** | 685 | /** |
676 | * Ask the Manager to handle KeyEvents for you. | 686 | * Ask the Manager to handle KeyEvents for you. |
677 | * All handled keys will emit a QSignal and return true | 687 | * All handled keys will emit a QSignal and return true |
678 | * that it handled the keyevent | 688 | * that it handled the keyevent |
679 | */ | 689 | */ |
680 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | 690 | void OKeyConfigManager::handleWidget( QWidget* wid ) { |
681 | wid->installEventFilter( this ); | 691 | wid->installEventFilter( this ); |
682 | } | 692 | } |
683 | 693 | ||
684 | /** | 694 | /** |
685 | * @internal | 695 | * @internal |
686 | */ | 696 | */ |
687 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | 697 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { |
688 | if ( !obj->isWidgetType() ) | 698 | if ( !obj->isWidgetType() ) |
689 | return false; | 699 | return false; |
690 | 700 | ||
691 | /* | 701 | /* |
692 | * check if we care for the event | 702 | * check if we care for the event |
693 | */ | 703 | */ |
694 | if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && | 704 | if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && |
695 | (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) | 705 | (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) |
696 | return false; | 706 | return false; |
697 | 707 | ||
698 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | 708 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); |
699 | OKeyConfigItem item = handleKeyEvent( key ); | 709 | OKeyConfigItem item = handleKeyEvent( key ); |
700 | 710 | ||
701 | if ( item.isEmpty() ) | 711 | if ( item.isEmpty() ) |
702 | return false; | 712 | return false; |
703 | 713 | ||
704 | QWidget *wid = static_cast<QWidget*>( obj ); | 714 | QWidget *wid = static_cast<QWidget*>( obj ); |
705 | 715 | ||
706 | if ( item.object() && !item.slot().isEmpty() ) { | 716 | if ( item.object() && !item.slot().isEmpty() ) { |
707 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | 717 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), |
708 | item.object(), item.slot().data() ); | 718 | item.object(), item.slot().data() ); |
709 | emit actionActivated(wid, key); | 719 | emit actionActivated(wid, key); |
710 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | 720 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), |
711 | item.object(), item.slot().data() ); | 721 | item.object(), item.slot().data() ); |
712 | } | 722 | } |
713 | emit actionActivated( wid, key, item ); | 723 | emit actionActivated( wid, key, item ); |
714 | 724 | ||
715 | return true; | 725 | return true; |
716 | } | 726 | } |
717 | 727 | ||
718 | /** | 728 | /** |
719 | * @internal | 729 | * @internal |
720 | */ | 730 | */ |
721 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | 731 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { |
722 | /* | 732 | /* |
723 | * Create the map if not existing anymore | 733 | * Create the map if not existing anymore |
724 | */ | 734 | */ |
725 | if ( !m_map ) { | 735 | if ( !m_map ) { |
726 | m_map = new OKeyMapConfigPrivate; | 736 | m_map = new OKeyMapConfigPrivate; |
727 | /* for every key */ | 737 | /* for every key */ |
728 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 738 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
729 | it!= m_keys.end(); ++it ) { | 739 | it!= m_keys.end(); ++it ) { |
730 | 740 | ||
731 | bool add = true; | 741 | bool add = true; |
732 | /* see if this key is blocked */ | 742 | /* see if this key is blocked */ |
733 | OKeyPair pair = (*it).keyPair(); | 743 | OKeyPair pair = (*it).keyPair(); |
734 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | 744 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); |
735 | pairIt != m_blackKeys.end(); ++pairIt ) { | 745 | pairIt != m_blackKeys.end(); ++pairIt ) { |
736 | if ( (*pairIt).keycode() == pair.keycode() && | 746 | if ( (*pairIt).keycode() == pair.keycode() && |
737 | (*pairIt).modifier() == pair.modifier() ) { | 747 | (*pairIt).modifier() == pair.modifier() ) { |
738 | add = false; | 748 | add = false; |
739 | break; | 749 | break; |
740 | } | 750 | } |
741 | } | 751 | } |
742 | /* check if we added it */ | 752 | /* check if we added it */ |
743 | if ( add ) | 753 | if ( add ) |
744 | (*m_map)[pair.keycode()].append( *it ); | 754 | (*m_map)[pair.keycode()].append( *it ); |
745 | } | 755 | } |
746 | } | 756 | } |
747 | return (*m_map)[keycode]; | 757 | return (*m_map)[keycode]; |
748 | } | 758 | } |
749 | 759 | ||
750 | } | 760 | } |
751 | } | 761 | } |