Diffstat (limited to 'libopie2/opieui/okeyconfigwidget.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 107 |
1 files changed, 83 insertions, 24 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index 414ee7e..b3309af 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -3,207 +3,266 @@ | |||
3 | * LGPL v2 zecke@handhelds.org | 3 | * LGPL v2 zecke@handhelds.org |
4 | */ | 4 | */ |
5 | 5 | ||
6 | 6 | ||
7 | #ifndef ODP_KEY_CONFIG_WIDGET_H | 7 | #ifndef ODP_KEY_CONFIG_WIDGET_H |
8 | #define ODP_KEY_CONFIG_WIDGET_H | 8 | #define ODP_KEY_CONFIG_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 <qbytearray.h> | 15 | #include <qcstring.h> |
16 | #include <qhbox.h> | 16 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 17 | #include <qvaluelist.h> |
18 | 18 | ||
19 | class QKeyEvent; | 19 | class QKeyEvent; |
20 | class QLabel; | ||
21 | class QPushButton; | ||
22 | class QListViewItem; | ||
23 | class QRadioButton; | ||
20 | 24 | ||
21 | namespace Opie { | 25 | namespace Opie { |
22 | namespace Ui { | 26 | namespace Ui { |
23 | 27 | namespace Private { | |
28 | class OKeyConfigWidgetPrivate; | ||
29 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | ||
30 | } | ||
31 | class OListViewItem; | ||
32 | class OListView; | ||
24 | 33 | ||
25 | /** | 34 | /** |
26 | * \brief small class representing a Key with possible modifiers | 35 | * \brief small class representing a Key with possible modifiers |
27 | * This class holds information about key code and possible | 36 | * This class holds information about key code and possible |
28 | * modifier state. That is the lowest level of the key input | 37 | * modifier state. That is the lowest level of the key input |
29 | * functions. | 38 | * functions. |
30 | * There are also static methods to get special keys. | 39 | * There are also static methods to get special keys. |
31 | * OKeyPair will be used with \see OKeyConfigItem | 40 | * OKeyPair will be used with \see OKeyConfigItem |
32 | * | 41 | * |
33 | * @since 1.2 | 42 | * @since 1.2 |
34 | */ | 43 | */ |
35 | class OKeyPair { | 44 | class OKeyPair { |
36 | public: | 45 | public: |
37 | typedef QValueList<OKeyPair> OKeyPairList; | 46 | typedef QValueList<OKeyPair> List; |
38 | OKeyPair( int key = -1, int modifier = -1); | 47 | OKeyPair( int key = -1, int modifier = -1); |
39 | ~OKeyPair(); | 48 | ~OKeyPair(); |
40 | 49 | ||
41 | bool operator==( const OKeyPair& ); | 50 | bool operator==( const OKeyPair& ); |
42 | bool operator!=( const OKeyPair& ); | 51 | bool operator!=( const OKeyPair& ); |
43 | 52 | ||
44 | bool isEmpty()const; | 53 | bool isEmpty()const; |
45 | 54 | ||
46 | int keycode()const; | 55 | int keycode()const; |
47 | int modifier()const; | 56 | int modifier()const; |
48 | 57 | ||
49 | void setKeycode( int ); | 58 | void setKeycode( int ); |
50 | void setModifier( int ); | 59 | void setModifier( int ); |
51 | 60 | ||
52 | static OKeyPair returnKey(); | 61 | static OKeyPair returnKey(); |
53 | static OKeyPair leftArrowKey(); | 62 | static OKeyPair leftArrowKey(); |
54 | static OKeyPair rightArrowKey(); | 63 | static OKeyPair rightArrowKey(); |
55 | static OKeyPair upArrowKey(); | 64 | static OKeyPair upArrowKey(); |
56 | static OKeyPair downArrowKey(); | 65 | static OKeyPair downArrowKey(); |
57 | static OKeyPair emptyKey(); | 66 | static OKeyPair emptyKey(); |
58 | static OKeyPairList hardwareKeys(); | 67 | static OKeyPair::List hardwareKeys(); |
59 | 68 | ||
60 | private: | 69 | private: |
61 | int m_key = -1; | 70 | int m_key; |
62 | int m_mod = -1; | 71 | int m_mod; |
63 | class Private; | 72 | class Private; |
64 | Private* d; | 73 | Private* d; |
65 | }; | 74 | }; |
66 | 75 | ||
67 | /** | 76 | /** |
68 | * A class to represent an OKeyPair. | 77 | * A class to represent an OKeyPair. |
69 | * It consists out of a Text exposed to the user, Config Key Item, | 78 | * It consists out of a Text exposed to the user, Config Key Item, |
70 | * Pixmap, A default OKeyPair and the set OKeyPair. | 79 | * Pixmap, A default OKeyPair and the set OKeyPair. |
71 | * You can also pass an id to it | 80 | * You can also pass an id to it |
72 | * | 81 | * |
73 | * @since 1.1.2 | 82 | * @since 1.1.2 |
74 | */ | 83 | */ |
75 | class OKeyConfigItem { | 84 | class OKeyConfigItem { |
76 | friend class OKeyConfigManager; | 85 | friend class OKeyConfigManager; |
77 | public: | 86 | public: |
78 | typedef QValueList<OKeyConfigItem> OKeyConfigItemList; | 87 | typedef QValueList<OKeyConfigItem> List; |
79 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | 88 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), |
80 | const QPixmap& symbol = QPixmap(), | 89 | const QPixmap& symbol = QPixmap(), |
81 | int id = -1, | 90 | int id = -1, |
82 | const OKeyPair& set = OKeyPair::emptyKey(), | 91 | const OKeyPair& def = OKeyPair::emptyKey(), |
83 | const OKeyPair& def = OKeyPair::emptyKey() ); | 92 | QObject *caller = 0, const char* slot = 0); |
84 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | 93 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); |
85 | ~OKeyConfigItem(); | 94 | ~OKeyConfigItem(); |
86 | 95 | ||
87 | bool operator==( const OKeyConfigItem& ); | 96 | bool operator==( const OKeyConfigItem& ); |
88 | bool operator!=( const OKeyConfigItem& ); | 97 | bool operator!=( const OKeyConfigItem& ); |
89 | 98 | ||
90 | QString text()const; | 99 | QString text()const; |
91 | QPixmap pixmap()const; | 100 | QPixmap pixmap()const; |
92 | int id()const; | 101 | int id()const; |
93 | 102 | ||
103 | |||
104 | |||
94 | OKeyPair keyPair()const; | 105 | OKeyPair keyPair()const; |
95 | OKeyPair defaultKeyPair()const; | 106 | OKeyPair defaultKeyPair()const; |
96 | QCString configKey()const; | 107 | QCString configKey()const; |
97 | 108 | ||
109 | |||
98 | void setText( const QString& text ); | 110 | void setText( const QString& text ); |
99 | void setPixmap( const QPixmap& ); | 111 | void setPixmap( const QPixmap& ); |
100 | void setKeyPair( const OKeyPair& ); | 112 | void setKeyPair( const OKeyPair& ); |
101 | void setDefaultKeyPair( const OKeyPair& ); | 113 | void setDefaultKeyPair( const OKeyPair& ); |
102 | 114 | ||
103 | bool isEmpty()const; | 115 | bool isEmpty()const; |
104 | 116 | ||
105 | protected: | 117 | protected: |
118 | QObject *object()const; | ||
119 | QCString slot()const; | ||
106 | void setId( int id ); | 120 | void setId( int id ); |
107 | void setConfigKey( const QCString& ); | 121 | void setConfigKey( const QCString& ); |
108 | 122 | ||
109 | private: | 123 | private: |
110 | int m_id; | ||
111 | QString m_text; | 124 | QString m_text; |
112 | QCString m_config; | 125 | QCString m_config; |
113 | QPixmap m_pix; | 126 | QPixmap m_pix; |
127 | int m_id; | ||
114 | OKeyPair m_key; | 128 | OKeyPair m_key; |
115 | OKeyPair m_def; | 129 | OKeyPair m_def; |
130 | QObject *m_obj; | ||
131 | QCString m_str; | ||
116 | class Private; | 132 | class Private; |
117 | Private *d; | 133 | Private *d; |
118 | }; | 134 | }; |
119 | 135 | ||
120 | 136 | ||
121 | 137 | ||
122 | /** | 138 | /** |
123 | * \brief A manager to load and save Key Actions and get notified | 139 | * \brief A manager to load and save Key Actions and get notified |
124 | * This is the Manager for KeyActions. | 140 | * This is the Manager for KeyActions. |
125 | * You can say from which config and group to read data, to grab the | 141 | * You can say from which config and group to read data, to grab the |
126 | * keyboard to handle hardware keys, you can supply a blacklist of | 142 | * keyboard to handle hardware keys, you can supply a blacklist of |
127 | * keys which should not be used by allowed to be used. | 143 | * keys which should not be used by allowed to be used. |
128 | * You can even pass this manager to a Widget to do the configuration for you. | 144 | * You can even pass this manager to a Widget to do the configuration for you. |
129 | * You need to add OKeyConfigItem for your keys and then issue a load() to | 145 | * You need to add OKeyConfigItem for your keys and then issue a load() to |
130 | * read the Key information. | 146 | * read the Key information. |
131 | * You can either handle the QKeyEvent yourself and ask this class if it is | 147 | * You can either handle the QKeyEvent yourself and ask this class if it is |
132 | * handled by your action and let give you the action. Or you can install | 148 | * handled by your action and let give you the action. Or you can install |
133 | * the event filter and get a signal. | 149 | * the event filter and get a signal. |
150 | * You need to load ans save yourself! | ||
134 | * | 151 | * |
135 | * @since 1.1.2 | 152 | * @since 1.1.2 |
136 | */ | 153 | */ |
137 | class OKeyConfigManager : public QObject { | 154 | class OKeyConfigManager : public QObject { |
138 | Q_OBJECT | 155 | Q_OBJECT |
139 | typedef QMap<it, OKeyConfigItemList> OKeyMapConfigPrivate; | 156 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; |
140 | public: | 157 | public: |
141 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | 158 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, |
142 | const QString& group = QString::null, | 159 | const QString& group = QString::null, |
143 | OKeyPairList &block = OKeyPairList(), | 160 | const OKeyPair::List &block = OKeyPair::List(), |
144 | bool grabkeyboard = false, QObject *= 0, | 161 | bool grabkeyboard = false, QObject * par = 0, |
145 | const char* name = 0 ); | 162 | const char* name = 0 ); |
146 | ~OKeyConfigManager(); | 163 | ~OKeyConfigManager(); |
147 | 164 | ||
148 | void load(); | 165 | void load(); |
149 | void save(); | 166 | void save(); |
150 | 167 | ||
151 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | 168 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); |
152 | int handleKeyEventId( QKeyEvent* ); | 169 | int handleKeyEventId( QKeyEvent* ); |
153 | 170 | ||
154 | void addKeyConfig( const OKeyConfigItem& ); | 171 | void addKeyConfig( const OKeyConfigItem& ); |
155 | void removeKeyConfig( const OKeyConfigItem& ); | 172 | void removeKeyConfig( const OKeyConfigItem& ); |
156 | void clearKeyConfig(); | 173 | void clearKeyConfig(); |
157 | 174 | ||
158 | void addToBlackList( const OKeyPair& ); | 175 | void addToBlackList( const OKeyPair& ); |
159 | void removeFromBlackList( const OKeyPair& ); | 176 | void removeFromBlackList( const OKeyPair& ); |
160 | void clearBlackList(); | 177 | void clearBlackList(); |
161 | OKeyPairList blackList()const; | 178 | OKeyPair::List blackList()const; |
162 | 179 | ||
163 | void handleWidget( QWidget* ); | 180 | void handleWidget( QWidget* ); |
164 | 181 | ||
165 | bool eventFilter( QObject*, QEvent* ); | 182 | bool eventFilter( QObject*, QEvent* ); |
166 | signals: | 183 | signals: |
167 | void keyConfigChanged( Opie::Ui::OKeyConfigManager* ); | 184 | /** |
185 | * The Signals are triggered on KeyPress and KeyRelease! | ||
186 | * You can check the isDown of the QKeyEvent | ||
187 | * @see QKeyEvent | ||
188 | */ | ||
168 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 189 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); |
169 | 190 | ||
191 | /** | ||
192 | * This Signal correspondents to the OKeyConfigItem slot | ||
193 | * and object | ||
194 | * | ||
195 | * @see OKeyConfigItem::slot | ||
196 | * @see OKeyConfigItem::object | ||
197 | */ | ||
198 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
199 | |||
170 | private: | 200 | private: |
171 | OKeyConfigItemList keyList( int ); | 201 | OKeyConfigItem::List keyList( int ); |
172 | OKeyPairList m_blackKeys; | 202 | OKeyConfigItem::List m_keys; |
173 | OKeyConfigItemList m_keys; | ||
174 | QValueList<QWidget*> m_widgets; | 203 | QValueList<QWidget*> m_widgets; |
175 | Opie::Core::OConfig *m_conf; | 204 | Opie::Core::OConfig *m_conf; |
176 | QString m_group; | 205 | QString m_group; |
206 | OKeyPair::List m_blackKeys; | ||
177 | bool m_grab : 1; | 207 | bool m_grab : 1; |
178 | OKeyMapConfigPrivate *m_map; | 208 | OKeyMapConfigPrivate *m_map; |
179 | class Private; | 209 | class Private; |
180 | Private *d; | 210 | Private *d; |
181 | }; | 211 | }; |
182 | 212 | ||
183 | 213 | ||
184 | class OKeyConfigWidget : public QHBox { | 214 | /** |
215 | * With this Widget you can let the Keyboard Shortcuts | ||
216 | * be configured by the user. | ||
217 | * There are two ways you can use this widget. Either in a tab were | ||
218 | * all changes are immediately getting into effect or in a queue | ||
219 | * were you ask for saving. Save won't write the data but only set | ||
220 | * it to the OKeyConfigManager | ||
221 | * | ||
222 | * @since 1.2 | ||
223 | */ | ||
224 | class OKeyConfigWidget : public QWidget { | ||
185 | Q_OBJECT | 225 | Q_OBJECT |
226 | |||
186 | public: | 227 | public: |
187 | enum ChangeMode { Imediate, Queu }; | 228 | /** |
229 | * Immediate Apply the change directly to the underlying OKeyConfigManager | ||
230 | * Queue Save all items and then apply when you save() | ||
231 | */ | ||
232 | enum ChangeMode { Imediate, Queue }; | ||
188 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 233 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
189 | OKeyConfigWidget( OKeyConfigManager *, QWidget* parent = 0, const char* = 0, WFlags = 0 ); | ||
190 | ~OKeyConfigWidget(); | 234 | ~OKeyConfigWidget(); |
191 | 235 | ||
192 | void setChangeMode( enum ChangeMode ); | 236 | void setChangeMode( enum ChangeMode ); |
193 | ChangeMode changeMode()const; | 237 | ChangeMode changeMode()const; |
194 | 238 | ||
195 | void setKeyConfig( OKeyConfigManager* ); | 239 | void insert( const QString& name, OKeyConfigManager* ); |
196 | 240 | ||
197 | void reload(); | 241 | void load(); |
198 | void save(); | 242 | void save(); |
243 | |||
244 | private slots: | ||
245 | void slotListViewItem( QListViewItem* ); | ||
246 | void slotNoKey(); | ||
247 | void slotDefaultKey(); | ||
248 | void slotCustomKey(); | ||
249 | |||
250 | |||
199 | private: | 251 | private: |
200 | OKeyConfigManager* m_manager; | 252 | void initUi(); |
253 | Opie::Ui::OListView *m_view; | ||
254 | Opie::Ui::Private::OKeyConfigWidgetPrivateList m_list; | ||
255 | QLabel *m_lbl; | ||
256 | QPushButton *m_btn; | ||
257 | QRadioButton *m_def, *m_cus, *m_none; | ||
258 | QWidget* m_box; | ||
259 | ChangeMode m_mode; | ||
201 | class Private; | 260 | class Private; |
202 | Private *d; | 261 | Private *d; |
203 | }; | 262 | }; |
204 | 263 | ||
205 | } | 264 | } |
206 | } | 265 | } |
207 | 266 | ||
208 | 267 | ||
209 | #endif | 268 | #endif |