author | zecke <zecke> | 2004-03-29 01:19:31 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-29 01:19:31 (UTC) |
commit | e8dd4582051e07a049ae8b3cd04b4463ecc33790 (patch) (unidiff) | |
tree | ab7d4d71eb460f0c1afff2d326c0447f5b986814 /libopie2 | |
parent | 28648c47d06c339ee893f8cef740bae9d54863bf (diff) | |
download | opie-e8dd4582051e07a049ae8b3cd04b4463ecc33790.zip opie-e8dd4582051e07a049ae8b3cd04b4463ecc33790.tar.gz opie-e8dd4582051e07a049ae8b3cd04b4463ecc33790.tar.bz2 |
-Bugfixes on compare operator and isEmpty
-Implement saving from the widget to the manager
-Fix Ctrl vs Alt mixup
Yeah now the user can select between none and default
A OKeyChooserDialog will soon be implemented
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 93 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 41 |
2 files changed, 119 insertions, 15 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index 273f15b..41be1be 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -362,4 +362,5 @@ bool OKeyConfigItem::isEmpty()const { | |||
362 | if ( !m_key.isEmpty() ) return false; | 362 | if ( !m_key.isEmpty() ) return false; |
363 | if ( !m_text.isEmpty() ) return false; | 363 | if ( !m_text.isEmpty() ) return false; |
364 | if ( m_id != -1 ) return false; | ||
364 | 365 | ||
365 | return true; | 366 | return true; |
@@ -370,13 +371,17 @@ bool OKeyConfigItem::isEmpty()const { | |||
370 | */ | 371 | */ |
371 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { | 372 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { |
372 | if ( isEmpty() == conf.isEmpty() ) return true; | 373 | /* if ( isEmpty() == conf.isEmpty() ) return true; |
373 | else if ( isEmpty() != conf.isEmpty() ) return false; | 374 | else if ( isEmpty() != conf.isEmpty() ) return false; |
374 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | 375 | else if ( !isEmpty()!= conf.isEmpty() ) return false; |
376 | */ | ||
375 | 377 | ||
376 | if ( m_id != conf.m_id ) return false; | 378 | if ( m_id != conf.m_id ) return false; |
379 | if ( m_obj != conf.m_obj ) return false; | ||
377 | if ( m_text != conf.m_text ) return false; | 380 | if ( m_text != conf.m_text ) return false; |
378 | if ( m_key != conf.m_key ) return false; | 381 | if ( m_key != conf.m_key ) return false; |
379 | if ( m_def != conf.m_def ) return false; | 382 | if ( m_def != conf.m_def ) return false; |
380 | 383 | ||
384 | |||
385 | |||
381 | return true; | 386 | return true; |
382 | 387 | ||
@@ -506,8 +511,11 @@ void OKeyConfigManager::save() { | |||
506 | OKeyPair pair = (*it).keyPair(); | 511 | OKeyPair pair = (*it).keyPair(); |
507 | OKeyPair deft = (*it).defaultKeyPair(); | 512 | OKeyPair deft = (*it).defaultKeyPair(); |
508 | /* don't write if it is the default setting */ | 513 | /* |
514 | * don't write if it is the default setting | ||
515 | * FIXME allow to remove Keys | ||
509 | if ( (pair.keycode() == deft.keycode()) && | 516 | if ( (pair.keycode() == deft.keycode()) && |
510 | (pair.modifier()== deft.modifier() ) ) | 517 | (pair.modifier()== deft.modifier() ) ) |
511 | return; | 518 | return; |
519 | */ | ||
512 | 520 | ||
513 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | 521 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
@@ -548,7 +556,7 @@ OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | |||
548 | new_mod |= Qt::ShiftButton; | 556 | new_mod |= Qt::ShiftButton; |
549 | else if ( mod & 512 ) | 557 | else if ( mod & 512 ) |
550 | new_mod |= Qt::AltButton; | ||
551 | else if ( mod & 1024 ) | ||
552 | new_mod |= Qt::ControlButton; | 558 | new_mod |= Qt::ControlButton; |
559 | else if ( mod & 1024 ) | ||
560 | new_mod |= Qt::AltButton; | ||
553 | 561 | ||
554 | mod = new_mod == 0? mod : new_mod; | 562 | mod = new_mod == 0? mod : new_mod; |
@@ -587,4 +595,5 @@ int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | |||
587 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | 595 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { |
588 | m_keys.append( item ); | 596 | m_keys.append( item ); |
597 | qWarning( "m_keys count is now %d", m_keys.count() ); | ||
589 | delete m_map; m_map = 0; | 598 | delete m_map; m_map = 0; |
590 | } | 599 | } |
@@ -596,4 +605,5 @@ void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | |||
596 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | 605 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { |
597 | m_keys.remove( item ); | 606 | m_keys.remove( item ); |
607 | qWarning( "m_keys count is now %d", m_keys.count() ); | ||
598 | delete m_map; m_map = 0; | 608 | delete m_map; m_map = 0; |
599 | } | 609 | } |
@@ -738,9 +748,12 @@ namespace Private { | |||
738 | 748 | ||
739 | OKeyConfigItem& item(); | 749 | OKeyConfigItem& item(); |
750 | OKeyConfigItem origItem()const; | ||
740 | void setItem( const OKeyConfigItem& item ); | 751 | void setItem( const OKeyConfigItem& item ); |
752 | void updateText(); | ||
741 | 753 | ||
742 | OKeyConfigManager *manager(); | 754 | OKeyConfigManager *manager(); |
743 | private: | 755 | private: |
744 | OKeyConfigItem m_item; | 756 | OKeyConfigItem m_item; |
757 | OKeyConfigItem m_origItem; | ||
745 | OKeyConfigManager* m_manager; | 758 | OKeyConfigManager* m_manager; |
746 | 759 | ||
@@ -749,4 +762,5 @@ namespace Private { | |||
749 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) | 762 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) |
750 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { | 763 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { |
764 | m_origItem = item; | ||
751 | setItem( item ); | 765 | setItem( item ); |
752 | } | 766 | } |
@@ -755,4 +769,7 @@ namespace Private { | |||
755 | return m_item; | 769 | return m_item; |
756 | } | 770 | } |
771 | OKeyConfigItem OKeyListViewItem::origItem() const{ | ||
772 | return m_origItem; | ||
773 | } | ||
757 | OKeyConfigManager* OKeyListViewItem::manager() { | 774 | OKeyConfigManager* OKeyListViewItem::manager() { |
758 | return m_manager; | 775 | return m_manager; |
@@ -762,6 +779,13 @@ namespace Private { | |||
762 | setPixmap( 0, m_item.pixmap() ); | 779 | setPixmap( 0, m_item.pixmap() ); |
763 | setText ( 1, m_item.text() ); | 780 | setText ( 1, m_item.text() ); |
764 | setText ( 2, keyToString( m_item.keyPair() ) ); | 781 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
765 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | 782 | setText( 2, keyToString( m_item.keyPair() ) ); |
783 | |||
784 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : | ||
785 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | ||
786 | } | ||
787 | void OKeyListViewItem::updateText() { | ||
788 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | ||
789 | setText( 2, keyToString( m_item.keyPair() ) ); | ||
766 | } | 790 | } |
767 | 791 | ||
@@ -849,4 +873,5 @@ void OKeyConfigWidget::initUi() { | |||
849 | m_view->addColumn( tr("Key" ) ); | 873 | m_view->addColumn( tr("Key" ) ); |
850 | m_view->addColumn( tr("Default Key" ) ); | 874 | m_view->addColumn( tr("Default Key" ) ); |
875 | m_view->setRootIsDecorated( true ); | ||
851 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), | 876 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), |
852 | this, SLOT(slotListViewItem(QListViewItem*)) ); | 877 | this, SLOT(slotListViewItem(QListViewItem*)) ); |
@@ -898,6 +923,8 @@ void OKeyConfigWidget::initUi() { | |||
898 | gridLay->addWidget( m_lbl, 2, 0 ); | 923 | gridLay->addWidget( m_lbl, 2, 0 ); |
899 | 924 | ||
925 | connect(m_btn, SIGNAL(clicked()), | ||
926 | this, SLOT(slotConfigure())); | ||
900 | 927 | ||
901 | m_box = gr; | 928 | m_box = box; |
902 | } | 929 | } |
903 | 930 | ||
@@ -950,4 +977,18 @@ void OKeyConfigWidget::load() { | |||
950 | */ | 977 | */ |
951 | void OKeyConfigWidget::save() { | 978 | void OKeyConfigWidget::save() { |
979 | /* | ||
980 | * Iterate over all config items | ||
981 | */ | ||
982 | QListViewItemIterator it( m_view ); | ||
983 | while ( it.current() ) { | ||
984 | if (it.current()->parent() ) { | ||
985 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( it.current() ); | ||
986 | OKeyConfigManager *man = item->manager(); | ||
987 | man->removeKeyConfig( item->origItem() ); | ||
988 | man->addKeyConfig( item->item() ); | ||
989 | } | ||
990 | ++it; | ||
991 | } | ||
992 | |||
952 | 993 | ||
953 | } | 994 | } |
@@ -968,4 +1009,5 @@ void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | |||
968 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); | 1009 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); |
969 | OKeyConfigItem keyItem= item->item(); | 1010 | OKeyConfigItem keyItem= item->item(); |
1011 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); | ||
970 | if ( keyItem.keyPair().isEmpty() ) { | 1012 | if ( keyItem.keyPair().isEmpty() ) { |
971 | m_none->setChecked( true ); | 1013 | m_none->setChecked( true ); |
@@ -989,5 +1031,5 @@ void OKeyConfigWidget::slotNoKey() { | |||
989 | m_def ->setChecked( false ); | 1031 | m_def ->setChecked( false ); |
990 | 1032 | ||
991 | if ( !m_view->currentItem() || m_view->currentItem()->parent() ) | 1033 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
992 | return; | 1034 | return; |
993 | 1035 | ||
@@ -1001,4 +1043,5 @@ void OKeyConfigWidget::slotNoKey() { | |||
1001 | item->manager()->removeKeyConfig( item->item() ); | 1043 | item->manager()->removeKeyConfig( item->item() ); |
1002 | item->item().setKeyPair( OKeyPair::emptyKey() ); | 1044 | item->item().setKeyPair( OKeyPair::emptyKey() ); |
1045 | item->updateText(); | ||
1003 | 1046 | ||
1004 | if ( m_mode == Imediate ) | 1047 | if ( m_mode == Imediate ) |
@@ -1008,11 +1051,10 @@ void OKeyConfigWidget::slotNoKey() { | |||
1008 | 1051 | ||
1009 | void OKeyConfigWidget::slotDefaultKey() { | 1052 | void OKeyConfigWidget::slotDefaultKey() { |
1010 | qWarning( "Slot Default Key" ); | 1053 | m_none->setChecked( false ); |
1011 | m_none->setChecked( true ); | ||
1012 | m_cus ->setChecked( false ); | 1054 | m_cus ->setChecked( false ); |
1013 | m_btn ->setEnabled( false ); | 1055 | m_btn ->setEnabled( false ); |
1014 | m_def ->setChecked( false ); | 1056 | m_def ->setChecked( true ); |
1015 | 1057 | ||
1016 | if ( !m_view->currentItem() || m_view->currentItem()->parent() ) | 1058 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1017 | return; | 1059 | return; |
1018 | 1060 | ||
@@ -1026,4 +1068,5 @@ void OKeyConfigWidget::slotDefaultKey() { | |||
1026 | 1068 | ||
1027 | item->item().setKeyPair( item->item().defaultKeyPair() ); | 1069 | item->item().setKeyPair( item->item().defaultKeyPair() ); |
1070 | item->updateText(); | ||
1028 | 1071 | ||
1029 | if ( m_mode == Imediate ) | 1072 | if ( m_mode == Imediate ) |
@@ -1032,5 +1075,4 @@ void OKeyConfigWidget::slotDefaultKey() { | |||
1032 | 1075 | ||
1033 | void OKeyConfigWidget::slotCustomKey() { | 1076 | void OKeyConfigWidget::slotCustomKey() { |
1034 | qWarning( "SlotCustom Key" ); | ||
1035 | m_cus ->setChecked( true ); | 1077 | m_cus ->setChecked( true ); |
1036 | m_btn ->setEnabled( true ); | 1078 | m_btn ->setEnabled( true ); |
@@ -1038,7 +1080,30 @@ void OKeyConfigWidget::slotCustomKey() { | |||
1038 | m_none->setChecked( false ); | 1080 | m_none->setChecked( false ); |
1039 | 1081 | ||
1040 | if ( !m_view->currentItem() || m_view->currentItem()->parent() ) | 1082 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1041 | return; | 1083 | return; |
1042 | 1084 | ||
1043 | } | 1085 | } |
1044 | 1086 | ||
1087 | void OKeyConfigWidget::slotConfigure() { | ||
1088 | |||
1089 | } | ||
1090 | |||
1091 | |||
1092 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | ||
1093 | bool mod, WFlags fl ) | ||
1094 | : QDialog( par, nam, mod, fl ) { | ||
1095 | } | ||
1096 | |||
1097 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | ||
1098 | } | ||
1099 | |||
1100 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | ||
1101 | } | ||
1102 | |||
1103 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | ||
1104 | ev->ignore(); | ||
1105 | } | ||
1106 | |||
1107 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | ||
1108 | ev->ignore(); | ||
1109 | } | ||
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index a7a5f48..8d2a1ef 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -249,5 +249,5 @@ private slots: | |||
249 | void slotDefaultKey(); | 249 | void slotDefaultKey(); |
250 | void slotCustomKey(); | 250 | void slotCustomKey(); |
251 | 251 | void slotConfigure(); | |
252 | 252 | ||
253 | private: | 253 | private: |
@@ -264,4 +264,43 @@ private: | |||
264 | }; | 264 | }; |
265 | 265 | ||
266 | |||
267 | /** | ||
268 | * This is a small dialog that allows you to | ||
269 | * capture a key sequence. | ||
270 | * If you want it to close after a key was captured you | ||
271 | * can use this code snippet. | ||
272 | * | ||
273 | * \code | ||
274 | * OKeyChooserConfigDialog diag(0,0,true); | ||
275 | * connect(&diag,SIGNAL(keyCaptured()), | ||
276 | * this,SLOT(accept())); | ||
277 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ | ||
278 | * take_the_key_and_do_something | ||
279 | * } | ||
280 | * | ||
281 | * \endcode | ||
282 | * | ||
283 | */ | ||
284 | class OKeyChooserConfigDialog : public QDialog { | ||
285 | Q_OBJECT | ||
286 | public: | ||
287 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | ||
288 | ~OKeyChooserConfigDialog(); | ||
289 | |||
290 | OKeyPair keyPair()const; | ||
291 | |||
292 | protected: | ||
293 | void keyPressEvent( QKeyEvent* ); | ||
294 | void keyReleaseEvent( QKeyEvent* ); | ||
295 | |||
296 | signals: | ||
297 | void keyCaptured(); | ||
298 | |||
299 | private: | ||
300 | OKeyPair m_keyPair; | ||
301 | class Private; | ||
302 | Private *d; | ||
303 | }; | ||
304 | |||
266 | } | 305 | } |
267 | } | 306 | } |