summaryrefslogtreecommitdiff
path: root/libopie2
authorzecke <zecke>2004-04-01 19:59:29 (UTC)
committer zecke <zecke>2004-04-01 19:59:29 (UTC)
commit7804289bee604cd1e299f4911fa18dcfda37352f (patch) (unidiff)
treeb36f3c14e11b7d89d9093999ad7503cc26d4aba8 /libopie2
parent79e746cae433ca33bbe138ff4ad2704d13215e88 (diff)
downloadopie-7804289bee604cd1e299f4911fa18dcfda37352f.zip
opie-7804289bee604cd1e299f4911fa18dcfda37352f.tar.gz
opie-7804289bee604cd1e299f4911fa18dcfda37352f.tar.bz2
Finally only two checks left and it is done
Capture keys
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp242
-rw-r--r--libopie2/opieui/okeyconfigwidget.h11
-rw-r--r--libopie2/opieui/okeyconfigwidget_p.h33
3 files changed, 216 insertions, 70 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp
index 41be1be..3e08416 100644
--- a/libopie2/opieui/okeyconfigwidget.cpp
+++ b/libopie2/opieui/okeyconfigwidget.cpp
@@ -1,41 +1,43 @@
1#include "okeyconfigwidget.h" 1#include "okeyconfigwidget.h"
2#include "okeyconfigwidget_p.h"
2 3
3#include <opie2/olistview.h>
4 4
5#include <qgroupbox.h> 5#include <qgroupbox.h>
6#include <qradiobutton.h> 6#include <qradiobutton.h>
7#include <qpushbutton.h> 7#include <qpushbutton.h>
8#include <qbuttongroup.h> 8#include <qbuttongroup.h>
9 9
10#include <qaccel.h> 10#include <qaccel.h>
11#include <qlayout.h> 11#include <qlayout.h>
12#include <qlabel.h> 12#include <qlabel.h>
13#include <qtimer.h>
13 14
14 15
15using namespace Opie::Ui; 16using namespace Opie::Ui;
16 17
17 18
19
18/** 20/**
19 * The default Constructor of a OKeyPair. 21 * The default Constructor of a OKeyPair.
20 * A Key and a Modifier ( Alt/Shift/Ctrl ) 22 * A Key and a Modifier ( Alt/Shift/Ctrl )
21 * needs to be supplied. 23 * needs to be supplied.
22 * Use Qt::Key for the information. 24 * Use Qt::Key for the information.
23 * The default arguments create an Empty OKeyPair. If you 25 * The default arguments create an Empty OKeyPair. If you
24 * want to get an empty OKeyPair use the static method for getting 26 * want to get an empty OKeyPair use the static method for getting
25 * the emptyKey() 27 * the emptyKey()
26 * 28 *
27 * @see OKeyPair OKeyPair::emptyKey() 29 * @see OKeyPair OKeyPair::emptyKey()
28 */ 30 */
29OKeyPair::OKeyPair( int key, int mod ) 31OKeyPair::OKeyPair( int key, int mod )
30 : m_key( key ), m_mod( mod ) 32 : m_key( key ), m_mod( mod )
31{} 33{}
32 34
33/** 35/**
34 * The destructor 36 * The destructor
35 */ 37 */
36OKeyPair::~OKeyPair() {} 38OKeyPair::~OKeyPair() {}
37 39
38 40
39/** 41/**
40 * Is this OKeyPair empty/valid? 42 * Is this OKeyPair empty/valid?
41 */ 43 */
@@ -518,70 +520,50 @@ void OKeyConfigManager::save() {
518 return; 520 return;
519 */ 521 */
520 522
521 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); 523 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() );
522 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); 524 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() );
523 } 525 }
524} 526}
525 527
526/** 528/**
527 * This is function uses a QMap internally but you can have the same keycode 529 * This is function uses a QMap internally but you can have the same keycode
528 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem 530 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem
529 * with same keycode and modifier key. The GUI takes care that a user can't 531 * with same keycode and modifier key. The GUI takes care that a user can't
530 * cofigure two keys. 532 * cofigure two keys.
531 * 533 *
532 * Make sure you call e->ignore if you don't want to handle this event 534 * Make sure you call e->ignore if you don't want to handle this event
533 */ 535 */
534OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { 536OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) {
535 /* 537 /*
536 * Fix Up issues with Qt/E, my keybard, and virtual input 538 * Fix Up issues with Qt/E, my keybard, and virtual input
537 * methods 539 * methods
538 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state 540 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state
539 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower 541 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower
540 * case ascii 542 * case ascii
541 */ 543 */
542 int key = e->key(); 544 int key, mod;
543 int mod = e->state(); 545 Opie::Ui::Private::fixupKeys( key, mod, e );
544
545/*
546 * virtual keyboard
547 * else change the button mod only
548 */
549 if ( key == 0 ) {
550 key = e->ascii();
551 if ( key > 96 && key < 123)
552 key -= 32;
553 }else{
554 int new_mod = 0;
555 if ( mod & 256 )
556 new_mod |= Qt::ShiftButton;
557 else if ( mod & 512 )
558 new_mod |= Qt::ControlButton;
559 else if ( mod & 1024 )
560 new_mod |= Qt::AltButton;
561
562 mod = new_mod == 0? mod : new_mod;
563 }
564 546
565 OKeyConfigItem::List _keyList = keyList( key ); 547 OKeyConfigItem::List _keyList = keyList( key );
566 if ( _keyList.isEmpty() ) 548 if ( _keyList.isEmpty() )
567 return OKeyConfigItem(); 549 return OKeyConfigItem();
568 550
569 OKeyConfigItem item; 551 OKeyConfigItem item;
570 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); 552 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end();
571 ++it ) { 553 ++it ) {
572 if ( (*it).keyPair().modifier() == mod ) { 554 if ( (*it).keyPair().modifier() == mod ) {
573 item = *it; 555 item = *it;
574 break; 556 break;
575 } 557 }
576 558
577 } 559 }
578 560
579 return item; 561 return item;
580} 562}
581 563
582/** 564/**
583 * Return the associated id of the item or -1 if no item 565 * Return the associated id of the item or -1 if no item
584 * matched the key 566 * matched the key
585 * 567 *
586 * @see handleKeyEvent 568 * @see handleKeyEvent
587 */ 569 */
@@ -711,144 +693,146 @@ OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) {
711 /* for every key */ 693 /* for every key */
712 for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); 694 for ( OKeyConfigItem::List::Iterator it = m_keys.begin();
713 it!= m_keys.end(); ++it ) { 695 it!= m_keys.end(); ++it ) {
714 696
715 bool add = true; 697 bool add = true;
716 /* see if this key is blocked */ 698 /* see if this key is blocked */
717 OKeyPair pair = (*it).keyPair(); 699 OKeyPair pair = (*it).keyPair();
718 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); 700 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin();
719 pairIt != m_blackKeys.end(); ++pairIt ) { 701 pairIt != m_blackKeys.end(); ++pairIt ) {
720 if ( (*pairIt).keycode() == pair.keycode() && 702 if ( (*pairIt).keycode() == pair.keycode() &&
721 (*pairIt).modifier() == pair.modifier() ) { 703 (*pairIt).modifier() == pair.modifier() ) {
722 add = false; 704 add = false;
723 break; 705 break;
724 } 706 }
725 } 707 }
726 /* check if we added it */ 708 /* check if we added it */
727 if ( add ) 709 if ( add )
728 (*m_map)[pair.keycode()].append( *it ); 710 (*m_map)[pair.keycode()].append( *it );
729 } 711 }
730 } 712 }
731 return (*m_map)[keycode]; 713 return (*m_map)[keycode];
732} 714}
733 715
734 716
735
736/////////////////////////
737//////// Widget Starts Here
738namespace Opie { 717namespace Opie {
739namespace Ui { 718namespace Ui {
740namespace Private { 719namespace Private {
741 static QString keyToString( const OKeyPair& );
742 class OKeyListViewItem : public Opie::Ui::OListViewItem {
743 public:
744 OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent);
745 ~OKeyListViewItem();
746
747 void setDefault();
748
749 OKeyConfigItem& item();
750 OKeyConfigItem origItem()const;
751 void setItem( const OKeyConfigItem& item );
752 void updateText();
753
754 OKeyConfigManager *manager();
755 private:
756 OKeyConfigItem m_item;
757 OKeyConfigItem m_origItem;
758 OKeyConfigManager* m_manager;
759
760 };
761 720
762 OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) 721 OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent)
763 : Opie::Ui::OListViewItem( parent ), m_manager( man ) { 722 : Opie::Ui::OListViewItem( parent ), m_manager( man ) {
764 m_origItem = item; 723 m_origItem = item;
765 setItem( item ); 724 setItem( item );
766 } 725 }
767 OKeyListViewItem::~OKeyListViewItem() {} 726 OKeyListViewItem::~OKeyListViewItem() {}
768 OKeyConfigItem &OKeyListViewItem::item(){ 727 OKeyConfigItem &OKeyListViewItem::item(){
769 return m_item; 728 return m_item;
770 } 729 }
771 OKeyConfigItem OKeyListViewItem::origItem() const{ 730 OKeyConfigItem OKeyListViewItem::origItem() const{
772 return m_origItem; 731 return m_origItem;
773 } 732 }
774 OKeyConfigManager* OKeyListViewItem::manager() { 733 OKeyConfigManager* OKeyListViewItem::manager() {
775 return m_manager; 734 return m_manager;
776 } 735 }
777 void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { 736 void OKeyListViewItem::setItem( const OKeyConfigItem& item ) {
778 m_item = item; 737 m_item = item;
779 setPixmap( 0, m_item.pixmap() ); 738 setPixmap( 0, m_item.pixmap() );
780 setText ( 1, m_item.text() ); 739 setText ( 1, m_item.text() );
781 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : 740 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) :
782 setText( 2, keyToString( m_item.keyPair() ) ); 741 setText( 2, keyToString( m_item.keyPair() ) );
783 742
784 m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : 743 m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) :
785 setText ( 3, keyToString( m_item.defaultKeyPair() ) ); 744 setText ( 3, keyToString( m_item.defaultKeyPair() ) );
786 } 745 }
787 void OKeyListViewItem::updateText() { 746 void OKeyListViewItem::updateText() {
788 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : 747 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) :
789 setText( 2, keyToString( m_item.keyPair() ) ); 748 setText( 2, keyToString( m_item.keyPair() ) );
790 } 749 }
791 750
792 QString keyToString( const OKeyPair& pair ) { 751 QString keyToString( const OKeyPair& pair ) {
793 int mod = 0; 752 int mod = 0;
794 if ( pair.modifier() & Qt::ShiftButton ) 753 if ( pair.modifier() & Qt::ShiftButton )
795 mod |= Qt::SHIFT; 754 mod |= Qt::SHIFT;
796 if ( pair.modifier() & Qt::ControlButton ) 755 if ( pair.modifier() & Qt::ControlButton )
797 mod |= Qt::CTRL; 756 mod |= Qt::CTRL;
798 if ( pair.modifier() & Qt::AltButton ) 757 if ( pair.modifier() & Qt::AltButton )
799 mod |= Qt::ALT; 758 mod |= Qt::ALT;
800 759
801 return QAccel::keyToString( mod + pair.keycode() ); 760 return QAccel::keyToString( mod + pair.keycode() );
802 } 761 }
803 762
763 void fixupKeys( int& key, int &mod, QKeyEvent* e ) {
764 key = e->key();
765 mod = e->state();
766 /*
767 * virtual keyboard
768 * else change the button mod only
769 */
770 if ( key == 0 ) {
771 key = e->ascii();
772 if ( key > 96 && key < 123)
773 key -= 32;
774 }else{
775 int new_mod = 0;
776 if ( mod & 256 )
777 new_mod |= Qt::ShiftButton;
778 else if ( mod & 512 )
779 new_mod |= Qt::ControlButton;
780 else if ( mod & 1024 )
781 new_mod |= Qt::AltButton;
782
783 mod = new_mod == 0? mod : new_mod;
784 }
785 }
786
804 struct OKeyConfigWidgetPrivate{ 787 struct OKeyConfigWidgetPrivate{
805 OKeyConfigWidgetPrivate(const QString& = QString::null, 788 OKeyConfigWidgetPrivate(const QString& = QString::null,
806 OKeyConfigManager* = 0); 789 OKeyConfigManager* = 0);
807 bool operator==( const OKeyConfigWidgetPrivate& ); 790 bool operator==( const OKeyConfigWidgetPrivate& );
808 QString name; 791 QString name;
809 OKeyConfigManager *manager; 792 OKeyConfigManager *manager;
810 }; 793 };
811 794
812 OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, 795 OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name,
813 OKeyConfigManager* man ) 796 OKeyConfigManager* man )
814 : name( _name ), manager( man ){} 797 : name( _name ), manager( man ){}
815 798
816 bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { 799 bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) {
817 if ( manager != item.manager) return false; 800 if ( manager != item.manager) return false;
818 if ( name != item.name ) return false; 801 if ( name != item.name ) return false;
819 802
820 return true; 803 return true;
821 } 804 }
822 805
823} 806}
824} 807}
825} 808}
826 809
827 810
828 811
829//////////////////////// 812////////////////////////
830 813////////////////////////
814//////// Widget Starts Here
831 815
832 816
833 817
834 818
835/** 819/**
836 * 820 *
837 * This is a c'tor. You still need to pass the OKeyConfigManager 821 * This is a c'tor. You still need to pass the OKeyConfigManager
838 * and then issue a load. 822 * and then issue a load.
839 * The default mode is Immediate 823 * The default mode is Immediate
840 * 824 *
841 */ 825 */
842OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) 826OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl )
843 : QWidget( parent, name, fl ) { 827 : QWidget( parent, name, fl ) {
844 initUi(); 828 initUi();
845} 829}
846 830
847 831
848 832
849/** 833/**
850 * c'tor 834 * c'tor
851 */ 835 */
852OKeyConfigWidget::~OKeyConfigWidget() { 836OKeyConfigWidget::~OKeyConfigWidget() {
853} 837}
854 838
@@ -1018,92 +1002,210 @@ void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) {
1018 m_none->setChecked( false ); 1002 m_none->setChecked( false );
1019 m_cus ->setChecked( true ); 1003 m_cus ->setChecked( true );
1020 m_btn ->setEnabled( true ); 1004 m_btn ->setEnabled( true );
1021 m_def ->setChecked( false ); 1005 m_def ->setChecked( false );
1022 } 1006 }
1023 } 1007 }
1024} 1008}
1025 1009
1026void OKeyConfigWidget::slotNoKey() { 1010void OKeyConfigWidget::slotNoKey() {
1027 qWarning( "No Key" ); 1011 qWarning( "No Key" );
1028 m_none->setChecked( true ); 1012 m_none->setChecked( true );
1029 m_cus ->setChecked( false ); 1013 m_cus ->setChecked( false );
1030 m_btn ->setEnabled( false ); 1014 m_btn ->setEnabled( false );
1031 m_def ->setChecked( false ); 1015 m_def ->setChecked( false );
1032 1016
1033 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 1017 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
1034 return; 1018 return;
1035 1019
1036 1020
1037 1021
1038 /* 1022 /*
1039 * If immediate we need to remove and readd the key 1023 * If immediate we need to remove and readd the key
1040 */ 1024 */
1041 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); 1025 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem());
1042 if ( m_mode == Imediate ) 1026 updateItem( item, OKeyPair::emptyKey() );
1043 item->manager()->removeKeyConfig( item->item() );
1044 item->item().setKeyPair( OKeyPair::emptyKey() );
1045 item->updateText();
1046
1047 if ( m_mode == Imediate )
1048 item->manager()->addKeyConfig( item->item() );
1049
1050} 1027}
1051 1028
1052void OKeyConfigWidget::slotDefaultKey() { 1029void OKeyConfigWidget::slotDefaultKey() {
1053 m_none->setChecked( false ); 1030 m_none->setChecked( false );
1054 m_cus ->setChecked( false ); 1031 m_cus ->setChecked( false );
1055 m_btn ->setEnabled( false ); 1032 m_btn ->setEnabled( false );
1056 m_def ->setChecked( true ); 1033 m_def ->setChecked( true );
1057 1034
1058 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 1035 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
1059 return; 1036 return;
1060 1037
1061 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); 1038 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem());
1062 1039 updateItem( item, item->item().defaultKeyPair() );
1063 /*
1064 * If immediate we need to remove and readd the key
1065 */
1066 if ( m_mode == Imediate )
1067 item->manager()->removeKeyConfig( item->item() );
1068
1069 item->item().setKeyPair( item->item().defaultKeyPair() );
1070 item->updateText();
1071
1072 if ( m_mode == Imediate )
1073 item->manager()->addKeyConfig( item->item() );
1074} 1040}
1075 1041
1076void OKeyConfigWidget::slotCustomKey() { 1042void OKeyConfigWidget::slotCustomKey() {
1077 m_cus ->setChecked( true ); 1043 m_cus ->setChecked( true );
1078 m_btn ->setEnabled( true ); 1044 m_btn ->setEnabled( true );
1079 m_def ->setChecked( false ); 1045 m_def ->setChecked( false );
1080 m_none->setChecked( false ); 1046 m_none->setChecked( false );
1081 1047
1082 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 1048 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
1083 return; 1049 return;
1084 1050
1051
1085} 1052}
1086 1053
1087void OKeyConfigWidget::slotConfigure() { 1054void OKeyConfigWidget::slotConfigure() {
1055 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
1056 return;
1057
1058 /* FIXME make use of OModalHelper */
1059 OKeyChooserConfigDialog dlg( this, "Dialog Name", true );
1060 dlg.setCaption(tr("Configure Key"));
1061 connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) );
1062
1063 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) {
1064 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem());
1065 updateItem( item, dlg.keyPair() );
1066 }
1067
1068
1069}
1070
1071void OKeyConfigWidget::updateItem( Opie::Ui::Private::OKeyListViewItem *item,
1072 const OKeyPair& newItem) {
1073 /* sanity check
1074 * check against the blacklist of the manager
1075 * check if another item uses this key which is o(n) at least
1076 */
1077 if ( !newItem.isEmpty() ) {
1078
1079 }
1088 1080
1081 /*
1082 * If immediate we need to remove and readd the key
1083 */
1084 if ( m_mode == Imediate )
1085 item->manager()->removeKeyConfig( item->item() );
1086
1087 item->item().setKeyPair( newItem );
1088 item->updateText();
1089
1090 if ( m_mode == Imediate )
1091 item->manager()->addKeyConfig( item->item() );
1089} 1092}
1090 1093
1091 1094
1095
1096/////
1092OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, 1097OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam,
1093 bool mod, WFlags fl ) 1098 bool mod, WFlags fl )
1094 : QDialog( par, nam, mod, fl ) { 1099 : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) ,
1100 m_key( 0 ), m_mod( 0 ) {
1101 setFocusPolicy( StrongFocus );
1102
1103 QHBoxLayout *lay = new QHBoxLayout( this );
1104
1105 QLabel *lbl = new QLabel( tr("Configure Key" ), this );
1106 lay->addWidget( lbl );
1107 lbl->setFocusPolicy( NoFocus );
1108
1109 m_lbl = new QLabel( this );
1110 lay->addWidget( m_lbl );
1111 m_lbl->setFocusPolicy( NoFocus );
1112
1113 m_timer = new QTimer( this );
1114 connect(m_timer, SIGNAL(timeout()),
1115 this, SLOT(slotTimeUp()) );
1095} 1116}
1096 1117
1097OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { 1118OKeyChooserConfigDialog::~OKeyChooserConfigDialog() {
1098} 1119}
1099 1120
1100Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ 1121Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{
1122 return m_keyPair;
1101} 1123}
1102 1124
1103void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { 1125void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) {
1104 ev->ignore(); 1126 QDialog::keyPressEvent( ev );
1127
1128 if ( ev->isAutoRepeat() )
1129 return;
1130
1131 qWarning( "Key Press Event" );
1132 int mod, key;
1133 Opie::Ui::Private::fixupKeys( key,mod, ev );
1134
1135 /* either we used software keyboard
1136 * or we've true support
1137 */
1138 if ( !m_virtKey && !ev->key()) {
1139 m_virtKey = true;
1140 m_keyPair = OKeyPair( key, mod );
1141 }else{
1142 mod = 0;
1143 switch( key ) {
1144 case Qt::Key_Control:
1145 mod = Qt::ControlButton;
1146 break;
1147 case Qt::Key_Shift:
1148 mod = Qt::ShiftButton;
1149 break;
1150 case Qt::Key_Alt:
1151 mod = Qt::AltButton;
1152 break;
1153 default:
1154 break;
1155 }
1156 if (mod ) {
1157 m_mod |= mod;
1158 }else
1159 m_key = key;
1160
1161 if ( ( !mod || m_key ) && !m_timer->isActive() )
1162 m_timer->start( 50, true );
1163
1164 m_keyPair = OKeyPair( m_key, m_mod );
1165 }
1166
1167 m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) );
1168
1105} 1169}
1106 1170
1107void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { 1171void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) {
1108 ev->ignore(); 1172 m_timer->stop();
1173 QDialog::keyPressEvent( ev );
1174
1175 if ( ev->isAutoRepeat() )
1176 return;
1177
1178
1179 if ( m_virtKey && !ev->key()) {
1180 m_virtKey = false;
1181 slotTimeUp();
1182 }else {
1183 int mod = 0;
1184 int key = ev->key();
1185 switch( key ) {
1186 case Qt::Key_Control:
1187 mod = Qt::ControlButton;
1188 break;
1189 case Qt::Key_Shift:
1190 mod = Qt::ShiftButton;
1191 break;
1192 case Qt::Key_Alt:
1193 mod = Qt::AltButton;
1194 break;
1195 default:
1196 break;
1197 }
1198 if (mod )
1199 m_mod &= ~mod;
1200 else
1201 m_key = key;
1202 m_keyPair = OKeyPair( m_key, m_mod );
1203 m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) );
1204 }
1205}
1206
1207
1208void OKeyChooserConfigDialog::slotTimeUp() {
1209 m_mod = m_key = 0;
1210 QTimer::singleShot(0, this, SIGNAL(keyCaptured()) );
1109} 1211}
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h
index 8d2a1ef..9e26719 100644
--- a/libopie2/opieui/okeyconfigwidget.h
+++ b/libopie2/opieui/okeyconfigwidget.h
@@ -1,53 +1,55 @@
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 <qcstring.h> 15#include <qcstring.h>
16#include <qhbox.h> 16#include <qhbox.h>
17#include <qvaluelist.h> 17#include <qvaluelist.h>
18 18
19class QKeyEvent; 19class QKeyEvent;
20class QLabel; 20class QLabel;
21class QPushButton; 21class QPushButton;
22class QListViewItem; 22class QListViewItem;
23class QRadioButton; 23class QRadioButton;
24class QTimer;
24 25
25namespace Opie { 26namespace Opie {
26namespace Ui { 27namespace Ui {
27namespace Private { 28namespace Private {
28 class OKeyConfigWidgetPrivate; 29 class OKeyConfigWidgetPrivate;
29 typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; 30 typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList;
31 class OKeyListViewItem;
30} 32}
31 class OListViewItem; 33 class OListViewItem;
32 class OListView; 34 class OListView;
33 35
34/** 36/**
35 * \brief small class representing a Key with possible modifiers 37 * \brief small class representing a Key with possible modifiers
36 * This class holds information about key code and possible 38 * This class holds information about key code and possible
37 * modifier state. That is the lowest level of the key input 39 * modifier state. That is the lowest level of the key input
38 * functions. 40 * functions.
39 * There are also static methods to get special keys. 41 * There are also static methods to get special keys.
40 * OKeyPair will be used with \see OKeyConfigItem 42 * OKeyPair will be used with \see OKeyConfigItem
41 * 43 *
42 * @since 1.2 44 * @since 1.2
43 */ 45 */
44class OKeyPair { 46class OKeyPair {
45public: 47public:
46 typedef QValueList<OKeyPair> List; 48 typedef QValueList<OKeyPair> List;
47 OKeyPair( int key = -1, int modifier = -1); 49 OKeyPair( int key = -1, int modifier = -1);
48 ~OKeyPair(); 50 ~OKeyPair();
49 51
50 bool operator==( const OKeyPair& ); 52 bool operator==( const OKeyPair& );
51 bool operator!=( const OKeyPair& ); 53 bool operator!=( const OKeyPair& );
52 54
53 bool isEmpty()const; 55 bool isEmpty()const;
@@ -230,80 +232,89 @@ public:
230 /** 232 /**
231 * Immediate Apply the change directly to the underlying OKeyConfigManager 233 * Immediate Apply the change directly to the underlying OKeyConfigManager
232 * Queue Save all items and then apply when you save() 234 * Queue Save all items and then apply when you save()
233 */ 235 */
234 enum ChangeMode { Imediate, Queue }; 236 enum ChangeMode { Imediate, Queue };
235 OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 237 OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
236 ~OKeyConfigWidget(); 238 ~OKeyConfigWidget();
237 239
238 void setChangeMode( enum ChangeMode ); 240 void setChangeMode( enum ChangeMode );
239 ChangeMode changeMode()const; 241 ChangeMode changeMode()const;
240 242
241 void insert( const QString& name, OKeyConfigManager* ); 243 void insert( const QString& name, OKeyConfigManager* );
242 244
243 void load(); 245 void load();
244 void save(); 246 void save();
245 247
246private slots: 248private slots:
247 void slotListViewItem( QListViewItem* ); 249 void slotListViewItem( QListViewItem* );
248 void slotNoKey(); 250 void slotNoKey();
249 void slotDefaultKey(); 251 void slotDefaultKey();
250 void slotCustomKey(); 252 void slotCustomKey();
251 void slotConfigure(); 253 void slotConfigure();
252 254
253private: 255private:
256 void updateItem( Opie::Ui::Private::OKeyListViewItem* man,
257 const OKeyPair& newItem);
254 void initUi(); 258 void initUi();
255 Opie::Ui::OListView *m_view; 259 Opie::Ui::OListView *m_view;
256 Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; 260 Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list;
257 QLabel *m_lbl; 261 QLabel *m_lbl;
258 QPushButton *m_btn; 262 QPushButton *m_btn;
259 QRadioButton *m_def, *m_cus, *m_none; 263 QRadioButton *m_def, *m_cus, *m_none;
260 QWidget* m_box; 264 QWidget* m_box;
261 ChangeMode m_mode; 265 ChangeMode m_mode;
262 class Private; 266 class Private;
263 Private *d; 267 Private *d;
264}; 268};
265 269
266 270
267/** 271/**
268 * This is a small dialog that allows you to 272 * This is a small dialog that allows you to
269 * capture a key sequence. 273 * capture a key sequence.
270 * If you want it to close after a key was captured you 274 * If you want it to close after a key was captured you
271 * can use this code snippet. 275 * can use this code snippet.
272 * 276 *
273 * \code 277 * \code
274 * OKeyChooserConfigDialog diag(0,0,true); 278 * OKeyChooserConfigDialog diag(0,0,true);
275 * connect(&diag,SIGNAL(keyCaptured()), 279 * connect(&diag,SIGNAL(keyCaptured()),
276 * this,SLOT(accept())); 280 * this,SLOT(accept()));
277 * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ 281 * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){
278 * take_the_key_and_do_something 282 * take_the_key_and_do_something
279 * } 283 * }
280 * 284 *
281 * \endcode 285 * \endcode
282 * 286 *
283 */ 287 */
284class OKeyChooserConfigDialog : public QDialog { 288class OKeyChooserConfigDialog : public QDialog {
285 Q_OBJECT 289 Q_OBJECT
286public: 290public:
287 OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); 291 OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 );
288 ~OKeyChooserConfigDialog(); 292 ~OKeyChooserConfigDialog();
289 293
290 OKeyPair keyPair()const; 294 OKeyPair keyPair()const;
291 295
292protected: 296protected:
293 void keyPressEvent( QKeyEvent* ); 297 void keyPressEvent( QKeyEvent* );
294 void keyReleaseEvent( QKeyEvent* ); 298 void keyReleaseEvent( QKeyEvent* );
295 299
296signals: 300signals:
297 void keyCaptured(); 301 void keyCaptured();
298 302
303private slots:
304 void slotTimeUp();
305
299private: 306private:
307 QTimer *m_timer;
308 QLabel *m_lbl;
309 bool m_virtKey : 1;
300 OKeyPair m_keyPair; 310 OKeyPair m_keyPair;
311 int m_key, m_mod;
301 class Private; 312 class Private;
302 Private *d; 313 Private *d;
303}; 314};
304 315
305} 316}
306} 317}
307 318
308 319
309#endif 320#endif
diff --git a/libopie2/opieui/okeyconfigwidget_p.h b/libopie2/opieui/okeyconfigwidget_p.h
new file mode 100644
index 0000000..e7eaba6
--- a/dev/null
+++ b/libopie2/opieui/okeyconfigwidget_p.h
@@ -0,0 +1,33 @@
1/*
2 * Only Internal implemented in the same .cpp file anyway
3 */
4#include <opie2/olistview.h>
5
6
7namespace Opie {
8namespace Ui {
9namespace Private {
10 static QString keyToString( const OKeyPair& );
11 static void fixupKeys( int&, int&, QKeyEvent* );
12 class OKeyListViewItem : public Opie::Ui::OListViewItem {
13 public:
14 OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent);
15 ~OKeyListViewItem();
16
17 void setDefault();
18
19 OKeyConfigItem& item();
20 OKeyConfigItem origItem()const;
21 void setItem( const OKeyConfigItem& item );
22 void updateText();
23
24 OKeyConfigManager *manager();
25 private:
26 OKeyConfigItem m_item;
27 OKeyConfigItem m_origItem;
28 OKeyConfigManager* m_manager;
29
30 };
31}
32}
33}