summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-20 14:08:07 (UTC)
committer alwin <alwin>2004-04-20 14:08:07 (UTC)
commit135990877f009bd05f00b064a1a255be3e5ab087 (patch) (side-by-side diff)
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 {
if ( m_def != conf.m_def ) return false;
return true;
}
bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const {
return !( *this == conf );
}
+/*! \enum OKeyConfigManager::EventMask
+ <a name="Eventmask flags"></a>
+ This enum is used to tell OKeyConfigManager which type of key events should inspected.
+
+ <ul>
+ <li>\c MaskPressed When a key is pressed an action performs
+ <li>\c MaskReleased When a key is released an action performs
+ </ul>
+*/
+
/**
* \brief c'tor
* The Constructor for a OKeyConfigManager
*
* You can use this manager in multiple ways. Either make it handle
- * QKeyEvents
+ * QKeyEvents. The EventMask is set to OKeyConfigManager::MaskReleased by default.
*
* \code
* Opie::Core::Config conf = oApp->config();
* Opie::Core::OKeyPairList blackList;
* blackList.append(Opie::Core::OKeyPair::leftArrowKey());
* blackList.append(Opie::Core::OKeyPair::rightArrowKey());
* Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList,
* false);
* QListView *view = new QListView();
* manager->handleWidget(view);
* manager->addKeyConfig( Opie::Core::OKeyPair::returnKey());
* manager->load();
@@ -464,24 +474,25 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const {
* @param par The parent/owner of this manager
* @param name The name of this object
*/
OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
const QString& group,
const OKeyPair::List& black,
bool grabkeyboard, QObject* par,
const char* name)
: QObject( par, name ), m_conf( conf ), m_group( group ),
m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){
if ( m_grab )
QPEApplication::grabKeyboard();
+ m_event_mask = OKeyConfigManager::MaskReleased;
}
/**
* Destructor
*/
OKeyConfigManager::~OKeyConfigManager() {
if ( m_grab )
QPEApplication::ungrabKeyboard();
}
/**
@@ -665,25 +676,26 @@ OKeyPair::List OKeyConfigManager::blackList()const {
*/
void OKeyConfigManager::handleWidget( QWidget* wid ) {
wid->installEventFilter( this );
}
/**
* @internal
*/
bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
if ( !obj->isWidgetType() )
return false;
- if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease )
+ if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) &&
+ (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) )
return false;
QKeyEvent *key = static_cast<QKeyEvent*>( ev );
OKeyConfigItem item = handleKeyEvent( key );
if ( item.isEmpty() )
return false;
QWidget *wid = static_cast<QWidget*>( obj );
if ( item.object() && !item.slot().isEmpty() ) {
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:
/**
* \brief A manager to load and save Key Actions and get notified
* This is the Manager for KeyActions.
* You can say from which config and group to read data, to grab the
* keyboard to handle hardware keys, you can supply a blacklist of
* keys which should not be used by allowed to be used.
* You can even pass this manager to a Widget to do the configuration for you.
* You need to add OKeyConfigItem for your keys and then issue a load() to
* read the Key information.
* You can either handle the QKeyEvent yourself and ask this class if it is
* handled by your action and let give you the action. Or you can install
* the event filter and get a signal.
- * You need to load ans save yourself!
+ * You need to load and save yourself!
*
* @since 1.1.2
*/
class OKeyConfigManager : public QObject {
Q_OBJECT
typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate;
public:
OKeyConfigManager(Opie::Core::OConfig *conf = 0,
const QString& group = QString::null,
const OKeyPair::List &block = OKeyPair::List(),
- bool grabkeyboard = false, QObject * par = 0,
+ bool grabkeyboard = false, QObject * par = 0,
const char* name = 0 );
~OKeyConfigManager();
void load();
void save();
OKeyConfigItem handleKeyEvent( QKeyEvent* );
int handleKeyEventId( QKeyEvent* );
void addKeyConfig( const OKeyConfigItem& );
void removeKeyConfig( const OKeyConfigItem& );
void clearKeyConfig();
void addToBlackList( const OKeyPair& );
void removeFromBlackList( const OKeyPair& );
void clearBlackList();
OKeyPair::List blackList()const;
void handleWidget( QWidget* );
bool eventFilter( QObject*, QEvent* );
+ /**
+ * Sets the event mask flags aMask.
+ *
+ * aMask is a combination of OKeyConfigManager::EventMask
+ *
+ * @see eventMask(), testEventMask(), addEventMask(), clearEventMask()
+ */
+ void setEventMask(uint aMask);
+ /**
+ * Returns the event mask flags set.
+ *
+ * aMask is a combination of OKeyConfigManager::EventMask
+ *
+ * @see setEventMask(), testEventMask(), addEventMask(), clearEventMask()
+ */
+ uint eventMask()const;
+ /**
+ * Test if the event mask flag aMask is set.
+ *
+ * @param aMask one of OKeyConfigManager::EventMask
+ *
+ * @see eventMask(), setEventMask(), addEventMask(), clearEventMask()
+ */
+ bool testEventMask(uint aMask);
+ /**
+ * Add the event mask flag aMask.
+ *
+ * @param aMask one of OKeyConfigManager::EventMask
+ *
+ * @see eventMask(), setEventMask(), addEventMask(), clearEventMask()
+ */
+ void addEventMask(uint aMask);
+ /**
+ * Clears the event mask flag aMask.
+ *
+ * @param aMask is one of OKeyConfigManager::EventMask
+ *
+ * @see eventMask(), testEventMask(), addEventMask(), setEventMask()
+ */
+ void clearEventMask(uint aMask);
+
OKeyConfigItem::List keyConfigList()const;
+
+ enum EventMask {
+ MaskPressed = 0x1,
+ MaskReleased = 0x2,
+ };
signals:
/**
* The Signals are triggered on KeyPress and KeyRelease!
* You can check the isDown of the QKeyEvent
* @see QKeyEvent
*/
void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& );
/**
* This Signal correspondents to the OKeyConfigItem slot
* and object
*
@@ -188,18 +234,44 @@ signals:
private:
OKeyConfigItem::List keyList( int );
OKeyConfigItem::List m_keys;
QValueList<QWidget*> m_widgets;
Opie::Core::OConfig *m_conf;
QString m_group;
OKeyPair::List m_blackKeys;
bool m_grab : 1;
OKeyMapConfigPrivate *m_map;
class Private;
Private *d;
+ uint m_event_mask;
};
+inline bool OKeyConfigManager::testEventMask(uint aMask)
+{
+ return (m_event_mask&aMask)!=0;
+}
+
+inline void OKeyConfigManager::addEventMask(uint aMask)
+{
+ m_event_mask |= aMask;
+}
+
+inline void OKeyConfigManager::clearEventMask(uint aMask)
+{
+ m_event_mask &= ~aMask;
+}
+
+inline void OKeyConfigManager::setEventMask(uint aMask)
+{
+ m_event_mask = aMask;
+}
+
+inline uint OKeyConfigManager::eventMask()const
+{
+ return m_event_mask;
+}
+
}
}
#endif