summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-10 11:04:16 (UTC)
committer zecke <zecke>2004-09-10 11:04:16 (UTC)
commit2ec724fc789cd34f6b3743896516f2fef2731456 (patch) (unidiff)
tree67830cb237efa4201ff530bb0c66e496222a5fd3
parent29ed6115bd14aa95d29cf922fd179a6e470b5d53 (diff)
downloadopie-2ec724fc789cd34f6b3743896516f2fef2731456.zip
opie-2ec724fc789cd34f6b3743896516f2fef2731456.tar.gz
opie-2ec724fc789cd34f6b3743896516f2fef2731456.tar.bz2
Move handleWidget of OKeyConfigManager to a slot
Add some @see statements to the OKeyConfigManager
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/okeyconfigmanager.cpp10
-rw-r--r--libopie2/opiecore/okeyconfigmanager.h7
2 files changed, 14 insertions, 3 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp
index ccb96cc..891cda7 100644
--- a/libopie2/opiecore/okeyconfigmanager.cpp
+++ b/libopie2/opiecore/okeyconfigmanager.cpp
@@ -1,751 +1,761 @@
1#include "okeyconfigmanager.h" 1#include "okeyconfigmanager.h"
2 2
3#include "okeyconfigmanager_p.h" 3#include "okeyconfigmanager_p.h"
4 4
5namespace Opie { 5namespace Opie {
6namespace Core { 6namespace Core {
7namespace Internal { 7namespace Internal {
8 /* 8 /*
9 * the virtual and hardware key events have both issues... 9 * the virtual and hardware key events have both issues...
10 */ 10 */
11 void fixupKeys( int& key, int &mod, QKeyEvent* e ) { 11 void fixupKeys( int& key, int &mod, QKeyEvent* e ) {
12 key = e->key(); 12 key = e->key();
13 mod = e->state(); 13 mod = e->state();
14 /* 14 /*
15 * virtual keyboard 15 * virtual keyboard
16 * else change the button mod only 16 * else change the button mod only
17 */ 17 */
18 if ( key == 0 ) { 18 if ( key == 0 ) {
19 key = e->ascii(); 19 key = e->ascii();
20 if ( key > 96 && key < 123) 20 if ( key > 96 && key < 123)
21 key -= 32; 21 key -= 32;
22 }else{ 22 }else{
23 int new_mod = 0; 23 int new_mod = 0;
24 if ( mod & 256 ) 24 if ( mod & 256 )
25 new_mod |= Qt::ShiftButton; 25 new_mod |= Qt::ShiftButton;
26 else if ( mod & 512 ) 26 else if ( mod & 512 )
27 new_mod |= Qt::ControlButton; 27 new_mod |= Qt::ControlButton;
28 else if ( mod & 1024 ) 28 else if ( mod & 1024 )
29 new_mod |= Qt::AltButton; 29 new_mod |= Qt::AltButton;
30 30
31 mod = new_mod == 0? mod : new_mod; 31 mod = new_mod == 0? mod : new_mod;
32 } 32 }
33 } 33 }
34} 34}
35 35
36/** 36/**
37 * The default Constructor of a OKeyPair. 37 * The default Constructor of a OKeyPair.
38 * A Key and a Modifier ( Alt/Shift/Ctrl ) 38 * A Key and a Modifier ( Alt/Shift/Ctrl )
39 * needs to be supplied. 39 * needs to be supplied.
40 * Use Qt::Key for the information. 40 * Use Qt::Key for the information.
41 * The default arguments create an Empty OKeyPair. If you 41 * The default arguments create an Empty OKeyPair. If you
42 * want to get an empty OKeyPair use the static method for getting 42 * want to get an empty OKeyPair use the static method for getting
43 * the emptyKey() 43 * the emptyKey()
44 * 44 *
45 * @see OKeyPair OKeyPair::emptyKey() 45 * @see OKeyPair OKeyPair::emptyKey()
46 */ 46 */
47OKeyPair::OKeyPair( int key, int mod ) 47OKeyPair::OKeyPair( int key, int mod )
48 : m_key( key ), m_mod( mod ) 48 : m_key( key ), m_mod( mod )
49{} 49{}
50 50
51/** 51/**
52 * The destructor 52 * The destructor
53 */ 53 */
54OKeyPair::~OKeyPair() {} 54OKeyPair::~OKeyPair() {}
55 55
56 56
57/** 57/**
58 * Is this OKeyPair empty/valid? 58 * Is this OKeyPair empty/valid?
59 */ 59 */
60bool OKeyPair::isEmpty()const { 60bool OKeyPair::isEmpty()const {
61 return ( ( m_key == -1 )&& ( m_mod == -1 ) ); 61 return ( ( m_key == -1 )&& ( m_mod == -1 ) );
62} 62}
63 63
64/** 64/**
65 * get the keycode for this OKeyPair. The Key relates to Qt::Key. 65 * get the keycode for this OKeyPair. The Key relates to Qt::Key.
66 * 66 *
67 * @see Qt::Key 67 * @see Qt::Key
68 * @see setKey 68 * @see setKey
69 */ 69 */
70int OKeyPair::keycode()const { 70int OKeyPair::keycode()const {
71 return m_key; 71 return m_key;
72} 72}
73 73
74/** 74/**
75 * get the modifier key for this OKeyPair. The Modifier State relates 75 * get the modifier key for this OKeyPair. The Modifier State relates
76 * to the Qt::ButtonState 76 * to the Qt::ButtonState
77 * 77 *
78 * @see Qt::ButtonState 78 * @see Qt::ButtonState
79 * @see setModifier 79 * @see setModifier
80 */ 80 */
81int OKeyPair::modifier()const { 81int OKeyPair::modifier()const {
82 return m_mod; 82 return m_mod;
83} 83}
84 84
85 85
86/** 86/**
87 * Set the keycode 87 * Set the keycode
88 * @param key The Keycode to set 88 * @param key The Keycode to set
89 * 89 *
90 * @see keycode() 90 * @see keycode()
91 * @see Qt::Key 91 * @see Qt::Key
92 */ 92 */
93void OKeyPair::setKeycode( int key ) { 93void OKeyPair::setKeycode( int key ) {
94 m_key = key; 94 m_key = key;
95} 95}
96 96
97/** 97/**
98 * Set the modifier key 98 * Set the modifier key
99 * 99 *
100 * @param the Modifier key 100 * @param the Modifier key
101 * @see Qt::ButtonState 101 * @see Qt::ButtonState
102 * @see modifier() 102 * @see modifier()
103 */ 103 */
104void OKeyPair::setModifier( int mod ) { 104void OKeyPair::setModifier( int mod ) {
105 m_mod = mod; 105 m_mod = mod;
106} 106}
107 107
108/** 108/**
109 * Return an OKeyPair for the Return Key without any modifier. 109 * Return an OKeyPair for the Return Key without any modifier.
110 */ 110 */
111OKeyPair OKeyPair::returnKey() { 111OKeyPair OKeyPair::returnKey() {
112 return OKeyPair( Qt::Key_Return, 0 ); 112 return OKeyPair( Qt::Key_Return, 0 );
113} 113}
114 114
115/** 115/**
116 * Return an OKeyPair for the Left Arrow Key 116 * Return an OKeyPair for the Left Arrow Key
117 * without any modifier Key 117 * without any modifier Key
118 */ 118 */
119OKeyPair OKeyPair::leftArrowKey() { 119OKeyPair OKeyPair::leftArrowKey() {
120 return OKeyPair( Qt::Key_Left, 0 ); 120 return OKeyPair( Qt::Key_Left, 0 );
121} 121}
122 122
123/** 123/**
124 * Return an OKeyPair for the Right Arrow Key 124 * Return an OKeyPair for the Right Arrow Key
125 * without any modifier Key 125 * without any modifier Key
126 */ 126 */
127OKeyPair OKeyPair::rightArrowKey() { 127OKeyPair OKeyPair::rightArrowKey() {
128 return OKeyPair( Qt::Key_Right, 0 ); 128 return OKeyPair( Qt::Key_Right, 0 );
129} 129}
130 130
131/** 131/**
132 * Return an OKeyPair for the Up Arrow Key 132 * Return an OKeyPair for the Up Arrow Key
133 * without any modifier Key 133 * without any modifier Key
134 */ 134 */
135OKeyPair OKeyPair::upArrowKey() { 135OKeyPair OKeyPair::upArrowKey() {
136 return OKeyPair( Qt::Key_Up, 0 ); 136 return OKeyPair( Qt::Key_Up, 0 );
137} 137}
138 138
139/** 139/**
140 * Return an OKeyPair for the Down Arrow Key 140 * Return an OKeyPair for the Down Arrow Key
141 * without any modifier Key 141 * without any modifier Key
142 */ 142 */
143OKeyPair OKeyPair::downArrowKey() { 143OKeyPair OKeyPair::downArrowKey() {
144 return OKeyPair( Qt::Key_Down, 0 ); 144 return OKeyPair( Qt::Key_Down, 0 );
145} 145}
146 146
147/** 147/**
148 * Return an Empty OKeyPair 148 * Return an Empty OKeyPair
149 */ 149 */
150OKeyPair OKeyPair::emptyKey() { 150OKeyPair OKeyPair::emptyKey() {
151 return OKeyPair(); 151 return OKeyPair();
152} 152}
153 153
154/** 154/**
155 * This functions uses the Opie::Core::ODevice::buttons 155 * This functions uses the Opie::Core::ODevice::buttons
156 * for OKeyPairList 156 * for OKeyPairList
157 * 157 *
158 * @see Opie::Core::ODevice 158 * @see Opie::Core::ODevice
159 * @see Opie::Core::ODeviceButton 159 * @see Opie::Core::ODeviceButton
160 * @see Opie::Core::ODevice::button 160 * @see Opie::Core::ODevice::button
161 */ 161 */
162OKeyPair::List OKeyPair::hardwareKeys() { 162OKeyPair::List OKeyPair::hardwareKeys() {
163 const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); 163 const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons();
164 OKeyPair::List lst; 164 OKeyPair::List lst;
165 165
166 for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); 166 for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin();
167 it != but.end(); ++it ) 167 it != but.end(); ++it )
168 lst.append( OKeyPair( (*it).keycode(), 0 ) ); 168 lst.append( OKeyPair( (*it).keycode(), 0 ) );
169 169
170 170
171 return lst; 171 return lst;
172} 172}
173 173
174/** 174/**
175 * Equals operator. Check if two OKeyPairs have the same key and modifier 175 * Equals operator. Check if two OKeyPairs have the same key and modifier
176 * @see operator!= 176 * @see operator!=
177 */ 177 */
178bool OKeyPair::operator==( const OKeyPair& pair)const { 178bool OKeyPair::operator==( const OKeyPair& pair)const {
179 if ( m_key != pair.m_key ) return false; 179 if ( m_key != pair.m_key ) return false;
180 if ( m_mod != pair.m_mod ) return false; 180 if ( m_mod != pair.m_mod ) return false;
181 181
182 return true; 182 return true;
183} 183}
184 184
185/** 185/**
186 * Not equal operator. calls the equal operator internally 186 * Not equal operator. calls the equal operator internally
187 */ 187 */
188bool OKeyPair::operator!=( const OKeyPair& pair)const { 188bool OKeyPair::operator!=( const OKeyPair& pair)const {
189 return !(*this == pair); 189 return !(*this == pair);
190} 190}
191 191
192 192
193/** 193/**
194 * The normal Constructor to create a OKeyConfigItem 194 * The normal Constructor to create a OKeyConfigItem
195 * 195 *
196 * You can set the the key paramater of this item but if 196 * You can set the the key paramater of this item but if
197 * you use this item with the OKeyConfigManager your setting 197 * you use this item with the OKeyConfigManager your setting
198 * will be overwritten. 198 * will be overwritten.
199 * You can also specify a QObject and slot which sould get called 199 * You can also specify a QObject and slot which sould get called
200 * once this item is activated. This slot only works if you 200 * once this item is activated. This slot only works if you
201 * use the OKeyConfigManager. 201 * use the OKeyConfigManager.
202 * The actual Key is read by load() 202 * The actual Key is read by load()
203 * 203 *
204 * \code 204 * \code
205 * void MySlot::create(){ 205 * void MySlot::create(){
206 * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), 206 * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"),
207 * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), 207 * 123, OKeyPair(Qt::Key_D,Qt::ControlButton),
208 * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); 208 * this,SLOT(slotDelete(QWidget*,QKeyEvent*)));
209 * } 209 * }
210 * \endcode 210 * \endcode
211 * 211 *
212 * @param text The text exposed to the user 212 * @param text The text exposed to the user
213 * @param config_key The key used in the config 213 * @param config_key The key used in the config
214 * @param pix A Pixmap associated with this Item 214 * @param pix A Pixmap associated with this Item
215 * @param def The OKeyPair used as default 215 * @param def The OKeyPair used as default
216 * @param caller The object where the slot exists 216 * @param caller The object where the slot exists
217 * @param slot The slot which should get called 217 * @param slot The slot which should get called
218 * 218 *
219 */ 219 */
220OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, 220OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key,
221 const QPixmap& pix, int id, const OKeyPair& def, 221 const QPixmap& pix, int id, const OKeyPair& def,
222 QObject *caller, 222 QObject *caller,
223 const char* slot ) 223 const char* slot )
224 : m_text( text ), m_config( config_key ), m_pix( pix ), 224 : m_text( text ), m_config( config_key ), m_pix( pix ),
225 m_id( id ), m_def( def ), 225 m_id( id ), m_def( def ),
226 m_obj( caller ), m_str( slot ) {} 226 m_obj( caller ), m_str( slot ) {}
227 227
228/** 228/**
229 * A special Constructor for converting from an Opie::Core::ODeviceButton 229 * A special Constructor for converting from an Opie::Core::ODeviceButton
230 * delivered by Opie::Core::ODevice::buttons() 230 * delivered by Opie::Core::ODevice::buttons()
231 * There is no Config Key set and both default key and key are set 231 * There is no Config Key set and both default key and key are set
232 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier 232 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier
233 * 233 *
234 * @see Opie::Core::ODevice 234 * @see Opie::Core::ODevice
235 * @see Opie::Core::ODeviceButton 235 * @see Opie::Core::ODeviceButton
236 * @see Opie::Core::ODevice::buttons() 236 * @see Opie::Core::ODevice::buttons()
237 */ 237 */
238OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) 238OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b )
239 : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), 239 : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ),
240 m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) 240 m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) )
241{} 241{}
242 242
243 243
244/** 244/**
245 * Destructor 245 * Destructor
246 */ 246 */
247OKeyConfigItem::~OKeyConfigItem() {} 247OKeyConfigItem::~OKeyConfigItem() {}
248 248
249 249
250/** 250/**
251 * The text exposed to the user 251 * The text exposed to the user
252 * 252 *
253 * @see setText 253 * @see setText
254 */ 254 */
255QString OKeyConfigItem::text()const { 255QString OKeyConfigItem::text()const {
256 return m_text; 256 return m_text;
257} 257}
258 258
259/** 259/**
260 * The pixmap shown to the user for your action/key 260 * The pixmap shown to the user for your action/key
261 * 261 *
262 * @see setPixmap 262 * @see setPixmap
263 */ 263 */
264QPixmap OKeyConfigItem::pixmap()const { 264QPixmap OKeyConfigItem::pixmap()const {
265 return m_pix; 265 return m_pix;
266} 266}
267 267
268/** 268/**
269 * Return the OKeyPair this OKeyConfigItem is configured for. 269 * Return the OKeyPair this OKeyConfigItem is configured for.
270 * 270 *
271 * @see setKeyPair 271 * @see setKeyPair
272 */ 272 */
273OKeyPair OKeyConfigItem::keyPair()const { 273OKeyPair OKeyConfigItem::keyPair()const {
274 return m_key; 274 return m_key;
275} 275}
276 276
277/** 277/**
278 * Return the default OKeyPair 278 * Return the default OKeyPair
279 * @see setDefaultKeyPair 279 * @see setDefaultKeyPair
280 */ 280 */
281OKeyPair OKeyConfigItem::defaultKeyPair()const { 281OKeyPair OKeyConfigItem::defaultKeyPair()const {
282 return m_def; 282 return m_def;
283} 283}
284 284
285 285
286/** 286/**
287 * Return the Id you assigned to this item. 287 * Return the Id you assigned to this item.
288 * setting is only possible by the constructor 288 * setting is only possible by the constructor
289 */ 289 */
290int OKeyConfigItem::id()const{ 290int OKeyConfigItem::id()const{
291 return m_id; 291 return m_id;
292} 292}
293 293
294/** 294/**
295 * reutrn the Config Key. Setting it is only possible 295 * reutrn the Config Key. Setting it is only possible
296 * by the constructor 296 * by the constructor
297 */ 297 */
298QCString OKeyConfigItem::configKey()const { 298QCString OKeyConfigItem::configKey()const {
299 return m_config; 299 return m_config;
300} 300}
301 301
302/** 302/**
303 * @internal 303 * @internal
304 */ 304 */
305QObject* OKeyConfigItem::object()const{ 305QObject* OKeyConfigItem::object()const{
306 return m_obj; 306 return m_obj;
307} 307}
308 308
309/** 309/**
310 * @internal 310 * @internal
311 */ 311 */
312QCString OKeyConfigItem::slot()const { 312QCString OKeyConfigItem::slot()const {
313 return m_str; 313 return m_str;
314} 314}
315 315
316/** 316/**
317 * Set the text 317 * Set the text
318 * 318 *
319 * @param text Set the Text of this Action to text 319 * @param text Set the Text of this Action to text
320 * @see text() 320 * @see text()
321 */ 321 */
322void OKeyConfigItem::setText( const QString& text ) { 322void OKeyConfigItem::setText( const QString& text ) {
323 m_text = text; 323 m_text = text;
324} 324}
325 325
326/** 326/**
327 * Set the pixmap of this action 327 * Set the pixmap of this action
328 * 328 *
329 * @param pix The Pixmap to set 329 * @param pix The Pixmap to set
330 * @see pixmap() 330 * @see pixmap()
331 */ 331 */
332void OKeyConfigItem::setPixmap( const QPixmap& pix ) { 332void OKeyConfigItem::setPixmap( const QPixmap& pix ) {
333 m_pix = pix; 333 m_pix = pix;
334} 334}
335 335
336/** 336/**
337 * Set the KeyPair the OKeyConfigItem uses. 337 * Set the KeyPair the OKeyConfigItem uses.
338 * Your set Key could get overwritten if you use 338 * Your set Key could get overwritten if you use
339 * the manager or GUI to configure the key 339 * the manager or GUI to configure the key
340 * 340 *
341 * @param key Set the OKeyPair used 341 * @param key Set the OKeyPair used
342 * @see keyPair() 342 * @see keyPair()
343 */ 343 */
344void OKeyConfigItem::setKeyPair( const OKeyPair& key) { 344void OKeyConfigItem::setKeyPair( const OKeyPair& key) {
345 m_key = key; 345 m_key = key;
346} 346}
347 347
348/** 348/**
349 * Set the default KeyPair. 349 * Set the default KeyPair.
350 * 350 *
351 * @param key The default keypair 351 * @param key The default keypair
352 * @see defaultKeyPair() 352 * @see defaultKeyPair()
353 */ 353 */
354void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { 354void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) {
355 m_def = key; 355 m_def = key;
356} 356}
357 357
358/** 358/**
359 * @internal 359 * @internal
360 */ 360 */
361void OKeyConfigItem::setConfigKey( const QCString& str) { 361void OKeyConfigItem::setConfigKey( const QCString& str) {
362 m_config = str; 362 m_config = str;
363 m_config.detach(); 363 m_config.detach();
364} 364}
365 365
366/** 366/**
367 * @internal 367 * @internal
368 */ 368 */
369void OKeyConfigItem::setId( int id ) { 369void OKeyConfigItem::setId( int id ) {
370 m_id = id; 370 m_id = id;
371} 371}
372 372
373/** 373/**
374 * If the item is not configured isEmpty() will return true 374 * If the item is not configured isEmpty() will return true
375 * It is empty if no text is present and no default 375 * It is empty if no text is present and no default
376 * and no configured key 376 * and no configured key
377 */ 377 */
378bool OKeyConfigItem::isEmpty()const { 378bool OKeyConfigItem::isEmpty()const {
379 if ( !m_def.isEmpty() ) return false; 379 if ( !m_def.isEmpty() ) return false;
380 if ( !m_key.isEmpty() ) return false; 380 if ( !m_key.isEmpty() ) return false;
381 if ( !m_text.isEmpty() ) return false; 381 if ( !m_text.isEmpty() ) return false;
382 if ( m_id != -1 ) return false; 382 if ( m_id != -1 ) return false;
383 383
384 return true; 384 return true;
385} 385}
386 386
387/** 387/**
388 * Check if the KeyPairs are the same 388 * Check if the KeyPairs are the same
389 */ 389 */
390bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { 390bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const {
391/* if ( isEmpty() == conf.isEmpty() ) return true; 391/* if ( isEmpty() == conf.isEmpty() ) return true;
392 else if ( isEmpty() != conf.isEmpty() ) return false; 392 else if ( isEmpty() != conf.isEmpty() ) return false;
393 else if ( !isEmpty()!= conf.isEmpty() ) return false; 393 else if ( !isEmpty()!= conf.isEmpty() ) return false;
394*/ 394*/
395 395
396 if ( m_id != conf.m_id ) return false; 396 if ( m_id != conf.m_id ) return false;
397 if ( m_obj != conf.m_obj ) return false; 397 if ( m_obj != conf.m_obj ) return false;
398 if ( m_text != conf.m_text ) return false; 398 if ( m_text != conf.m_text ) return false;
399 if ( m_key != conf.m_key ) return false; 399 if ( m_key != conf.m_key ) return false;
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 412/*! \enum OKeyConfigManager::EventMask
413 <a name="Eventmask flags"></a> 413 <a name="Eventmask flags"></a>
414 This enum is used to tell OKeyConfigManager which type of key events should inspected. 414 This enum is used to tell OKeyConfigManager which type of key events should inspected.
415 415
416 <ul> 416 <ul>
417 <li>\c MaskPressed When a key is pressed an action performs 417 <li>\c MaskPressed When a key is pressed an action performs
418 <li>\c MaskReleased When a key is released an action performs 418 <li>\c MaskReleased When a key is released an action performs
419 </ul> 419 </ul>
420*/ 420*/
421 421
422/** 422/**
423 * \brief c'tor 423 * \brief c'tor
424 * The Constructor for a OKeyConfigManager 424 * The Constructor for a OKeyConfigManager
425 * 425 *
426 * 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
427 * QKeyEvents. The EventMask is set to OKeyConfigManager::MaskReleased by default. 427 * QKeyEvents. The EventMask is set to OKeyConfigManager::MaskReleased by default.
428 * 428 *
429 * \code 429 * \code
430 * Opie::Core::Config conf = oApp->config(); 430 * Opie::Core::Config conf = oApp->config();
431 * Opie::Core::OKeyPairList blackList; 431 * Opie::Core::OKeyPairList blackList;
432 * blackList.append(Opie::Core::OKeyPair::leftArrowKey()); 432 * blackList.append(Opie::Core::OKeyPair::leftArrowKey());
433 * blackList.append(Opie::Core::OKeyPair::rightArrowKey()); 433 * blackList.append(Opie::Core::OKeyPair::rightArrowKey());
434 * 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,
435 * false); 435 * false);
436 * QListView *view = new QListView(); 436 * QListView *view = new QListView();
437 * manager->handleWidget(view); 437 * manager->handleWidget(view);
438 * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey()); 438 * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey());
439 * manager->load(); 439 * manager->load();
440 * 440 *
441 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), 441 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)),
442 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&))); 442 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)));
443 * 443 *
444 * .... 444 * ....
445 * 445 *
446 * void update(){ 446 * void update(){
447 * QDialog diag(true); 447 * QDialog diag(true);
448 * QHBoxLayout *lay = new QHBoxLayout(&diag); 448 * QHBoxLayout *lay = new QHBoxLayout(&diag);
449 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); 449 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag);
450 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); 450 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu);
451 * lay->addWidget(wid); 451 * lay->addWidget(wid);
452 * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ 452 * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){
453 * wid->save(); 453 * wid->save();
454 * } 454 * }
455 * } 455 * }
456 * 456 *
457 * .... 457 * ....
458 * MyListView::keyPressEvent( QKeyEvent* e ){ 458 * MyListView::keyPressEvent( QKeyEvent* e ){
459 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); 459 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e);
460 * if(!item.isEmpty() ){ 460 * if(!item.isEmpty() ){
461 * switch(item.id()){ 461 * switch(item.id()){
462 * case My_Delete_Key: 462 * case My_Delete_Key:
463 * break; 463 * break;
464 * } 464 * }
465 * } 465 * }
466 * } 466 * }
467 * 467 *
468 * \endcode 468 * \endcode
469 * 469 *
470 * @param conf The Config where the KeySetting should be stored 470 * @param conf The Config where the KeySetting should be stored
471 * @param group The group where the KeySetting will be stored 471 * @param group The group where the KeySetting will be stored
472 * @param black Which keys shouldn't be allowed to handle 472 * @param black Which keys shouldn't be allowed to handle
473 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons 473 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons
474 * @param par The parent/owner of this manager 474 * @param par The parent/owner of this manager
475 * @param name The name of this object 475 * @param name The name of this object
476 */ 476 */
477OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, 477OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
478 const QString& group, 478 const QString& group,
479 const OKeyPair::List& black, 479 const OKeyPair::List& black,
480 bool grabkeyboard, QObject* par, 480 bool grabkeyboard, QObject* par,
481 const char* name) 481 const char* name)
482 : QObject( par, name ), m_conf( conf ), m_group( group ), 482 : QObject( par, name ), m_conf( conf ), m_group( group ),
483 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ 483 m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){
484 if ( m_grab ) 484 if ( m_grab )
485 QPEApplication::grabKeyboard(); 485 QPEApplication::grabKeyboard();
486 m_event_mask = OKeyConfigManager::MaskReleased; 486 m_event_mask = OKeyConfigManager::MaskReleased;
487} 487}
488 488
489 489
490/** 490/**
491 * Destructor 491 * Destructor
492 */ 492 */
493OKeyConfigManager::~OKeyConfigManager() { 493OKeyConfigManager::~OKeyConfigManager() {
494 if ( m_grab ) 494 if ( m_grab )
495 QPEApplication::ungrabKeyboard(); 495 QPEApplication::ungrabKeyboard();
496 delete m_map; 496 delete m_map;
497} 497}
498 498
499/** 499/**
500 * Load the Configuration from the OConfig 500 * Load the Configuration from the OConfig
501 * If a Key is restricted but was in the config we will 501 * If a Key is restricted but was in the config we will
502 * make it be the empty key paur 502 * make it be the empty key paur
503 * We will change the group but restore to the previous. 503 * We will change the group but restore to the previous.
504 * 504 *
505 * @see OKeyPair::emptyKey 505 * @see OKeyPair::emptyKey
506 */ 506 */
507void OKeyConfigManager::load() { 507void OKeyConfigManager::load() {
508 Opie::Core::OConfigGroupSaver grp( m_conf, m_group ); 508 Opie::Core::OConfigGroupSaver grp( m_conf, m_group );
509 509
510 /* 510 /*
511 * Read each item 511 * Read each item
512 */ 512 */
513 int key, mod; 513 int key, mod;
514 for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { 514 for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) {
515 key = m_conf->readNumEntry( (*it).configKey()+"key", 515 key = m_conf->readNumEntry( (*it).configKey()+"key",
516 (*it).defaultKeyPair().keycode() ); 516 (*it).defaultKeyPair().keycode() );
517 mod = m_conf->readNumEntry( (*it).configKey()+"mod", 517 mod = m_conf->readNumEntry( (*it).configKey()+"mod",
518 (*it).defaultKeyPair().modifier() ); 518 (*it).defaultKeyPair().modifier() );
519 OKeyPair okey( key, mod ); 519 OKeyPair okey( key, mod );
520 520
521 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) 521 if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 )
522 (*it).setKeyPair( okey ); 522 (*it).setKeyPair( okey );
523 else 523 else
524 (*it).setKeyPair( OKeyPair::emptyKey() ); 524 (*it).setKeyPair( OKeyPair::emptyKey() );
525 } 525 }
526 delete m_map; m_map = 0; 526 delete m_map; m_map = 0;
527} 527}
528 528
529/** 529/**
530 * We will save the current configuration 530 * We will save the current configuration
531 * to the OConfig. We will change the group but restore 531 * to the OConfig. We will change the group but restore
532 * to the previous 532 * to the previous
533 */ 533 */
534void OKeyConfigManager::save() { 534void OKeyConfigManager::save() {
535 Opie::Core::OConfigGroupSaver grp( m_conf, m_group ); 535 Opie::Core::OConfigGroupSaver grp( m_conf, m_group );
536 536
537 /* 537 /*
538 * Write each item 538 * Write each item
539 */ 539 */
540 for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { 540 for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) {
541 /* skip empty items */ 541 /* skip empty items */
542 if ( (*it).isEmpty() ) 542 if ( (*it).isEmpty() )
543 continue; 543 continue;
544 OKeyPair pair = (*it).keyPair(); 544 OKeyPair pair = (*it).keyPair();
545 OKeyPair deft = (*it).defaultKeyPair(); 545 OKeyPair deft = (*it).defaultKeyPair();
546 /* 546 /*
547 * don't write if it is the default setting 547 * don't write if it is the default setting
548 * FIXME allow to remove Keys from config 548 * FIXME allow to remove Keys from config
549 if ( (pair.keycode() == deft.keycode()) && 549 if ( (pair.keycode() == deft.keycode()) &&
550 (pair.modifier()== deft.modifier() ) ) 550 (pair.modifier()== deft.modifier() ) )
551 return; 551 return;
552 */ 552 */
553 553
554 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); 554 m_conf->writeEntry((*it).configKey()+"key", pair.keycode() );
555 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); 555 m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() );
556 } 556 }
557 m_conf->write(); 557 m_conf->write();
558} 558}
559 559
560/** 560/**
561 * This is function uses a QMap internally but you can have the same keycode 561 * This is function uses a QMap internally but you can have the same keycode
562 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem 562 * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem
563 * with same keycode and modifier key. The GUI takes care that a user can't 563 * with same keycode and modifier key. The GUI takes care that a user can't
564 * cofigure two keys. 564 * cofigure two keys.
565 * 565 *
566 * Make sure you call e->ignore if you don't want to handle this event 566 * Make sure you call e->ignore if you don't want to handle this event
567 */ 567 */
568OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { 568OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) {
569 /* 569 /*
570 * Fix Up issues with Qt/E, my keybard, and virtual input 570 * Fix Up issues with Qt/E, my keybard, and virtual input
571 * methods 571 * methods
572 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state 572 * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state
573 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower 573 * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower
574 * case ascii 574 * case ascii
575 */ 575 */
576 int key, mod; 576 int key, mod;
577 Opie::Core::Internal::fixupKeys( key, mod, e ); 577 Opie::Core::Internal::fixupKeys( key, mod, e );
578 578
579 OKeyConfigItem::List _keyList = keyList( key ); 579 OKeyConfigItem::List _keyList = keyList( key );
580 if ( _keyList.isEmpty() ) 580 if ( _keyList.isEmpty() )
581 return OKeyConfigItem(); 581 return OKeyConfigItem();
582 582
583 OKeyConfigItem item; 583 OKeyConfigItem item;
584 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); 584 for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end();
585 ++it ) { 585 ++it ) {
586 if ( (*it).keyPair().modifier() == mod ) { 586 if ( (*it).keyPair().modifier() == mod ) {
587 item = *it; 587 item = *it;
588 break; 588 break;
589 } 589 }
590 590
591 } 591 }
592 592
593 return item; 593 return item;
594} 594}
595 595
596/** 596/**
597 * Return the associated id of the item or -1 if no item 597 * Return the associated id of the item or -1 if no item
598 * matched the key 598 * matched the key
599 * 599 *
600 * @see handleKeyEvent 600 * @see handleKeyEvent
601 */ 601 */
602int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { 602int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) {
603 return handleKeyEvent( ev ).id(); 603 return handleKeyEvent( ev ).id();
604} 604}
605 605
606/** 606/**
607 * Add Key Config to the List of items 607 * Add Key Config to the List of items
608 */ 608 */
609void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { 609void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) {
610 m_keys.append( item ); 610 m_keys.append( item );
611 delete m_map; m_map = 0; 611 delete m_map; m_map = 0;
612} 612}
613 613
614/** 614/**
615 * Remove the Key from the Config. Internal lists will be destroyed 615 * Remove the Key from the Config. Internal lists will be destroyed
616 * and rebuild on demand later 616 * and rebuild on demand later
617 */ 617 */
618void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { 618void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) {
619 m_keys.remove( item ); 619 m_keys.remove( item );
620 delete m_map; m_map = 0; 620 delete m_map; m_map = 0;
621} 621}
622 622
623/** 623/**
624 * Clears the complete list 624 * Clears the complete list
625 */ 625 */
626void OKeyConfigManager::clearKeyConfig() { 626void OKeyConfigManager::clearKeyConfig() {
627 m_keys.clear(); 627 m_keys.clear();
628 delete m_map; m_map = 0; 628 delete m_map; m_map = 0;
629} 629}
630 630
631/** 631/**
632 * 632 *
633 */ 633 */
634Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ 634Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{
635 return m_keys; 635 return m_keys;
636} 636}
637 637
638/** 638/**
639 * Add this OKeyPair to the blackList. 639 * Add this OKeyPair to the blackList.
640 * Internal lists will be destroyed 640 * Internal lists will be destroyed
641 *
642 * @see clearBlackList
643 * @see removeFromBlackList
641 */ 644 */
642void OKeyConfigManager::addToBlackList( const OKeyPair& key) { 645void OKeyConfigManager::addToBlackList( const OKeyPair& key) {
643 m_blackKeys.append( key ); 646 m_blackKeys.append( key );
644 delete m_map; m_map = 0; 647 delete m_map; m_map = 0;
645} 648}
646 649
647 650
648/** 651/**
649 * Remove this OKeyPair from the black List 652 * Remove this OKeyPair from the black List
650 * Internal lists will be destroyed 653 * Internal lists will be destroyed
654 *
655 * @see addToBlackList
656 * @see clearBlackList
651 */ 657 */
652void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { 658void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) {
653 m_blackKeys.remove( key ); 659 m_blackKeys.remove( key );
654 delete m_map; m_map = 0; 660 delete m_map; m_map = 0;
655} 661}
656 662
657 663
658/** 664/**
659 * Clear the blackList 665 * Clear the blackList
660 */ 666 */
661void OKeyConfigManager::clearBlackList() { 667void OKeyConfigManager::clearBlackList() {
662 m_blackKeys.clear(); 668 m_blackKeys.clear();
663 delete m_map; m_map = 0; 669 delete m_map; m_map = 0;
664} 670}
665 671
666 672
667/** 673/**
668 * Return a copy of the blackList 674 * Return a copy of the blackList
675 *
676 * @see addToBlackList
677 * @see clearBlackList
678 * @see removeFromBlackList
669 */ 679 */
670OKeyPair::List OKeyConfigManager::blackList()const { 680OKeyPair::List OKeyConfigManager::blackList()const {
671 return m_blackKeys; 681 return m_blackKeys;
672} 682}
673 683
674 684
675/** 685/**
676 * Ask the Manager to handle KeyEvents for you. 686 * Ask the Manager to handle KeyEvents for you.
677 * All handled keys will emit a QSignal and return true 687 * All handled keys will emit a QSignal and return true
678 * that it handled the keyevent 688 * that it handled the keyevent
679 */ 689 */
680void OKeyConfigManager::handleWidget( QWidget* wid ) { 690void OKeyConfigManager::handleWidget( QWidget* wid ) {
681 wid->installEventFilter( this ); 691 wid->installEventFilter( this );
682} 692}
683 693
684/** 694/**
685 * @internal 695 * @internal
686 */ 696 */
687bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { 697bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
688 if ( !obj->isWidgetType() ) 698 if ( !obj->isWidgetType() )
689 return false; 699 return false;
690 700
691 /* 701 /*
692 * check if we care for the event 702 * check if we care for the event
693 */ 703 */
694 if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && 704 if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) &&
695 (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) 705 (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) )
696 return false; 706 return false;
697 707
698 QKeyEvent *key = static_cast<QKeyEvent*>( ev ); 708 QKeyEvent *key = static_cast<QKeyEvent*>( ev );
699 OKeyConfigItem item = handleKeyEvent( key ); 709 OKeyConfigItem item = handleKeyEvent( key );
700 710
701 if ( item.isEmpty() ) 711 if ( item.isEmpty() )
702 return false; 712 return false;
703 713
704 QWidget *wid = static_cast<QWidget*>( obj ); 714 QWidget *wid = static_cast<QWidget*>( obj );
705 715
706 if ( item.object() && !item.slot().isEmpty() ) { 716 if ( item.object() && !item.slot().isEmpty() ) {
707 connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), 717 connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)),
708 item.object(), item.slot().data() ); 718 item.object(), item.slot().data() );
709 emit actionActivated(wid, key); 719 emit actionActivated(wid, key);
710 disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), 720 disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)),
711 item.object(), item.slot().data() ); 721 item.object(), item.slot().data() );
712 } 722 }
713 emit actionActivated( wid, key, item ); 723 emit actionActivated( wid, key, item );
714 724
715 return true; 725 return true;
716} 726}
717 727
718/** 728/**
719 * @internal 729 * @internal
720 */ 730 */
721OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { 731OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) {
722 /* 732 /*
723 * Create the map if not existing anymore 733 * Create the map if not existing anymore
724 */ 734 */
725 if ( !m_map ) { 735 if ( !m_map ) {
726 m_map = new OKeyMapConfigPrivate; 736 m_map = new OKeyMapConfigPrivate;
727 /* for every key */ 737 /* for every key */
728 for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); 738 for ( OKeyConfigItem::List::Iterator it = m_keys.begin();
729 it!= m_keys.end(); ++it ) { 739 it!= m_keys.end(); ++it ) {
730 740
731 bool add = true; 741 bool add = true;
732 /* see if this key is blocked */ 742 /* see if this key is blocked */
733 OKeyPair pair = (*it).keyPair(); 743 OKeyPair pair = (*it).keyPair();
734 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); 744 for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin();
735 pairIt != m_blackKeys.end(); ++pairIt ) { 745 pairIt != m_blackKeys.end(); ++pairIt ) {
736 if ( (*pairIt).keycode() == pair.keycode() && 746 if ( (*pairIt).keycode() == pair.keycode() &&
737 (*pairIt).modifier() == pair.modifier() ) { 747 (*pairIt).modifier() == pair.modifier() ) {
738 add = false; 748 add = false;
739 break; 749 break;
740 } 750 }
741 } 751 }
742 /* check if we added it */ 752 /* check if we added it */
743 if ( add ) 753 if ( add )
744 (*m_map)[pair.keycode()].append( *it ); 754 (*m_map)[pair.keycode()].append( *it );
745 } 755 }
746 } 756 }
747 return (*m_map)[keycode]; 757 return (*m_map)[keycode];
748} 758}
749 759
750} 760}
751} 761}
diff --git a/libopie2/opiecore/okeyconfigmanager.h b/libopie2/opiecore/okeyconfigmanager.h
index d0a6247..12804ee 100644
--- a/libopie2/opiecore/okeyconfigmanager.h
+++ b/libopie2/opiecore/okeyconfigmanager.h
@@ -1,280 +1,281 @@
1/* 1/*
2 * Copyright (C) 2004 2 * Copyright (C) 2004
3 * LGPL v2 zecke@handhelds.org 3 * LGPL v2 zecke@handhelds.org
4 */ 4 */
5 5
6 6
7#ifndef ODP_KEY_MANAGER_WIDGET_H 7#ifndef ODP_KEY_MANAGER_WIDGET_H
8#define ODP_KEY_MANAGER_WIDGET_H 8#define ODP_KEY_MANAGER_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 <qcstring.h> 15#include <qcstring.h>
16#include <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18namespace Opie { 18namespace Opie {
19namespace Core { 19namespace Core {
20 20
21/** 21/**
22 * \brief small class representing a Key with possible modifiers 22 * \brief small class representing a Key with possible modifiers
23 * This class holds information about key code and possible 23 * This class holds information about key code and possible
24 * modifier state. That is the lowest level of the key input 24 * modifier state. That is the lowest level of the key input
25 * functions. 25 * functions.
26 * There are also static methods to get special keys. 26 * There are also static methods to get special keys.
27 * OKeyPair will be used with \see OKeyConfigItem 27 * OKeyPair will be used with \see OKeyConfigItem
28 * 28 *
29 * @since 1.2 29 * @since 1.2
30 */ 30 */
31class OKeyPair { 31class OKeyPair {
32public: 32public:
33 typedef QValueList<OKeyPair> List; 33 typedef QValueList<OKeyPair> List;
34 OKeyPair( int key = -1, int modifier = -1); 34 OKeyPair( int key = -1, int modifier = -1);
35 ~OKeyPair(); 35 ~OKeyPair();
36 36
37 bool operator==( const OKeyPair& )const; 37 bool operator==( const OKeyPair& )const;
38 bool operator!=( const OKeyPair& )const; 38 bool operator!=( const OKeyPair& )const;
39 39
40 bool isEmpty()const; 40 bool isEmpty()const;
41 41
42 int keycode()const; 42 int keycode()const;
43 int modifier()const; 43 int modifier()const;
44 44
45 void setKeycode( int ); 45 void setKeycode( int );
46 void setModifier( int ); 46 void setModifier( int );
47 47
48 static OKeyPair returnKey(); 48 static OKeyPair returnKey();
49 static OKeyPair leftArrowKey(); 49 static OKeyPair leftArrowKey();
50 static OKeyPair rightArrowKey(); 50 static OKeyPair rightArrowKey();
51 static OKeyPair upArrowKey(); 51 static OKeyPair upArrowKey();
52 static OKeyPair downArrowKey(); 52 static OKeyPair downArrowKey();
53 static OKeyPair emptyKey(); 53 static OKeyPair emptyKey();
54 static OKeyPair::List hardwareKeys(); 54 static OKeyPair::List hardwareKeys();
55 55
56private: 56private:
57 int m_key; 57 int m_key;
58 int m_mod; 58 int m_mod;
59 class Private; 59 class Private;
60 Private* d; 60 Private* d;
61}; 61};
62 62
63/** 63/**
64 * A class to represent an OKeyPair. 64 * A class to represent an OKeyPair.
65 * It consists out of a Text exposed to the user, Config Key Item, 65 * It consists out of a Text exposed to the user, Config Key Item,
66 * Pixmap, A default OKeyPair and the set OKeyPair. 66 * Pixmap, A default OKeyPair and the set OKeyPair.
67 * You can also pass an id to it 67 * You can also pass an id to it
68 * 68 *
69 * @since 1.1.2 69 * @since 1.2
70 */ 70 */
71class OKeyConfigItem { 71class OKeyConfigItem {
72 friend class OKeyConfigManager; 72 friend class OKeyConfigManager;
73public: 73public:
74 typedef QValueList<OKeyConfigItem> List; 74 typedef QValueList<OKeyConfigItem> List;
75 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), 75 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(),
76 const QPixmap& symbol = QPixmap(), 76 const QPixmap& symbol = QPixmap(),
77 int id = -1, 77 int id = -1,
78 const OKeyPair& def = OKeyPair::emptyKey(), 78 const OKeyPair& def = OKeyPair::emptyKey(),
79 QObject *caller = 0, const char* slot = 0); 79 QObject *caller = 0, const char* slot = 0);
80 OKeyConfigItem( const Opie::Core::ODeviceButton& ); 80 OKeyConfigItem( const Opie::Core::ODeviceButton& );
81 ~OKeyConfigItem(); 81 ~OKeyConfigItem();
82 82
83 bool operator==( const OKeyConfigItem& )const; 83 bool operator==( const OKeyConfigItem& )const;
84 bool operator!=( const OKeyConfigItem& )const; 84 bool operator!=( const OKeyConfigItem& )const;
85 85
86 QString text()const; 86 QString text()const;
87 QPixmap pixmap()const; 87 QPixmap pixmap()const;
88 int id()const; 88 int id()const;
89 89
90 90
91 91
92 OKeyPair keyPair()const; 92 OKeyPair keyPair()const;
93 OKeyPair defaultKeyPair()const; 93 OKeyPair defaultKeyPair()const;
94 QCString configKey()const; 94 QCString configKey()const;
95 95
96 96
97 void setText( const QString& text ); 97 void setText( const QString& text );
98 void setPixmap( const QPixmap& ); 98 void setPixmap( const QPixmap& );
99 void setKeyPair( const OKeyPair& ); 99 void setKeyPair( const OKeyPair& );
100 void setDefaultKeyPair( const OKeyPair& ); 100 void setDefaultKeyPair( const OKeyPair& );
101 101
102 bool isEmpty()const; 102 bool isEmpty()const;
103 103
104protected: 104protected:
105 QObject *object()const; 105 QObject *object()const;
106 QCString slot()const; 106 QCString slot()const;
107 void setId( int id ); 107 void setId( int id );
108 void setConfigKey( const QCString& ); 108 void setConfigKey( const QCString& );
109 109
110private: 110private:
111 QString m_text; 111 QString m_text;
112 QCString m_config; 112 QCString m_config;
113 QPixmap m_pix; 113 QPixmap m_pix;
114 int m_id; 114 int m_id;
115 OKeyPair m_key; 115 OKeyPair m_key;
116 OKeyPair m_def; 116 OKeyPair m_def;
117 QObject *m_obj; 117 QObject *m_obj;
118 QCString m_str; 118 QCString m_str;
119 class Private; 119 class Private;
120 Private *d; 120 Private *d;
121}; 121};
122 122
123 123
124 124
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 and save yourself! 137 * You need to load and save yourself!
138 * 138 *
139 * Again if you want to extend it and I missed a virtual, tell me so I can improve (zecke@handhelds.org) 139 * Again if you want to extend it and I missed a virtual, tell me so I can improve (zecke@handhelds.org)
140 * 140 *
141 * @since 1.1.2 141 * @since 1.1.2
142 */ 142 */
143class OKeyConfigManager : public QObject { 143class OKeyConfigManager : public QObject {
144 Q_OBJECT 144 Q_OBJECT
145 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; 145 typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate;
146public: 146public:
147 enum EventMask { 147 enum EventMask {
148 MaskPressed = 0x1, 148 MaskPressed = 0x1,
149 MaskReleased = 0x2, 149 MaskReleased = 0x2,
150 }; 150 };
151 151
152 OKeyConfigManager(Opie::Core::OConfig *conf = 0, 152 OKeyConfigManager(Opie::Core::OConfig *conf = 0,
153 const QString& group = QString::null, 153 const QString& group = QString::null,
154 const OKeyPair::List &block = OKeyPair::List(), 154 const OKeyPair::List &block = OKeyPair::List(),
155 bool grabkeyboard = false, QObject * par = 0, 155 bool grabkeyboard = false, QObject * par = 0,
156 const char* name = 0 ); 156 const char* name = 0 );
157 virtual ~OKeyConfigManager(); 157 virtual ~OKeyConfigManager();
158 158
159public slots:
159 virtual void load(); 160 virtual void load();
160 virtual void save(); 161 virtual void save();
162 void handleWidget( QWidget* );
161 163
164public:
162 virtual OKeyConfigItem handleKeyEvent( QKeyEvent* ); 165 virtual OKeyConfigItem handleKeyEvent( QKeyEvent* );
163 int handleKeyEventId( QKeyEvent* ); 166 int handleKeyEventId( QKeyEvent* );
164 167
165 void addKeyConfig( const OKeyConfigItem& ); 168 void addKeyConfig( const OKeyConfigItem& );
166 void removeKeyConfig( const OKeyConfigItem& ); 169 void removeKeyConfig( const OKeyConfigItem& );
167 void clearKeyConfig(); 170 void clearKeyConfig();
168 171
169 void addToBlackList( const OKeyPair& ); 172 void addToBlackList( const OKeyPair& );
170 void removeFromBlackList( const OKeyPair& ); 173 void removeFromBlackList( const OKeyPair& );
171 void clearBlackList(); 174 void clearBlackList();
172 OKeyPair::List blackList()const; 175 OKeyPair::List blackList()const;
173 176
174 void handleWidget( QWidget* );
175
176 bool eventFilter( QObject*, QEvent* ); 177 bool eventFilter( QObject*, QEvent* );
177 178
178 /** 179 /**
179 * Sets the event mask flags aMask. 180 * Sets the event mask flags aMask.
180 * 181 *
181 * aMask is a combination of OKeyConfigManager::EventMask 182 * aMask is a combination of OKeyConfigManager::EventMask
182 * 183 *
183 * @see eventMask(), testEventMask(), addEventMask(), clearEventMask() 184 * @see eventMask(), testEventMask(), addEventMask(), clearEventMask()
184 */ 185 */
185 void setEventMask(uint aMask); 186 void setEventMask(uint aMask);
186 /** 187 /**
187 * Returns the event mask flags set. 188 * Returns the event mask flags set.
188 * 189 *
189 * aMask is a combination of OKeyConfigManager::EventMask 190 * aMask is a combination of OKeyConfigManager::EventMask
190 * 191 *
191 * @see setEventMask(), testEventMask(), addEventMask(), clearEventMask() 192 * @see setEventMask(), testEventMask(), addEventMask(), clearEventMask()
192 */ 193 */
193 uint eventMask()const; 194 uint eventMask()const;
194 /** 195 /**
195 * Test if the event mask flag aMask is set. 196 * Test if the event mask flag aMask is set.
196 * 197 *
197 * @param aMask one of OKeyConfigManager::EventMask 198 * @param aMask one of OKeyConfigManager::EventMask
198 * 199 *
199 * @see eventMask(), setEventMask(), addEventMask(), clearEventMask() 200 * @see eventMask(), setEventMask(), addEventMask(), clearEventMask()
200 */ 201 */
201 bool testEventMask(uint aMask); 202 bool testEventMask(uint aMask);
202 /** 203 /**
203 * Add the event mask flag aMask. 204 * Add the event mask flag aMask.
204 * 205 *
205 * @param aMask one of OKeyConfigManager::EventMask 206 * @param aMask one of OKeyConfigManager::EventMask
206 * 207 *
207 * @see eventMask(), setEventMask(), addEventMask(), clearEventMask() 208 * @see eventMask(), setEventMask(), addEventMask(), clearEventMask()
208 */ 209 */
209 void addEventMask(uint aMask); 210 void addEventMask(uint aMask);
210 /** 211 /**
211 * Clears the event mask flag aMask. 212 * Clears the event mask flag aMask.
212 * 213 *
213 * @param aMask is one of OKeyConfigManager::EventMask 214 * @param aMask is one of OKeyConfigManager::EventMask
214 * 215 *
215 * @see eventMask(), testEventMask(), addEventMask(), setEventMask() 216 * @see eventMask(), testEventMask(), addEventMask(), setEventMask()
216 */ 217 */
217 void clearEventMask(uint aMask); 218 void clearEventMask(uint aMask);
218 219
219 OKeyConfigItem::List keyConfigList()const; 220 OKeyConfigItem::List keyConfigList()const;
220 221
221signals: 222signals:
222 /** 223 /**
223 * The Signals are triggered on KeyPress and KeyRelease! 224 * The Signals are triggered on KeyPress and KeyRelease!
224 * You can check the isDown of the QKeyEvent 225 * You can check the isDown of the QKeyEvent
225 * @see QKeyEvent 226 * @see QKeyEvent
226 */ 227 */
227 void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); 228 void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& );
228 229
229 /** 230 /**
230 * This Signal correspondents to the OKeyConfigItem slot 231 * This Signal correspondents to the OKeyConfigItem slot
231 * and object 232 * and object
232 * 233 *
233 * @see OKeyConfigItem::slot 234 * @see OKeyConfigItem::slot
234 * @see OKeyConfigItem::object 235 * @see OKeyConfigItem::object
235 */ 236 */
236 void actionActivated( QWidget* par, QKeyEvent* key); 237 void actionActivated( QWidget* par, QKeyEvent* key);
237 238
238private: 239private:
239 OKeyConfigItem::List keyList( int ); 240 OKeyConfigItem::List keyList( int );
240 OKeyConfigItem::List m_keys; 241 OKeyConfigItem::List m_keys;
241 QValueList<QWidget*> m_widgets; 242 QValueList<QWidget*> m_widgets;
242 Opie::Core::OConfig *m_conf; 243 Opie::Core::OConfig *m_conf;
243 QString m_group; 244 QString m_group;
244 OKeyPair::List m_blackKeys; 245 OKeyPair::List m_blackKeys;
245 bool m_grab : 1; 246 bool m_grab : 1;
246 OKeyMapConfigPrivate *m_map; 247 OKeyMapConfigPrivate *m_map;
247 class Private; 248 class Private;
248 Private *d; 249 Private *d;
249 uint m_event_mask; 250 uint m_event_mask;
250}; 251};
251 252
252inline bool OKeyConfigManager::testEventMask(uint aMask) 253inline bool OKeyConfigManager::testEventMask(uint aMask)
253{ 254{
254 return (m_event_mask&aMask)!=0; 255 return (m_event_mask&aMask)!=0;
255} 256}
256 257
257inline void OKeyConfigManager::addEventMask(uint aMask) 258inline void OKeyConfigManager::addEventMask(uint aMask)
258{ 259{
259 m_event_mask |= aMask; 260 m_event_mask |= aMask;
260} 261}
261 262
262inline void OKeyConfigManager::clearEventMask(uint aMask) 263inline void OKeyConfigManager::clearEventMask(uint aMask)
263{ 264{
264 m_event_mask &= ~aMask; 265 m_event_mask &= ~aMask;
265} 266}
266 267
267inline void OKeyConfigManager::setEventMask(uint aMask) 268inline void OKeyConfigManager::setEventMask(uint aMask)
268{ 269{
269 m_event_mask = aMask; 270 m_event_mask = aMask;
270} 271}
271 272
272inline uint OKeyConfigManager::eventMask()const 273inline uint OKeyConfigManager::eventMask()const
273{ 274{
274 return m_event_mask; 275 return m_event_mask;
275} 276}
276 277
277} 278}
278} 279}
279 280
280#endif 281#endif