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 | |
parent | e8e8033dfd17bee04782866c1b84bb558fd91d74 (diff) | |
download | opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.zip opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.tar.gz opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.tar.bz2 |
Only GUI config is left
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 452 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 107 |
2 files changed, 453 insertions, 106 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 | |||
@@ -2,3 +2,12 @@ | |||
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 | ||
@@ -66,3 +75,3 @@ int OKeyPair::modifier()const { | |||
66 | void OKeyPair::setKeycode( int key ) { | 75 | void OKeyPair::setKeycode( int key ) { |
67 | 76 | m_key = key; | |
68 | } | 77 | } |
@@ -77,3 +86,3 @@ void OKeyPair::setKeycode( int key ) { | |||
77 | void OKeyPair::setModifier( int mod ) { | 86 | void OKeyPair::setModifier( int mod ) { |
78 | 87 | m_mod = mod; | |
79 | } | 88 | } |
@@ -123,3 +132,3 @@ OKeyPair OKeyPair::downArrowKey() { | |||
123 | OKeyPair OKeyPair::emptyKey() { | 132 | OKeyPair OKeyPair::emptyKey() { |
124 | return OKeyPair; | 133 | return OKeyPair(); |
125 | } | 134 | } |
@@ -134,7 +143,7 @@ OKeyPair OKeyPair::emptyKey() { | |||
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 ) |
@@ -171,2 +180,14 @@ bool OKeyPair::operator!=( const OKeyPair& pair) { | |||
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 | * |
@@ -175,4 +196,5 @@ bool OKeyPair::operator!=( const OKeyPair& pair) { | |||
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 | * |
@@ -181,5 +203,7 @@ 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 | ||
@@ -195,5 +219,5 @@ OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | |||
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 | {} |
@@ -260,2 +284,16 @@ QCString OKeyConfigItem::configKey()const { | |||
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 |
@@ -339,3 +377,2 @@ bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { | |||
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; |
@@ -381,3 +418,3 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | |||
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(); |
@@ -408,3 +445,3 @@ 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, |
@@ -412,4 +449,6 @@ OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | |||
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 | ||
@@ -419,3 +458,6 @@ OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | |||
419 | */ | 458 | */ |
420 | OKeyConfigManager::~OKeyConfigManager() {} | 459 | OKeyConfigManager::~OKeyConfigManager() { |
460 | if ( m_grab ) | ||
461 | QPEApplication::ungrabKeyboard(); | ||
462 | } | ||
421 | 463 | ||
@@ -429,3 +471,3 @@ OKeyConfigManager::~OKeyConfigManager() {} | |||
429 | */ | 471 | */ |
430 | void OKeyConfigWidget::load() { | 472 | void OKeyConfigManager::load() { |
431 | m_conf->setGroup( m_group ); | 473 | m_conf->setGroup( m_group ); |
@@ -436,3 +478,3 @@ void OKeyConfigWidget::load() { | |||
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 ) { |
@@ -453,3 +495,3 @@ void OKeyConfigWidget::load() { | |||
453 | */ | 495 | */ |
454 | void OKeyConfigWidget::save() { | 496 | void OKeyConfigManager::save() { |
455 | m_conf->setGroup( m_group ); | 497 | m_conf->setGroup( m_group ); |
@@ -459,4 +501,3 @@ void OKeyConfigWidget::save() { | |||
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 ) { |
@@ -465,4 +506,4 @@ void OKeyConfigWidget::save() { | |||
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 | } |
@@ -479,4 +520,4 @@ void OKeyConfigWidget::save() { | |||
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(); |
@@ -484,3 +525,3 @@ OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | |||
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 ) { |
@@ -564,3 +605,3 @@ void OKeyConfigManager::clearBlackList() { | |||
564 | */ | 605 | */ |
565 | OKeyPairList OKeyConfigManager::blackList()const { | 606 | OKeyPair::List OKeyConfigManager::blackList()const { |
566 | return m_blackKeys; | 607 | return m_blackKeys; |
@@ -594,3 +635,13 @@ bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | |||
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; |
@@ -601,3 +652,6 @@ bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | |||
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 ) { |
@@ -605,10 +659,12 @@ OKeyConfigItemList OKeyConfigManager::keyList( int keycode) { | |||
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; |
@@ -618,11 +674,7 @@ OKeyConfigItemList OKeyConfigManager::keyList( int keycode) { | |||
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 | } |
@@ -637,46 +689,36 @@ 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 | } |
@@ -684,12 +726,32 @@ namespace Private { | |||
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 | } |
@@ -704,2 +766,228 @@ namespace Private { | |||
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 | |||
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index 414ee7e..b3309af 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -14,3 +14,3 @@ | |||
14 | #include <qpixmap.h> | 14 | #include <qpixmap.h> |
15 | #include <qbytearray.h> | 15 | #include <qcstring.h> |
16 | #include <qhbox.h> | 16 | #include <qhbox.h> |
@@ -19,2 +19,6 @@ | |||
19 | class QKeyEvent; | 19 | class QKeyEvent; |
20 | class QLabel; | ||
21 | class QPushButton; | ||
22 | class QListViewItem; | ||
23 | class QRadioButton; | ||
20 | 24 | ||
@@ -22,3 +26,8 @@ namespace Opie { | |||
22 | namespace Ui { | 26 | namespace Ui { |
23 | 27 | namespace Private { | |
28 | class OKeyConfigWidgetPrivate; | ||
29 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | ||
30 | } | ||
31 | class OListViewItem; | ||
32 | class OListView; | ||
24 | 33 | ||
@@ -36,3 +45,3 @@ class OKeyPair { | |||
36 | public: | 45 | public: |
37 | typedef QValueList<OKeyPair> OKeyPairList; | 46 | typedef QValueList<OKeyPair> List; |
38 | OKeyPair( int key = -1, int modifier = -1); | 47 | OKeyPair( int key = -1, int modifier = -1); |
@@ -57,7 +66,7 @@ public: | |||
57 | static OKeyPair emptyKey(); | 66 | static OKeyPair emptyKey(); |
58 | static OKeyPairList hardwareKeys(); | 67 | static OKeyPair::List hardwareKeys(); |
59 | 68 | ||
60 | private: | 69 | private: |
61 | int m_key = -1; | 70 | int m_key; |
62 | int m_mod = -1; | 71 | int m_mod; |
63 | class Private; | 72 | class Private; |
@@ -77,3 +86,3 @@ class OKeyConfigItem { | |||
77 | public: | 86 | public: |
78 | typedef QValueList<OKeyConfigItem> OKeyConfigItemList; | 87 | typedef QValueList<OKeyConfigItem> List; |
79 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 88 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
@@ -81,4 +90,4 @@ public: | |||
81 | int id = -1, | 90 | int id = -1, |
82 | const OKeyPair& set = OKeyPair::emptyKey(), | 91 | const OKeyPair& def = OKeyPair::emptyKey(), |
83 | const OKeyPair& def = OKeyPair::emptyKey() ); | 92 | QObject *caller = 0, const char* slot = 0); |
84 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 93 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
@@ -93,2 +102,4 @@ public: | |||
93 | 102 | ||
103 | |||
104 | |||
94 | OKeyPair keyPair()const; | 105 | OKeyPair keyPair()const; |
@@ -97,2 +108,3 @@ public: | |||
97 | 108 | ||
109 | |||
98 | void setText( const QString& text ); | 110 | void setText( const QString& text ); |
@@ -105,2 +117,4 @@ public: | |||
105 | protected: | 117 | protected: |
118 | QObject *object()const; | ||
119 | QCString slot()const; | ||
106 | void setId( int id ); | 120 | void setId( int id ); |
@@ -109,3 +123,2 @@ protected: | |||
109 | private: | 123 | private: |
110 | int m_id; | ||
111 | QString m_text; | 124 | QString m_text; |
@@ -113,4 +126,7 @@ private: | |||
113 | QPixmap m_pix; | 126 | QPixmap m_pix; |
127 | int m_id; | ||
114 | OKeyPair m_key; | 128 | OKeyPair m_key; |
115 | OKeyPair m_def; | 129 | OKeyPair m_def; |
130 | QObject *m_obj; | ||
131 | QCString m_str; | ||
116 | class Private; | 132 | class Private; |
@@ -133,2 +149,3 @@ private: | |||
133 | * the event filter and get a signal. | 149 | * the event filter and get a signal. |
150 | * You need to load ans save yourself! | ||
134 | * | 151 | * |
@@ -138,3 +155,3 @@ class OKeyConfigManager : public QObject { | |||
138 | Q_OBJECT | 155 | Q_OBJECT |
139 | typedef QMap<it, OKeyConfigItemList> OKeyMapConfigPrivate; | 156 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; |
140 | public: | 157 | public: |
@@ -142,4 +159,4 @@ public: | |||
142 | const QString& group = QString::null, | 159 | const QString& group = QString::null, |
143 | OKeyPairList &block = OKeyPairList(), | 160 | const OKeyPair::List &block = OKeyPair::List(), |
144 | bool grabkeyboard = false, QObject *= 0, | 161 | bool grabkeyboard = false, QObject * par = 0, |
145 | const char* name = 0 ); | 162 | const char* name = 0 ); |
@@ -160,3 +177,3 @@ public: | |||
160 | void clearBlackList(); | 177 | void clearBlackList(); |
161 | OKeyPairList blackList()const; | 178 | OKeyPair::List blackList()const; |
162 | 179 | ||
@@ -166,9 +183,21 @@ public: | |||
166 | signals: | 183 | signals: |
167 | void keyConfigChanged( Opie::Ui::OKeyConfigManager* ); | 184 | /** |
185 | * The Signals are triggered on KeyPress and KeyRelease! | ||
186 | * You can check the isDown of the QKeyEvent | ||
187 | * @see QKeyEvent | ||
188 | */ | ||
168 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 189 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); |
169 | 190 | ||
191 | /** | ||
192 | * This Signal correspondents to the OKeyConfigItem slot | ||
193 | * and object | ||
194 | * | ||
195 | * @see OKeyConfigItem::slot | ||
196 | * @see OKeyConfigItem::object | ||
197 | */ | ||
198 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
199 | |||
170 | private: | 200 | private: |
171 | OKeyConfigItemList keyList( int ); | 201 | OKeyConfigItem::List keyList( int ); |
172 | OKeyPairList m_blackKeys; | 202 | OKeyConfigItem::List m_keys; |
173 | OKeyConfigItemList m_keys; | ||
174 | QValueList<QWidget*> m_widgets; | 203 | QValueList<QWidget*> m_widgets; |
@@ -176,2 +205,3 @@ private: | |||
176 | QString m_group; | 205 | QString m_group; |
206 | OKeyPair::List m_blackKeys; | ||
177 | bool m_grab : 1; | 207 | bool m_grab : 1; |
@@ -183,8 +213,22 @@ private: | |||
183 | 213 | ||
184 | class OKeyConfigWidget : public QHBox { | 214 | /** |
215 | * With this Widget you can let the Keyboard Shortcuts | ||
216 | * be configured by the user. | ||
217 | * There are two ways you can use this widget. Either in a tab were | ||
218 | * all changes are immediately getting into effect or in a queue | ||
219 | * were you ask for saving. Save won't write the data but only set | ||
220 | * it to the OKeyConfigManager | ||
221 | * | ||
222 | * @since 1.2 | ||
223 | */ | ||
224 | class OKeyConfigWidget : public QWidget { | ||
185 | Q_OBJECT | 225 | Q_OBJECT |
226 | |||
186 | public: | 227 | public: |
187 | enum ChangeMode { Imediate, Queu }; | 228 | /** |
229 | * Immediate Apply the change directly to the underlying OKeyConfigManager | ||
230 | * Queue Save all items and then apply when you save() | ||
231 | */ | ||
232 | enum ChangeMode { Imediate, Queue }; | ||
188 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 233 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
189 | OKeyConfigWidget( OKeyConfigManager *, QWidget* parent = 0, const char* = 0, WFlags = 0 ); | ||
190 | ~OKeyConfigWidget(); | 234 | ~OKeyConfigWidget(); |
@@ -194,8 +238,23 @@ public: | |||
194 | 238 | ||
195 | void setKeyConfig( OKeyConfigManager* ); | 239 | void insert( const QString& name, OKeyConfigManager* ); |
196 | 240 | ||
197 | void reload(); | 241 | void load(); |
198 | void save(); | 242 | void save(); |
243 | |||
244 | private slots: | ||
245 | void slotListViewItem( QListViewItem* ); | ||
246 | void slotNoKey(); | ||
247 | void slotDefaultKey(); | ||
248 | void slotCustomKey(); | ||
249 | |||
250 | |||
199 | private: | 251 | private: |
200 | OKeyConfigManager* m_manager; | 252 | void initUi(); |
253 | Opie::Ui::OListView *m_view; | ||
254 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; | ||
255 | QLabel *m_lbl; | ||
256 | QPushButton *m_btn; | ||
257 | QRadioButton *m_def, *m_cus, *m_none; | ||
258 | QWidget* m_box; | ||
259 | ChangeMode m_mode; | ||
201 | class Private; | 260 | class Private; |