summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp89
-rw-r--r--libopie2/opieui/okeyconfigwidget.h41
2 files changed, 117 insertions, 13 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
@@ -361,6 +361,7 @@ bool OKeyConfigItem::isEmpty()const {
361 if ( !m_def.isEmpty() ) return false; 361 if ( !m_def.isEmpty() ) return false;
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;
366} 367}
@@ -369,15 +370,19 @@ bool OKeyConfigItem::isEmpty()const {
369 * Check if the KeyPairs are the same 370 * Check if the KeyPairs are the same
370 */ 371 */
371bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { 372bool 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
383} 388}
@@ -505,10 +510,13 @@ void OKeyConfigManager::save() {
505 continue; 510 continue;
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() );
514 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); 522 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() );
@@ -547,9 +555,9 @@ OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) {
547 if ( mod & 256 ) 555 if ( mod & 256 )
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;
555 } 563 }
@@ -586,6 +594,7 @@ int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) {
586 */ 594 */
587void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { 595void 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}
591 600
@@ -595,6 +604,7 @@ void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) {
595 */ 604 */
596void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { 605void 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}
600 610
@@ -737,23 +747,30 @@ namespace Private {
737 void setDefault(); 747 void setDefault();
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
747 }; 760 };
748 761
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 }
753 OKeyListViewItem::~OKeyListViewItem() {} 767 OKeyListViewItem::~OKeyListViewItem() {}
754 OKeyConfigItem &OKeyListViewItem::item(){ 768 OKeyConfigItem &OKeyListViewItem::item(){
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;
759 } 776 }
@@ -761,9 +778,16 @@ namespace Private {
761 m_item = item; 778 m_item = item;
762 setPixmap( 0, m_item.pixmap() ); 779 setPixmap( 0, m_item.pixmap() );
763 setText ( 1, m_item.text() ); 780 setText ( 1, m_item.text() );
781 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) :
764 setText ( 2, keyToString( m_item.keyPair() ) ); 782 setText ( 2, keyToString( m_item.keyPair() ) );
783
784 m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) :
765 setText ( 3, keyToString( m_item.defaultKeyPair() ) ); 785 setText ( 3, keyToString( m_item.defaultKeyPair() ) );
766 } 786 }
787 void OKeyListViewItem::updateText() {
788 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) :
789 setText( 2, keyToString( m_item.keyPair() ) );
790 }
767 791
768 QString keyToString( const OKeyPair& pair ) { 792 QString keyToString( const OKeyPair& pair ) {
769 int mod = 0; 793 int mod = 0;
@@ -848,6 +872,7 @@ void OKeyConfigWidget::initUi() {
848 m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); 872 m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) );
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*)) );
853 878
@@ -897,8 +922,10 @@ void OKeyConfigWidget::initUi() {
897 m_lbl= new QLabel( tr( "Default: " ), box ); 922 m_lbl= new QLabel( tr( "Default: " ), box );
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
904/** 931/**
@@ -949,6 +976,20 @@ void OKeyConfigWidget::load() {
949 * If in Queue mode it'll just return 976 * If in Queue mode it'll just return
950 */ 977 */
951void OKeyConfigWidget::save() { 978void 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}
954 995
@@ -967,6 +1008,7 @@ void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) {
967 m_box->setEnabled( true ); 1008 m_box->setEnabled( true );
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 );
972 m_btn ->setEnabled( false ); 1014 m_btn ->setEnabled( false );
@@ -988,7 +1030,7 @@ void OKeyConfigWidget::slotNoKey() {
988 m_btn ->setEnabled( false ); 1030 m_btn ->setEnabled( false );
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
994 1036
@@ -1000,6 +1042,7 @@ void OKeyConfigWidget::slotNoKey() {
1000 if ( m_mode == Imediate ) 1042 if ( m_mode == Imediate )
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 )
1005 item->manager()->addKeyConfig( item->item() ); 1048 item->manager()->addKeyConfig( item->item() );
@@ -1007,13 +1050,12 @@ void OKeyConfigWidget::slotNoKey() {
1007} 1050}
1008 1051
1009void OKeyConfigWidget::slotDefaultKey() { 1052void 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
1019 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); 1061 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem());
@@ -1025,20 +1067,43 @@ void OKeyConfigWidget::slotDefaultKey() {
1025 item->manager()->removeKeyConfig( item->item() ); 1067 item->manager()->removeKeyConfig( item->item() );
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 )
1030 item->manager()->addKeyConfig( item->item() ); 1073 item->manager()->addKeyConfig( item->item() );
1031} 1074}
1032 1075
1033void OKeyConfigWidget::slotCustomKey() { 1076void 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 );
1037 m_def ->setChecked( false ); 1079 m_def ->setChecked( false );
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
1087void OKeyConfigWidget::slotConfigure() {
1088
1089}
1090
1091
1092OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam,
1093 bool mod, WFlags fl )
1094 : QDialog( par, nam, mod, fl ) {
1095}
1096
1097OKeyChooserConfigDialog::~OKeyChooserConfigDialog() {
1098}
1099
1100Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{
1101}
1102
1103void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) {
1104 ev->ignore();
1105}
1106
1107void 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
@@ -248,7 +248,7 @@ private slots:
248 void slotNoKey(); 248 void slotNoKey();
249 void slotDefaultKey(); 249 void slotDefaultKey();
250 void slotCustomKey(); 250 void slotCustomKey();
251 251 void slotConfigure();
252 252
253private: 253private:
254 void initUi(); 254 void initUi();
@@ -263,6 +263,45 @@ private:
263 Private *d; 263 Private *d;
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 */
284class OKeyChooserConfigDialog : public QDialog {
285 Q_OBJECT
286public:
287 OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 );
288 ~OKeyChooserConfigDialog();
289
290 OKeyPair keyPair()const;
291
292protected:
293 void keyPressEvent( QKeyEvent* );
294 void keyReleaseEvent( QKeyEvent* );
295
296signals:
297 void keyCaptured();
298
299private:
300 OKeyPair m_keyPair;
301 class Private;
302 Private *d;
303};
304
266} 305}
267} 306}
268 307