summaryrefslogtreecommitdiff
authorzecke <zecke>2004-03-26 00:12:39 (UTC)
committer zecke <zecke>2004-03-26 00:12:39 (UTC)
commitbb64860402d6b088168927162813735eaf68e09c (patch) (unidiff)
tree849397a417bbf54ea06ea5c68065314f9cd17b08
parent98721c16aa480c4a160d3492462cb8f0de783268 (diff)
downloadopie-bb64860402d6b088168927162813735eaf68e09c.zip
opie-bb64860402d6b088168927162813735eaf68e09c.tar.gz
opie-bb64860402d6b088168927162813735eaf68e09c.tar.bz2
Some more Implementation.
Basicly all of the non GUI part is done
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp311
-rw-r--r--libopie2/opieui/okeyconfigwidget.h10
2 files changed, 311 insertions, 10 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp
index d52a55f..4482754 100644
--- a/libopie2/opieui/okeyconfigwidget.cpp
+++ b/libopie2/opieui/okeyconfigwidget.cpp
@@ -48,5 +48,5 @@ int OKeyPair::keycode()const {
48 * get the modifier key for this OKeyPair. The Modifier State relates 48 * get the modifier key for this OKeyPair. The Modifier State relates
49 * to the Qt::Modifier 49 * to the Qt::ButtonState
50 * 50 *
51 * @see Qt::Modifier 51 * @see Qt::ButtonState
52 * @see setModifier 52 * @see setModifier
@@ -73,3 +73,3 @@ void OKeyPair::setKeycode( int key ) {
73 * @param the Modifier key 73 * @param the Modifier key
74 * @see Qt::Modifier 74 * @see Qt::ButtonState
75 * @see modifier() 75 * @see modifier()
@@ -147,2 +147,21 @@ OKeyPairList OKeyPair::hardwareKeys() {
147/** 147/**
148 * Equals operator. Check if two OKeyPairs have the same key and modifier
149 * @see operator!=
150 */
151bool OKeyPair::operator==( const OKeyPair& pair) {
152 if ( m_key != pair.m_key ) return false;
153 if ( m_mod != pair.m_mod ) return false;
154
155 return true;
156}
157
158/**
159 * Not equal operator. calls the equal operator internally
160 */
161bool OKeyPair::operator!=( const OKeyPair& pair) {
162 return !(*this == pair);
163}
164
165
166/**
148 * The normal Constructor to create a OKeyConfigItem 167 * The normal Constructor to create a OKeyConfigItem
@@ -311,2 +330,24 @@ bool OKeyConfigItem::isEmpty()const {
311/** 330/**
331 * Check if the KeyPairs are the same
332 */
333bool OKeyConfigItem::operator==( const OKeyConfigItem& conf ) {
334 if ( isEmpty() == conf.isEmpty() ) return true;
335 else if ( isEmpty() != conf.isEmpty() ) return false;
336 else if ( !isEmpty()!= conf.isEmpty() ) return false;
337
338 if ( m_id != conf.m_id ) return false;
339 if ( m_text != conf.m_text ) return false;
340 if ( m_pix != conf.m_pix ) return false;
341 if ( m_key != conf.m_key ) return false;
342 if ( m_def != conf.m_def ) return false;
343
344 return true;
345
346}
347
348bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf ) {
349 return !( *this == conf );
350}
351
352/**
312 * \brief c'tor 353 * \brief c'tor
@@ -371,3 +412,3 @@ OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
371 : QObject( par, name ), m_conf( conf ), m_group( group ), 412 : QObject( par, name ), m_conf( conf ), m_group( group ),
372 m_blackKeys( black ), m_grab( grabkeyboard ) 413 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 )
373{} 414{}
@@ -378,3 +419,3 @@ OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
378 */ 419 */
379OKeyConfigWidget::~OKeyConfigWidget() {} 420OKeyConfigManager::~OKeyConfigManager() {}
380 421
@@ -383,4 +424,6 @@ OKeyConfigWidget::~OKeyConfigWidget() {}
383 * If a Key is restricted but was in the config we will 424 * If a Key is restricted but was in the config we will
384 * make the empty 425 * make it be the empty key paur
385 * We will change the group of the OConfig Item! 426 * We will change the group of the OConfig Item!
427 *
428 * @see OKeyPair::emptyKey
386 */ 429 */
@@ -397,4 +440,9 @@ void OKeyConfigWidget::load() {
397 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); 440 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() );
398 (*it).setKeyPair( OKeyPair(key, mod) ); 441 OKeyPair okey( key, mod );
442 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 )
443 (*it).setKeyPair( OKeyPair(key, mod) );
444 else
445 (*it).setKeyPair( OKeyPair::emptyKey() );
399 } 446 }
447 delete m_map; m_map = 0;
400} 448}
@@ -406,3 +454,252 @@ void OKeyConfigWidget::load() {
406void OKeyConfigWidget::save() { 454void OKeyConfigWidget::save() {
455 m_conf->setGroup( m_group );
407 456
457 /*
458 * Write each item
459 */
460 int key, mod;
461 for( OKeyConfigItemList::Iterator it = m_keys.begin();
462 it != m_keys.end(); ++it ) {
463 if ( (*it).isEmpty() )
464 continue;
465 OKeyPair pair = (*it).keyPair();
466 m_conf->writeEntry(pair.configKey()+"key", pair.keycode() );
467 m_conf->writeEntry(pair.configKey()+"mod", pair.modifier() );
468 }
408} 469}
470
471/**
472 * This is function uses a QMap internally but you can have the same keycode
473 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem
474 * with same keycode and modifier key. The GUI takes care that a user can't
475 * cofigure two keys.
476 *
477 * Make sure you call e->ignore if you don't want to handle this event
478 */
479OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) {
480 OKeyConfigItemList keyList = keyList( e->key() );
481 if ( keyList.isEmpty() )
482 return OKeyConfigItem();
483
484 OKeyConfigItem item;
485 for ( OKeyConfigItemList::Iterator it = keyList.begin(); it != keyList.end();
486 ++it ) {
487 if ( (*it).keyPair().modifier() == e->state() ) {
488 item = *it;
489 break;
490 }
491
492 }
493
494 return item;
495}
496
497/**
498 * Return the associated id of the item or -1 if no item
499 * matched the key
500 *
501 * @see handleKeyEvent
502 */
503int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) {
504 return handleKeyEvent( ev ).id();
505}
506
507/**
508 * Add Key Config to the List of items
509 */
510void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) {
511 m_keys.append( item );
512 delete m_map; m_map = 0;
513}
514
515/**
516 * Remove the Key from the Config. Internal lists will be destroyed
517 * and rebuild on demand later
518 */
519void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) {
520 m_keys.remove( item );
521 delete m_map; m_map = 0;
522}
523
524/**
525 * Clears the complete list
526 */
527void OKeyConfigManager::clearKeyConfig() {
528 m_keys.clear();
529 delete m_map; m_map = 0;
530}
531
532
533/**
534 * Add this OKeyPair to the blackList.
535 * Internal lists will be destroyed
536 */
537void OKeyConfigManager::addToBlackList( const OKeyPair& key) {
538 m_blackKeys.append( key );
539 delete m_map; m_map = 0;
540}
541
542
543/**
544 * Remove this OKeyPair from the black List
545 * Internal lists will be destroyed
546 */
547void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) {
548 m_blackKeys.remove( key );
549 delete m_map; m_map = 0;
550}
551
552
553/**
554 * Clear the blackList
555 */
556void OKeyConfigManager::clearBlackList() {
557 m_blackKeys.clear();
558 delete m_map; m_map = 0;
559}
560
561
562/**
563 * Return a copy of the blackList
564 */
565OKeyPairList OKeyConfigManager::blackList()const {
566 return m_blackKeys;
567}
568
569
570/**
571 * Ask the Manager to handle KeyEvents for you.
572 * All handled keys will emit a QSignal and return true
573 * that it handled the keyevent
574 */
575void OKeyConfigManager::handleWidget( QWidget* wid ) {
576 wid->installEventFilter( this );
577}
578
579/**
580 * @internal
581 */
582bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
583 if ( !obj->isWidgetType() )
584 return false;
585
586 if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease )
587 return false;
588
589 QKeyEvent *key = static_cast<QKeyEvent*>( ev );
590 OKeyConfigItem item = handleKeyEvent( key );
591
592 if ( item.isEmpty() )
593 return false;
594
595 emit actionActivated( static_cast<QWidget*>( obj ), key, item );
596 return true;
597}
598
599/**
600 * @internal
601 */
602OKeyConfigItemList OKeyConfigManager::keyList( int keycode) {
603 if ( !m_map ) {
604 m_map = new OKeyMapConfigPrivate;
605 /* for every key */
606 for ( OKeyConfigItemList::Iterator it = m_keys.begin();
607 it!= m_keys.end(); ++it ) {
608 bool add = true;
609 /* see if this key is blocked */
610 for ( OKeyPairList::Iterator pairIt = m_blackKeys.begin();
611 pairIt != m_blackKeys.end(); ++pairIt ) {
612 if ( (*pairIt).keycode() == (*it).keycode() &&
613 (*pairIt).modifier() == (*it).modifier() ) {
614 add = false;
615 break;
616 }
617 }
618 /* check if we added it */
619 if ( add ) {
620 if ( m_map->contains( (*it).keycode() ) )
621 (m_map[(*it).keycode()]).append( *it );
622 else
623 m_map.insert( (*it).keycode(), OKeyConfigItemList( *it ) );
624 }
625 }
626 }
627 return m_map[keycode];
628}
629
630
631
632/////////////////////////
633//////// Widget Starts Here
634namespace Opie {
635namespace Ui {
636namespace Private {
637 static QString keyToString( const OKeyPair& );
638 class OItemBox : public QHBox {
639 Q_OBJECT
640 public:
641 OItemBox( const OKeyConfigItem& item, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
642 ~OItemBox();
643
644 OKeyConfigItem item()const;
645 void setItem( const OKeyConfigItem& item );
646 private slots:
647 void slotClicked();
648 signals:
649 void configureBox( OItemBox* );
650 private:
651 QLabel *m_pix;
652 QLabel *m_text;
653 QPushButton *m_btn;
654 OKeyConfigItem m_item;
655 };
656
657 OItemBox::OItemBox( const OKeyConfigItem& item, QWidget* parent,
658 const char* name, WFlags fl )
659 : QHBox( parent, name, fl ), {
660 m_pix = new QLabel( this );
661 m_text = new QLabel( this );
662 m_btn = new QPushButton( this );
663
664 connect(m_btn, SIGNAL(clicked()),
665 this, SLOT(slotClicked()));
666
667 setItem( item );
668 }
669
670 OItemBox::~OItemBox() {}
671 OKeyConfigItem OItemBox::item()const{
672 return m_item;
673 }
674 void OKeyConfigItem::setItem( const OKeyConfigItem& item ) {
675 m_item = item;
676 m_pix ->setPixmap( item.pixmap() );
677 m_text->setText( item.text() );
678 m_btn->setText( keyToString( item.keyPair() ) );
679 }
680 void OKeyConfigItem::slotClicked() {
681 emit configureBox( this );
682 }
683
684 QString keyToString( const OKeyPair& pair ) {
685 QStringList mod;
686 if ( ( pair.modifier() & Qt::ShiftButton )== Qt::ShiftButton )
687 mod.append( QObject::tr( "Shift", "The Keyboard key" ) );
688 if ( ( pair.modifier() & Qt::ControlButton )== Qt::ControlButton )
689 mod.append( QObject::tr( "Ctrl", "The Ctrl key" ) );
690 if ( ( pair.modifier() & Qt::AltButton ) )== Qt::AltButton )
691 mod.append( QObject::tr( "Alt", "The keyboard Alt Key" ) );
692
693
694 }
695}
696}
697}
698
699
700
701////////////////////////
702
703
704
705#include "okeyconfigwidget.moc"
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h
index 0d5d26f..414ee7e 100644
--- a/libopie2/opieui/okeyconfigwidget.h
+++ b/libopie2/opieui/okeyconfigwidget.h
@@ -138,2 +138,3 @@ class OKeyConfigManager : public QObject {
138 Q_OBJECT 138 Q_OBJECT
139 typedef QMap<it, OKeyConfigItemList> OKeyMapConfigPrivate;
139public: 140public:
@@ -150,3 +151,3 @@ public:
150 OKeyConfigItem handleKeyEvent( QKeyEvent* ); 151 OKeyConfigItem handleKeyEvent( QKeyEvent* );
151 QString handleKeyEventString( QKeyEvent* ); 152 int handleKeyEventId( QKeyEvent* );
152 153
@@ -154,5 +155,6 @@ public:
154 void removeKeyConfig( const OKeyConfigItem& ); 155 void removeKeyConfig( const OKeyConfigItem& );
156 void clearKeyConfig();
155 157
156 void addBlackList( const OKeyPair& ); 158 void addToBlackList( const OKeyPair& );
157 void removeBlackList( const OKeyPair& ); 159 void removeFromBlackList( const OKeyPair& );
158 void clearBlackList(); 160 void clearBlackList();
@@ -168,2 +170,3 @@ signals:
168private: 170private:
171 OKeyConfigItemList keyList( int );
169 OKeyPairList m_blackKeys; 172 OKeyPairList m_blackKeys;
@@ -174,2 +177,3 @@ private:
174 bool m_grab : 1; 177 bool m_grab : 1;
178 OKeyMapConfigPrivate *m_map;
175 class Private; 179 class Private;