summaryrefslogtreecommitdiff
authorzecke <zecke>2004-03-28 20:39:22 (UTC)
committer zecke <zecke>2004-03-28 20:39:22 (UTC)
commitb4c5da4a6cf51753e8d2da505197326e05323d73 (patch) (unidiff)
tree6b9814683e717f8445496dc0d4c8d23eda223dc3
parent4cbd5ad37e51b7bc9c749f8eda2e46a806d904b0 (diff)
downloadopie-b4c5da4a6cf51753e8d2da505197326e05323d73.zip
opie-b4c5da4a6cf51753e8d2da505197326e05323d73.tar.gz
opie-b4c5da4a6cf51753e8d2da505197326e05323d73.tar.bz2
From yesterday. Some sort of GUI loading
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp20
-rw-r--r--libopie2/opieui/okeyconfigwidget.h2
2 files changed, 19 insertions, 3 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp
index 2ea0bd5..273f15b 100644
--- a/libopie2/opieui/okeyconfigwidget.cpp
+++ b/libopie2/opieui/okeyconfigwidget.cpp
@@ -349,682 +349,696 @@ void OKeyConfigItem::setConfigKey( const QCString& str) {
349 * @internal 349 * @internal
350 */ 350 */
351void OKeyConfigItem::setId( int id ) { 351void OKeyConfigItem::setId( int id ) {
352 m_id = id; 352 m_id = id;
353} 353}
354 354
355/** 355/**
356 * If the item is not configured isEmpty() will return true 356 * If the item is not configured isEmpty() will return true
357 * It is empty if no text is present and no default 357 * It is empty if no text is present and no default
358 * and no configured key 358 * and no configured key
359 */ 359 */
360bool OKeyConfigItem::isEmpty()const { 360bool OKeyConfigItem::isEmpty()const {
361 if ( !m_def.isEmpty() ) return false; 361 if ( !m_def.isEmpty() ) return false;
362 if ( !m_key.isEmpty() ) return false; 362 if ( !m_key.isEmpty() ) return false;
363 if ( !m_text.isEmpty() ) return false; 363 if ( !m_text.isEmpty() ) return false;
364 364
365 return true; 365 return true;
366} 366}
367 367
368/** 368/**
369 * Check if the KeyPairs are the same 369 * Check if the KeyPairs are the same
370 */ 370 */
371bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { 371bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) {
372 if ( isEmpty() == conf.isEmpty() ) return true; 372 if ( isEmpty() == conf.isEmpty() ) return true;
373 else if ( isEmpty() != conf.isEmpty() ) return false; 373 else if ( isEmpty() != conf.isEmpty() ) return false;
374 else if ( !isEmpty()!= conf.isEmpty() ) return false; 374 else if ( !isEmpty()!= conf.isEmpty() ) return false;
375 375
376 if ( m_id != conf.m_id ) return false; 376 if ( m_id != conf.m_id ) return false;
377 if ( m_text != conf.m_text ) return false; 377 if ( m_text != conf.m_text ) return false;
378 if ( m_key != conf.m_key ) return false; 378 if ( m_key != conf.m_key ) return false;
379 if ( m_def != conf.m_def ) return false; 379 if ( m_def != conf.m_def ) return false;
380 380
381 return true; 381 return true;
382 382
383} 383}
384 384
385bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { 385bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) {
386 return !( *this == conf ); 386 return !( *this == conf );
387} 387}
388 388
389/** 389/**
390 * \brief c'tor 390 * \brief c'tor
391 * The Constructor for a OKeyConfigManager 391 * The Constructor for a OKeyConfigManager
392 * 392 *
393 * You can use this manager in multiple ways. Either make it handle 393 * You can use this manager in multiple ways. Either make it handle
394 * QKeyEvents 394 * QKeyEvents
395 * 395 *
396 * \code 396 * \code
397 * Opie::Core::Config conf = oApp->config(); 397 * Opie::Core::Config conf = oApp->config();
398 * Opie::Ui::OKeyPairList blackList; 398 * Opie::Ui::OKeyPairList blackList;
399 * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); 399 * blackList.append(Opie::Ui::OKeyPair::leftArrowKey());
400 * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); 400 * blackList.append(Opie::Ui::OKeyPair::rightArrowKey());
401 * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, 401 * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList,
402 * false); 402 * false);
403 * QListView *view = new QListView(); 403 * QListView *view = new QListView();
404 * manager->handleWidget(view); 404 * manager->handleWidget(view);
405 * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); 405 * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey());
406 * manager->load(); 406 * manager->load();
407 * 407 *
408 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), 408 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)),
409 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); 409 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)));
410 * 410 *
411 * .... 411 * ....
412 * 412 *
413 * void update(){ 413 * void update(){
414 * QDialog diag(true); 414 * QDialog diag(true);
415 * QHBoxLayout *lay = new QHBoxLayout(&diag); 415 * QHBoxLayout *lay = new QHBoxLayout(&diag);
416 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); 416 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag);
417 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); 417 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu);
418 * lay->addWidget(wid); 418 * lay->addWidget(wid);
419 * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ 419 * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){
420 * wid->save(); 420 * wid->save();
421 * } 421 * }
422 * } 422 * }
423 * 423 *
424 * .... 424 * ....
425 * MyListView::keyPressEvent( QKeyEvent* e ){ 425 * MyListView::keyPressEvent( QKeyEvent* e ){
426 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); 426 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e);
427 * if(!item.isEmpty() ){ 427 * if(!item.isEmpty() ){
428 * switch(item.id()){ 428 * switch(item.id()){
429 * case My_Delete_Key: 429 * case My_Delete_Key:
430 * break; 430 * break;
431 * } 431 * }
432 * } 432 * }
433 * } 433 * }
434 * 434 *
435 * \endcode 435 * \endcode
436 * 436 *
437 * @param conf The Config where the KeySetting should be stored 437 * @param conf The Config where the KeySetting should be stored
438 * @param group The group where the KeySetting will be stored 438 * @param group The group where the KeySetting will be stored
439 * @param black Which keys shouldn't be allowed to handle 439 * @param black Which keys shouldn't be allowed to handle
440 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons 440 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons
441 * @param par The parent/owner of this manager 441 * @param par The parent/owner of this manager
442 * @param name The name of this object 442 * @param name The name of this object
443 */ 443 */
444OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, 444OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
445 const QString& group, 445 const QString& group,
446 const OKeyPair::List& black, 446 const OKeyPair::List& black,
447 bool grabkeyboard, QObject* par, 447 bool grabkeyboard, QObject* par,
448 const char* name) 448 const char* name)
449 : QObject( par, name ), m_conf( conf ), m_group( group ), 449 : QObject( par, name ), m_conf( conf ), m_group( group ),
450 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ 450 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){
451 if ( m_grab ) 451 if ( m_grab )
452 QPEApplication::grabKeyboard(); 452 QPEApplication::grabKeyboard();
453} 453}
454 454
455 455
456/** 456/**
457 * Destructor 457 * Destructor
458 */ 458 */
459OKeyConfigManager::~OKeyConfigManager() { 459OKeyConfigManager::~OKeyConfigManager() {
460 if ( m_grab ) 460 if ( m_grab )
461 QPEApplication::ungrabKeyboard(); 461 QPEApplication::ungrabKeyboard();
462} 462}
463 463
464/** 464/**
465 * Load the Configuration from the OConfig 465 * Load the Configuration from the OConfig
466 * 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
467 * make it be the empty key paur 467 * make it be the empty key paur
468 * We will change the group of the OConfig Item! 468 * We will change the group of the OConfig Item!
469 * 469 *
470 * @see OKeyPair::emptyKey 470 * @see OKeyPair::emptyKey
471 */ 471 */
472void OKeyConfigManager::load() { 472void OKeyConfigManager::load() {
473 m_conf->setGroup( m_group ); 473 m_conf->setGroup( m_group );
474 474
475 /* 475 /*
476 * Read each item 476 * Read each item
477 */ 477 */
478 int key, mod; 478 int key, mod;
479 for( OKeyConfigItem::List::Iterator it = m_keys.begin(); 479 for( OKeyConfigItem::List::Iterator it = m_keys.begin();
480 it != m_keys.end(); ++it ) { 480 it != m_keys.end(); ++it ) {
481 key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); 481 key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() );
482 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); 482 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() );
483 OKeyPair okey( key, mod ); 483 OKeyPair okey( key, mod );
484 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) 484 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 )
485 (*it).setKeyPair( OKeyPair(key, mod) ); 485 (*it).setKeyPair( OKeyPair(key, mod) );
486 else 486 else
487 (*it).setKeyPair( OKeyPair::emptyKey() ); 487 (*it).setKeyPair( OKeyPair::emptyKey() );
488 } 488 }
489 delete m_map; m_map = 0; 489 delete m_map; m_map = 0;
490} 490}
491 491
492/** 492/**
493 * We will save the current configuration 493 * We will save the current configuration
494 * to the OConfig. We will change the group. 494 * to the OConfig. We will change the group.
495 */ 495 */
496void OKeyConfigManager::save() { 496void OKeyConfigManager::save() {
497 m_conf->setGroup( m_group ); 497 m_conf->setGroup( m_group );
498 498
499 /* 499 /*
500 * Write each item 500 * Write each item
501 */ 501 */
502 for( OKeyConfigItem::List::Iterator it = m_keys.begin(); 502 for( OKeyConfigItem::List::Iterator it = m_keys.begin();
503 it != m_keys.end(); ++it ) { 503 it != m_keys.end(); ++it ) {
504 if ( (*it).isEmpty() ) 504 if ( (*it).isEmpty() )
505 continue; 505 continue;
506 OKeyPair pair = (*it).keyPair(); 506 OKeyPair pair = (*it).keyPair();
507 OKeyPair deft = (*it).defaultKeyPair(); 507 OKeyPair deft = (*it).defaultKeyPair();
508 /* don't write if it is the default setting */ 508 /* don't write if it is the default setting */
509 if ( (pair.keycode() == deft.keycode()) && 509 if ( (pair.keycode() == deft.keycode()) &&
510 (pair.modifier()== deft.modifier() ) ) 510 (pair.modifier()== deft.modifier() ) )
511 return; 511 return;
512 512
513 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); 513 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() );
514 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); 514 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() );
515 } 515 }
516} 516}
517 517
518/** 518/**
519 * This is function uses a QMap internally but you can have the same keycode 519 * This is function uses a QMap internally but you can have the same keycode
520 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem 520 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem
521 * with same keycode and modifier key. The GUI takes care that a user can't 521 * with same keycode and modifier key. The GUI takes care that a user can't
522 * cofigure two keys. 522 * cofigure two keys.
523 * 523 *
524 * Make sure you call e->ignore if you don't want to handle this event 524 * Make sure you call e->ignore if you don't want to handle this event
525 */ 525 */
526OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { 526OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) {
527 /* 527 /*
528 * Fix Up issues with Qt/E, my keybard, and virtual input 528 * Fix Up issues with Qt/E, my keybard, and virtual input
529 * methods 529 * methods
530 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state 530 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state
531 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower 531 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower
532 * case ascii 532 * case ascii
533 */ 533 */
534 int key = e->key(); 534 int key = e->key();
535 int mod = e->state(); 535 int mod = e->state();
536 536
537/* 537/*
538 * virtual keyboard 538 * virtual keyboard
539 * else change the button mod only 539 * else change the button mod only
540 */ 540 */
541 qWarning( "handleKeyEvent...." );
542 if ( key == 0 ) { 541 if ( key == 0 ) {
543 key = e->ascii(); 542 key = e->ascii();
544 if ( key > 96 && key < 123) 543 if ( key > 96 && key < 123)
545 key -= 32; 544 key -= 32;
546 }else{ 545 }else{
547 int new_mod = 0; 546 int new_mod = 0;
548 if ( mod & 256 ) 547 if ( mod & 256 )
549 new_mod |= Qt::ShiftButton; 548 new_mod |= Qt::ShiftButton;
550 else if ( mod & 512 ) 549 else if ( mod & 512 )
551 new_mod |= Qt::AltButton; 550 new_mod |= Qt::AltButton;
552 else if ( mod & 1024 ) 551 else if ( mod & 1024 )
553 new_mod |= Qt::ControlButton; 552 new_mod |= Qt::ControlButton;
554 553
555 mod = new_mod == 0? mod : new_mod; 554 mod = new_mod == 0? mod : new_mod;
556 } 555 }
557 556
558 OKeyConfigItem::List _keyList = keyList( key ); 557 OKeyConfigItem::List _keyList = keyList( key );
559 if ( _keyList.isEmpty() ) 558 if ( _keyList.isEmpty() )
560 return OKeyConfigItem(); 559 return OKeyConfigItem();
561 560
562 OKeyConfigItem item; 561 OKeyConfigItem item;
563 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); 562 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end();
564 ++it ) { 563 ++it ) {
565 if ( (*it).keyPair().modifier() == mod ) { 564 if ( (*it).keyPair().modifier() == mod ) {
566 item = *it; 565 item = *it;
567 break; 566 break;
568 } 567 }
569 568
570 } 569 }
571 570
572 return item; 571 return item;
573} 572}
574 573
575/** 574/**
576 * Return the associated id of the item or -1 if no item 575 * Return the associated id of the item or -1 if no item
577 * matched the key 576 * matched the key
578 * 577 *
579 * @see handleKeyEvent 578 * @see handleKeyEvent
580 */ 579 */
581int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { 580int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) {
582 return handleKeyEvent( ev ).id(); 581 return handleKeyEvent( ev ).id();
583} 582}
584 583
585/** 584/**
586 * Add Key Config to the List of items 585 * Add Key Config to the List of items
587 */ 586 */
588void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { 587void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) {
589 m_keys.append( item ); 588 m_keys.append( item );
590 delete m_map; m_map = 0; 589 delete m_map; m_map = 0;
591} 590}
592 591
593/** 592/**
594 * Remove the Key from the Config. Internal lists will be destroyed 593 * Remove the Key from the Config. Internal lists will be destroyed
595 * and rebuild on demand later 594 * and rebuild on demand later
596 */ 595 */
597void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { 596void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) {
598 m_keys.remove( item ); 597 m_keys.remove( item );
599 delete m_map; m_map = 0; 598 delete m_map; m_map = 0;
600} 599}
601 600
602/** 601/**
603 * Clears the complete list 602 * Clears the complete list
604 */ 603 */
605void OKeyConfigManager::clearKeyConfig() { 604void OKeyConfigManager::clearKeyConfig() {
606 m_keys.clear(); 605 m_keys.clear();
607 delete m_map; m_map = 0; 606 delete m_map; m_map = 0;
608} 607}
609 608
609/**
610 *
611 */
612Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{
613 return m_keys;
614}
610 615
611/** 616/**
612 * Add this OKeyPair to the blackList. 617 * Add this OKeyPair to the blackList.
613 * Internal lists will be destroyed 618 * Internal lists will be destroyed
614 */ 619 */
615void OKeyConfigManager::addToBlackList( const OKeyPair& key) { 620void OKeyConfigManager::addToBlackList( const OKeyPair& key) {
616 m_blackKeys.append( key ); 621 m_blackKeys.append( key );
617 delete m_map; m_map = 0; 622 delete m_map; m_map = 0;
618} 623}
619 624
620 625
621/** 626/**
622 * Remove this OKeyPair from the black List 627 * Remove this OKeyPair from the black List
623 * Internal lists will be destroyed 628 * Internal lists will be destroyed
624 */ 629 */
625void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { 630void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) {
626 m_blackKeys.remove( key ); 631 m_blackKeys.remove( key );
627 delete m_map; m_map = 0; 632 delete m_map; m_map = 0;
628} 633}
629 634
630 635
631/** 636/**
632 * Clear the blackList 637 * Clear the blackList
633 */ 638 */
634void OKeyConfigManager::clearBlackList() { 639void OKeyConfigManager::clearBlackList() {
635 m_blackKeys.clear(); 640 m_blackKeys.clear();
636 delete m_map; m_map = 0; 641 delete m_map; m_map = 0;
637} 642}
638 643
639 644
640/** 645/**
641 * Return a copy of the blackList 646 * Return a copy of the blackList
642 */ 647 */
643OKeyPair::List OKeyConfigManager::blackList()const { 648OKeyPair::List OKeyConfigManager::blackList()const {
644 return m_blackKeys; 649 return m_blackKeys;
645} 650}
646 651
647 652
648/** 653/**
649 * Ask the Manager to handle KeyEvents for you. 654 * Ask the Manager to handle KeyEvents for you.
650 * All handled keys will emit a QSignal and return true 655 * All handled keys will emit a QSignal and return true
651 * that it handled the keyevent 656 * that it handled the keyevent
652 */ 657 */
653void OKeyConfigManager::handleWidget( QWidget* wid ) { 658void OKeyConfigManager::handleWidget( QWidget* wid ) {
654 wid->installEventFilter( this ); 659 wid->installEventFilter( this );
655} 660}
656 661
657/** 662/**
658 * @internal 663 * @internal
659 */ 664 */
660bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { 665bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
661 if ( !obj->isWidgetType() ) 666 if ( !obj->isWidgetType() )
662 return false; 667 return false;
663 668
664 if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) 669 if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease )
665 return false; 670 return false;
666 671
667 QKeyEvent *key = static_cast<QKeyEvent*>( ev ); 672 QKeyEvent *key = static_cast<QKeyEvent*>( ev );
668 OKeyConfigItem item = handleKeyEvent( key ); 673 OKeyConfigItem item = handleKeyEvent( key );
669 674
670 if ( item.isEmpty() ) 675 if ( item.isEmpty() )
671 return false; 676 return false;
672 677
673 QWidget *wid = static_cast<QWidget*>( obj ); 678 QWidget *wid = static_cast<QWidget*>( obj );
674 679
675 if ( item.object() && !item.slot().isEmpty() ) { 680 if ( item.object() && !item.slot().isEmpty() ) {
676 connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), 681 connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)),
677 item.object(), item.slot().data() ); 682 item.object(), item.slot().data() );
678 emit actionActivated(wid, key); 683 emit actionActivated(wid, key);
679 disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), 684 disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)),
680 item.object(), item.slot().data() ); 685 item.object(), item.slot().data() );
681 } 686 }
682 emit actionActivated( wid, key, item ); 687 emit actionActivated( wid, key, item );
683 688
684 return true; 689 return true;
685} 690}
686 691
687/** 692/**
688 * @internal 693 * @internal
689 */ 694 */
690OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { 695OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) {
691 /* 696 /*
692 * Create the map if not existing anymore 697 * Create the map if not existing anymore
693 */ 698 */
694 if ( !m_map ) { 699 if ( !m_map ) {
695 m_map = new OKeyMapConfigPrivate; 700 m_map = new OKeyMapConfigPrivate;
696 /* for every key */ 701 /* for every key */
697 for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); 702 for ( OKeyConfigItem::List::Iterator it = m_keys.begin();
698 it!= m_keys.end(); ++it ) { 703 it!= m_keys.end(); ++it ) {
699 704
700 bool add = true; 705 bool add = true;
701 /* see if this key is blocked */ 706 /* see if this key is blocked */
702 OKeyPair pair = (*it).keyPair(); 707 OKeyPair pair = (*it).keyPair();
703 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); 708 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin();
704 pairIt != m_blackKeys.end(); ++pairIt ) { 709 pairIt != m_blackKeys.end(); ++pairIt ) {
705 if ( (*pairIt).keycode() == pair.keycode() && 710 if ( (*pairIt).keycode() == pair.keycode() &&
706 (*pairIt).modifier() == pair.modifier() ) { 711 (*pairIt).modifier() == pair.modifier() ) {
707 add = false; 712 add = false;
708 break; 713 break;
709 } 714 }
710 } 715 }
711 /* check if we added it */ 716 /* check if we added it */
712 if ( add ) 717 if ( add )
713 (*m_map)[pair.keycode()].append( *it ); 718 (*m_map)[pair.keycode()].append( *it );
714 } 719 }
715 } 720 }
716 return (*m_map)[keycode]; 721 return (*m_map)[keycode];
717} 722}
718 723
719 724
720 725
721///////////////////////// 726/////////////////////////
722//////// Widget Starts Here 727//////// Widget Starts Here
723namespace Opie { 728namespace Opie {
724namespace Ui { 729namespace Ui {
725namespace Private { 730namespace Private {
726 static QString keyToString( const OKeyPair& ); 731 static QString keyToString( const OKeyPair& );
727 class OKeyListViewItem : public Opie::Ui::OListViewItem { 732 class OKeyListViewItem : public Opie::Ui::OListViewItem {
728 public: 733 public:
729 OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); 734 OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent);
730 ~OKeyListViewItem(); 735 ~OKeyListViewItem();
731 736
732 void setDefault(); 737 void setDefault();
733 738
734 OKeyConfigItem& item(); 739 OKeyConfigItem& item();
735 void setItem( const OKeyConfigItem& item ); 740 void setItem( const OKeyConfigItem& item );
736 741
737 OKeyConfigManager *manager(); 742 OKeyConfigManager *manager();
738 private: 743 private:
739 OKeyConfigItem m_item; 744 OKeyConfigItem m_item;
740 OKeyConfigManager* m_manager; 745 OKeyConfigManager* m_manager;
741 746
742 }; 747 };
743 748
744 OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) 749 OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent)
745 : Opie::Ui::OListViewItem( parent ), m_manager( man ) { 750 : Opie::Ui::OListViewItem( parent ), m_manager( man ) {
746 setItem( item ); 751 setItem( item );
747 } 752 }
748 OKeyListViewItem::~OKeyListViewItem() {} 753 OKeyListViewItem::~OKeyListViewItem() {}
749 OKeyConfigItem &OKeyListViewItem::item(){ 754 OKeyConfigItem &OKeyListViewItem::item(){
750 return m_item; 755 return m_item;
751 } 756 }
752 OKeyConfigManager* OKeyListViewItem::manager() { 757 OKeyConfigManager* OKeyListViewItem::manager() {
753 return m_manager; 758 return m_manager;
754 } 759 }
755 void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { 760 void OKeyListViewItem::setItem( const OKeyConfigItem& item ) {
761 m_item = item;
756 setPixmap( 0, m_item.pixmap() ); 762 setPixmap( 0, m_item.pixmap() );
757 setText ( 1, m_item.text() ); 763 setText ( 1, m_item.text() );
758 setText ( 2, keyToString( m_item.keyPair() ) ); 764 setText ( 2, keyToString( m_item.keyPair() ) );
759 setText ( 3, keyToString( m_item.defaultKeyPair() ) ); 765 setText ( 3, keyToString( m_item.defaultKeyPair() ) );
760 m_item = item;
761 } 766 }
762 767
763 QString keyToString( const OKeyPair& pair ) { 768 QString keyToString( const OKeyPair& pair ) {
764 int mod = 0; 769 int mod = 0;
765 if ( pair.modifier() & Qt::ShiftButton ) 770 if ( pair.modifier() & Qt::ShiftButton )
766 mod |= Qt::SHIFT; 771 mod |= Qt::SHIFT;
767 if ( pair.modifier() & Qt::ControlButton ) 772 if ( pair.modifier() & Qt::ControlButton )
768 mod |= Qt::CTRL; 773 mod |= Qt::CTRL;
769 if ( pair.modifier() & Qt::AltButton ) 774 if ( pair.modifier() & Qt::AltButton )
770 mod |= Qt::ALT; 775 mod |= Qt::ALT;
771 776
772 return QAccel::keyToString( mod + pair.keycode() ); 777 return QAccel::keyToString( mod + pair.keycode() );
773 } 778 }
774 779
775 struct OKeyConfigWidgetPrivate{ 780 struct OKeyConfigWidgetPrivate{
776 OKeyConfigWidgetPrivate(const QString& = QString::null, 781 OKeyConfigWidgetPrivate(const QString& = QString::null,
777 OKeyConfigManager* = 0); 782 OKeyConfigManager* = 0);
778 bool operator==( const OKeyConfigWidgetPrivate& ); 783 bool operator==( const OKeyConfigWidgetPrivate& );
779 QString name; 784 QString name;
780 OKeyConfigManager *manager; 785 OKeyConfigManager *manager;
781 }; 786 };
782 787
783 OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, 788 OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name,
784 OKeyConfigManager* man ) 789 OKeyConfigManager* man )
785 : name( _name ), manager( man ){} 790 : name( _name ), manager( man ){}
786 791
787 bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { 792 bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) {
788 if ( manager != item.manager) return false; 793 if ( manager != item.manager) return false;
789 if ( name != item.name ) return false; 794 if ( name != item.name ) return false;
790 795
791 return true; 796 return true;
792 } 797 }
793 798
794} 799}
795} 800}
796} 801}
797 802
798 803
799 804
800//////////////////////// 805////////////////////////
801 806
802 807
803 808
804 809
805 810
806/** 811/**
807 * 812 *
808 * This is a c'tor. You still need to pass the OKeyConfigManager 813 * This is a c'tor. You still need to pass the OKeyConfigManager
809 * and then issue a load. 814 * and then issue a load.
810 * The default mode is Immediate 815 * The default mode is Immediate
811 * 816 *
812 */ 817 */
813OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) 818OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl )
814 : QWidget( parent, name, fl ) { 819 : QWidget( parent, name, fl ) {
815 initUi(); 820 initUi();
816} 821}
817 822
818 823
819 824
820/** 825/**
821 * c'tor 826 * c'tor
822 */ 827 */
823OKeyConfigWidget::~OKeyConfigWidget() { 828OKeyConfigWidget::~OKeyConfigWidget() {
824} 829}
825 830
826 831
827/** 832/**
828 * @internal 833 * @internal
829 */ 834 */
830void OKeyConfigWidget::initUi() { 835void OKeyConfigWidget::initUi() {
831 QBoxLayout *layout = new QVBoxLayout( this ); 836 QBoxLayout *layout = new QVBoxLayout( this );
832 QGridLayout *gridLay = new QGridLayout( 2, 2 ); 837 QGridLayout *gridLay = new QGridLayout( 2, 2 );
833 layout->addLayout( gridLay, 10 ); 838 layout->addLayout( gridLay, 10 );
834 gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth 839 gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth
835 840
836/* 841/*
837 * LISTVIEW with the Keys 842 * LISTVIEW with the Keys
838 */ 843 */
839 m_view = new Opie::Ui::OListView( this ); 844 m_view = new Opie::Ui::OListView( this );
840 m_view->setFocus(); 845 m_view->setFocus();
841 m_view->setAllColumnsShowFocus( true ); 846 m_view->setAllColumnsShowFocus( true );
842 m_view->addColumn( tr("Pixmap") ); 847 m_view->addColumn( tr("Pixmap") );
843 m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); 848 m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) );
844 m_view->addColumn( tr("Key" ) ); 849 m_view->addColumn( tr("Key" ) );
845 m_view->addColumn( tr("Default Key" ) ); 850 m_view->addColumn( tr("Default Key" ) );
846 connect(m_view, SIGNAL(currentChanged(QListViewItem*)), 851 connect(m_view, SIGNAL(currentChanged(QListViewItem*)),
847 this, SLOT(slotListViewItem(QListViewItem*)) ); 852 this, SLOT(slotListViewItem(QListViewItem*)) );
848 853
849 gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); 854 gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 );
850 855
851/* 856/*
852 * GROUP with button info 857 * GROUP with button info
853 */ 858 */
854 859
855 QGroupBox *box = new QGroupBox( this ); 860 QGroupBox *box = new QGroupBox( this );
856 box ->setEnabled( false );
857 box ->setTitle( tr("Shortcut for Selected Action") ); 861 box ->setTitle( tr("Shortcut for Selected Action") );
858 box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); 862 box ->setFrameStyle( QFrame::Box | QFrame::Sunken );
859 layout->addWidget( box, 1 ); 863 layout->addWidget( box, 1 );
860 864
861 gridLay = new QGridLayout( box, 3, 4 ); 865 gridLay = new QGridLayout( box, 3, 4 );
862 gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); 866 gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() );
863 gridLay->setMargin( 4 ); 867 gridLay->setMargin( 4 );
864 868
865 QButtonGroup *gr = new QButtonGroup( box ); 869 QButtonGroup *gr = new QButtonGroup( box );
866 gr->hide(); 870 gr->hide();
867 gr->setExclusive( true ); 871 gr->setExclusive( true );
868 872
869 QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); 873 QRadioButton *rad = new QRadioButton( tr( "&None" ), box );
870 connect( rad, SIGNAL(clicked()), 874 connect( rad, SIGNAL(clicked()),
871 this, SLOT(slotNoKey()) ); 875 this, SLOT(slotNoKey()) );
872 gr->insert( rad, 10 ); 876 gr->insert( rad, 10 );
873 gridLay->addWidget( rad, 1, 0 ); 877 gridLay->addWidget( rad, 1, 0 );
874 m_none = rad; 878 m_none = rad;
875 879
876 rad = new QRadioButton( tr("&Default" ), box ); 880 rad = new QRadioButton( tr("&Default" ), box );
877 connect( rad, SIGNAL(clicked()), 881 connect( rad, SIGNAL(clicked()),
878 this, SLOT(slotDefaultKey()) ); 882 this, SLOT(slotDefaultKey()) );
879 gr->insert( rad, 11 ); 883 gr->insert( rad, 11 );
880 gridLay->addWidget( rad, 1, 1 ); 884 gridLay->addWidget( rad, 1, 1 );
881 m_def = rad; 885 m_def = rad;
882 886
883 rad = new QRadioButton( tr("C&ustom"), box ); 887 rad = new QRadioButton( tr("C&ustom"), box );
884 connect( rad, SIGNAL(clicked()), 888 connect( rad, SIGNAL(clicked()),
885 this, SLOT(slotCustomKey()) ); 889 this, SLOT(slotCustomKey()) );
886 gr->insert( rad, 12 ); 890 gr->insert( rad, 12 );
887 gridLay->addWidget( rad, 1, 2 ); 891 gridLay->addWidget( rad, 1, 2 );
888 m_cus = rad; 892 m_cus = rad;
889 893
890 m_btn = new QPushButton( tr("Configure Key"), box ); 894 m_btn = new QPushButton( tr("Configure Key"), box );
891 gridLay->addWidget( m_btn, 1, 4 ); 895 gridLay->addWidget( m_btn, 1, 4 );
892 896
893 m_lbl= new QLabel( tr( "Default: " ), box ); 897 m_lbl= new QLabel( tr( "Default: " ), box );
894 gridLay->addWidget( m_lbl, 2, 0 ); 898 gridLay->addWidget( m_lbl, 2, 0 );
895 899
896 900
897 m_box = gr; 901 m_box = gr;
898} 902}
899 903
900/** 904/**
901 * Set the ChangeMode. 905 * Set the ChangeMode.
902 * You need to call this function prior to load 906 * You need to call this function prior to load
903 * If you call this function past load the behaviour is undefined 907 * If you call this function past load the behaviour is undefined
904 * But caling load again is safe 908 * But caling load again is safe
905 */ 909 */
906void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { 910void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) {
907 m_mode = mode; 911 m_mode = mode;
908} 912}
909 913
910 914
911/** 915/**
912 * return the current mode 916 * return the current mode
913 */ 917 */
914OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { 918OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const {
915 return m_mode; 919 return m_mode;
916} 920}
917 921
918 922
919/** 923/**
920 * insert these items before calling load 924 * insert these items before calling load
921 */ 925 */
922void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { 926void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) {
923 Opie::Ui::Private::OKeyConfigWidgetPrivate root( str, man ); 927 Opie::Ui::Private::OKeyConfigWidgetPrivate root( str, man );
924 m_list.append(root); 928 m_list.append(root);
925} 929}
926 930
927 931
928/** 932/**
929 * loads the items and allows editing them 933 * loads the items and allows editing them
930 */ 934 */
931void OKeyConfigWidget::load() { 935void OKeyConfigWidget::load() {
936 Opie::Ui::Private::OKeyConfigWidgetPrivateList::Iterator it;
937 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
938 OListViewItem *item = new OListViewItem( m_view, (*it).name );
939 OKeyConfigItem::List list = (*it).manager->keyConfigList();
940 for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt )
941 (void )new Opie::Ui::Private::OKeyListViewItem(*keyIt, (*it).manager, item );
932 942
943 }
933} 944}
934 945
935/** 946/**
936 * Saves if in Queue Mode. It'll update the supplied 947 * Saves if in Queue Mode. It'll update the supplied
937 * OKeyConfigManager objects. 948 * OKeyConfigManager objects.
938 * If in Queue mode it'll just return 949 * If in Queue mode it'll just return
939 */ 950 */
940void OKeyConfigWidget::save() { 951void OKeyConfigWidget::save() {
941 952
942} 953}
943 954
944 955
945/** 956/**
946 * @internal 957 * @internal
947 */ 958 */
948void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { 959void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) {
949 if ( !_item || !_item->parent() ) { 960 if ( !_item || !_item->parent() ) {
950 m_box->setEnabled( false ); 961 m_box->setEnabled( false );
951 m_none->setChecked( true ); 962 m_none->setChecked( true );
952 m_btn ->setEnabled( false ); 963 m_btn ->setEnabled( false );
953 m_def ->setChecked( false ); 964 m_def ->setChecked( false );
954 m_cus ->setChecked( false ); 965 m_cus ->setChecked( false );
955 }else{ 966 }else{
956 m_box->setEnabled( true ); 967 m_box->setEnabled( true );
957 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); 968 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item );
958 OKeyConfigItem keyItem= item->item(); 969 OKeyConfigItem keyItem= item->item();
959 if ( keyItem.keyPair().isEmpty() ) { 970 if ( keyItem.keyPair().isEmpty() ) {
960 m_none->setChecked( true ); 971 m_none->setChecked( true );
961 m_btn ->setEnabled( false ); 972 m_btn ->setEnabled( false );
962 m_def ->setChecked( false ); 973 m_def ->setChecked( false );
963 m_cus ->setChecked( false ); 974 m_cus ->setChecked( false );
964 }else { 975 }else {
965 m_none->setChecked( false ); 976 m_none->setChecked( false );
966 m_cus ->setChecked( true ); 977 m_cus ->setChecked( true );
967 m_btn ->setEnabled( true ); 978 m_btn ->setEnabled( true );
968 m_def ->setChecked( false ); 979 m_def ->setChecked( false );
969 } 980 }
970 } 981 }
971} 982}
972 983
973void OKeyConfigWidget::slotNoKey() { 984void OKeyConfigWidget::slotNoKey() {
985 qWarning( "No Key" );
974 m_none->setChecked( true ); 986 m_none->setChecked( true );
975 m_cus ->setChecked( false ); 987 m_cus ->setChecked( false );
976 m_btn ->setEnabled( false ); 988 m_btn ->setEnabled( false );
977 m_def ->setChecked( false ); 989 m_def ->setChecked( false );
978 990
979 if ( !m_view->currentItem() || m_view->currentItem()->parent() ) 991 if ( !m_view->currentItem() || m_view->currentItem()->parent() )
980 return; 992 return;
981 993
982 994
983 995
984 /* 996 /*
985 * If immediate we need to remove and readd the key 997 * If immediate we need to remove and readd the key
986 */ 998 */
987 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); 999 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem());
988 if ( m_mode == Imediate ) 1000 if ( m_mode == Imediate )
989 item->manager()->removeKeyConfig( item->item() ); 1001 item->manager()->removeKeyConfig( item->item() );
990 item->item().setKeyPair( OKeyPair::emptyKey() ); 1002 item->item().setKeyPair( OKeyPair::emptyKey() );
991 1003
992 if ( m_mode == Imediate ) 1004 if ( m_mode == Imediate )
993 item->manager()->addKeyConfig( item->item() ); 1005 item->manager()->addKeyConfig( item->item() );
994 1006
995} 1007}
996 1008
997void OKeyConfigWidget::slotDefaultKey() { 1009void OKeyConfigWidget::slotDefaultKey() {
1010 qWarning( "Slot Default Key" );
998 m_none->setChecked( true ); 1011 m_none->setChecked( true );
999 m_cus ->setChecked( false ); 1012 m_cus ->setChecked( false );
1000 m_btn ->setEnabled( false ); 1013 m_btn ->setEnabled( false );
1001 m_def ->setChecked( false ); 1014 m_def ->setChecked( false );
1002 1015
1003 if ( !m_view->currentItem() || m_view->currentItem()->parent() ) 1016 if ( !m_view->currentItem() || m_view->currentItem()->parent() )
1004 return; 1017 return;
1005 1018
1006 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); 1019 Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem());
1007 1020
1008 /* 1021 /*
1009 * If immediate we need to remove and readd the key 1022 * If immediate we need to remove and readd the key
1010 */ 1023 */
1011 if ( m_mode == Imediate ) 1024 if ( m_mode == Imediate )
1012 item->manager()->removeKeyConfig( item->item() ); 1025 item->manager()->removeKeyConfig( item->item() );
1013 1026
1014 item->item().setKeyPair( item->item().defaultKeyPair() ); 1027 item->item().setKeyPair( item->item().defaultKeyPair() );
1015 1028
1016 if ( m_mode == Imediate ) 1029 if ( m_mode == Imediate )
1017 item->manager()->addKeyConfig( item->item() ); 1030 item->manager()->addKeyConfig( item->item() );
1018} 1031}
1019 1032
1020void OKeyConfigWidget::slotCustomKey() { 1033void OKeyConfigWidget::slotCustomKey() {
1034 qWarning( "SlotCustom Key" );
1021 m_cus ->setChecked( true ); 1035 m_cus ->setChecked( true );
1022 m_btn ->setEnabled( true ); 1036 m_btn ->setEnabled( true );
1023 m_def ->setChecked( false ); 1037 m_def ->setChecked( false );
1024 m_none->setChecked( false ); 1038 m_none->setChecked( false );
1025 1039
1026 if ( !m_view->currentItem() || m_view->currentItem()->parent() ) 1040 if ( !m_view->currentItem() || m_view->currentItem()->parent() )
1027 return; 1041 return;
1028 1042
1029} 1043}
1030 1044
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h
index b3309af..a7a5f48 100644
--- a/libopie2/opieui/okeyconfigwidget.h
+++ b/libopie2/opieui/okeyconfigwidget.h
@@ -1,268 +1,270 @@
1/* 1/*
2 * Copyright (C) 2004 2 * Copyright (C) 2004
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 <qcstring.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; 20class QLabel;
21class QPushButton; 21class QPushButton;
22class QListViewItem; 22class QListViewItem;
23class QRadioButton; 23class QRadioButton;
24 24
25namespace Opie { 25namespace Opie {
26namespace Ui { 26namespace Ui {
27namespace Private { 27namespace Private {
28 class OKeyConfigWidgetPrivate; 28 class OKeyConfigWidgetPrivate;
29 typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; 29 typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList;
30} 30}
31 class OListViewItem; 31 class OListViewItem;
32 class OListView; 32 class OListView;
33 33
34/** 34/**
35 * \brief small class representing a Key with possible modifiers 35 * \brief small class representing a Key with possible modifiers
36 * This class holds information about key code and possible 36 * This class holds information about key code and possible
37 * modifier state. That is the lowest level of the key input 37 * modifier state. That is the lowest level of the key input
38 * functions. 38 * functions.
39 * There are also static methods to get special keys. 39 * There are also static methods to get special keys.
40 * OKeyPair will be used with \see OKeyConfigItem 40 * OKeyPair will be used with \see OKeyConfigItem
41 * 41 *
42 * @since 1.2 42 * @since 1.2
43 */ 43 */
44class OKeyPair { 44class OKeyPair {
45public: 45public:
46 typedef QValueList<OKeyPair> List; 46 typedef QValueList<OKeyPair> List;
47 OKeyPair( int key = -1, int modifier = -1); 47 OKeyPair( int key = -1, int modifier = -1);
48 ~OKeyPair(); 48 ~OKeyPair();
49 49
50 bool operator==( const OKeyPair& ); 50 bool operator==( const OKeyPair& );
51 bool operator!=( const OKeyPair& ); 51 bool operator!=( const OKeyPair& );
52 52
53 bool isEmpty()const; 53 bool isEmpty()const;
54 54
55 int keycode()const; 55 int keycode()const;
56 int modifier()const; 56 int modifier()const;
57 57
58 void setKeycode( int ); 58 void setKeycode( int );
59 void setModifier( int ); 59 void setModifier( int );
60 60
61 static OKeyPair returnKey(); 61 static OKeyPair returnKey();
62 static OKeyPair leftArrowKey(); 62 static OKeyPair leftArrowKey();
63 static OKeyPair rightArrowKey(); 63 static OKeyPair rightArrowKey();
64 static OKeyPair upArrowKey(); 64 static OKeyPair upArrowKey();
65 static OKeyPair downArrowKey(); 65 static OKeyPair downArrowKey();
66 static OKeyPair emptyKey(); 66 static OKeyPair emptyKey();
67 static OKeyPair::List hardwareKeys(); 67 static OKeyPair::List hardwareKeys();
68 68
69private: 69private:
70 int m_key; 70 int m_key;
71 int m_mod; 71 int m_mod;
72 class Private; 72 class Private;
73 Private* d; 73 Private* d;
74}; 74};
75 75
76/** 76/**
77 * A class to represent an OKeyPair. 77 * A class to represent an OKeyPair.
78 * 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,
79 * Pixmap, A default OKeyPair and the set OKeyPair. 79 * Pixmap, A default OKeyPair and the set OKeyPair.
80 * You can also pass an id to it 80 * You can also pass an id to it
81 * 81 *
82 * @since 1.1.2 82 * @since 1.1.2
83 */ 83 */
84class OKeyConfigItem { 84class OKeyConfigItem {
85 friend class OKeyConfigManager; 85 friend class OKeyConfigManager;
86public: 86public:
87 typedef QValueList<OKeyConfigItem> List; 87 typedef QValueList<OKeyConfigItem> List;
88 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), 88 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(),
89 const QPixmap& symbol = QPixmap(), 89 const QPixmap& symbol = QPixmap(),
90 int id = -1, 90 int id = -1,
91 const OKeyPair& def = OKeyPair::emptyKey(), 91 const OKeyPair& def = OKeyPair::emptyKey(),
92 QObject *caller = 0, const char* slot = 0); 92 QObject *caller = 0, const char* slot = 0);
93 OKeyConfigItem( const Opie::Core::ODeviceButton& ); 93 OKeyConfigItem( const Opie::Core::ODeviceButton& );
94 ~OKeyConfigItem(); 94 ~OKeyConfigItem();
95 95
96 bool operator==( const OKeyConfigItem& ); 96 bool operator==( const OKeyConfigItem& );
97 bool operator!=( const OKeyConfigItem& ); 97 bool operator!=( const OKeyConfigItem& );
98 98
99 QString text()const; 99 QString text()const;
100 QPixmap pixmap()const; 100 QPixmap pixmap()const;
101 int id()const; 101 int id()const;
102 102
103 103
104 104
105 OKeyPair keyPair()const; 105 OKeyPair keyPair()const;
106 OKeyPair defaultKeyPair()const; 106 OKeyPair defaultKeyPair()const;
107 QCString configKey()const; 107 QCString configKey()const;
108 108
109 109
110 void setText( const QString& text ); 110 void setText( const QString& text );
111 void setPixmap( const QPixmap& ); 111 void setPixmap( const QPixmap& );
112 void setKeyPair( const OKeyPair& ); 112 void setKeyPair( const OKeyPair& );
113 void setDefaultKeyPair( const OKeyPair& ); 113 void setDefaultKeyPair( const OKeyPair& );
114 114
115 bool isEmpty()const; 115 bool isEmpty()const;
116 116
117protected: 117protected:
118 QObject *object()const; 118 QObject *object()const;
119 QCString slot()const; 119 QCString slot()const;
120 void setId( int id ); 120 void setId( int id );
121 void setConfigKey( const QCString& ); 121 void setConfigKey( const QCString& );
122 122
123private: 123private:
124 QString m_text; 124 QString m_text;
125 QCString m_config; 125 QCString m_config;
126 QPixmap m_pix; 126 QPixmap m_pix;
127 int m_id; 127 int m_id;
128 OKeyPair m_key; 128 OKeyPair m_key;
129 OKeyPair m_def; 129 OKeyPair m_def;
130 QObject *m_obj; 130 QObject *m_obj;
131 QCString m_str; 131 QCString m_str;
132 class Private; 132 class Private;
133 Private *d; 133 Private *d;
134}; 134};
135 135
136 136
137 137
138/** 138/**
139 * \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
140 * This is the Manager for KeyActions. 140 * This is the Manager for KeyActions.
141 * 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
142 * keyboard to handle hardware keys, you can supply a blacklist of 142 * keyboard to handle hardware keys, you can supply a blacklist of
143 * keys which should not be used by allowed to be used. 143 * keys which should not be used by allowed to be used.
144 * 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.
145 * 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
146 * read the Key information. 146 * read the Key information.
147 * 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
148 * 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
149 * the event filter and get a signal. 149 * the event filter and get a signal.
150 * You need to load ans save yourself! 150 * You need to load ans save yourself!
151 * 151 *
152 * @since 1.1.2 152 * @since 1.1.2
153 */ 153 */
154class OKeyConfigManager : public QObject { 154class OKeyConfigManager : public QObject {
155 Q_OBJECT 155 Q_OBJECT
156 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; 156 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate;
157public: 157public:
158 OKeyConfigManager(Opie::Core::OConfig *conf = 0, 158 OKeyConfigManager(Opie::Core::OConfig *conf = 0,
159 const QString& group = QString::null, 159 const QString& group = QString::null,
160 const OKeyPair::List &block = OKeyPair::List(), 160 const OKeyPair::List &block = OKeyPair::List(),
161 bool grabkeyboard = false, QObject * par = 0, 161 bool grabkeyboard = false, QObject * par = 0,
162 const char* name = 0 ); 162 const char* name = 0 );
163 ~OKeyConfigManager(); 163 ~OKeyConfigManager();
164 164
165 void load(); 165 void load();
166 void save(); 166 void save();
167 167
168 OKeyConfigItem handleKeyEvent( QKeyEvent* ); 168 OKeyConfigItem handleKeyEvent( QKeyEvent* );
169 int handleKeyEventId( QKeyEvent* ); 169 int handleKeyEventId( QKeyEvent* );
170 170
171 void addKeyConfig( const OKeyConfigItem& ); 171 void addKeyConfig( const OKeyConfigItem& );
172 void removeKeyConfig( const OKeyConfigItem& ); 172 void removeKeyConfig( const OKeyConfigItem& );
173 void clearKeyConfig(); 173 void clearKeyConfig();
174 174
175 void addToBlackList( const OKeyPair& ); 175 void addToBlackList( const OKeyPair& );
176 void removeFromBlackList( const OKeyPair& ); 176 void removeFromBlackList( const OKeyPair& );
177 void clearBlackList(); 177 void clearBlackList();
178 OKeyPair::List blackList()const; 178 OKeyPair::List blackList()const;
179 179
180 void handleWidget( QWidget* ); 180 void handleWidget( QWidget* );
181 181
182 bool eventFilter( QObject*, QEvent* ); 182 bool eventFilter( QObject*, QEvent* );
183
184 OKeyConfigItem::List keyConfigList()const;
183signals: 185signals:
184 /** 186 /**
185 * The Signals are triggered on KeyPress and KeyRelease! 187 * The Signals are triggered on KeyPress and KeyRelease!
186 * You can check the isDown of the QKeyEvent 188 * You can check the isDown of the QKeyEvent
187 * @see QKeyEvent 189 * @see QKeyEvent
188 */ 190 */
189 void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); 191 void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& );
190 192
191 /** 193 /**
192 * This Signal correspondents to the OKeyConfigItem slot 194 * This Signal correspondents to the OKeyConfigItem slot
193 * and object 195 * and object
194 * 196 *
195 * @see OKeyConfigItem::slot 197 * @see OKeyConfigItem::slot
196 * @see OKeyConfigItem::object 198 * @see OKeyConfigItem::object
197 */ 199 */
198 void actionActivated( QWidget* par, QKeyEvent* key); 200 void actionActivated( QWidget* par, QKeyEvent* key);
199 201
200private: 202private:
201 OKeyConfigItem::List keyList( int ); 203 OKeyConfigItem::List keyList( int );
202 OKeyConfigItem::List m_keys; 204 OKeyConfigItem::List m_keys;
203 QValueList<QWidget*> m_widgets; 205 QValueList<QWidget*> m_widgets;
204 Opie::Core::OConfig *m_conf; 206 Opie::Core::OConfig *m_conf;
205 QString m_group; 207 QString m_group;
206 OKeyPair::List m_blackKeys; 208 OKeyPair::List m_blackKeys;
207 bool m_grab : 1; 209 bool m_grab : 1;
208 OKeyMapConfigPrivate *m_map; 210 OKeyMapConfigPrivate *m_map;
209 class Private; 211 class Private;
210 Private *d; 212 Private *d;
211}; 213};
212 214
213 215
214/** 216/**
215 * With this Widget you can let the Keyboard Shortcuts 217 * With this Widget you can let the Keyboard Shortcuts
216 * be configured by the user. 218 * be configured by the user.
217 * There are two ways you can use this widget. Either in a tab were 219 * 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 220 * 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 221 * were you ask for saving. Save won't write the data but only set
220 * it to the OKeyConfigManager 222 * it to the OKeyConfigManager
221 * 223 *
222 * @since 1.2 224 * @since 1.2
223 */ 225 */
224class OKeyConfigWidget : public QWidget { 226class OKeyConfigWidget : public QWidget {
225 Q_OBJECT 227 Q_OBJECT
226 228
227public: 229public:
228 /** 230 /**
229 * Immediate Apply the change directly to the underlying OKeyConfigManager 231 * Immediate Apply the change directly to the underlying OKeyConfigManager
230 * Queue Save all items and then apply when you save() 232 * Queue Save all items and then apply when you save()
231 */ 233 */
232 enum ChangeMode { Imediate, Queue }; 234 enum ChangeMode { Imediate, Queue };
233 OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 235 OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
234 ~OKeyConfigWidget(); 236 ~OKeyConfigWidget();
235 237
236 void setChangeMode( enum ChangeMode ); 238 void setChangeMode( enum ChangeMode );
237 ChangeMode changeMode()const; 239 ChangeMode changeMode()const;
238 240
239 void insert( const QString& name, OKeyConfigManager* ); 241 void insert( const QString& name, OKeyConfigManager* );
240 242
241 void load(); 243 void load();
242 void save(); 244 void save();
243 245
244private slots: 246private slots:
245 void slotListViewItem( QListViewItem* ); 247 void slotListViewItem( QListViewItem* );
246 void slotNoKey(); 248 void slotNoKey();
247 void slotDefaultKey(); 249 void slotDefaultKey();
248 void slotCustomKey(); 250 void slotCustomKey();
249 251
250 252
251private: 253private:
252 void initUi(); 254 void initUi();
253 Opie::Ui::OListView *m_view; 255 Opie::Ui::OListView *m_view;
254 Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; 256 Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list;
255 QLabel *m_lbl; 257 QLabel *m_lbl;
256 QPushButton *m_btn; 258 QPushButton *m_btn;
257 QRadioButton *m_def, *m_cus, *m_none; 259 QRadioButton *m_def, *m_cus, *m_none;
258 QWidget* m_box; 260 QWidget* m_box;
259 ChangeMode m_mode; 261 ChangeMode m_mode;
260 class Private; 262 class Private;
261 Private *d; 263 Private *d;
262}; 264};
263 265
264} 266}
265} 267}
266 268
267 269
268#endif 270#endif