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
@@ -400,30 +400,40 @@ bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const {
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();
@@ -464,24 +474,25 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const {
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/**
@@ -665,25 +676,26 @@ OKeyPair::List OKeyConfigManager::blackList()const {
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*)),
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
@@ -125,59 +125,105 @@ private:
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 *
@@ -188,18 +234,44 @@ signals:
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