author | zecke <zecke> | 2004-04-01 19:59:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-01 19:59:29 (UTC) |
commit | 7804289bee604cd1e299f4911fa18dcfda37352f (patch) (unidiff) | |
tree | b36f3c14e11b7d89d9093999ad7503cc26d4aba8 /libopie2/opieui | |
parent | 79e746cae433ca33bbe138ff4ad2704d13215e88 (diff) | |
download | opie-7804289bee604cd1e299f4911fa18dcfda37352f.zip opie-7804289bee604cd1e299f4911fa18dcfda37352f.tar.gz opie-7804289bee604cd1e299f4911fa18dcfda37352f.tar.bz2 |
Finally only two checks left and it is done
Capture keys
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 242 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 11 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget_p.h | 33 |
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,6 +1,6 @@ | |||
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> |
@@ -10,11 +10,13 @@ | |||
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 | ||
15 | using namespace Opie::Ui; | 16 | using 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 ) |
@@ -539,28 +541,8 @@ OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | |||
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() ) |
@@ -732,32 +714,9 @@ OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | |||
732 | } | 714 | } |
733 | 715 | ||
734 | 716 | ||
735 | |||
736 | ///////////////////////// | ||
737 | //////// Widget Starts Here | ||
738 | namespace Opie { | 717 | namespace Opie { |
739 | namespace Ui { | 718 | namespace Ui { |
740 | namespace Private { | 719 | namespace 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 ) { |
@@ -801,6 +760,30 @@ namespace Private { | |||
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); |
@@ -827,7 +810,8 @@ namespace Private { | |||
827 | 810 | ||
828 | 811 | ||
829 | //////////////////////// | 812 | //////////////////////// |
830 | 813 | //////////////////////// | |
814 | //////// Widget Starts Here | ||
831 | 815 | ||
832 | 816 | ||
833 | 817 | ||
@@ -1039,14 +1023,7 @@ void OKeyConfigWidget::slotNoKey() { | |||
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 | ||
1052 | void OKeyConfigWidget::slotDefaultKey() { | 1029 | void OKeyConfigWidget::slotDefaultKey() { |
@@ -1059,18 +1036,7 @@ void OKeyConfigWidget::slotDefaultKey() { | |||
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 | ||
1076 | void OKeyConfigWidget::slotCustomKey() { | 1042 | void OKeyConfigWidget::slotCustomKey() { |
@@ -1082,28 +1048,164 @@ void OKeyConfigWidget::slotCustomKey() { | |||
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 | ||
1087 | void OKeyConfigWidget::slotConfigure() { | 1054 | void 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 | |||
1071 | void 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 | ///// | ||
1092 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | 1097 | OKeyChooserConfigDialog::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 | ||
1097 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 1118 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1098 | } | 1119 | } |
1099 | 1120 | ||
1100 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 1121 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1122 | return m_keyPair; | ||
1101 | } | 1123 | } |
1102 | 1124 | ||
1103 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | 1125 | void 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 | ||
1107 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | 1171 | void 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 | |||
1208 | void 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 | |||
@@ -21,12 +21,14 @@ class QLabel; | |||
21 | class QPushButton; | 21 | class QPushButton; |
22 | class QListViewItem; | 22 | class QListViewItem; |
23 | class QRadioButton; | 23 | class QRadioButton; |
24 | class QTimer; | ||
24 | 25 | ||
25 | namespace Opie { | 26 | namespace Opie { |
26 | namespace Ui { | 27 | namespace Ui { |
27 | namespace Private { | 28 | namespace 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; |
@@ -251,6 +253,8 @@ private slots: | |||
251 | void slotConfigure(); | 253 | void slotConfigure(); |
252 | 254 | ||
253 | private: | 255 | private: |
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; |
@@ -296,8 +300,15 @@ protected: | |||
296 | signals: | 300 | signals: |
297 | void keyCaptured(); | 301 | void keyCaptured(); |
298 | 302 | ||
303 | private slots: | ||
304 | void slotTimeUp(); | ||
305 | |||
299 | private: | 306 | private: |
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 | }; |
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 | |||
7 | namespace Opie { | ||
8 | namespace Ui { | ||
9 | namespace 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 | } | ||