summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/okeyconfigmanager.h
Unidiff
Diffstat (limited to 'libopie2/opiecore/okeyconfigmanager.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/okeyconfigmanager.h205
1 files changed, 205 insertions, 0 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.h b/libopie2/opiecore/okeyconfigmanager.h
new file mode 100644
index 0000000..d610375
--- a/dev/null
+++ b/libopie2/opiecore/okeyconfigmanager.h
@@ -0,0 +1,205 @@
1/*
2 * Copyright (C) 2004
3 * LGPL v2 zecke@handhelds.org
4 */
5
6
7#ifndef ODP_KEY_MANAGER_WIDGET_H
8#define ODP_KEY_MANAGER_WIDGET_H
9
10#include <opie2/oconfig.h>
11#include <opie2/odevice.h>
12
13#include <qstring.h>
14#include <qpixmap.h>
15#include <qcstring.h>
16#include <qvaluelist.h>
17
18namespace Opie {
19namespace Core {
20
21/**
22 * \brief small class representing a Key with possible modifiers
23 * This class holds information about key code and possible
24 * modifier state. That is the lowest level of the key input
25 * functions.
26 * There are also static methods to get special keys.
27 * OKeyPair will be used with \see OKeyConfigItem
28 *
29 * @since 1.2
30 */
31class OKeyPair {
32public:
33 typedef QValueList<OKeyPair> List;
34 OKeyPair( int key = -1, int modifier = -1);
35 ~OKeyPair();
36
37 bool operator==( const OKeyPair& )const;
38 bool operator!=( const OKeyPair& )const;
39
40 bool isEmpty()const;
41
42 int keycode()const;
43 int modifier()const;
44
45 void setKeycode( int );
46 void setModifier( int );
47
48 static OKeyPair returnKey();
49 static OKeyPair leftArrowKey();
50 static OKeyPair rightArrowKey();
51 static OKeyPair upArrowKey();
52 static OKeyPair downArrowKey();
53 static OKeyPair emptyKey();
54 static OKeyPair::List hardwareKeys();
55
56private:
57 int m_key;
58 int m_mod;
59 class Private;
60 Private* d;
61};
62
63/**
64 * A class to represent an OKeyPair.
65 * It consists out of a Text exposed to the user, Config Key Item,
66 * Pixmap, A default OKeyPair and the set OKeyPair.
67 * You can also pass an id to it
68 *
69 * @since 1.1.2
70 */
71class OKeyConfigItem {
72 friend class OKeyConfigManager;
73public:
74 typedef QValueList<OKeyConfigItem> List;
75 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(),
76 const QPixmap& symbol = QPixmap(),
77 int id = -1,
78 const OKeyPair& def = OKeyPair::emptyKey(),
79 QObject *caller = 0, const char* slot = 0);
80 OKeyConfigItem( const Opie::Core::ODeviceButton& );
81 ~OKeyConfigItem();
82
83 bool operator==( const OKeyConfigItem& )const;
84 bool operator!=( const OKeyConfigItem& )const;
85
86 QString text()const;
87 QPixmap pixmap()const;
88 int id()const;
89
90
91
92 OKeyPair keyPair()const;
93 OKeyPair defaultKeyPair()const;
94 QCString configKey()const;
95
96
97 void setText( const QString& text );
98 void setPixmap( const QPixmap& );
99 void setKeyPair( const OKeyPair& );
100 void setDefaultKeyPair( const OKeyPair& );
101
102 bool isEmpty()const;
103
104protected:
105 QObject *object()const;
106 QCString slot()const;
107 void setId( int id );
108 void setConfigKey( const QCString& );
109
110private:
111 QString m_text;
112 QCString m_config;
113 QPixmap m_pix;
114 int m_id;
115 OKeyPair m_key;
116 OKeyPair m_def;
117 QObject *m_obj;
118 QCString m_str;
119 class Private;
120 Private *d;
121};
122
123
124
125/**
126 * \brief A manager to load and save Key Actions and get notified
127 * This is the Manager for KeyActions.
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
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.
132 * You need to add OKeyConfigItem for your keys and then issue a load() to
133 * read the Key information.
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
136 * the event filter and get a signal.
137 * You need to load ans save yourself!
138 *
139 * @since 1.1.2
140 */
141class OKeyConfigManager : public QObject {
142 Q_OBJECT
143 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate;
144public:
145 OKeyConfigManager(Opie::Core::OConfig *conf = 0,
146 const QString& group = QString::null,
147 const OKeyPair::List &block = OKeyPair::List(),
148 bool grabkeyboard = false, QObject * par = 0,
149 const char* name = 0 );
150 ~OKeyConfigManager();
151
152 void load();
153 void save();
154
155 OKeyConfigItem handleKeyEvent( QKeyEvent* );
156 int handleKeyEventId( QKeyEvent* );
157
158 void addKeyConfig( const OKeyConfigItem& );
159 void removeKeyConfig( const OKeyConfigItem& );
160 void clearKeyConfig();
161
162 void addToBlackList( const OKeyPair& );
163 void removeFromBlackList( const OKeyPair& );
164 void clearBlackList();
165 OKeyPair::List blackList()const;
166
167 void handleWidget( QWidget* );
168
169 bool eventFilter( QObject*, QEvent* );
170
171 OKeyConfigItem::List keyConfigList()const;
172signals:
173 /**
174 * The Signals are triggered on KeyPress and KeyRelease!
175 * You can check the isDown of the QKeyEvent
176 * @see QKeyEvent
177 */
178 void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& );
179
180 /**
181 * This Signal correspondents to the OKeyConfigItem slot
182 * and object
183 *
184 * @see OKeyConfigItem::slot
185 * @see OKeyConfigItem::object
186 */
187 void actionActivated( QWidget* par, QKeyEvent* key);
188
189private:
190 OKeyConfigItem::List keyList( int );
191 OKeyConfigItem::List m_keys;
192 QValueList<QWidget*> m_widgets;
193 Opie::Core::OConfig *m_conf;
194 QString m_group;
195 OKeyPair::List m_blackKeys;
196 bool m_grab : 1;
197 OKeyMapConfigPrivate *m_map;
198 class Private;
199 Private *d;
200};
201
202}
203}
204
205#endif