author | zecke <zecke> | 2004-03-26 23:11:28 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-26 23:11:28 (UTC) |
commit | 9f7ac64758dabb1694c7dfe1bd649d25f9f483fe (patch) (unidiff) | |
tree | 5486932cab0aa837b92c35137ce3ad34713e14f5 /libopie2/opieui/okeyconfigwidget.cpp | |
parent | e8e8033dfd17bee04782866c1b84bb558fd91d74 (diff) | |
download | opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.zip opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.tar.gz opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.tar.bz2 |
Only GUI config is left
Diffstat (limited to 'libopie2/opieui/okeyconfigwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 452 |
1 files changed, 370 insertions, 82 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index 4482754..b4f1c5e 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,6 +1,15 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | 2 | ||
3 | #include <opie2/olistview.h> | ||
3 | 4 | ||
5 | #include <qgroupbox.h> | ||
6 | #include <qradiobutton.h> | ||
7 | #include <qpushbutton.h> | ||
8 | #include <qbuttongroup.h> | ||
9 | |||
10 | #include <qaccel.h> | ||
11 | #include <qlayout.h> | ||
12 | #include <qlabel.h> | ||
4 | 13 | ||
5 | 14 | ||
6 | using namespace Opie::Ui; | 15 | using namespace Opie::Ui; |
@@ -64,7 +73,7 @@ int OKeyPair::modifier()const { | |||
64 | * @see Qt::Key | 73 | * @see Qt::Key |
65 | */ | 74 | */ |
66 | void OKeyPair::setKeycode( int key ) { | 75 | void OKeyPair::setKeycode( int key ) { |
67 | 76 | m_key = key; | |
68 | } | 77 | } |
69 | 78 | ||
70 | /** | 79 | /** |
@@ -75,7 +84,7 @@ void OKeyPair::setKeycode( int key ) { | |||
75 | * @see modifier() | 84 | * @see modifier() |
76 | */ | 85 | */ |
77 | void OKeyPair::setModifier( int mod ) { | 86 | void OKeyPair::setModifier( int mod ) { |
78 | 87 | m_mod = mod; | |
79 | } | 88 | } |
80 | 89 | ||
81 | /** | 90 | /** |
@@ -121,7 +130,7 @@ OKeyPair OKeyPair::downArrowKey() { | |||
121 | * Return an Empty OKeyPair | 130 | * Return an Empty OKeyPair |
122 | */ | 131 | */ |
123 | OKeyPair OKeyPair::emptyKey() { | 132 | OKeyPair OKeyPair::emptyKey() { |
124 | return OKeyPair; | 133 | return OKeyPair(); |
125 | } | 134 | } |
126 | 135 | ||
127 | /** | 136 | /** |
@@ -132,11 +141,11 @@ OKeyPair OKeyPair::emptyKey() { | |||
132 | * @see Opie::Core::ODeviceButton | 141 | * @see Opie::Core::ODeviceButton |
133 | * @see Opie::Core::ODevice::button | 142 | * @see Opie::Core::ODevice::button |
134 | */ | 143 | */ |
135 | OKeyPairList OKeyPair::hardwareKeys() { | 144 | OKeyPair::List OKeyPair::hardwareKeys() { |
136 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | 145 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); |
137 | OKeyPairList lst; | 146 | OKeyPair::List lst; |
138 | 147 | ||
139 | for ( QValueList<Opie::Core::ODeviceButton>::Iterator it = but.begin(); | 148 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); |
140 | it != but.end(); ++it ) | 149 | it != but.end(); ++it ) |
141 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | 150 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); |
142 | 151 | ||
@@ -169,19 +178,34 @@ bool OKeyPair::operator!=( const OKeyPair& pair) { | |||
169 | * You can set the the key paramater of this item but if | 178 | * You can set the the key paramater of this item but if |
170 | * you use this item with the OKeyConfigManager your setting | 179 | * you use this item with the OKeyConfigManager your setting |
171 | * will be overwritten. | 180 | * will be overwritten. |
181 | * You can also specify a QObject and slot which sould get called | ||
182 | * once this item is activated. This slot only works if you | ||
183 | * use the OKeyConfigManager. | ||
184 | * The actual Key is read by load() | ||
185 | * | ||
186 | * \code | ||
187 | * void MySlot::create(){ | ||
188 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | ||
189 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | ||
190 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | ||
191 | * } | ||
192 | * \endcode | ||
172 | * | 193 | * |
173 | * @param text The text exposed to the user | 194 | * @param text The text exposed to the user |
174 | * @param config_key The key used in the config | 195 | * @param config_key The key used in the config |
175 | * @param pix A Pixmap associated with this Item | 196 | * @param pix A Pixmap associated with this Item |
176 | * @param key The OKeyPair used | ||
177 | * @param def The OKeyPair used as default | 197 | * @param def The OKeyPair used as default |
198 | * @param caller The object where the slot exists | ||
199 | * @param slot The slot which should get called | ||
178 | * | 200 | * |
179 | */ | 201 | */ |
180 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | 202 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, |
181 | const QPixmap& pix, int id, const OKeyPair& def, | 203 | const QPixmap& pix, int id, const OKeyPair& def, |
182 | const OKeyPair& key) | 204 | QObject *caller, |
205 | const char* slot ) | ||
183 | : m_text( text ), m_config( config_key ), m_pix( pix ), | 206 | : m_text( text ), m_config( config_key ), m_pix( pix ), |
184 | m_id( id ), m_def( def ), m_key( key ) {} | 207 | m_id( id ), m_def( def ), |
208 | m_obj( caller ), m_str( slot ) {} | ||
185 | 209 | ||
186 | /** | 210 | /** |
187 | * A special Constructor for converting from an Opie::Core::ODeviceButton | 211 | * A special Constructor for converting from an Opie::Core::ODeviceButton |
@@ -193,9 +217,9 @@ OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | |||
193 | * @see Opie::Core::ODeviceButton | 217 | * @see Opie::Core::ODeviceButton |
194 | * @see Opie::Core::ODevice::buttons() | 218 | * @see Opie::Core::ODevice::buttons() |
195 | */ | 219 | */ |
196 | OKeyConfigItem::OKeyConfigItem( Opie::Core::ODeviceButton& b ) | 220 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) |
197 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ) | 221 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), |
198 | m_def( OKeyPair( b.keycode(), 0 ) ), m_key( OKeyPair( b.keycode(), 0 ) ) | 222 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) |
199 | {} | 223 | {} |
200 | 224 | ||
201 | 225 | ||
@@ -258,6 +282,20 @@ QCString OKeyConfigItem::configKey()const { | |||
258 | } | 282 | } |
259 | 283 | ||
260 | /** | 284 | /** |
285 | * @internal | ||
286 | */ | ||
287 | QObject* OKeyConfigItem::object()const{ | ||
288 | return m_obj; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * @internal | ||
293 | */ | ||
294 | QCString OKeyConfigItem::slot()const { | ||
295 | return m_str; | ||
296 | } | ||
297 | |||
298 | /** | ||
261 | * Set the text | 299 | * Set the text |
262 | * | 300 | * |
263 | * @param text Set the Text of this Action to text | 301 | * @param text Set the Text of this Action to text |
@@ -337,7 +375,6 @@ bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { | |||
337 | 375 | ||
338 | if ( m_id != conf.m_id ) return false; | 376 | if ( m_id != conf.m_id ) return false; |
339 | if ( m_text != conf.m_text ) return false; | 377 | if ( m_text != conf.m_text ) return false; |
340 | if ( m_pix != conf.m_pix ) return false; | ||
341 | if ( m_key != conf.m_key ) return false; | 378 | if ( m_key != conf.m_key ) return false; |
342 | if ( m_def != conf.m_def ) return false; | 379 | if ( m_def != conf.m_def ) return false; |
343 | 380 | ||
@@ -379,7 +416,7 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | |||
379 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | 416 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); |
380 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | 417 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); |
381 | * lay->addWidget(wid); | 418 | * lay->addWidget(wid); |
382 | * if(QPEApplication::execDialog( &diag)== QDialog::Accept){ | 419 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ |
383 | * wid->save(); | 420 | * wid->save(); |
384 | * } | 421 | * } |
385 | * } | 422 | * } |
@@ -406,18 +443,23 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | |||
406 | */ | 443 | */ |
407 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 444 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
408 | const QString& group, | 445 | const QString& group, |
409 | OKeyPairList black, | 446 | const OKeyPair::List& black, |
410 | bool grabkeyboard, QObject* par, | 447 | bool grabkeyboard, QObject* par, |
411 | const char* name) | 448 | const char* name) |
412 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 449 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
413 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ) | 450 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ |
414 | {} | 451 | if ( m_grab ) |
452 | QPEApplication::grabKeyboard(); | ||
453 | } | ||
415 | 454 | ||
416 | 455 | ||
417 | /** | 456 | /** |
418 | * Destructor | 457 | * Destructor |
419 | */ | 458 | */ |
420 | OKeyConfigManager::~OKeyConfigManager() {} | 459 | OKeyConfigManager::~OKeyConfigManager() { |
460 | if ( m_grab ) | ||
461 | QPEApplication::ungrabKeyboard(); | ||
462 | } | ||
421 | 463 | ||
422 | /** | 464 | /** |
423 | * Load the Configuration from the OConfig | 465 | * Load the Configuration from the OConfig |
@@ -427,14 +469,14 @@ OKeyConfigManager::~OKeyConfigManager() {} | |||
427 | * | 469 | * |
428 | * @see OKeyPair::emptyKey | 470 | * @see OKeyPair::emptyKey |
429 | */ | 471 | */ |
430 | void OKeyConfigWidget::load() { | 472 | void OKeyConfigManager::load() { |
431 | m_conf->setGroup( m_group ); | 473 | m_conf->setGroup( m_group ); |
432 | 474 | ||
433 | /* | 475 | /* |
434 | * Read each item | 476 | * Read each item |
435 | */ | 477 | */ |
436 | int key, mod; | 478 | int key, mod; |
437 | for( OKeyConfigItemList::Iterator it = m_keys.begin(); | 479 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
438 | it != m_keys.end(); ++it ) { | 480 | it != m_keys.end(); ++it ) { |
439 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 481 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); |
440 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 482 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); |
@@ -451,20 +493,19 @@ void OKeyConfigWidget::load() { | |||
451 | * We will save the current configuration | 493 | * We will save the current configuration |
452 | * to the OConfig. We will change the group. | 494 | * to the OConfig. We will change the group. |
453 | */ | 495 | */ |
454 | void OKeyConfigWidget::save() { | 496 | void OKeyConfigManager::save() { |
455 | m_conf->setGroup( m_group ); | 497 | m_conf->setGroup( m_group ); |
456 | 498 | ||
457 | /* | 499 | /* |
458 | * Write each item | 500 | * Write each item |
459 | */ | 501 | */ |
460 | int key, mod; | 502 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
461 | for( OKeyConfigItemList::Iterator it = m_keys.begin(); | ||
462 | it != m_keys.end(); ++it ) { | 503 | it != m_keys.end(); ++it ) { |
463 | if ( (*it).isEmpty() ) | 504 | if ( (*it).isEmpty() ) |
464 | continue; | 505 | continue; |
465 | OKeyPair pair = (*it).keyPair(); | 506 | OKeyPair pair = (*it).keyPair(); |
466 | m_conf->writeEntry(pair.configKey()+"key", pair.keycode() ); | 507 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
467 | m_conf->writeEntry(pair.configKey()+"mod", pair.modifier() ); | 508 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); |
468 | } | 509 | } |
469 | } | 510 | } |
470 | 511 | ||
@@ -477,12 +518,12 @@ void OKeyConfigWidget::save() { | |||
477 | * Make sure you call e->ignore if you don't want to handle this event | 518 | * Make sure you call e->ignore if you don't want to handle this event |
478 | */ | 519 | */ |
479 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | 520 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { |
480 | OKeyConfigItemList keyList = keyList( e->key() ); | 521 | OKeyConfigItem::List _keyList = keyList( e->key() ); |
481 | if ( keyList.isEmpty() ) | 522 | if ( _keyList.isEmpty() ) |
482 | return OKeyConfigItem(); | 523 | return OKeyConfigItem(); |
483 | 524 | ||
484 | OKeyConfigItem item; | 525 | OKeyConfigItem item; |
485 | for ( OKeyConfigItemList::Iterator it = keyList.begin(); it != keyList.end(); | 526 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); |
486 | ++it ) { | 527 | ++it ) { |
487 | if ( (*it).keyPair().modifier() == e->state() ) { | 528 | if ( (*it).keyPair().modifier() == e->state() ) { |
488 | item = *it; | 529 | item = *it; |
@@ -562,7 +603,7 @@ void OKeyConfigManager::clearBlackList() { | |||
562 | /** | 603 | /** |
563 | * Return a copy of the blackList | 604 | * Return a copy of the blackList |
564 | */ | 605 | */ |
565 | OKeyPairList OKeyConfigManager::blackList()const { | 606 | OKeyPair::List OKeyConfigManager::blackList()const { |
566 | return m_blackKeys; | 607 | return m_blackKeys; |
567 | } | 608 | } |
568 | 609 | ||
@@ -592,39 +633,50 @@ bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | |||
592 | if ( item.isEmpty() ) | 633 | if ( item.isEmpty() ) |
593 | return false; | 634 | return false; |
594 | 635 | ||
595 | emit actionActivated( static_cast<QWidget*>( obj ), key, item ); | 636 | QWidget *wid = static_cast<QWidget*>( obj ); |
637 | |||
638 | if ( item.object() && !item.slot().isEmpty() ) { | ||
639 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | ||
640 | item.object(), item.slot().data() ); | ||
641 | emit actionActivated(wid, key); | ||
642 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | ||
643 | item.object(), item.slot().data() ); | ||
644 | } | ||
645 | emit actionActivated( wid, key, item ); | ||
646 | |||
596 | return true; | 647 | return true; |
597 | } | 648 | } |
598 | 649 | ||
599 | /** | 650 | /** |
600 | * @internal | 651 | * @internal |
601 | */ | 652 | */ |
602 | OKeyConfigItemList OKeyConfigManager::keyList( int keycode) { | 653 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { |
654 | /* | ||
655 | * Create the map if not existing anymore | ||
656 | */ | ||
603 | if ( !m_map ) { | 657 | if ( !m_map ) { |
604 | m_map = new OKeyMapConfigPrivate; | 658 | m_map = new OKeyMapConfigPrivate; |
605 | /* for every key */ | 659 | /* for every key */ |
606 | for ( OKeyConfigItemList::Iterator it = m_keys.begin(); | 660 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); |
607 | it!= m_keys.end(); ++it ) { | 661 | it!= m_keys.end(); ++it ) { |
662 | |||
608 | bool add = true; | 663 | bool add = true; |
609 | /* see if this key is blocked */ | 664 | /* see if this key is blocked */ |
610 | for ( OKeyPairList::Iterator pairIt = m_blackKeys.begin(); | 665 | OKeyPair pair = (*it).keyPair(); |
666 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | ||
611 | pairIt != m_blackKeys.end(); ++pairIt ) { | 667 | pairIt != m_blackKeys.end(); ++pairIt ) { |
612 | if ( (*pairIt).keycode() == (*it).keycode() && | 668 | if ( (*pairIt).keycode() == pair.keycode() && |
613 | (*pairIt).modifier() == (*it).modifier() ) { | 669 | (*pairIt).modifier() == pair.modifier() ) { |
614 | add = false; | 670 | add = false; |
615 | break; | 671 | break; |
616 | } | 672 | } |
617 | } | 673 | } |
618 | /* check if we added it */ | 674 | /* check if we added it */ |
619 | if ( add ) { | 675 | if ( add ) |
620 | if ( m_map->contains( (*it).keycode() ) ) | 676 | (*m_map)[pair.keycode()].append( *it ); |
621 | (m_map[(*it).keycode()]).append( *it ); | ||
622 | else | ||
623 | m_map.insert( (*it).keycode(), OKeyConfigItemList( *it ) ); | ||
624 | } | ||
625 | } | 677 | } |
626 | } | 678 | } |
627 | return m_map[keycode]; | 679 | return (*m_map)[keycode]; |
628 | } | 680 | } |
629 | 681 | ||
630 | 682 | ||
@@ -635,63 +687,73 @@ namespace Opie { | |||
635 | namespace Ui { | 687 | namespace Ui { |
636 | namespace Private { | 688 | namespace Private { |
637 | static QString keyToString( const OKeyPair& ); | 689 | static QString keyToString( const OKeyPair& ); |
638 | class OItemBox : public QHBox { | 690 | class OKeyListViewItem : public Opie::Ui::OListViewItem { |
639 | Q_OBJECT | ||
640 | public: | 691 | public: |
641 | OItemBox( const OKeyConfigItem& item, QWidget* parent = 0, const char* name = 0, WFlags fl = 0); | 692 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); |
642 | ~OItemBox(); | 693 | ~OKeyListViewItem(); |
643 | 694 | ||
644 | OKeyConfigItem item()const; | 695 | void setDefault(); |
696 | |||
697 | OKeyConfigItem& item(); | ||
645 | void setItem( const OKeyConfigItem& item ); | 698 | void setItem( const OKeyConfigItem& item ); |
646 | private slots: | 699 | |
647 | void slotClicked(); | 700 | OKeyConfigManager *manager(); |
648 | signals: | ||
649 | void configureBox( OItemBox* ); | ||
650 | private: | 701 | private: |
651 | QLabel *m_pix; | ||
652 | QLabel *m_text; | ||
653 | QPushButton *m_btn; | ||
654 | OKeyConfigItem m_item; | 702 | OKeyConfigItem m_item; |
655 | }; | 703 | OKeyConfigManager* m_manager; |
656 | |||
657 | OItemBox::OItemBox( const OKeyConfigItem& item, QWidget* parent, | ||
658 | const char* name, WFlags fl ) | ||
659 | : QHBox( parent, name, fl ), { | ||
660 | m_pix = new QLabel( this ); | ||
661 | m_text = new QLabel( this ); | ||
662 | m_btn = new QPushButton( this ); | ||
663 | 704 | ||
664 | connect(m_btn, SIGNAL(clicked()), | 705 | }; |
665 | this, SLOT(slotClicked())); | ||
666 | 706 | ||
707 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) | ||
708 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { | ||
667 | setItem( item ); | 709 | setItem( item ); |
668 | } | 710 | } |
669 | 711 | OKeyListViewItem::~OKeyListViewItem() {} | |
670 | OItemBox::~OItemBox() {} | 712 | OKeyConfigItem &OKeyListViewItem::item(){ |
671 | OKeyConfigItem OItemBox::item()const{ | ||
672 | return m_item; | 713 | return m_item; |
673 | } | 714 | } |
674 | void OKeyConfigItem::setItem( const OKeyConfigItem& item ) { | 715 | OKeyConfigManager* OKeyListViewItem::manager() { |
675 | m_item = item; | 716 | return m_manager; |
676 | m_pix ->setPixmap( item.pixmap() ); | ||
677 | m_text->setText( item.text() ); | ||
678 | m_btn->setText( keyToString( item.keyPair() ) ); | ||
679 | } | 717 | } |
680 | void OKeyConfigItem::slotClicked() { | 718 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { |
681 | emit configureBox( this ); | 719 | setPixmap( 0, m_item.pixmap() ); |
720 | setText ( 1, m_item.text() ); | ||
721 | setText ( 2, keyToString( m_item.keyPair() ) ); | ||
722 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | ||
723 | m_item = item; | ||
682 | } | 724 | } |
683 | 725 | ||
684 | QString keyToString( const OKeyPair& pair ) { | 726 | QString keyToString( const OKeyPair& pair ) { |
685 | QStringList mod; | 727 | int mod = 0; |
686 | if ( ( pair.modifier() & Qt::ShiftButton )== Qt::ShiftButton ) | 728 | if ( pair.modifier() & Qt::ShiftButton ) |
687 | mod.append( QObject::tr( "Shift", "The Keyboard key" ) ); | 729 | mod |= Qt::SHIFT; |
688 | if ( ( pair.modifier() & Qt::ControlButton )== Qt::ControlButton ) | 730 | if ( pair.modifier() & Qt::ControlButton ) |
689 | mod.append( QObject::tr( "Ctrl", "The Ctrl key" ) ); | 731 | mod |= Qt::CTRL; |
690 | if ( ( pair.modifier() & Qt::AltButton ) )== Qt::AltButton ) | 732 | if ( pair.modifier() & Qt::AltButton ) |
691 | mod.append( QObject::tr( "Alt", "The keyboard Alt Key" ) ); | 733 | mod |= Qt::ALT; |
734 | |||
735 | return QAccel::keyToString( mod + pair.keycode() ); | ||
736 | } | ||
737 | |||
738 | struct OKeyConfigWidgetPrivate{ | ||
739 | OKeyConfigWidgetPrivate(const QString& = QString::null, | ||
740 | OKeyConfigManager* = 0); | ||
741 | bool operator==( const OKeyConfigWidgetPrivate& ); | ||
742 | QString name; | ||
743 | OKeyConfigManager *manager; | ||
744 | }; | ||
692 | 745 | ||
746 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, | ||
747 | OKeyConfigManager* man ) | ||
748 | : name( _name ), manager( man ){} | ||
693 | 749 | ||
750 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { | ||
751 | if ( manager != item.manager) return false; | ||
752 | if ( name != item.name ) return false; | ||
753 | |||
754 | return true; | ||
694 | } | 755 | } |
756 | |||
695 | } | 757 | } |
696 | } | 758 | } |
697 | } | 759 | } |
@@ -702,4 +764,230 @@ namespace Private { | |||
702 | 764 | ||
703 | 765 | ||
704 | 766 | ||
705 | #include "okeyconfigwidget.moc" | 767 | |
768 | |||
769 | /** | ||
770 | * | ||
771 | * This is a c'tor. You still need to pass the OKeyConfigManager | ||
772 | * and then issue a load. | ||
773 | * The default mode is Immediate | ||
774 | * | ||
775 | */ | ||
776 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) | ||
777 | : QWidget( parent, name, fl ) { | ||
778 | initUi(); | ||
779 | } | ||
780 | |||
781 | |||
782 | |||
783 | /** | ||
784 | * c'tor | ||
785 | */ | ||
786 | OKeyConfigWidget::~OKeyConfigWidget() { | ||
787 | } | ||
788 | |||
789 | |||
790 | /** | ||
791 | * @internal | ||
792 | */ | ||
793 | void OKeyConfigWidget::initUi() { | ||
794 | QBoxLayout *layout = new QVBoxLayout( this ); | ||
795 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); | ||
796 | layout->addLayout( gridLay, 10 ); | ||
797 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth | ||
798 | |||
799 | /* | ||
800 | * LISTVIEW with the Keys | ||
801 | */ | ||
802 | m_view = new Opie::Ui::OListView( this ); | ||
803 | m_view->setFocus(); | ||
804 | m_view->setAllColumnsShowFocus( true ); | ||
805 | m_view->addColumn( tr("Pixmap") ); | ||
806 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); | ||
807 | m_view->addColumn( tr("Key" ) ); | ||
808 | m_view->addColumn( tr("Default Key" ) ); | ||
809 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), | ||
810 | this, SLOT(slotListViewItem(QListViewItem*)) ); | ||
811 | |||
812 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); | ||
813 | |||
814 | /* | ||
815 | * GROUP with button info | ||
816 | */ | ||
817 | |||
818 | QGroupBox *box = new QGroupBox( this ); | ||
819 | box ->setEnabled( false ); | ||
820 | box ->setTitle( tr("Shortcut for Selected Action") ); | ||
821 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); | ||
822 | layout->addWidget( box, 1 ); | ||
823 | |||
824 | gridLay = new QGridLayout( box, 3, 4 ); | ||
825 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); | ||
826 | gridLay->setMargin( 4 ); | ||
827 | |||
828 | QButtonGroup *gr = new QButtonGroup( box ); | ||
829 | gr->hide(); | ||
830 | gr->setExclusive( true ); | ||
831 | |||
832 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); | ||
833 | connect( rad, SIGNAL(clicked()), | ||
834 | this, SLOT(slotNoKey()) ); | ||
835 | gr->insert( rad, 10 ); | ||
836 | gridLay->addWidget( rad, 1, 0 ); | ||
837 | m_none = rad; | ||
838 | |||
839 | rad = new QRadioButton( tr("&Default" ), box ); | ||
840 | connect( rad, SIGNAL(clicked()), | ||
841 | this, SLOT(slotDefaultKey()) ); | ||
842 | gr->insert( rad, 11 ); | ||
843 | gridLay->addWidget( rad, 1, 1 ); | ||
844 | m_def = rad; | ||
845 | |||
846 | rad = new QRadioButton( tr("C&ustom"), box ); | ||
847 | connect( rad, SIGNAL(clicked()), | ||
848 | this, SLOT(slotCustomKey()) ); | ||
849 | gr->insert( rad, 12 ); | ||
850 | gridLay->addWidget( rad, 1, 2 ); | ||
851 | m_cus = rad; | ||
852 | |||
853 | m_btn = new QPushButton( tr("Configure Key"), box ); | ||
854 | gridLay->addWidget( m_btn, 1, 4 ); | ||
855 | |||
856 | m_lbl= new QLabel( tr( "Default: " ), box ); | ||
857 | gridLay->addWidget( m_lbl, 2, 0 ); | ||
858 | |||
859 | |||
860 | m_box = gr; | ||
861 | } | ||
862 | |||
863 | /** | ||
864 | * Set the ChangeMode. | ||
865 | * You need to call this function prior to load | ||
866 | * If you call this function past load the behaviour is undefined | ||
867 | * But caling load again is safe | ||
868 | */ | ||
869 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { | ||
870 | m_mode = mode; | ||
871 | } | ||
872 | |||
873 | |||
874 | /** | ||
875 | * return the current mode | ||
876 | */ | ||
877 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { | ||
878 | return m_mode; | ||
879 | } | ||
880 | |||
881 | |||
882 | /** | ||
883 | * insert these items before calling load | ||
884 | */ | ||
885 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { | ||
886 | Opie::Ui::Private::OKeyConfigWidgetPrivate root( str, man ); | ||
887 | m_list.append(root); | ||
888 | } | ||
889 | |||
890 | |||
891 | /** | ||
892 | * loads the items and allows editing them | ||
893 | */ | ||
894 | void OKeyConfigWidget::load() { | ||
895 | |||
896 | } | ||
897 | |||
898 | /** | ||
899 | * Saves if in Queue Mode. It'll update the supplied | ||
900 | * OKeyConfigManager objects. | ||
901 | * If in Queue mode it'll just return | ||
902 | */ | ||
903 | void OKeyConfigWidget::save() { | ||
904 | |||
905 | } | ||
906 | |||
907 | |||
908 | /** | ||
909 | * @internal | ||
910 | */ | ||
911 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | ||
912 | if ( !_item || !_item->parent() ) { | ||
913 | m_box->setEnabled( false ); | ||
914 | m_none->setChecked( true ); | ||
915 | m_btn ->setEnabled( false ); | ||
916 | m_def ->setChecked( false ); | ||
917 | m_cus ->setChecked( false ); | ||
918 | }else{ | ||
919 | m_box->setEnabled( true ); | ||
920 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); | ||
921 | OKeyConfigItem keyItem= item->item(); | ||
922 | if ( keyItem.keyPair().isEmpty() ) { | ||
923 | m_none->setChecked( true ); | ||
924 | m_btn ->setEnabled( false ); | ||
925 | m_def ->setChecked( false ); | ||
926 | m_cus ->setChecked( false ); | ||
927 | }else { | ||
928 | m_none->setChecked( false ); | ||
929 | m_cus ->setChecked( true ); | ||
930 | m_btn ->setEnabled( true ); | ||
931 | m_def ->setChecked( false ); | ||
932 | } | ||
933 | } | ||
934 | } | ||
935 | |||
936 | void OKeyConfigWidget::slotNoKey() { | ||
937 | m_none->setChecked( true ); | ||
938 | m_cus ->setChecked( false ); | ||
939 | m_btn ->setEnabled( false ); | ||
940 | m_def ->setChecked( false ); | ||
941 | |||
942 | if ( !m_view->currentItem() || m_view->currentItem()->parent() ) | ||
943 | return; | ||
944 | |||
945 | |||
946 | |||
947 | /* | ||
948 | * If immediate we need to remove and readd the key | ||
949 | */ | ||
950 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | ||
951 | if ( m_mode == Imediate ) | ||
952 | item->manager()->removeKeyConfig( item->item() ); | ||
953 | item->item().setKeyPair( OKeyPair::emptyKey() ); | ||
954 | |||
955 | if ( m_mode == Imediate ) | ||
956 | item->manager()->addKeyConfig( item->item() ); | ||
957 | |||
958 | } | ||
959 | |||
960 | void OKeyConfigWidget::slotDefaultKey() { | ||
961 | m_none->setChecked( true ); | ||
962 | m_cus ->setChecked( false ); | ||
963 | m_btn ->setEnabled( false ); | ||
964 | m_def ->setChecked( false ); | ||
965 | |||
966 | if ( !m_view->currentItem() || m_view->currentItem()->parent() ) | ||
967 | return; | ||
968 | |||
969 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | ||
970 | |||
971 | /* | ||
972 | * If immediate we need to remove and readd the key | ||
973 | */ | ||
974 | if ( m_mode == Imediate ) | ||
975 | item->manager()->removeKeyConfig( item->item() ); | ||
976 | |||
977 | item->item().setKeyPair( item->item().defaultKeyPair() ); | ||
978 | |||
979 | if ( m_mode == Imediate ) | ||
980 | item->manager()->addKeyConfig( item->item() ); | ||
981 | } | ||
982 | |||
983 | void OKeyConfigWidget::slotCustomKey() { | ||
984 | m_cus ->setChecked( true ); | ||
985 | m_btn ->setEnabled( true ); | ||
986 | m_def ->setChecked( false ); | ||
987 | m_none->setChecked( false ); | ||
988 | |||
989 | if ( !m_view->currentItem() || m_view->currentItem()->parent() ) | ||
990 | return; | ||
991 | |||
992 | } | ||
993 | |||