summaryrefslogtreecommitdiff
Unidiff
Diffstat (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,15 +1,24 @@
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;
7 16
8 17
9/** 18/**
10 * The default Constructor of a OKeyPair. 19 * The default Constructor of a OKeyPair.
11 * A Key and a Modifier ( Alt/Shift/Ctrl ) 20 * A Key and a Modifier ( Alt/Shift/Ctrl )
12 * needs to be supplied. 21 * needs to be supplied.
13 * Use Qt::Key for the information. 22 * Use Qt::Key for the information.
14 * The default arguments create an Empty OKeyPair. If you 23 * The default arguments create an Empty OKeyPair. If you
15 * want to get an empty OKeyPair use the static method for getting 24 * want to get an empty OKeyPair use the static method for getting
@@ -55,36 +64,36 @@ int OKeyPair::modifier()const {
55 return m_mod; 64 return m_mod;
56} 65}
57 66
58 67
59/** 68/**
60 * Set the keycode 69 * Set the keycode
61 * @param key The Keycode to set 70 * @param key The Keycode to set
62 * 71 *
63 * @see keycode() 72 * @see keycode()
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/**
71 * Set the modifier key 80 * Set the modifier key
72 * 81 *
73 * @param the Modifier key 82 * @param the Modifier key
74 * @see Qt::ButtonState 83 * @see Qt::ButtonState
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/**
82 * Return an OKeyPair for the Return Key without any modifier. 91 * Return an OKeyPair for the Return Key without any modifier.
83 */ 92 */
84OKeyPair OKeyPair::returnKey() { 93OKeyPair OKeyPair::returnKey() {
85 return OKeyPair( Qt::Key_Return, 0 ); 94 return OKeyPair( Qt::Key_Return, 0 );
86} 95}
87 96
88/** 97/**
89 * Return an OKeyPair for the Left Arrow Key 98 * Return an OKeyPair for the Left Arrow Key
90 * without any modifier Key 99 * without any modifier Key
@@ -112,40 +121,40 @@ OKeyPair OKeyPair::upArrowKey() {
112/** 121/**
113 * Return an OKeyPair for the Down Arrow Key 122 * Return an OKeyPair for the Down Arrow Key
114 * without any modifier Key 123 * without any modifier Key
115 */ 124 */
116OKeyPair OKeyPair::downArrowKey() { 125OKeyPair OKeyPair::downArrowKey() {
117 return OKeyPair( Qt::Key_Down, 0 ); 126 return OKeyPair( Qt::Key_Down, 0 );
118} 127}
119 128
120/** 129/**
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/**
128 * This functions uses the Opie::Core::ODevice::buttons 137 * This functions uses the Opie::Core::ODevice::buttons
129 * for OKeyPairList 138 * for OKeyPairList
130 * 139 *
131 * @see Opie::Core::ODevice 140 * @see Opie::Core::ODevice
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
143 152
144 return lst; 153 return lst;
145} 154}
146 155
147/** 156/**
148 * Equals operator. Check if two OKeyPairs have the same key and modifier 157 * Equals operator. Check if two OKeyPairs have the same key and modifier
149 * @see operator!= 158 * @see operator!=
150 */ 159 */
151bool OKeyPair::operator==( const OKeyPair& pair) { 160bool OKeyPair::operator==( const OKeyPair& pair) {
@@ -160,51 +169,66 @@ bool OKeyPair::operator==( const OKeyPair& pair) {
160 */ 169 */
161bool OKeyPair::operator!=( const OKeyPair& pair) { 170bool OKeyPair::operator!=( const OKeyPair& pair) {
162 return !(*this == pair); 171 return !(*this == pair);
163} 172}
164 173
165 174
166/** 175/**
167 * The normal Constructor to create a OKeyConfigItem 176 * The normal Constructor to create a OKeyConfigItem
168 * 177 *
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
188 * delivered by Opie::Core::ODevice::buttons() 212 * delivered by Opie::Core::ODevice::buttons()
189 * There is no Config Key set and both default key and key are set 213 * There is no Config Key set and both default key and key are set
190 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier 214 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier
191 * 215 *
192 * @see Opie::Core::ODevice 216 * @see Opie::Core::ODevice
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
202/** 226/**
203 * Destructor 227 * Destructor
204 */ 228 */
205OKeyConfigItem::~OKeyConfigItem() {} 229OKeyConfigItem::~OKeyConfigItem() {}
206 230
207 231
208/** 232/**
209 * The text exposed to the user 233 * The text exposed to the user
210 * 234 *
@@ -249,24 +273,38 @@ int OKeyConfigItem::id()const{
249 return m_id; 273 return m_id;
250} 274}
251 275
252/** 276/**
253 * reutrn the Config Key. Setting it is only possible 277 * reutrn the Config Key. Setting it is only possible
254 * by the constructor 278 * by the constructor
255 */ 279 */
256QCString OKeyConfigItem::configKey()const { 280QCString OKeyConfigItem::configKey()const {
257 return m_config; 281 return m_config;
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
264 * @see text() 302 * @see text()
265 */ 303 */
266void OKeyConfigItem::setText( const QString& text ) { 304void OKeyConfigItem::setText( const QString& text ) {
267 m_text = text; 305 m_text = text;
268} 306}
269 307
270/** 308/**
271 * Set the pixmap of this action 309 * Set the pixmap of this action
272 * 310 *
@@ -328,25 +366,24 @@ bool OKeyConfigItem::isEmpty()const {
328} 366}
329 367
330/** 368/**
331 * Check if the KeyPairs are the same 369 * Check if the KeyPairs are the same
332 */ 370 */
333bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { 371bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) {
334 if ( isEmpty() == conf.isEmpty() ) return true; 372 if ( isEmpty() == conf.isEmpty() ) return true;
335 else if ( isEmpty() != conf.isEmpty() ) return false; 373 else if ( isEmpty() != conf.isEmpty() ) return false;
336 else if ( !isEmpty()!= conf.isEmpty() ) return false; 374 else if ( !isEmpty()!= conf.isEmpty() ) return false;
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
344 return true; 381 return true;
345 382
346} 383}
347 384
348bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { 385bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) {
349 return !( *this == conf ); 386 return !( *this == conf );
350} 387}
351 388
352/** 389/**
@@ -370,25 +407,25 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) {
370 * 407 *
371 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), 408 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)),
372 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); 409 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)));
373 * 410 *
374 * .... 411 * ....
375 * 412 *
376 * void update(){ 413 * void update(){
377 * QDialog diag(true); 414 * QDialog diag(true);
378 * QHBoxLayout *lay = new QHBoxLayout(&diag); 415 * QHBoxLayout *lay = new QHBoxLayout(&diag);
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 * }
386 * 423 *
387 * .... 424 * ....
388 * MyListView::keyPressEvent( QKeyEvent* e ){ 425 * MyListView::keyPressEvent( QKeyEvent* e ){
389 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); 426 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e);
390 * if(!item.isEmpty() ){ 427 * if(!item.isEmpty() ){
391 * switch(item.id()){ 428 * switch(item.id()){
392 * case My_Delete_Key: 429 * case My_Delete_Key:
393 * break; 430 * break;
394 * } 431 * }
@@ -397,101 +434,105 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) {
397 * 434 *
398 * \endcode 435 * \endcode
399 * 436 *
400 * @param conf The Config where the KeySetting should be stored 437 * @param conf The Config where the KeySetting should be stored
401 * @param group The group where the KeySetting will be stored 438 * @param group The group where the KeySetting will be stored
402 * @param black Which keys shouldn't be allowed to handle 439 * @param black Which keys shouldn't be allowed to handle
403 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons 440 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons
404 * @param par The parent/owner of this manager 441 * @param par The parent/owner of this manager
405 * @param name The name of this object 442 * @param name The name of this object
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
424 * If a Key is restricted but was in the config we will 466 * If a Key is restricted but was in the config we will
425 * make it be the empty key paur 467 * make it be the empty key paur
426 * We will change the group of the OConfig Item! 468 * We will change the group of the OConfig Item!
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() );
441 OKeyPair okey( key, mod ); 483 OKeyPair okey( key, mod );
442 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) 484 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 )
443 (*it).setKeyPair( OKeyPair(key, mod) ); 485 (*it).setKeyPair( OKeyPair(key, mod) );
444 else 486 else
445 (*it).setKeyPair( OKeyPair::emptyKey() ); 487 (*it).setKeyPair( OKeyPair::emptyKey() );
446 } 488 }
447 delete m_map; m_map = 0; 489 delete m_map; m_map = 0;
448} 490}
449 491
450/** 492/**
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
471/** 512/**
472 * This is function uses a QMap internally but you can have the same keycode 513 * This is function uses a QMap internally but you can have the same keycode
473 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem 514 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem
474 * with same keycode and modifier key. The GUI takes care that a user can't 515 * with same keycode and modifier key. The GUI takes care that a user can't
475 * cofigure two keys. 516 * cofigure two keys.
476 * 517 *
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;
489 break; 530 break;
490 } 531 }
491 532
492 } 533 }
493 534
494 return item; 535 return item;
495} 536}
496 537
497/** 538/**
@@ -553,25 +594,25 @@ void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) {
553/** 594/**
554 * Clear the blackList 595 * Clear the blackList
555 */ 596 */
556void OKeyConfigManager::clearBlackList() { 597void OKeyConfigManager::clearBlackList() {
557 m_blackKeys.clear(); 598 m_blackKeys.clear();
558 delete m_map; m_map = 0; 599 delete m_map; m_map = 0;
559} 600}
560 601
561 602
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
569 610
570/** 611/**
571 * Ask the Manager to handle KeyEvents for you. 612 * Ask the Manager to handle KeyEvents for you.
572 * All handled keys will emit a QSignal and return true 613 * All handled keys will emit a QSignal and return true
573 * that it handled the keyevent 614 * that it handled the keyevent
574 */ 615 */
575void OKeyConfigManager::handleWidget( QWidget* wid ) { 616void OKeyConfigManager::handleWidget( QWidget* wid ) {
576 wid->installEventFilter( this ); 617 wid->installEventFilter( this );
577} 618}
@@ -583,123 +624,370 @@ bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
583 if ( !obj->isWidgetType() ) 624 if ( !obj->isWidgetType() )
584 return false; 625 return false;
585 626
586 if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) 627 if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease )
587 return false; 628 return false;
588 629
589 QKeyEvent *key = static_cast<QKeyEvent*>( ev ); 630 QKeyEvent *key = static_cast<QKeyEvent*>( ev );
590 OKeyConfigItem item = handleKeyEvent( key ); 631 OKeyConfigItem item = handleKeyEvent( key );
591 632
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
631 683
632///////////////////////// 684/////////////////////////
633//////// Widget Starts Here 685//////// Widget Starts Here
634namespace Opie { 686namespace 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}
698 760
699 761
700 762
701//////////////////////// 763////////////////////////
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
@@ -3,207 +3,266 @@
3 * LGPL v2 zecke@handhelds.org 3 * LGPL v2 zecke@handhelds.org
4 */ 4 */
5 5
6 6
7#ifndef ODP_KEY_CONFIG_WIDGET_H 7#ifndef ODP_KEY_CONFIG_WIDGET_H
8#define ODP_KEY_CONFIG_WIDGET_H 8#define ODP_KEY_CONFIG_WIDGET_H
9 9
10#include <opie2/oconfig.h> 10#include <opie2/oconfig.h>
11#include <opie2/odevice.h> 11#include <opie2/odevice.h>
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
27 * This class holds information about key code and possible 36 * This class holds information about key code and possible
28 * modifier state. That is the lowest level of the key input 37 * modifier state. That is the lowest level of the key input
29 * functions. 38 * functions.
30 * There are also static methods to get special keys. 39 * There are also static methods to get special keys.
31 * OKeyPair will be used with \see OKeyConfigItem 40 * OKeyPair will be used with \see OKeyConfigItem
32 * 41 *
33 * @since 1.2 42 * @since 1.2
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
41 bool operator==( const OKeyPair& ); 50 bool operator==( const OKeyPair& );
42 bool operator!=( const OKeyPair& ); 51 bool operator!=( const OKeyPair& );
43 52
44 bool isEmpty()const; 53 bool isEmpty()const;
45 54
46 int keycode()const; 55 int keycode()const;
47 int modifier()const; 56 int modifier()const;
48 57
49 void setKeycode( int ); 58 void setKeycode( int );
50 void setModifier( int ); 59 void setModifier( int );
51 60
52 static OKeyPair returnKey(); 61 static OKeyPair returnKey();
53 static OKeyPair leftArrowKey(); 62 static OKeyPair leftArrowKey();
54 static OKeyPair rightArrowKey(); 63 static OKeyPair rightArrowKey();
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};
66 75
67/** 76/**
68 * A class to represent an OKeyPair. 77 * A class to represent an OKeyPair.
69 * It consists out of a Text exposed to the user, Config Key Item, 78 * It consists out of a Text exposed to the user, Config Key Item,
70 * Pixmap, A default OKeyPair and the set OKeyPair. 79 * Pixmap, A default OKeyPair and the set OKeyPair.
71 * You can also pass an id to it 80 * You can also pass an id to it
72 * 81 *
73 * @since 1.1.2 82 * @since 1.1.2
74 */ 83 */
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
87 bool operator==( const OKeyConfigItem& ); 96 bool operator==( const OKeyConfigItem& );
88 bool operator!=( const OKeyConfigItem& ); 97 bool operator!=( const OKeyConfigItem& );
89 98
90 QString text()const; 99 QString text()const;
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& );
101 void setDefaultKeyPair( const OKeyPair& ); 113 void setDefaultKeyPair( const OKeyPair& );
102 114
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};
119 135
120 136
121 137
122/** 138/**
123 * \brief A manager to load and save Key Actions and get notified 139 * \brief A manager to load and save Key Actions and get notified
124 * This is the Manager for KeyActions. 140 * This is the Manager for KeyActions.
125 * You can say from which config and group to read data, to grab the 141 * You can say from which config and group to read data, to grab the
126 * keyboard to handle hardware keys, you can supply a blacklist of 142 * keyboard to handle hardware keys, you can supply a blacklist of
127 * keys which should not be used by allowed to be used. 143 * keys which should not be used by allowed to be used.
128 * You can even pass this manager to a Widget to do the configuration for you. 144 * You can even pass this manager to a Widget to do the configuration for you.
129 * You need to add OKeyConfigItem for your keys and then issue a load() to 145 * You need to add OKeyConfigItem for your keys and then issue a load() to
130 * read the Key information. 146 * read the Key information.
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
148 void load(); 165 void load();
149 void save(); 166 void save();
150 167
151 OKeyConfigItem handleKeyEvent( QKeyEvent* ); 168 OKeyConfigItem handleKeyEvent( QKeyEvent* );
152 int handleKeyEventId( QKeyEvent* ); 169 int handleKeyEventId( QKeyEvent* );
153 170
154 void addKeyConfig( const OKeyConfigItem& ); 171 void addKeyConfig( const OKeyConfigItem& );
155 void removeKeyConfig( const OKeyConfigItem& ); 172 void removeKeyConfig( const OKeyConfigItem& );
156 void clearKeyConfig(); 173 void clearKeyConfig();
157 174
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;
180 Private *d; 210 Private *d;
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};
204 263
205} 264}
206} 265}
207 266
208 267
209#endif 268#endif