summaryrefslogtreecommitdiff
path: root/libopie2
authorzecke <zecke>2004-03-26 23:11:28 (UTC)
committer zecke <zecke>2004-03-26 23:11:28 (UTC)
commit9f7ac64758dabb1694c7dfe1bd649d25f9f483fe (patch) (unidiff)
tree5486932cab0aa837b92c35137ce3ad34713e14f5 /libopie2
parente8e8033dfd17bee04782866c1b84bb558fd91d74 (diff)
downloadopie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.zip
opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.tar.gz
opie-9f7ac64758dabb1694c7dfe1bd649d25f9f483fe.tar.bz2
Only GUI config is left
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp452
-rw-r--r--libopie2/opieui/okeyconfigwidget.h107
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
@@ -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
6using namespace Opie::Ui; 15using namespace Opie::Ui;
@@ -64,7 +73,7 @@ int OKeyPair::modifier()const {
64 * @see Qt::Key 73 * @see Qt::Key
65 */ 74 */
66void OKeyPair::setKeycode( int key ) { 75void 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 */
77void OKeyPair::setModifier( int mod ) { 86void 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 */
123OKeyPair OKeyPair::emptyKey() { 132OKeyPair 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 */
135OKeyPairList OKeyPair::hardwareKeys() { 144OKeyPair::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 */
180OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, 202OKeyConfigItem::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 */
196OKeyConfigItem::OKeyConfigItem( Opie::Core::ODeviceButton& b ) 220OKeyConfigItem::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 */
287QObject* OKeyConfigItem::object()const{
288 return m_obj;
289}
290
291/**
292 * @internal
293 */
294QCString 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 */
407OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, 444OKeyConfigManager::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 */
420OKeyConfigManager::~OKeyConfigManager() {} 459OKeyConfigManager::~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 */
430void OKeyConfigWidget::load() { 472void 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 */
454void OKeyConfigWidget::save() { 496void 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 */
479OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { 520OKeyConfigItem 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 */
565OKeyPairList OKeyConfigManager::blackList()const { 606OKeyPair::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 */
602OKeyConfigItemList OKeyConfigManager::keyList( int keycode) { 653OKeyConfigItem::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 {
635namespace Ui { 687namespace Ui {
636namespace Private { 688namespace 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 */
776OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl )
777 : QWidget( parent, name, fl ) {
778 initUi();
779}
780
781
782
783/**
784 * c'tor
785 */
786OKeyConfigWidget::~OKeyConfigWidget() {
787}
788
789
790/**
791 * @internal
792 */
793void 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 */
869void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) {
870 m_mode = mode;
871}
872
873
874/**
875 * return the current mode
876 */
877OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const {
878 return m_mode;
879}
880
881
882/**
883 * insert these items before calling load
884 */
885void 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 */
894void 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 */
903void OKeyConfigWidget::save() {
904
905}
906
907
908/**
909 * @internal
910 */
911void 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
936void 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
960void 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
983void 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
@@ -12,15 +12,24 @@
12 12
13#include <qstring.h> 13#include <qstring.h>
14#include <qpixmap.h> 14#include <qpixmap.h>
15#include <qbytearray.h> 15#include <qcstring.h>
16#include <qhbox.h> 16#include <qhbox.h>
17#include <qvaluelist.h> 17#include <qvaluelist.h>
18 18
19class QKeyEvent; 19class QKeyEvent;
20class QLabel;
21class QPushButton;
22class QListViewItem;
23class QRadioButton;
20 24
21namespace Opie { 25namespace Opie {
22namespace Ui { 26namespace Ui {
23 27namespace Private {
28 class OKeyConfigWidgetPrivate;
29 typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList;
30}
31 class OListViewItem;
32 class OListView;
24 33
25/** 34/**
26 * \brief small class representing a Key with possible modifiers 35 * \brief small class representing a Key with possible modifiers
@@ -34,7 +43,7 @@ namespace Ui {
34 */ 43 */
35class OKeyPair { 44class OKeyPair {
36public: 45public:
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);
39 ~OKeyPair(); 48 ~OKeyPair();
40 49
@@ -55,11 +64,11 @@ public:
55 static OKeyPair upArrowKey(); 64 static OKeyPair upArrowKey();
56 static OKeyPair downArrowKey(); 65 static OKeyPair downArrowKey();
57 static OKeyPair emptyKey(); 66 static OKeyPair emptyKey();
58 static OKeyPairList hardwareKeys(); 67 static OKeyPair::List hardwareKeys();
59 68
60private: 69private:
61 int m_key = -1; 70 int m_key;
62 int m_mod = -1; 71 int m_mod;
63 class Private; 72 class Private;
64 Private* d; 73 Private* d;
65}; 74};
@@ -75,12 +84,12 @@ private:
75class OKeyConfigItem { 84class OKeyConfigItem {
76 friend class OKeyConfigManager; 85 friend class OKeyConfigManager;
77public: 86public:
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(),
80 const QPixmap& symbol = QPixmap(), 89 const QPixmap& symbol = QPixmap(),
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& );
85 ~OKeyConfigItem(); 94 ~OKeyConfigItem();
86 95
@@ -91,10 +100,13 @@ public:
91 QPixmap pixmap()const; 100 QPixmap pixmap()const;
92 int id()const; 101 int id()const;
93 102
103
104
94 OKeyPair keyPair()const; 105 OKeyPair keyPair()const;
95 OKeyPair defaultKeyPair()const; 106 OKeyPair defaultKeyPair()const;
96 QCString configKey()const; 107 QCString configKey()const;
97 108
109
98 void setText( const QString& text ); 110 void setText( const QString& text );
99 void setPixmap( const QPixmap& ); 111 void setPixmap( const QPixmap& );
100 void setKeyPair( const OKeyPair& ); 112 void setKeyPair( const OKeyPair& );
@@ -103,16 +115,20 @@ public:
103 bool isEmpty()const; 115 bool isEmpty()const;
104 116
105protected: 117protected:
118 QObject *object()const;
119 QCString slot()const;
106 void setId( int id ); 120 void setId( int id );
107 void setConfigKey( const QCString& ); 121 void setConfigKey( const QCString& );
108 122
109private: 123private:
110 int m_id;
111 QString m_text; 124 QString m_text;
112 QCString m_config; 125 QCString m_config;
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;
117 Private *d; 133 Private *d;
118}; 134};
@@ -131,17 +147,18 @@ private:
131 * You can either handle the QKeyEvent yourself and ask this class if it is 147 * You can either handle the QKeyEvent yourself and ask this class if it is
132 * handled by your action and let give you the action. Or you can install 148 * handled by your action and let give you the action. Or you can install
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 *
135 * @since 1.1.2 152 * @since 1.1.2
136 */ 153 */
137class OKeyConfigManager : public QObject { 154class OKeyConfigManager : public QObject {
138 Q_OBJECT 155 Q_OBJECT
139 typedef QMap<it, OKeyConfigItemList> OKeyMapConfigPrivate; 156 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate;
140public: 157public:
141 OKeyConfigManager(Opie::Core::OConfig *conf = 0, 158 OKeyConfigManager(Opie::Core::OConfig *conf = 0,
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 );
146 ~OKeyConfigManager(); 163 ~OKeyConfigManager();
147 164
@@ -158,22 +175,35 @@ public:
158 void addToBlackList( const OKeyPair& ); 175 void addToBlackList( const OKeyPair& );
159 void removeFromBlackList( const OKeyPair& ); 176 void removeFromBlackList( const OKeyPair& );
160 void clearBlackList(); 177 void clearBlackList();
161 OKeyPairList blackList()const; 178 OKeyPair::List blackList()const;
162 179
163 void handleWidget( QWidget* ); 180 void handleWidget( QWidget* );
164 181
165 bool eventFilter( QObject*, QEvent* ); 182 bool eventFilter( QObject*, QEvent* );
166signals: 183signals:
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
170private: 200private:
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;
175 Opie::Core::OConfig *m_conf; 204 Opie::Core::OConfig *m_conf;
176 QString m_group; 205 QString m_group;
206 OKeyPair::List m_blackKeys;
177 bool m_grab : 1; 207 bool m_grab : 1;
178 OKeyMapConfigPrivate *m_map; 208 OKeyMapConfigPrivate *m_map;
179 class Private; 209 class Private;
@@ -181,23 +211,52 @@ private:
181}; 211};
182 212
183 213
184class 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 */
224class OKeyConfigWidget : public QWidget {
185 Q_OBJECT 225 Q_OBJECT
226
186public: 227public:
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();
191 235
192 void setChangeMode( enum ChangeMode ); 236 void setChangeMode( enum ChangeMode );
193 ChangeMode changeMode()const; 237 ChangeMode changeMode()const;
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
244private slots:
245 void slotListViewItem( QListViewItem* );
246 void slotNoKey();
247 void slotDefaultKey();
248 void slotCustomKey();
249
250
199private: 251private:
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;
202 Private *d; 261 Private *d;
203}; 262};