-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 73 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 12 |
2 files changed, 61 insertions, 24 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index 3e08416..8967d77 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,36 +1,38 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | #include "okeyconfigwidget_p.h" | 2 | #include "okeyconfigwidget_p.h" |
3 | 3 | ||
4 | 4 | ||
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qradiobutton.h> | 6 | #include <qradiobutton.h> |
7 | #include <qpushbutton.h> | 7 | #include <qpushbutton.h> |
8 | #include <qbuttongroup.h> | 8 | #include <qbuttongroup.h> |
9 | 9 | #include <qmessagebox.h> | |
10 | #include <qaccel.h> | 10 | #include <qaccel.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | #include <qlabel.h> | 12 | #include <qlabel.h> |
13 | |||
14 | /* non gui */ | ||
13 | #include <qtimer.h> | 15 | #include <qtimer.h> |
14 | 16 | ||
15 | 17 | ||
16 | using namespace Opie::Ui; | 18 | using namespace Opie::Ui; |
17 | 19 | ||
18 | 20 | ||
19 | 21 | ||
20 | /** | 22 | /** |
21 | * The default Constructor of a OKeyPair. | 23 | * The default Constructor of a OKeyPair. |
22 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | 24 | * A Key and a Modifier ( Alt/Shift/Ctrl ) |
23 | * needs to be supplied. | 25 | * needs to be supplied. |
24 | * Use Qt::Key for the information. | 26 | * Use Qt::Key for the information. |
25 | * The default arguments create an Empty OKeyPair. If you | 27 | * The default arguments create an Empty OKeyPair. If you |
26 | * want to get an empty OKeyPair use the static method for getting | 28 | * want to get an empty OKeyPair use the static method for getting |
27 | * the emptyKey() | 29 | * the emptyKey() |
28 | * | 30 | * |
29 | * @see OKeyPair OKeyPair::emptyKey() | 31 | * @see OKeyPair OKeyPair::emptyKey() |
30 | */ | 32 | */ |
31 | OKeyPair::OKeyPair( int key, int mod ) | 33 | OKeyPair::OKeyPair( int key, int mod ) |
32 | : m_key( key ), m_mod( mod ) | 34 | : m_key( key ), m_mod( mod ) |
33 | {} | 35 | {} |
34 | 36 | ||
35 | /** | 37 | /** |
36 | * The destructor | 38 | * The destructor |
@@ -138,59 +140,59 @@ OKeyPair OKeyPair::emptyKey() { | |||
138 | /** | 140 | /** |
139 | * This functions uses the Opie::Core::ODevice::buttons | 141 | * This functions uses the Opie::Core::ODevice::buttons |
140 | * for OKeyPairList | 142 | * for OKeyPairList |
141 | * | 143 | * |
142 | * @see Opie::Core::ODevice | 144 | * @see Opie::Core::ODevice |
143 | * @see Opie::Core::ODeviceButton | 145 | * @see Opie::Core::ODeviceButton |
144 | * @see Opie::Core::ODevice::button | 146 | * @see Opie::Core::ODevice::button |
145 | */ | 147 | */ |
146 | OKeyPair::List OKeyPair::hardwareKeys() { | 148 | OKeyPair::List OKeyPair::hardwareKeys() { |
147 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | 149 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); |
148 | OKeyPair::List lst; | 150 | OKeyPair::List lst; |
149 | 151 | ||
150 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | 152 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); |
151 | it != but.end(); ++it ) | 153 | it != but.end(); ++it ) |
152 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | 154 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); |
153 | 155 | ||
154 | 156 | ||
155 | return lst; | 157 | return lst; |
156 | } | 158 | } |
157 | 159 | ||
158 | /** | 160 | /** |
159 | * Equals operator. Check if two OKeyPairs have the same key and modifier | 161 | * Equals operator. Check if two OKeyPairs have the same key and modifier |
160 | * @see operator!= | 162 | * @see operator!= |
161 | */ | 163 | */ |
162 | bool OKeyPair::operator==( const OKeyPair& pair) { | 164 | bool OKeyPair::operator==( const OKeyPair& pair)const { |
163 | if ( m_key != pair.m_key ) return false; | 165 | if ( m_key != pair.m_key ) return false; |
164 | if ( m_mod != pair.m_mod ) return false; | 166 | if ( m_mod != pair.m_mod ) return false; |
165 | 167 | ||
166 | return true; | 168 | return true; |
167 | } | 169 | } |
168 | 170 | ||
169 | /** | 171 | /** |
170 | * Not equal operator. calls the equal operator internally | 172 | * Not equal operator. calls the equal operator internally |
171 | */ | 173 | */ |
172 | bool OKeyPair::operator!=( const OKeyPair& pair) { | 174 | bool OKeyPair::operator!=( const OKeyPair& pair)const { |
173 | return !(*this == pair); | 175 | return !(*this == pair); |
174 | } | 176 | } |
175 | 177 | ||
176 | 178 | ||
177 | /** | 179 | /** |
178 | * The normal Constructor to create a OKeyConfigItem | 180 | * The normal Constructor to create a OKeyConfigItem |
179 | * | 181 | * |
180 | * You can set the the key paramater of this item but if | 182 | * You can set the the key paramater of this item but if |
181 | * you use this item with the OKeyConfigManager your setting | 183 | * you use this item with the OKeyConfigManager your setting |
182 | * will be overwritten. | 184 | * will be overwritten. |
183 | * You can also specify a QObject and slot which sould get called | 185 | * You can also specify a QObject and slot which sould get called |
184 | * once this item is activated. This slot only works if you | 186 | * once this item is activated. This slot only works if you |
185 | * use the OKeyConfigManager. | 187 | * use the OKeyConfigManager. |
186 | * The actual Key is read by load() | 188 | * The actual Key is read by load() |
187 | * | 189 | * |
188 | * \code | 190 | * \code |
189 | * void MySlot::create(){ | 191 | * void MySlot::create(){ |
190 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | 192 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), |
191 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | 193 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), |
192 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | 194 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); |
193 | * } | 195 | * } |
194 | * \endcode | 196 | * \endcode |
195 | * | 197 | * |
196 | * @param text The text exposed to the user | 198 | * @param text The text exposed to the user |
@@ -350,67 +352,67 @@ void OKeyConfigItem::setConfigKey( const QCString& str) { | |||
350 | /** | 352 | /** |
351 | * @internal | 353 | * @internal |
352 | */ | 354 | */ |
353 | void OKeyConfigItem::setId( int id ) { | 355 | void OKeyConfigItem::setId( int id ) { |
354 | m_id = id; | 356 | m_id = id; |
355 | } | 357 | } |
356 | 358 | ||
357 | /** | 359 | /** |
358 | * If the item is not configured isEmpty() will return true | 360 | * If the item is not configured isEmpty() will return true |
359 | * It is empty if no text is present and no default | 361 | * It is empty if no text is present and no default |
360 | * and no configured key | 362 | * and no configured key |
361 | */ | 363 | */ |
362 | bool OKeyConfigItem::isEmpty()const { | 364 | bool OKeyConfigItem::isEmpty()const { |
363 | if ( !m_def.isEmpty() ) return false; | 365 | if ( !m_def.isEmpty() ) return false; |
364 | if ( !m_key.isEmpty() ) return false; | 366 | if ( !m_key.isEmpty() ) return false; |
365 | if ( !m_text.isEmpty() ) return false; | 367 | if ( !m_text.isEmpty() ) return false; |
366 | if ( m_id != -1 ) return false; | 368 | if ( m_id != -1 ) return false; |
367 | 369 | ||
368 | return true; | 370 | return true; |
369 | } | 371 | } |
370 | 372 | ||
371 | /** | 373 | /** |
372 | * Check if the KeyPairs are the same | 374 | * Check if the KeyPairs are the same |
373 | */ | 375 | */ |
374 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) { | 376 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { |
375 | /* if ( isEmpty() == conf.isEmpty() ) return true; | 377 | /* if ( isEmpty() == conf.isEmpty() ) return true; |
376 | else if ( isEmpty() != conf.isEmpty() ) return false; | 378 | else if ( isEmpty() != conf.isEmpty() ) return false; |
377 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | 379 | else if ( !isEmpty()!= conf.isEmpty() ) return false; |
378 | */ | 380 | */ |
379 | 381 | ||
380 | if ( m_id != conf.m_id ) return false; | 382 | if ( m_id != conf.m_id ) return false; |
381 | if ( m_obj != conf.m_obj ) return false; | 383 | if ( m_obj != conf.m_obj ) return false; |
382 | if ( m_text != conf.m_text ) return false; | 384 | if ( m_text != conf.m_text ) return false; |
383 | if ( m_key != conf.m_key ) return false; | 385 | if ( m_key != conf.m_key ) return false; |
384 | if ( m_def != conf.m_def ) return false; | 386 | if ( m_def != conf.m_def ) return false; |
385 | 387 | ||
386 | 388 | ||
387 | 389 | ||
388 | return true; | 390 | return true; |
389 | 391 | ||
390 | } | 392 | } |
391 | 393 | ||
392 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) { | 394 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { |
393 | return !( *this == conf ); | 395 | return !( *this == conf ); |
394 | } | 396 | } |
395 | 397 | ||
396 | /** | 398 | /** |
397 | * \brief c'tor | 399 | * \brief c'tor |
398 | * The Constructor for a OKeyConfigManager | 400 | * The Constructor for a OKeyConfigManager |
399 | * | 401 | * |
400 | * You can use this manager in multiple ways. Either make it handle | 402 | * You can use this manager in multiple ways. Either make it handle |
401 | * QKeyEvents | 403 | * QKeyEvents |
402 | * | 404 | * |
403 | * \code | 405 | * \code |
404 | * Opie::Core::Config conf = oApp->config(); | 406 | * Opie::Core::Config conf = oApp->config(); |
405 | * Opie::Ui::OKeyPairList blackList; | 407 | * Opie::Ui::OKeyPairList blackList; |
406 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | 408 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); |
407 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | 409 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); |
408 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | 410 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, |
409 | * false); | 411 | * false); |
410 | * QListView *view = new QListView(); | 412 | * QListView *view = new QListView(); |
411 | * manager->handleWidget(view); | 413 | * manager->handleWidget(view); |
412 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | 414 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); |
413 | * manager->load(); | 415 | * manager->load(); |
414 | * | 416 | * |
415 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | 417 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), |
416 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | 418 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); |
@@ -462,80 +464,80 @@ OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | |||
462 | 464 | ||
463 | /** | 465 | /** |
464 | * Destructor | 466 | * Destructor |
465 | */ | 467 | */ |
466 | OKeyConfigManager::~OKeyConfigManager() { | 468 | OKeyConfigManager::~OKeyConfigManager() { |
467 | if ( m_grab ) | 469 | if ( m_grab ) |
468 | QPEApplication::ungrabKeyboard(); | 470 | QPEApplication::ungrabKeyboard(); |
469 | } | 471 | } |
470 | 472 | ||
471 | /** | 473 | /** |
472 | * Load the Configuration from the OConfig | 474 | * Load the Configuration from the OConfig |
473 | * If a Key is restricted but was in the config we will | 475 | * If a Key is restricted but was in the config we will |
474 | * make it be the empty key paur | 476 | * make it be the empty key paur |
475 | * We will change the group of the OConfig Item! | 477 | * We will change the group of the OConfig Item! |
476 | * | 478 | * |
477 | * @see OKeyPair::emptyKey | 479 | * @see OKeyPair::emptyKey |
478 | */ | 480 | */ |
479 | void OKeyConfigManager::load() { | 481 | void OKeyConfigManager::load() { |
480 | m_conf->setGroup( m_group ); | 482 | m_conf->setGroup( m_group ); |
481 | 483 | ||
482 | /* | 484 | /* |
483 | * Read each item | 485 | * Read each item |
484 | */ | 486 | */ |
485 | int key, mod; | 487 | int key, mod; |
486 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 488 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { |
487 | it != m_keys.end(); ++it ) { | ||
488 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 489 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); |
489 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 490 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); |
490 | OKeyPair okey( key, mod ); | 491 | OKeyPair okey( key, mod ); |
492 | |||
491 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | 493 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) |
492 | (*it).setKeyPair( OKeyPair(key, mod) ); | 494 | (*it).setKeyPair( OKeyPair(key, mod) ); |
493 | else | 495 | else |
494 | (*it).setKeyPair( OKeyPair::emptyKey() ); | 496 | (*it).setKeyPair( OKeyPair::emptyKey() ); |
495 | } | 497 | } |
496 | delete m_map; m_map = 0; | 498 | delete m_map; m_map = 0; |
497 | } | 499 | } |
498 | 500 | ||
499 | /** | 501 | /** |
500 | * We will save the current configuration | 502 | * We will save the current configuration |
501 | * to the OConfig. We will change the group. | 503 | * to the OConfig. We will change the group. |
502 | */ | 504 | */ |
503 | void OKeyConfigManager::save() { | 505 | void OKeyConfigManager::save() { |
504 | m_conf->setGroup( m_group ); | 506 | m_conf->setGroup( m_group ); |
505 | 507 | ||
506 | /* | 508 | /* |
507 | * Write each item | 509 | * Write each item |
508 | */ | 510 | */ |
509 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); | 511 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { |
510 | it != m_keys.end(); ++it ) { | 512 | /* skip empty items */ |
511 | if ( (*it).isEmpty() ) | 513 | if ( (*it).isEmpty() ) |
512 | continue; | 514 | continue; |
513 | OKeyPair pair = (*it).keyPair(); | 515 | OKeyPair pair = (*it).keyPair(); |
514 | OKeyPair deft = (*it).defaultKeyPair(); | 516 | OKeyPair deft = (*it).defaultKeyPair(); |
515 | /* | 517 | /* |
516 | * don't write if it is the default setting | 518 | * don't write if it is the default setting |
517 | * FIXME allow to remove Keys | 519 | * FIXME allow to remove Keys from config |
518 | if ( (pair.keycode() == deft.keycode()) && | 520 | if ( (pair.keycode() == deft.keycode()) && |
519 | (pair.modifier()== deft.modifier() ) ) | 521 | (pair.modifier()== deft.modifier() ) ) |
520 | return; | 522 | return; |
521 | */ | 523 | */ |
522 | 524 | ||
523 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | 525 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); |
524 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | 526 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); |
525 | } | 527 | } |
526 | } | 528 | } |
527 | 529 | ||
528 | /** | 530 | /** |
529 | * This is function uses a QMap internally but you can have the same keycode | 531 | * This is function uses a QMap internally but you can have the same keycode |
530 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | 532 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem |
531 | * with same keycode and modifier key. The GUI takes care that a user can't | 533 | * with same keycode and modifier key. The GUI takes care that a user can't |
532 | * cofigure two keys. | 534 | * cofigure two keys. |
533 | * | 535 | * |
534 | * Make sure you call e->ignore if you don't want to handle this event | 536 | * Make sure you call e->ignore if you don't want to handle this event |
535 | */ | 537 | */ |
536 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | 538 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { |
537 | /* | 539 | /* |
538 | * Fix Up issues with Qt/E, my keybard, and virtual input | 540 | * Fix Up issues with Qt/E, my keybard, and virtual input |
539 | * methods | 541 | * methods |
540 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | 542 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state |
541 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | 543 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower |
@@ -555,59 +557,57 @@ OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | |||
555 | item = *it; | 557 | item = *it; |
556 | break; | 558 | break; |
557 | } | 559 | } |
558 | 560 | ||
559 | } | 561 | } |
560 | 562 | ||
561 | return item; | 563 | return item; |
562 | } | 564 | } |
563 | 565 | ||
564 | /** | 566 | /** |
565 | * Return the associated id of the item or -1 if no item | 567 | * Return the associated id of the item or -1 if no item |
566 | * matched the key | 568 | * matched the key |
567 | * | 569 | * |
568 | * @see handleKeyEvent | 570 | * @see handleKeyEvent |
569 | */ | 571 | */ |
570 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | 572 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { |
571 | return handleKeyEvent( ev ).id(); | 573 | return handleKeyEvent( ev ).id(); |
572 | } | 574 | } |
573 | 575 | ||
574 | /** | 576 | /** |
575 | * Add Key Config to the List of items | 577 | * Add Key Config to the List of items |
576 | */ | 578 | */ |
577 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | 579 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { |
578 | m_keys.append( item ); | 580 | m_keys.append( item ); |
579 | qWarning( "m_keys count is now %d", m_keys.count() ); | ||
580 | delete m_map; m_map = 0; | 581 | delete m_map; m_map = 0; |
581 | } | 582 | } |
582 | 583 | ||
583 | /** | 584 | /** |
584 | * Remove the Key from the Config. Internal lists will be destroyed | 585 | * Remove the Key from the Config. Internal lists will be destroyed |
585 | * and rebuild on demand later | 586 | * and rebuild on demand later |
586 | */ | 587 | */ |
587 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | 588 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { |
588 | m_keys.remove( item ); | 589 | m_keys.remove( item ); |
589 | qWarning( "m_keys count is now %d", m_keys.count() ); | ||
590 | delete m_map; m_map = 0; | 590 | delete m_map; m_map = 0; |
591 | } | 591 | } |
592 | 592 | ||
593 | /** | 593 | /** |
594 | * Clears the complete list | 594 | * Clears the complete list |
595 | */ | 595 | */ |
596 | void OKeyConfigManager::clearKeyConfig() { | 596 | void OKeyConfigManager::clearKeyConfig() { |
597 | m_keys.clear(); | 597 | m_keys.clear(); |
598 | delete m_map; m_map = 0; | 598 | delete m_map; m_map = 0; |
599 | } | 599 | } |
600 | 600 | ||
601 | /** | 601 | /** |
602 | * | 602 | * |
603 | */ | 603 | */ |
604 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | 604 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ |
605 | return m_keys; | 605 | return m_keys; |
606 | } | 606 | } |
607 | 607 | ||
608 | /** | 608 | /** |
609 | * Add this OKeyPair to the blackList. | 609 | * Add this OKeyPair to the blackList. |
610 | * Internal lists will be destroyed | 610 | * Internal lists will be destroyed |
611 | */ | 611 | */ |
612 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | 612 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { |
613 | m_blackKeys.append( key ); | 613 | m_blackKeys.append( key ); |
@@ -739,48 +739,51 @@ namespace Private { | |||
739 | setText ( 1, m_item.text() ); | 739 | setText ( 1, m_item.text() ); |
740 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 740 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
741 | setText( 2, keyToString( m_item.keyPair() ) ); | 741 | setText( 2, keyToString( m_item.keyPair() ) ); |
742 | 742 | ||
743 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : | 743 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : |
744 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | 744 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); |
745 | } | 745 | } |
746 | void OKeyListViewItem::updateText() { | 746 | void OKeyListViewItem::updateText() { |
747 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 747 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
748 | setText( 2, keyToString( m_item.keyPair() ) ); | 748 | setText( 2, keyToString( m_item.keyPair() ) ); |
749 | } | 749 | } |
750 | 750 | ||
751 | QString keyToString( const OKeyPair& pair ) { | 751 | QString keyToString( const OKeyPair& pair ) { |
752 | int mod = 0; | 752 | int mod = 0; |
753 | if ( pair.modifier() & Qt::ShiftButton ) | 753 | if ( pair.modifier() & Qt::ShiftButton ) |
754 | mod |= Qt::SHIFT; | 754 | mod |= Qt::SHIFT; |
755 | if ( pair.modifier() & Qt::ControlButton ) | 755 | if ( pair.modifier() & Qt::ControlButton ) |
756 | mod |= Qt::CTRL; | 756 | mod |= Qt::CTRL; |
757 | if ( pair.modifier() & Qt::AltButton ) | 757 | if ( pair.modifier() & Qt::AltButton ) |
758 | mod |= Qt::ALT; | 758 | mod |= Qt::ALT; |
759 | 759 | ||
760 | return QAccel::keyToString( mod + pair.keycode() ); | 760 | return QAccel::keyToString( mod + pair.keycode() ); |
761 | } | 761 | } |
762 | 762 | ||
763 | /* | ||
764 | * the virtual and hardware key events have both issues... | ||
765 | */ | ||
763 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | 766 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { |
764 | key = e->key(); | 767 | key = e->key(); |
765 | mod = e->state(); | 768 | mod = e->state(); |
766 | /* | 769 | /* |
767 | * virtual keyboard | 770 | * virtual keyboard |
768 | * else change the button mod only | 771 | * else change the button mod only |
769 | */ | 772 | */ |
770 | if ( key == 0 ) { | 773 | if ( key == 0 ) { |
771 | key = e->ascii(); | 774 | key = e->ascii(); |
772 | if ( key > 96 && key < 123) | 775 | if ( key > 96 && key < 123) |
773 | key -= 32; | 776 | key -= 32; |
774 | }else{ | 777 | }else{ |
775 | int new_mod = 0; | 778 | int new_mod = 0; |
776 | if ( mod & 256 ) | 779 | if ( mod & 256 ) |
777 | new_mod |= Qt::ShiftButton; | 780 | new_mod |= Qt::ShiftButton; |
778 | else if ( mod & 512 ) | 781 | else if ( mod & 512 ) |
779 | new_mod |= Qt::ControlButton; | 782 | new_mod |= Qt::ControlButton; |
780 | else if ( mod & 1024 ) | 783 | else if ( mod & 1024 ) |
781 | new_mod |= Qt::AltButton; | 784 | new_mod |= Qt::AltButton; |
782 | 785 | ||
783 | mod = new_mod == 0? mod : new_mod; | 786 | mod = new_mod == 0? mod : new_mod; |
784 | } | 787 | } |
785 | } | 788 | } |
786 | 789 | ||
@@ -987,49 +990,48 @@ void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | |||
987 | m_none->setChecked( true ); | 990 | m_none->setChecked( true ); |
988 | m_btn ->setEnabled( false ); | 991 | m_btn ->setEnabled( false ); |
989 | m_def ->setChecked( false ); | 992 | m_def ->setChecked( false ); |
990 | m_cus ->setChecked( false ); | 993 | m_cus ->setChecked( false ); |
991 | }else{ | 994 | }else{ |
992 | m_box->setEnabled( true ); | 995 | m_box->setEnabled( true ); |
993 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); | 996 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>( _item ); |
994 | OKeyConfigItem keyItem= item->item(); | 997 | OKeyConfigItem keyItem= item->item(); |
995 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); | 998 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); |
996 | if ( keyItem.keyPair().isEmpty() ) { | 999 | if ( keyItem.keyPair().isEmpty() ) { |
997 | m_none->setChecked( true ); | 1000 | m_none->setChecked( true ); |
998 | m_btn ->setEnabled( false ); | 1001 | m_btn ->setEnabled( false ); |
999 | m_def ->setChecked( false ); | 1002 | m_def ->setChecked( false ); |
1000 | m_cus ->setChecked( false ); | 1003 | m_cus ->setChecked( false ); |
1001 | }else { | 1004 | }else { |
1002 | m_none->setChecked( false ); | 1005 | m_none->setChecked( false ); |
1003 | m_cus ->setChecked( true ); | 1006 | m_cus ->setChecked( true ); |
1004 | m_btn ->setEnabled( true ); | 1007 | m_btn ->setEnabled( true ); |
1005 | m_def ->setChecked( false ); | 1008 | m_def ->setChecked( false ); |
1006 | } | 1009 | } |
1007 | } | 1010 | } |
1008 | } | 1011 | } |
1009 | 1012 | ||
1010 | void OKeyConfigWidget::slotNoKey() { | 1013 | void OKeyConfigWidget::slotNoKey() { |
1011 | qWarning( "No Key" ); | ||
1012 | m_none->setChecked( true ); | 1014 | m_none->setChecked( true ); |
1013 | m_cus ->setChecked( false ); | 1015 | m_cus ->setChecked( false ); |
1014 | m_btn ->setEnabled( false ); | 1016 | m_btn ->setEnabled( false ); |
1015 | m_def ->setChecked( false ); | 1017 | m_def ->setChecked( false ); |
1016 | 1018 | ||
1017 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1019 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1018 | return; | 1020 | return; |
1019 | 1021 | ||
1020 | 1022 | ||
1021 | 1023 | ||
1022 | /* | 1024 | /* |
1023 | * If immediate we need to remove and readd the key | 1025 | * If immediate we need to remove and readd the key |
1024 | */ | 1026 | */ |
1025 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1027 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); |
1026 | updateItem( item, OKeyPair::emptyKey() ); | 1028 | updateItem( item, OKeyPair::emptyKey() ); |
1027 | } | 1029 | } |
1028 | 1030 | ||
1029 | void OKeyConfigWidget::slotDefaultKey() { | 1031 | void OKeyConfigWidget::slotDefaultKey() { |
1030 | m_none->setChecked( false ); | 1032 | m_none->setChecked( false ); |
1031 | m_cus ->setChecked( false ); | 1033 | m_cus ->setChecked( false ); |
1032 | m_btn ->setEnabled( false ); | 1034 | m_btn ->setEnabled( false ); |
1033 | m_def ->setChecked( true ); | 1035 | m_def ->setChecked( true ); |
1034 | 1036 | ||
1035 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1037 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
@@ -1047,57 +1049,91 @@ void OKeyConfigWidget::slotCustomKey() { | |||
1047 | 1049 | ||
1048 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1050 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1049 | return; | 1051 | return; |
1050 | 1052 | ||
1051 | 1053 | ||
1052 | } | 1054 | } |
1053 | 1055 | ||
1054 | void OKeyConfigWidget::slotConfigure() { | 1056 | void OKeyConfigWidget::slotConfigure() { |
1055 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 1057 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1056 | return; | 1058 | return; |
1057 | 1059 | ||
1058 | /* FIXME make use of OModalHelper */ | 1060 | /* FIXME make use of OModalHelper */ |
1059 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); | 1061 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); |
1060 | dlg.setCaption(tr("Configure Key")); | 1062 | dlg.setCaption(tr("Configure Key")); |
1061 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); | 1063 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); |
1062 | 1064 | ||
1063 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { | 1065 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { |
1064 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); | 1066 | Opie::Ui::Private::OKeyListViewItem *item = static_cast<Opie::Ui::Private::OKeyListViewItem*>(m_view->currentItem()); |
1065 | updateItem( item, dlg.keyPair() ); | 1067 | updateItem( item, dlg.keyPair() ); |
1066 | } | 1068 | } |
1067 | 1069 | ||
1068 | 1070 | ||
1069 | } | 1071 | } |
1070 | 1072 | ||
1073 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Private::OKeyListViewItem* item, | ||
1074 | const OKeyPair& newItem ) { | ||
1075 | OKeyPair::List bList = item->manager()->blackList(); | ||
1076 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { | ||
1077 | /* black list matched */ | ||
1078 | if ( *it == newItem ) { | ||
1079 | QMessageBox::warning( 0, tr("Key is on BlackList" ), | ||
1080 | tr("<qt>The Key you choose is on the black list " | ||
1081 | "and may not be used with this manager. Please " | ||
1082 | "use a different key.</qt>" ) ); | ||
1083 | return false; | ||
1084 | } | ||
1085 | } | ||
1086 | /* no we need to check the other items which is dog slow */ | ||
1087 | QListViewItemIterator it( item->parent() ); | ||
1088 | while ( it.current() ) { | ||
1089 | /* if not our parent and not us */ | ||
1090 | if (it.current()->parent() && it.current() != item) { | ||
1091 | /* damn already given away*/ | ||
1092 | if ( newItem == static_cast<Opie::Ui::Private::OKeyListViewItem*>(it.current() )->item().keyPair() ) { | ||
1093 | QMessageBox::warning( 0, tr("Key is already assigned" ), | ||
1094 | tr("<qt>The Key you choose is already taken by " | ||
1095 | "a different Item of your config. Please try" | ||
1096 | "using a different key.</qt>" ) ); | ||
1097 | return false; | ||
1098 | } | ||
1099 | } | ||
1100 | ++it; | ||
1101 | } | ||
1102 | |||
1103 | return true; | ||
1104 | } | ||
1105 | |||
1071 | void OKeyConfigWidget::updateItem( Opie::Ui::Private::OKeyListViewItem *item, | 1106 | void OKeyConfigWidget::updateItem( Opie::Ui::Private::OKeyListViewItem *item, |
1072 | const OKeyPair& newItem) { | 1107 | const OKeyPair& newItem) { |
1073 | /* sanity check | 1108 | /* sanity check |
1074 | * check against the blacklist of the manager | 1109 | * check against the blacklist of the manager |
1075 | * check if another item uses this key which is o(n) at least | 1110 | * check if another item uses this key which is o(n) at least |
1076 | */ | 1111 | */ |
1077 | if ( !newItem.isEmpty() ) { | 1112 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) |
1113 | return; | ||
1114 | |||
1078 | 1115 | ||
1079 | } | ||
1080 | 1116 | ||
1081 | /* | 1117 | /* |
1082 | * If immediate we need to remove and readd the key | 1118 | * If immediate we need to remove and readd the key |
1083 | */ | 1119 | */ |
1084 | if ( m_mode == Imediate ) | 1120 | if ( m_mode == Imediate ) |
1085 | item->manager()->removeKeyConfig( item->item() ); | 1121 | item->manager()->removeKeyConfig( item->item() ); |
1086 | 1122 | ||
1087 | item->item().setKeyPair( newItem ); | 1123 | item->item().setKeyPair( newItem ); |
1088 | item->updateText(); | 1124 | item->updateText(); |
1089 | 1125 | ||
1090 | if ( m_mode == Imediate ) | 1126 | if ( m_mode == Imediate ) |
1091 | item->manager()->addKeyConfig( item->item() ); | 1127 | item->manager()->addKeyConfig( item->item() ); |
1092 | } | 1128 | } |
1093 | 1129 | ||
1094 | 1130 | ||
1095 | 1131 | ||
1096 | ///// | 1132 | ///// |
1097 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | 1133 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, |
1098 | bool mod, WFlags fl ) | 1134 | bool mod, WFlags fl ) |
1099 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , | 1135 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , |
1100 | m_key( 0 ), m_mod( 0 ) { | 1136 | m_key( 0 ), m_mod( 0 ) { |
1101 | setFocusPolicy( StrongFocus ); | 1137 | setFocusPolicy( StrongFocus ); |
1102 | 1138 | ||
1103 | QHBoxLayout *lay = new QHBoxLayout( this ); | 1139 | QHBoxLayout *lay = new QHBoxLayout( this ); |
@@ -1107,80 +1143,79 @@ OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | |||
1107 | lbl->setFocusPolicy( NoFocus ); | 1143 | lbl->setFocusPolicy( NoFocus ); |
1108 | 1144 | ||
1109 | m_lbl = new QLabel( this ); | 1145 | m_lbl = new QLabel( this ); |
1110 | lay->addWidget( m_lbl ); | 1146 | lay->addWidget( m_lbl ); |
1111 | m_lbl->setFocusPolicy( NoFocus ); | 1147 | m_lbl->setFocusPolicy( NoFocus ); |
1112 | 1148 | ||
1113 | m_timer = new QTimer( this ); | 1149 | m_timer = new QTimer( this ); |
1114 | connect(m_timer, SIGNAL(timeout()), | 1150 | connect(m_timer, SIGNAL(timeout()), |
1115 | this, SLOT(slotTimeUp()) ); | 1151 | this, SLOT(slotTimeUp()) ); |
1116 | } | 1152 | } |
1117 | 1153 | ||
1118 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 1154 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1119 | } | 1155 | } |
1120 | 1156 | ||
1121 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 1157 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1122 | return m_keyPair; | 1158 | return m_keyPair; |
1123 | } | 1159 | } |
1124 | 1160 | ||
1125 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | 1161 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { |
1126 | QDialog::keyPressEvent( ev ); | 1162 | QDialog::keyPressEvent( ev ); |
1127 | 1163 | ||
1128 | if ( ev->isAutoRepeat() ) | 1164 | if ( ev->isAutoRepeat() ) |
1129 | return; | 1165 | return; |
1130 | 1166 | ||
1131 | qWarning( "Key Press Event" ); | ||
1132 | int mod, key; | 1167 | int mod, key; |
1133 | Opie::Ui::Private::fixupKeys( key,mod, ev ); | 1168 | Opie::Ui::Private::fixupKeys( key,mod, ev ); |
1134 | 1169 | ||
1135 | /* either we used software keyboard | 1170 | /* either we used software keyboard |
1136 | * or we've true support | 1171 | * or we've true support |
1137 | */ | 1172 | */ |
1138 | if ( !m_virtKey && !ev->key()) { | 1173 | if ( !m_virtKey && !ev->key()) { |
1139 | m_virtKey = true; | 1174 | m_virtKey = true; |
1140 | m_keyPair = OKeyPair( key, mod ); | 1175 | m_keyPair = OKeyPair( key, mod ); |
1141 | }else{ | 1176 | }else{ |
1142 | mod = 0; | 1177 | mod = 0; |
1143 | switch( key ) { | 1178 | switch( key ) { |
1144 | case Qt::Key_Control: | 1179 | case Qt::Key_Control: |
1145 | mod = Qt::ControlButton; | 1180 | mod = Qt::ControlButton; |
1146 | break; | 1181 | break; |
1147 | case Qt::Key_Shift: | 1182 | case Qt::Key_Shift: |
1148 | mod = Qt::ShiftButton; | 1183 | mod = Qt::ShiftButton; |
1149 | break; | 1184 | break; |
1150 | case Qt::Key_Alt: | 1185 | case Qt::Key_Alt: |
1151 | mod = Qt::AltButton; | 1186 | mod = Qt::AltButton; |
1152 | break; | 1187 | break; |
1153 | default: | 1188 | default: |
1154 | break; | 1189 | break; |
1155 | } | 1190 | } |
1156 | if (mod ) { | 1191 | if (mod ) |
1157 | m_mod |= mod; | 1192 | m_mod |= mod; |
1158 | }else | 1193 | else |
1159 | m_key = key; | 1194 | m_key = key; |
1160 | 1195 | ||
1161 | if ( ( !mod || m_key ) && !m_timer->isActive() ) | 1196 | if ( ( !mod || m_key ) && !m_timer->isActive() ) |
1162 | m_timer->start( 50, true ); | 1197 | m_timer->start( 150, true ); |
1163 | 1198 | ||
1164 | m_keyPair = OKeyPair( m_key, m_mod ); | 1199 | m_keyPair = OKeyPair( m_key, m_mod ); |
1165 | } | 1200 | } |
1166 | 1201 | ||
1167 | m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) ); | 1202 | m_lbl->setText( Opie::Ui::Private::keyToString( m_keyPair ) ); |
1168 | 1203 | ||
1169 | } | 1204 | } |
1170 | 1205 | ||
1171 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | 1206 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { |
1172 | m_timer->stop(); | 1207 | m_timer->stop(); |
1173 | QDialog::keyPressEvent( ev ); | 1208 | QDialog::keyPressEvent( ev ); |
1174 | 1209 | ||
1175 | if ( ev->isAutoRepeat() ) | 1210 | if ( ev->isAutoRepeat() ) |
1176 | return; | 1211 | return; |
1177 | 1212 | ||
1178 | 1213 | ||
1179 | if ( m_virtKey && !ev->key()) { | 1214 | if ( m_virtKey && !ev->key()) { |
1180 | m_virtKey = false; | 1215 | m_virtKey = false; |
1181 | slotTimeUp(); | 1216 | slotTimeUp(); |
1182 | }else { | 1217 | }else { |
1183 | int mod = 0; | 1218 | int mod = 0; |
1184 | int key = ev->key(); | 1219 | int key = ev->key(); |
1185 | switch( key ) { | 1220 | switch( key ) { |
1186 | case Qt::Key_Control: | 1221 | case Qt::Key_Control: |
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index 9e26719..f75ed99 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -28,96 +28,96 @@ namespace Ui { | |||
28 | namespace Private { | 28 | namespace Private { |
29 | class OKeyConfigWidgetPrivate; | 29 | class OKeyConfigWidgetPrivate; |
30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | 30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; |
31 | class OKeyListViewItem; | 31 | class OKeyListViewItem; |
32 | } | 32 | } |
33 | class OListViewItem; | 33 | class OListViewItem; |
34 | class OListView; | 34 | class OListView; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * \brief small class representing a Key with possible modifiers | 37 | * \brief small class representing a Key with possible modifiers |
38 | * This class holds information about key code and possible | 38 | * This class holds information about key code and possible |
39 | * modifier state. That is the lowest level of the key input | 39 | * modifier state. That is the lowest level of the key input |
40 | * functions. | 40 | * functions. |
41 | * There are also static methods to get special keys. | 41 | * There are also static methods to get special keys. |
42 | * OKeyPair will be used with \see OKeyConfigItem | 42 | * OKeyPair will be used with \see OKeyConfigItem |
43 | * | 43 | * |
44 | * @since 1.2 | 44 | * @since 1.2 |
45 | */ | 45 | */ |
46 | class OKeyPair { | 46 | class OKeyPair { |
47 | public: | 47 | public: |
48 | typedef QValueList<OKeyPair> List; | 48 | typedef QValueList<OKeyPair> List; |
49 | OKeyPair( int key = -1, int modifier = -1); | 49 | OKeyPair( int key = -1, int modifier = -1); |
50 | ~OKeyPair(); | 50 | ~OKeyPair(); |
51 | 51 | ||
52 | bool operator==( const OKeyPair& ); | 52 | bool operator==( const OKeyPair& )const; |
53 | bool operator!=( const OKeyPair& ); | 53 | bool operator!=( const OKeyPair& )const; |
54 | 54 | ||
55 | bool isEmpty()const; | 55 | bool isEmpty()const; |
56 | 56 | ||
57 | int keycode()const; | 57 | int keycode()const; |
58 | int modifier()const; | 58 | int modifier()const; |
59 | 59 | ||
60 | void setKeycode( int ); | 60 | void setKeycode( int ); |
61 | void setModifier( int ); | 61 | void setModifier( int ); |
62 | 62 | ||
63 | static OKeyPair returnKey(); | 63 | static OKeyPair returnKey(); |
64 | static OKeyPair leftArrowKey(); | 64 | static OKeyPair leftArrowKey(); |
65 | static OKeyPair rightArrowKey(); | 65 | static OKeyPair rightArrowKey(); |
66 | static OKeyPair upArrowKey(); | 66 | static OKeyPair upArrowKey(); |
67 | static OKeyPair downArrowKey(); | 67 | static OKeyPair downArrowKey(); |
68 | static OKeyPair emptyKey(); | 68 | static OKeyPair emptyKey(); |
69 | static OKeyPair::List hardwareKeys(); | 69 | static OKeyPair::List hardwareKeys(); |
70 | 70 | ||
71 | private: | 71 | private: |
72 | int m_key; | 72 | int m_key; |
73 | int m_mod; | 73 | int m_mod; |
74 | class Private; | 74 | class Private; |
75 | Private* d; | 75 | Private* d; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * A class to represent an OKeyPair. | 79 | * A class to represent an OKeyPair. |
80 | * It consists out of a Text exposed to the user, Config Key Item, | 80 | * It consists out of a Text exposed to the user, Config Key Item, |
81 | * Pixmap, A default OKeyPair and the set OKeyPair. | 81 | * Pixmap, A default OKeyPair and the set OKeyPair. |
82 | * You can also pass an id to it | 82 | * You can also pass an id to it |
83 | * | 83 | * |
84 | * @since 1.1.2 | 84 | * @since 1.1.2 |
85 | */ | 85 | */ |
86 | class OKeyConfigItem { | 86 | class OKeyConfigItem { |
87 | friend class OKeyConfigManager; | 87 | friend class OKeyConfigManager; |
88 | public: | 88 | public: |
89 | typedef QValueList<OKeyConfigItem> List; | 89 | typedef QValueList<OKeyConfigItem> List; |
90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
91 | const QPixmap& symbol = QPixmap(), | 91 | const QPixmap& symbol = QPixmap(), |
92 | int id = -1, | 92 | int id = -1, |
93 | const OKeyPair& def = OKeyPair::emptyKey(), | 93 | const OKeyPair& def = OKeyPair::emptyKey(), |
94 | QObject *caller = 0, const char* slot = 0); | 94 | QObject *caller = 0, const char* slot = 0); |
95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
96 | ~OKeyConfigItem(); | 96 | ~OKeyConfigItem(); |
97 | 97 | ||
98 | bool operator==( const OKeyConfigItem& ); | 98 | bool operator==( const OKeyConfigItem& )const; |
99 | bool operator!=( const OKeyConfigItem& ); | 99 | bool operator!=( const OKeyConfigItem& )const; |
100 | 100 | ||
101 | QString text()const; | 101 | QString text()const; |
102 | QPixmap pixmap()const; | 102 | QPixmap pixmap()const; |
103 | int id()const; | 103 | int id()const; |
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | OKeyPair keyPair()const; | 107 | OKeyPair keyPair()const; |
108 | OKeyPair defaultKeyPair()const; | 108 | OKeyPair defaultKeyPair()const; |
109 | QCString configKey()const; | 109 | QCString configKey()const; |
110 | 110 | ||
111 | 111 | ||
112 | void setText( const QString& text ); | 112 | void setText( const QString& text ); |
113 | void setPixmap( const QPixmap& ); | 113 | void setPixmap( const QPixmap& ); |
114 | void setKeyPair( const OKeyPair& ); | 114 | void setKeyPair( const OKeyPair& ); |
115 | void setDefaultKeyPair( const OKeyPair& ); | 115 | void setDefaultKeyPair( const OKeyPair& ); |
116 | 116 | ||
117 | bool isEmpty()const; | 117 | bool isEmpty()const; |
118 | 118 | ||
119 | protected: | 119 | protected: |
120 | QObject *object()const; | 120 | QObject *object()const; |
121 | QCString slot()const; | 121 | QCString slot()const; |
122 | void setId( int id ); | 122 | void setId( int id ); |
123 | void setConfigKey( const QCString& ); | 123 | void setConfigKey( const QCString& ); |
@@ -232,50 +232,52 @@ public: | |||
232 | /** | 232 | /** |
233 | * Immediate Apply the change directly to the underlying OKeyConfigManager | 233 | * Immediate Apply the change directly to the underlying OKeyConfigManager |
234 | * Queue Save all items and then apply when you save() | 234 | * Queue Save all items and then apply when you save() |
235 | */ | 235 | */ |
236 | enum ChangeMode { Imediate, Queue }; | 236 | enum ChangeMode { Imediate, Queue }; |
237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
238 | ~OKeyConfigWidget(); | 238 | ~OKeyConfigWidget(); |
239 | 239 | ||
240 | void setChangeMode( enum ChangeMode ); | 240 | void setChangeMode( enum ChangeMode ); |
241 | ChangeMode changeMode()const; | 241 | ChangeMode changeMode()const; |
242 | 242 | ||
243 | void insert( const QString& name, OKeyConfigManager* ); | 243 | void insert( const QString& name, OKeyConfigManager* ); |
244 | 244 | ||
245 | void load(); | 245 | void load(); |
246 | void save(); | 246 | void save(); |
247 | 247 | ||
248 | private slots: | 248 | private slots: |
249 | void slotListViewItem( QListViewItem* ); | 249 | void slotListViewItem( QListViewItem* ); |
250 | void slotNoKey(); | 250 | void slotNoKey(); |
251 | void slotDefaultKey(); | 251 | void slotDefaultKey(); |
252 | void slotCustomKey(); | 252 | void slotCustomKey(); |
253 | void slotConfigure(); | 253 | void slotConfigure(); |
254 | 254 | ||
255 | private: | 255 | private: |
256 | static bool sanityCheck( Opie::Ui::Private::OKeyListViewItem* man, | ||
257 | const OKeyPair& newItem ); | ||
256 | void updateItem( Opie::Ui::Private::OKeyListViewItem* man, | 258 | void updateItem( Opie::Ui::Private::OKeyListViewItem* man, |
257 | const OKeyPair& newItem); | 259 | const OKeyPair& newItem); |
258 | void initUi(); | 260 | void initUi(); |
259 | Opie::Ui::OListView *m_view; | 261 | Opie::Ui::OListView *m_view; |
260 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; | 262 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; |
261 | QLabel *m_lbl; | 263 | QLabel *m_lbl; |
262 | QPushButton *m_btn; | 264 | QPushButton *m_btn; |
263 | QRadioButton *m_def, *m_cus, *m_none; | 265 | QRadioButton *m_def, *m_cus, *m_none; |
264 | QWidget* m_box; | 266 | QWidget* m_box; |
265 | ChangeMode m_mode; | 267 | ChangeMode m_mode; |
266 | class Private; | 268 | class Private; |
267 | Private *d; | 269 | Private *d; |
268 | }; | 270 | }; |
269 | 271 | ||
270 | 272 | ||
271 | /** | 273 | /** |
272 | * This is a small dialog that allows you to | 274 | * This is a small dialog that allows you to |
273 | * capture a key sequence. | 275 | * capture a key sequence. |
274 | * If you want it to close after a key was captured you | 276 | * If you want it to close after a key was captured you |
275 | * can use this code snippet. | 277 | * can use this code snippet. |
276 | * | 278 | * |
277 | * \code | 279 | * \code |
278 | * OKeyChooserConfigDialog diag(0,0,true); | 280 | * OKeyChooserConfigDialog diag(0,0,true); |
279 | * connect(&diag,SIGNAL(keyCaptured()), | 281 | * connect(&diag,SIGNAL(keyCaptured()), |
280 | * this,SLOT(accept())); | 282 | * this,SLOT(accept())); |
281 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ | 283 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ |