summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-20 14:08:07 (UTC)
committer alwin <alwin>2004-04-20 14:08:07 (UTC)
commit135990877f009bd05f00b064a1a255be3e5ab087 (patch) (unidiff)
tree4265e1686a329afe435f2695115eeba93a37e617
parent76b2ca3aff26929dd4e86b66a6f49e99cddd1bda (diff)
downloadopie-135990877f009bd05f00b064a1a255be3e5ab087.zip
opie-135990877f009bd05f00b064a1a255be3e5ab087.tar.gz
opie-135990877f009bd05f00b064a1a255be3e5ab087.tar.bz2
added EventMask for keynotifiers. eg., a mask on which type of keyevents
(press and/or release) the keyconfig makes an action
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/okeyconfigmanager.cpp16
-rw-r--r--libopie2/opiecore/okeyconfigmanager.h76
2 files changed, 88 insertions, 4 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp
index e6055e0..18740ef 100644
--- a/libopie2/opiecore/okeyconfigmanager.cpp
+++ b/libopie2/opiecore/okeyconfigmanager.cpp
@@ -220,514 +220,526 @@ bool OKeyPair::operator!=( const OKeyPair& pair)const {
220OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, 220OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key,
221 const QPixmap& pix, int id, const OKeyPair& def, 221 const QPixmap& pix, int id, const OKeyPair& def,
222 QObject *caller, 222 QObject *caller,
223 const char* slot ) 223 const char* slot )
224 : m_text( text ), m_config( config_key ), m_pix( pix ), 224 : m_text( text ), m_config( config_key ), m_pix( pix ),
225 m_id( id ), m_def( def ), 225 m_id( id ), m_def( def ),
226 m_obj( caller ), m_str( slot ) {} 226 m_obj( caller ), m_str( slot ) {}
227 227
228/** 228/**
229 * A special Constructor for converting from an Opie::Core::ODeviceButton 229 * A special Constructor for converting from an Opie::Core::ODeviceButton
230 * delivered by Opie::Core::ODevice::buttons() 230 * delivered by Opie::Core::ODevice::buttons()
231 * There is no Config Key set and both default key and key are set 231 * There is no Config Key set and both default key and key are set
232 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier 232 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier
233 * 233 *
234 * @see Opie::Core::ODevice 234 * @see Opie::Core::ODevice
235 * @see Opie::Core::ODeviceButton 235 * @see Opie::Core::ODeviceButton
236 * @see Opie::Core::ODevice::buttons() 236 * @see Opie::Core::ODevice::buttons()
237 */ 237 */
238OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) 238OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b )
239 : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), 239 : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ),
240 m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) 240 m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) )
241{} 241{}
242 242
243 243
244/** 244/**
245 * Destructor 245 * Destructor
246 */ 246 */
247OKeyConfigItem::~OKeyConfigItem() {} 247OKeyConfigItem::~OKeyConfigItem() {}
248 248
249 249
250/** 250/**
251 * The text exposed to the user 251 * The text exposed to the user
252 * 252 *
253 * @see setText 253 * @see setText
254 */ 254 */
255QString OKeyConfigItem::text()const { 255QString OKeyConfigItem::text()const {
256 return m_text; 256 return m_text;
257} 257}
258 258
259/** 259/**
260 * The pixmap shown to the user for your action/key 260 * The pixmap shown to the user for your action/key
261 * 261 *
262 * @see setPixmap 262 * @see setPixmap
263 */ 263 */
264QPixmap OKeyConfigItem::pixmap()const { 264QPixmap OKeyConfigItem::pixmap()const {
265 return m_pix; 265 return m_pix;
266} 266}
267 267
268/** 268/**
269 * Return the OKeyPair this OKeyConfigItem is configured for. 269 * Return the OKeyPair this OKeyConfigItem is configured for.
270 * 270 *
271 * @see setKeyPair 271 * @see setKeyPair
272 */ 272 */
273OKeyPair OKeyConfigItem::keyPair()const { 273OKeyPair OKeyConfigItem::keyPair()const {
274 return m_key; 274 return m_key;
275} 275}
276 276
277/** 277/**
278 * Return the default OKeyPair 278 * Return the default OKeyPair
279 * @see setDefaultKeyPair 279 * @see setDefaultKeyPair
280 */ 280 */
281OKeyPair OKeyConfigItem::defaultKeyPair()const { 281OKeyPair OKeyConfigItem::defaultKeyPair()const {
282 return m_def; 282 return m_def;
283} 283}
284 284
285 285
286/** 286/**
287 * Return the Id you assigned to this item. 287 * Return the Id you assigned to this item.
288 * setting is only possible by the constructor 288 * setting is only possible by the constructor
289 */ 289 */
290int OKeyConfigItem::id()const{ 290int OKeyConfigItem::id()const{
291 return m_id; 291 return m_id;
292} 292}
293 293
294/** 294/**
295 * reutrn the Config Key. Setting it is only possible 295 * reutrn the Config Key. Setting it is only possible
296 * by the constructor 296 * by the constructor
297 */ 297 */
298QCString OKeyConfigItem::configKey()const { 298QCString OKeyConfigItem::configKey()const {
299 return m_config; 299 return m_config;
300} 300}
301 301
302/** 302/**
303 * @internal 303 * @internal
304 */ 304 */
305QObject* OKeyConfigItem::object()const{ 305QObject* OKeyConfigItem::object()const{
306 return m_obj; 306 return m_obj;
307} 307}
308 308
309/** 309/**
310 * @internal 310 * @internal
311 */ 311 */
312QCString OKeyConfigItem::slot()const { 312QCString OKeyConfigItem::slot()const {
313 return m_str; 313 return m_str;
314} 314}
315 315
316/** 316/**
317 * Set the text 317 * Set the text
318 * 318 *
319 * @param text Set the Text of this Action to text 319 * @param text Set the Text of this Action to text
320 * @see text() 320 * @see text()
321 */ 321 */
322void OKeyConfigItem::setText( const QString& text ) { 322void OKeyConfigItem::setText( const QString& text ) {
323 m_text = text; 323 m_text = text;
324} 324}
325 325
326/** 326/**
327 * Set the pixmap of this action 327 * Set the pixmap of this action
328 * 328 *
329 * @param pix The Pixmap to set 329 * @param pix The Pixmap to set
330 * @see pixmap() 330 * @see pixmap()
331 */ 331 */
332void OKeyConfigItem::setPixmap( const QPixmap& pix ) { 332void OKeyConfigItem::setPixmap( const QPixmap& pix ) {
333 m_pix = pix; 333 m_pix = pix;
334} 334}
335 335
336/** 336/**
337 * Set the KeyPair the OKeyConfigItem uses. 337 * Set the KeyPair the OKeyConfigItem uses.
338 * Your set Key could get overwritten if you use 338 * Your set Key could get overwritten if you use
339 * the manager or GUI to configure the key 339 * the manager or GUI to configure the key
340 * 340 *
341 * @param key Set the OKeyPair used 341 * @param key Set the OKeyPair used
342 * @see keyPair() 342 * @see keyPair()
343 */ 343 */
344void OKeyConfigItem::setKeyPair( const OKeyPair& key) { 344void OKeyConfigItem::setKeyPair( const OKeyPair& key) {
345 m_key = key; 345 m_key = key;
346} 346}
347 347
348/** 348/**
349 * Set the default KeyPair. 349 * Set the default KeyPair.
350 * 350 *
351 * @param key The default keypair 351 * @param key The default keypair
352 * @see defaultKeyPair() 352 * @see defaultKeyPair()
353 */ 353 */
354void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { 354void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) {
355 m_def = key; 355 m_def = key;
356} 356}
357 357
358/** 358/**
359 * @internal 359 * @internal
360 */ 360 */
361void OKeyConfigItem::setConfigKey( const QCString& str) { 361void OKeyConfigItem::setConfigKey( const QCString& str) {
362 m_config = str; 362 m_config = str;
363 m_config.detach(); 363 m_config.detach();
364} 364}
365 365
366/** 366/**
367 * @internal 367 * @internal
368 */ 368 */
369void OKeyConfigItem::setId( int id ) { 369void OKeyConfigItem::setId( int id ) {
370 m_id = id; 370 m_id = id;
371} 371}
372 372
373/** 373/**
374 * If the item is not configured isEmpty() will return true 374 * If the item is not configured isEmpty() will return true
375 * It is empty if no text is present and no default 375 * It is empty if no text is present and no default
376 * and no configured key 376 * and no configured key
377 */ 377 */
378bool OKeyConfigItem::isEmpty()const { 378bool OKeyConfigItem::isEmpty()const {
379 if ( !m_def.isEmpty() ) return false; 379 if ( !m_def.isEmpty() ) return false;
380 if ( !m_key.isEmpty() ) return false; 380 if ( !m_key.isEmpty() ) return false;
381 if ( !m_text.isEmpty() ) return false; 381 if ( !m_text.isEmpty() ) return false;
382 if ( m_id != -1 ) return false; 382 if ( m_id != -1 ) return false;
383 383
384 return true; 384 return true;
385} 385}
386 386
387/** 387/**
388 * Check if the KeyPairs are the same 388 * Check if the KeyPairs are the same
389 */ 389 */
390bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { 390bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const {
391/* if ( isEmpty() == conf.isEmpty() ) return true; 391/* if ( isEmpty() == conf.isEmpty() ) return true;
392 else if ( isEmpty() != conf.isEmpty() ) return false; 392 else if ( isEmpty() != conf.isEmpty() ) return false;
393 else if ( !isEmpty()!= conf.isEmpty() ) return false; 393 else if ( !isEmpty()!= conf.isEmpty() ) return false;
394*/ 394*/
395 395
396 if ( m_id != conf.m_id ) return false; 396 if ( m_id != conf.m_id ) return false;
397 if ( m_obj != conf.m_obj ) return false; 397 if ( m_obj != conf.m_obj ) return false;
398 if ( m_text != conf.m_text ) return false; 398 if ( m_text != conf.m_text ) return false;
399 if ( m_key != conf.m_key ) return false; 399 if ( m_key != conf.m_key ) return false;
400 if ( m_def != conf.m_def ) return false; 400 if ( m_def != conf.m_def ) return false;
401 401
402 402
403 403
404 return true; 404 return true;
405 405
406} 406}
407 407
408bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { 408bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const {
409 return !( *this == conf ); 409 return !( *this == conf );
410} 410}
411 411
412/*! \enum OKeyConfigManager::EventMask
413 <a name="Eventmask flags"></a>
414 This enum is used to tell OKeyConfigManager which type of key events should inspected.
415
416 <ul>
417 <li>\c MaskPressed When a key is pressed an action performs
418 <li>\c MaskReleased When a key is released an action performs
419 </ul>
420*/
421
412/** 422/**
413 * \brief c'tor 423 * \brief c'tor
414 * The Constructor for a OKeyConfigManager 424 * The Constructor for a OKeyConfigManager
415 * 425 *
416 * You can use this manager in multiple ways. Either make it handle 426 * You can use this manager in multiple ways. Either make it handle
417 * QKeyEvents 427 * QKeyEvents. The EventMask is set to OKeyConfigManager::MaskReleased by default.
418 * 428 *
419 * \code 429 * \code
420 * Opie::Core::Config conf = oApp->config(); 430 * Opie::Core::Config conf = oApp->config();
421 * Opie::Core::OKeyPairList blackList; 431 * Opie::Core::OKeyPairList blackList;
422 * blackList.append(Opie::Core::OKeyPair::leftArrowKey()); 432 * blackList.append(Opie::Core::OKeyPair::leftArrowKey());
423 * blackList.append(Opie::Core::OKeyPair::rightArrowKey()); 433 * blackList.append(Opie::Core::OKeyPair::rightArrowKey());
424 * Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList, 434 * Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList,
425 * false); 435 * false);
426 * QListView *view = new QListView(); 436 * QListView *view = new QListView();
427 * manager->handleWidget(view); 437 * manager->handleWidget(view);
428 * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey()); 438 * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey());
429 * manager->load(); 439 * manager->load();
430 * 440 *
431 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), 441 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)),
432 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&))); 442 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)));
433 * 443 *
434 * .... 444 * ....
435 * 445 *
436 * void update(){ 446 * void update(){
437 * QDialog diag(true); 447 * QDialog diag(true);
438 * QHBoxLayout *lay = new QHBoxLayout(&diag); 448 * QHBoxLayout *lay = new QHBoxLayout(&diag);
439 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); 449 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag);
440 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); 450 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu);
441 * lay->addWidget(wid); 451 * lay->addWidget(wid);
442 * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ 452 * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){
443 * wid->save(); 453 * wid->save();
444 * } 454 * }
445 * } 455 * }
446 * 456 *
447 * .... 457 * ....
448 * MyListView::keyPressEvent( QKeyEvent* e ){ 458 * MyListView::keyPressEvent( QKeyEvent* e ){
449 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); 459 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e);
450 * if(!item.isEmpty() ){ 460 * if(!item.isEmpty() ){
451 * switch(item.id()){ 461 * switch(item.id()){
452 * case My_Delete_Key: 462 * case My_Delete_Key:
453 * break; 463 * break;
454 * } 464 * }
455 * } 465 * }
456 * } 466 * }
457 * 467 *
458 * \endcode 468 * \endcode
459 * 469 *
460 * @param conf The Config where the KeySetting should be stored 470 * @param conf The Config where the KeySetting should be stored
461 * @param group The group where the KeySetting will be stored 471 * @param group The group where the KeySetting will be stored
462 * @param black Which keys shouldn't be allowed to handle 472 * @param black Which keys shouldn't be allowed to handle
463 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons 473 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons
464 * @param par The parent/owner of this manager 474 * @param par The parent/owner of this manager
465 * @param name The name of this object 475 * @param name The name of this object
466 */ 476 */
467OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, 477OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
468 const QString& group, 478 const QString& group,
469 const OKeyPair::List& black, 479 const OKeyPair::List& black,
470 bool grabkeyboard, QObject* par, 480 bool grabkeyboard, QObject* par,
471 const char* name) 481 const char* name)
472 : QObject( par, name ), m_conf( conf ), m_group( group ), 482 : QObject( par, name ), m_conf( conf ), m_group( group ),
473 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ 483 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){
474 if ( m_grab ) 484 if ( m_grab )
475 QPEApplication::grabKeyboard(); 485 QPEApplication::grabKeyboard();
486 m_event_mask = OKeyConfigManager::MaskReleased;
476} 487}
477 488
478 489
479/** 490/**
480 * Destructor 491 * Destructor
481 */ 492 */
482OKeyConfigManager::~OKeyConfigManager() { 493OKeyConfigManager::~OKeyConfigManager() {
483 if ( m_grab ) 494 if ( m_grab )
484 QPEApplication::ungrabKeyboard(); 495 QPEApplication::ungrabKeyboard();
485} 496}
486 497
487/** 498/**
488 * Load the Configuration from the OConfig 499 * Load the Configuration from the OConfig
489 * If a Key is restricted but was in the config we will 500 * If a Key is restricted but was in the config we will
490 * make it be the empty key paur 501 * make it be the empty key paur
491 * We will change the group but restore to the previous. 502 * We will change the group but restore to the previous.
492 * 503 *
493 * @see OKeyPair::emptyKey 504 * @see OKeyPair::emptyKey
494 */ 505 */
495void OKeyConfigManager::load() { 506void OKeyConfigManager::load() {
496 Opie::Core::OConfigGroupSaver( m_conf, m_group ); 507 Opie::Core::OConfigGroupSaver( m_conf, m_group );
497 508
498 /* 509 /*
499 * Read each item 510 * Read each item
500 */ 511 */
501 int key, mod; 512 int key, mod;
502 for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { 513 for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) {
503 key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); 514 key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() );
504 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); 515 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() );
505 OKeyPair okey( key, mod ); 516 OKeyPair okey( key, mod );
506 517
507 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) 518 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 )
508 (*it).setKeyPair( OKeyPair(key, mod) ); 519 (*it).setKeyPair( OKeyPair(key, mod) );
509 else 520 else
510 (*it).setKeyPair( OKeyPair::emptyKey() ); 521 (*it).setKeyPair( OKeyPair::emptyKey() );
511 } 522 }
512 delete m_map; m_map = 0; 523 delete m_map; m_map = 0;
513} 524}
514 525
515/** 526/**
516 * We will save the current configuration 527 * We will save the current configuration
517 * to the OConfig. We will change the group but restore 528 * to the OConfig. We will change the group but restore
518 * to the previous 529 * to the previous
519 */ 530 */
520void OKeyConfigManager::save() { 531void OKeyConfigManager::save() {
521 Opie::Core::OConfigGroupSaver( m_conf, m_group ); 532 Opie::Core::OConfigGroupSaver( m_conf, m_group );
522 533
523 /* 534 /*
524 * Write each item 535 * Write each item
525 */ 536 */
526 for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { 537 for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) {
527 /* skip empty items */ 538 /* skip empty items */
528 if ( (*it).isEmpty() ) 539 if ( (*it).isEmpty() )
529 continue; 540 continue;
530 OKeyPair pair = (*it).keyPair(); 541 OKeyPair pair = (*it).keyPair();
531 OKeyPair deft = (*it).defaultKeyPair(); 542 OKeyPair deft = (*it).defaultKeyPair();
532 /* 543 /*
533 * don't write if it is the default setting 544 * don't write if it is the default setting
534 * FIXME allow to remove Keys from config 545 * FIXME allow to remove Keys from config
535 if ( (pair.keycode() == deft.keycode()) && 546 if ( (pair.keycode() == deft.keycode()) &&
536 (pair.modifier()== deft.modifier() ) ) 547 (pair.modifier()== deft.modifier() ) )
537 return; 548 return;
538 */ 549 */
539 550
540 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); 551 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() );
541 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); 552 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() );
542 } 553 }
543 m_conf->write(); 554 m_conf->write();
544} 555}
545 556
546/** 557/**
547 * This is function uses a QMap internally but you can have the same keycode 558 * This is function uses a QMap internally but you can have the same keycode
548 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem 559 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem
549 * with same keycode and modifier key. The GUI takes care that a user can't 560 * with same keycode and modifier key. The GUI takes care that a user can't
550 * cofigure two keys. 561 * cofigure two keys.
551 * 562 *
552 * Make sure you call e->ignore if you don't want to handle this event 563 * Make sure you call e->ignore if you don't want to handle this event
553 */ 564 */
554OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { 565OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) {
555 /* 566 /*
556 * Fix Up issues with Qt/E, my keybard, and virtual input 567 * Fix Up issues with Qt/E, my keybard, and virtual input
557 * methods 568 * methods
558 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state 569 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state
559 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower 570 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower
560 * case ascii 571 * case ascii
561 */ 572 */
562 int key, mod; 573 int key, mod;
563 Opie::Core::Internal::fixupKeys( key, mod, e ); 574 Opie::Core::Internal::fixupKeys( key, mod, e );
564 575
565 OKeyConfigItem::List _keyList = keyList( key ); 576 OKeyConfigItem::List _keyList = keyList( key );
566 if ( _keyList.isEmpty() ) 577 if ( _keyList.isEmpty() )
567 return OKeyConfigItem(); 578 return OKeyConfigItem();
568 579
569 OKeyConfigItem item; 580 OKeyConfigItem item;
570 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); 581 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end();
571 ++it ) { 582 ++it ) {
572 if ( (*it).keyPair().modifier() == mod ) { 583 if ( (*it).keyPair().modifier() == mod ) {
573 item = *it; 584 item = *it;
574 break; 585 break;
575 } 586 }
576 587
577 } 588 }
578 589
579 return item; 590 return item;
580} 591}
581 592
582/** 593/**
583 * Return the associated id of the item or -1 if no item 594 * Return the associated id of the item or -1 if no item
584 * matched the key 595 * matched the key
585 * 596 *
586 * @see handleKeyEvent 597 * @see handleKeyEvent
587 */ 598 */
588int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { 599int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) {
589 return handleKeyEvent( ev ).id(); 600 return handleKeyEvent( ev ).id();
590} 601}
591 602
592/** 603/**
593 * Add Key Config to the List of items 604 * Add Key Config to the List of items
594 */ 605 */
595void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { 606void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) {
596 m_keys.append( item ); 607 m_keys.append( item );
597 delete m_map; m_map = 0; 608 delete m_map; m_map = 0;
598} 609}
599 610
600/** 611/**
601 * Remove the Key from the Config. Internal lists will be destroyed 612 * Remove the Key from the Config. Internal lists will be destroyed
602 * and rebuild on demand later 613 * and rebuild on demand later
603 */ 614 */
604void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { 615void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) {
605 m_keys.remove( item ); 616 m_keys.remove( item );
606 delete m_map; m_map = 0; 617 delete m_map; m_map = 0;
607} 618}
608 619
609/** 620/**
610 * Clears the complete list 621 * Clears the complete list
611 */ 622 */
612void OKeyConfigManager::clearKeyConfig() { 623void OKeyConfigManager::clearKeyConfig() {
613 m_keys.clear(); 624 m_keys.clear();
614 delete m_map; m_map = 0; 625 delete m_map; m_map = 0;
615} 626}
616 627
617/** 628/**
618 * 629 *
619 */ 630 */
620Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ 631Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{
621 return m_keys; 632 return m_keys;
622} 633}
623 634
624/** 635/**
625 * Add this OKeyPair to the blackList. 636 * Add this OKeyPair to the blackList.
626 * Internal lists will be destroyed 637 * Internal lists will be destroyed
627 */ 638 */
628void OKeyConfigManager::addToBlackList( const OKeyPair& key) { 639void OKeyConfigManager::addToBlackList( const OKeyPair& key) {
629 m_blackKeys.append( key ); 640 m_blackKeys.append( key );
630 delete m_map; m_map = 0; 641 delete m_map; m_map = 0;
631} 642}
632 643
633 644
634/** 645/**
635 * Remove this OKeyPair from the black List 646 * Remove this OKeyPair from the black List
636 * Internal lists will be destroyed 647 * Internal lists will be destroyed
637 */ 648 */
638void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { 649void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) {
639 m_blackKeys.remove( key ); 650 m_blackKeys.remove( key );
640 delete m_map; m_map = 0; 651 delete m_map; m_map = 0;
641} 652}
642 653
643 654
644/** 655/**
645 * Clear the blackList 656 * Clear the blackList
646 */ 657 */
647void OKeyConfigManager::clearBlackList() { 658void OKeyConfigManager::clearBlackList() {
648 m_blackKeys.clear(); 659 m_blackKeys.clear();
649 delete m_map; m_map = 0; 660 delete m_map; m_map = 0;
650} 661}
651 662
652 663
653/** 664/**
654 * Return a copy of the blackList 665 * Return a copy of the blackList
655 */ 666 */
656OKeyPair::List OKeyConfigManager::blackList()const { 667OKeyPair::List OKeyConfigManager::blackList()const {
657 return m_blackKeys; 668 return m_blackKeys;
658} 669}
659 670
660 671
661/** 672/**
662 * Ask the Manager to handle KeyEvents for you. 673 * Ask the Manager to handle KeyEvents for you.
663 * All handled keys will emit a QSignal and return true 674 * All handled keys will emit a QSignal and return true
664 * that it handled the keyevent 675 * that it handled the keyevent
665 */ 676 */
666void OKeyConfigManager::handleWidget( QWidget* wid ) { 677void OKeyConfigManager::handleWidget( QWidget* wid ) {
667 wid->installEventFilter( this ); 678 wid->installEventFilter( this );
668} 679}
669 680
670/** 681/**
671 * @internal 682 * @internal
672 */ 683 */
673bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { 684bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
674 if ( !obj->isWidgetType() ) 685 if ( !obj->isWidgetType() )
675 return false; 686 return false;
676 687
677 if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) 688 if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) &&
689 (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) )
678 return false; 690 return false;
679 691
680 QKeyEvent *key = static_cast<QKeyEvent*>( ev ); 692 QKeyEvent *key = static_cast<QKeyEvent*>( ev );
681 OKeyConfigItem item = handleKeyEvent( key ); 693 OKeyConfigItem item = handleKeyEvent( key );
682 694
683 if ( item.isEmpty() ) 695 if ( item.isEmpty() )
684 return false; 696 return false;
685 697
686 QWidget *wid = static_cast<QWidget*>( obj ); 698 QWidget *wid = static_cast<QWidget*>( obj );
687 699
688 if ( item.object() && !item.slot().isEmpty() ) { 700 if ( item.object() && !item.slot().isEmpty() ) {
689 connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), 701 connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)),
690 item.object(), item.slot().data() ); 702 item.object(), item.slot().data() );
691 emit actionActivated(wid, key); 703 emit actionActivated(wid, key);
692 disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), 704 disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)),
693 item.object(), item.slot().data() ); 705 item.object(), item.slot().data() );
694 } 706 }
695 emit actionActivated( wid, key, item ); 707 emit actionActivated( wid, key, item );
696 708
697 return true; 709 return true;
698} 710}
699 711
700/** 712/**
701 * @internal 713 * @internal
702 */ 714 */
703OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { 715OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) {
704 /* 716 /*
705 * Create the map if not existing anymore 717 * Create the map if not existing anymore
706 */ 718 */
707 if ( !m_map ) { 719 if ( !m_map ) {
708 m_map = new OKeyMapConfigPrivate; 720 m_map = new OKeyMapConfigPrivate;
709 /* for every key */ 721 /* for every key */
710 for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); 722 for ( OKeyConfigItem::List::Iterator it = m_keys.begin();
711 it!= m_keys.end(); ++it ) { 723 it!= m_keys.end(); ++it ) {
712 724
713 bool add = true; 725 bool add = true;
714 /* see if this key is blocked */ 726 /* see if this key is blocked */
715 OKeyPair pair = (*it).keyPair(); 727 OKeyPair pair = (*it).keyPair();
716 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); 728 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin();
717 pairIt != m_blackKeys.end(); ++pairIt ) { 729 pairIt != m_blackKeys.end(); ++pairIt ) {
718 if ( (*pairIt).keycode() == pair.keycode() && 730 if ( (*pairIt).keycode() == pair.keycode() &&
719 (*pairIt).modifier() == pair.modifier() ) { 731 (*pairIt).modifier() == pair.modifier() ) {
720 add = false; 732 add = false;
721 break; 733 break;
722 } 734 }
723 } 735 }
724 /* check if we added it */ 736 /* check if we added it */
725 if ( add ) 737 if ( add )
726 (*m_map)[pair.keycode()].append( *it ); 738 (*m_map)[pair.keycode()].append( *it );
727 } 739 }
728 } 740 }
729 return (*m_map)[keycode]; 741 return (*m_map)[keycode];
730} 742}
731 743
732} 744}
733} 745}
diff --git a/libopie2/opiecore/okeyconfigmanager.h b/libopie2/opiecore/okeyconfigmanager.h
index d610375..b861675 100644
--- a/libopie2/opiecore/okeyconfigmanager.h
+++ b/libopie2/opiecore/okeyconfigmanager.h
@@ -1,205 +1,277 @@
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_MANAGER_WIDGET_H 7#ifndef ODP_KEY_MANAGER_WIDGET_H
8#define ODP_KEY_MANAGER_WIDGET_H 8#define ODP_KEY_MANAGER_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 <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18namespace Opie { 18namespace Opie {
19namespace Core { 19namespace Core {
20 20
21/** 21/**
22 * \brief small class representing a Key with possible modifiers 22 * \brief small class representing a Key with possible modifiers
23 * This class holds information about key code and possible 23 * This class holds information about key code and possible
24 * modifier state. That is the lowest level of the key input 24 * modifier state. That is the lowest level of the key input
25 * functions. 25 * functions.
26 * There are also static methods to get special keys. 26 * There are also static methods to get special keys.
27 * OKeyPair will be used with \see OKeyConfigItem 27 * OKeyPair will be used with \see OKeyConfigItem
28 * 28 *
29 * @since 1.2 29 * @since 1.2
30 */ 30 */
31class OKeyPair { 31class OKeyPair {
32public: 32public:
33 typedef QValueList<OKeyPair> List; 33 typedef QValueList<OKeyPair> List;
34 OKeyPair( int key = -1, int modifier = -1); 34 OKeyPair( int key = -1, int modifier = -1);
35 ~OKeyPair(); 35 ~OKeyPair();
36 36
37 bool operator==( const OKeyPair& )const; 37 bool operator==( const OKeyPair& )const;
38 bool operator!=( const OKeyPair& )const; 38 bool operator!=( const OKeyPair& )const;
39 39
40 bool isEmpty()const; 40 bool isEmpty()const;
41 41
42 int keycode()const; 42 int keycode()const;
43 int modifier()const; 43 int modifier()const;
44 44
45 void setKeycode( int ); 45 void setKeycode( int );
46 void setModifier( int ); 46 void setModifier( int );
47 47
48 static OKeyPair returnKey(); 48 static OKeyPair returnKey();
49 static OKeyPair leftArrowKey(); 49 static OKeyPair leftArrowKey();
50 static OKeyPair rightArrowKey(); 50 static OKeyPair rightArrowKey();
51 static OKeyPair upArrowKey(); 51 static OKeyPair upArrowKey();
52 static OKeyPair downArrowKey(); 52 static OKeyPair downArrowKey();
53 static OKeyPair emptyKey(); 53 static OKeyPair emptyKey();
54 static OKeyPair::List hardwareKeys(); 54 static OKeyPair::List hardwareKeys();
55 55
56private: 56private:
57 int m_key; 57 int m_key;
58 int m_mod; 58 int m_mod;
59 class Private; 59 class Private;
60 Private* d; 60 Private* d;
61}; 61};
62 62
63/** 63/**
64 * A class to represent an OKeyPair. 64 * A class to represent an OKeyPair.
65 * It consists out of a Text exposed to the user, Config Key Item, 65 * It consists out of a Text exposed to the user, Config Key Item,
66 * Pixmap, A default OKeyPair and the set OKeyPair. 66 * Pixmap, A default OKeyPair and the set OKeyPair.
67 * You can also pass an id to it 67 * You can also pass an id to it
68 * 68 *
69 * @since 1.1.2 69 * @since 1.1.2
70 */ 70 */
71class OKeyConfigItem { 71class OKeyConfigItem {
72 friend class OKeyConfigManager; 72 friend class OKeyConfigManager;
73public: 73public:
74 typedef QValueList<OKeyConfigItem> List; 74 typedef QValueList<OKeyConfigItem> List;
75 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), 75 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(),
76 const QPixmap& symbol = QPixmap(), 76 const QPixmap& symbol = QPixmap(),
77 int id = -1, 77 int id = -1,
78 const OKeyPair& def = OKeyPair::emptyKey(), 78 const OKeyPair& def = OKeyPair::emptyKey(),
79 QObject *caller = 0, const char* slot = 0); 79 QObject *caller = 0, const char* slot = 0);
80 OKeyConfigItem( const Opie::Core::ODeviceButton& ); 80 OKeyConfigItem( const Opie::Core::ODeviceButton& );
81 ~OKeyConfigItem(); 81 ~OKeyConfigItem();
82 82
83 bool operator==( const OKeyConfigItem& )const; 83 bool operator==( const OKeyConfigItem& )const;
84 bool operator!=( const OKeyConfigItem& )const; 84 bool operator!=( const OKeyConfigItem& )const;
85 85
86 QString text()const; 86 QString text()const;
87 QPixmap pixmap()const; 87 QPixmap pixmap()const;
88 int id()const; 88 int id()const;
89 89
90 90
91 91
92 OKeyPair keyPair()const; 92 OKeyPair keyPair()const;
93 OKeyPair defaultKeyPair()const; 93 OKeyPair defaultKeyPair()const;
94 QCString configKey()const; 94 QCString configKey()const;
95 95
96 96
97 void setText( const QString& text ); 97 void setText( const QString& text );
98 void setPixmap( const QPixmap& ); 98 void setPixmap( const QPixmap& );
99 void setKeyPair( const OKeyPair& ); 99 void setKeyPair( const OKeyPair& );
100 void setDefaultKeyPair( const OKeyPair& ); 100 void setDefaultKeyPair( const OKeyPair& );
101 101
102 bool isEmpty()const; 102 bool isEmpty()const;
103 103
104protected: 104protected:
105 QObject *object()const; 105 QObject *object()const;
106 QCString slot()const; 106 QCString slot()const;
107 void setId( int id ); 107 void setId( int id );
108 void setConfigKey( const QCString& ); 108 void setConfigKey( const QCString& );
109 109
110private: 110private:
111 QString m_text; 111 QString m_text;
112 QCString m_config; 112 QCString m_config;
113 QPixmap m_pix; 113 QPixmap m_pix;
114 int m_id; 114 int m_id;
115 OKeyPair m_key; 115 OKeyPair m_key;
116 OKeyPair m_def; 116 OKeyPair m_def;
117 QObject *m_obj; 117 QObject *m_obj;
118 QCString m_str; 118 QCString m_str;
119 class Private; 119 class Private;
120 Private *d; 120 Private *d;
121}; 121};
122 122
123 123
124 124
125/** 125/**
126 * \brief A manager to load and save Key Actions and get notified 126 * \brief A manager to load and save Key Actions and get notified
127 * This is the Manager for KeyActions. 127 * This is the Manager for KeyActions.
128 * You can say from which config and group to read data, to grab the 128 * You can say from which config and group to read data, to grab the
129 * keyboard to handle hardware keys, you can supply a blacklist of 129 * keyboard to handle hardware keys, you can supply a blacklist of
130 * keys which should not be used by allowed to be used. 130 * keys which should not be used by allowed to be used.
131 * You can even pass this manager to a Widget to do the configuration for you. 131 * You can even pass this manager to a Widget to do the configuration for you.
132 * You need to add OKeyConfigItem for your keys and then issue a load() to 132 * You need to add OKeyConfigItem for your keys and then issue a load() to
133 * read the Key information. 133 * read the Key information.
134 * You can either handle the QKeyEvent yourself and ask this class if it is 134 * You can either handle the QKeyEvent yourself and ask this class if it is
135 * handled by your action and let give you the action. Or you can install 135 * handled by your action and let give you the action. Or you can install
136 * the event filter and get a signal. 136 * the event filter and get a signal.
137 * You need to load ans save yourself! 137 * You need to load and save yourself!
138 * 138 *
139 * @since 1.1.2 139 * @since 1.1.2
140 */ 140 */
141class OKeyConfigManager : public QObject { 141class OKeyConfigManager : public QObject {
142 Q_OBJECT 142 Q_OBJECT
143 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; 143 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate;
144public: 144public:
145 OKeyConfigManager(Opie::Core::OConfig *conf = 0, 145 OKeyConfigManager(Opie::Core::OConfig *conf = 0,
146 const QString& group = QString::null, 146 const QString& group = QString::null,
147 const OKeyPair::List &block = OKeyPair::List(), 147 const OKeyPair::List &block = OKeyPair::List(),
148 bool grabkeyboard = false, QObject * par = 0, 148 bool grabkeyboard = false, QObject * par = 0,
149 const char* name = 0 ); 149 const char* name = 0 );
150 ~OKeyConfigManager(); 150 ~OKeyConfigManager();
151 151
152 void load(); 152 void load();
153 void save(); 153 void save();
154 154
155 OKeyConfigItem handleKeyEvent( QKeyEvent* ); 155 OKeyConfigItem handleKeyEvent( QKeyEvent* );
156 int handleKeyEventId( QKeyEvent* ); 156 int handleKeyEventId( QKeyEvent* );
157 157
158 void addKeyConfig( const OKeyConfigItem& ); 158 void addKeyConfig( const OKeyConfigItem& );
159 void removeKeyConfig( const OKeyConfigItem& ); 159 void removeKeyConfig( const OKeyConfigItem& );
160 void clearKeyConfig(); 160 void clearKeyConfig();
161 161
162 void addToBlackList( const OKeyPair& ); 162 void addToBlackList( const OKeyPair& );
163 void removeFromBlackList( const OKeyPair& ); 163 void removeFromBlackList( const OKeyPair& );
164 void clearBlackList(); 164 void clearBlackList();
165 OKeyPair::List blackList()const; 165 OKeyPair::List blackList()const;
166 166
167 void handleWidget( QWidget* ); 167 void handleWidget( QWidget* );
168 168
169 bool eventFilter( QObject*, QEvent* ); 169 bool eventFilter( QObject*, QEvent* );
170 170
171 /**
172 * Sets the event mask flags aMask.
173 *
174 * aMask is a combination of OKeyConfigManager::EventMask
175 *
176 * @see eventMask(), testEventMask(), addEventMask(), clearEventMask()
177 */
178 void setEventMask(uint aMask);
179 /**
180 * Returns the event mask flags set.
181 *
182 * aMask is a combination of OKeyConfigManager::EventMask
183 *
184 * @see setEventMask(), testEventMask(), addEventMask(), clearEventMask()
185 */
186 uint eventMask()const;
187 /**
188 * Test if the event mask flag aMask is set.
189 *
190 * @param aMask one of OKeyConfigManager::EventMask
191 *
192 * @see eventMask(), setEventMask(), addEventMask(), clearEventMask()
193 */
194 bool testEventMask(uint aMask);
195 /**
196 * Add the event mask flag aMask.
197 *
198 * @param aMask one of OKeyConfigManager::EventMask
199 *
200 * @see eventMask(), setEventMask(), addEventMask(), clearEventMask()
201 */
202 void addEventMask(uint aMask);
203 /**
204 * Clears the event mask flag aMask.
205 *
206 * @param aMask is one of OKeyConfigManager::EventMask
207 *
208 * @see eventMask(), testEventMask(), addEventMask(), setEventMask()
209 */
210 void clearEventMask(uint aMask);
211
171 OKeyConfigItem::List keyConfigList()const; 212 OKeyConfigItem::List keyConfigList()const;
213
214 enum EventMask {
215 MaskPressed = 0x1,
216 MaskReleased = 0x2,
217 };
172signals: 218signals:
173 /** 219 /**
174 * The Signals are triggered on KeyPress and KeyRelease! 220 * The Signals are triggered on KeyPress and KeyRelease!
175 * You can check the isDown of the QKeyEvent 221 * You can check the isDown of the QKeyEvent
176 * @see QKeyEvent 222 * @see QKeyEvent
177 */ 223 */
178 void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); 224 void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& );
179 225
180 /** 226 /**
181 * This Signal correspondents to the OKeyConfigItem slot 227 * This Signal correspondents to the OKeyConfigItem slot
182 * and object 228 * and object
183 * 229 *
184 * @see OKeyConfigItem::slot 230 * @see OKeyConfigItem::slot
185 * @see OKeyConfigItem::object 231 * @see OKeyConfigItem::object
186 */ 232 */
187 void actionActivated( QWidget* par, QKeyEvent* key); 233 void actionActivated( QWidget* par, QKeyEvent* key);
188 234
189private: 235private:
190 OKeyConfigItem::List keyList( int ); 236 OKeyConfigItem::List keyList( int );
191 OKeyConfigItem::List m_keys; 237 OKeyConfigItem::List m_keys;
192 QValueList<QWidget*> m_widgets; 238 QValueList<QWidget*> m_widgets;
193 Opie::Core::OConfig *m_conf; 239 Opie::Core::OConfig *m_conf;
194 QString m_group; 240 QString m_group;
195 OKeyPair::List m_blackKeys; 241 OKeyPair::List m_blackKeys;
196 bool m_grab : 1; 242 bool m_grab : 1;
197 OKeyMapConfigPrivate *m_map; 243 OKeyMapConfigPrivate *m_map;
198 class Private; 244 class Private;
199 Private *d; 245 Private *d;
246 uint m_event_mask;
200}; 247};
201 248
249inline bool OKeyConfigManager::testEventMask(uint aMask)
250{
251 return (m_event_mask&aMask)!=0;
252}
253
254inline void OKeyConfigManager::addEventMask(uint aMask)
255{
256 m_event_mask |= aMask;
257}
258
259inline void OKeyConfigManager::clearEventMask(uint aMask)
260{
261 m_event_mask &= ~aMask;
262}
263
264inline void OKeyConfigManager::setEventMask(uint aMask)
265{
266 m_event_mask = aMask;
267}
268
269inline uint OKeyConfigManager::eventMask()const
270{
271 return m_event_mask;
272}
273
202} 274}
203} 275}
204 276
205#endif 277#endif