author | zecke <zecke> | 2004-04-13 14:53:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-13 14:53:58 (UTC) |
commit | b51d88d7b0b517b71ae3b59d8228335f38ca9fc7 (patch) (unidiff) | |
tree | 302377973a897934c944c7a126e5e0a510694979 /libopie2/opieui | |
parent | c4c842558e1457f64d43b237f24f6ea1a4f9d76b (diff) | |
download | opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.zip opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.tar.gz opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.tar.bz2 |
Split the KeyConfig Manager and Widget into Ui and Core parts
Adjust the only user...
Don't add a 2nd example to core but mention the one for the classes
in opieui/okeyconfigwidget
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 742 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 199 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget_p.h | 22 |
3 files changed, 29 insertions, 934 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index d6d34f5..1991381 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -1,1249 +1,527 @@ | |||
1 | #include "okeyconfigwidget.h" | 1 | #include "okeyconfigwidget.h" |
2 | #include "okeyconfigwidget_p.h" | 2 | #include "okeyconfigwidget_p.h" |
3 | 3 | ||
4 | 4 | ||
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qradiobutton.h> | 6 | #include <qradiobutton.h> |
7 | #include <qpushbutton.h> | 7 | #include <qpushbutton.h> |
8 | #include <qbuttongroup.h> | 8 | #include <qbuttongroup.h> |
9 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
10 | #include <qaccel.h> | 10 | #include <qaccel.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | #include <qlabel.h> | 12 | #include <qlabel.h> |
13 | 13 | ||
14 | /* non gui */ | 14 | /* non gui */ |
15 | #include <qtimer.h> | 15 | #include <qtimer.h> |
16 | 16 | ||
17 | 17 | using Opie::Core::OKeyConfigItem; | |
18 | using namespace Opie::Ui; | 18 | using Opie::Core::OKeyPair; |
19 | 19 | using Opie::Core::OKeyConfigManager; | |
20 | |||
21 | |||
22 | /** | ||
23 | * The default Constructor of a OKeyPair. | ||
24 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | ||
25 | * needs to be supplied. | ||
26 | * Use Qt::Key for the information. | ||
27 | * The default arguments create an Empty OKeyPair. If you | ||
28 | * want to get an empty OKeyPair use the static method for getting | ||
29 | * the emptyKey() | ||
30 | * | ||
31 | * @see OKeyPair OKeyPair::emptyKey() | ||
32 | */ | ||
33 | OKeyPair::OKeyPair( int key, int mod ) | ||
34 | : m_key( key ), m_mod( mod ) | ||
35 | {} | ||
36 | |||
37 | /** | ||
38 | * The destructor | ||
39 | */ | ||
40 | OKeyPair::~OKeyPair() {} | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Is this OKeyPair empty/valid? | ||
45 | */ | ||
46 | bool OKeyPair::isEmpty()const { | ||
47 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | ||
52 | * | ||
53 | * @see Qt::Key | ||
54 | * @see setKey | ||
55 | */ | ||
56 | int OKeyPair::keycode()const { | ||
57 | return m_key; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * get the modifier key for this OKeyPair. The Modifier State relates | ||
62 | * to the Qt::ButtonState | ||
63 | * | ||
64 | * @see Qt::ButtonState | ||
65 | * @see setModifier | ||
66 | */ | ||
67 | int OKeyPair::modifier()const { | ||
68 | return m_mod; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Set the keycode | ||
74 | * @param key The Keycode to set | ||
75 | * | ||
76 | * @see keycode() | ||
77 | * @see Qt::Key | ||
78 | */ | ||
79 | void OKeyPair::setKeycode( int key ) { | ||
80 | m_key = key; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Set the modifier key | ||
85 | * | ||
86 | * @param the Modifier key | ||
87 | * @see Qt::ButtonState | ||
88 | * @see modifier() | ||
89 | */ | ||
90 | void OKeyPair::setModifier( int mod ) { | ||
91 | m_mod = mod; | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * Return an OKeyPair for the Return Key without any modifier. | ||
96 | */ | ||
97 | OKeyPair OKeyPair::returnKey() { | ||
98 | return OKeyPair( Qt::Key_Return, 0 ); | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Return an OKeyPair for the Left Arrow Key | ||
103 | * without any modifier Key | ||
104 | */ | ||
105 | OKeyPair OKeyPair::leftArrowKey() { | ||
106 | return OKeyPair( Qt::Key_Left, 0 ); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * Return an OKeyPair for the Right Arrow Key | ||
111 | * without any modifier Key | ||
112 | */ | ||
113 | OKeyPair OKeyPair::rightArrowKey() { | ||
114 | return OKeyPair( Qt::Key_Right, 0 ); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Return an OKeyPair for the Up Arrow Key | ||
119 | * without any modifier Key | ||
120 | */ | ||
121 | OKeyPair OKeyPair::upArrowKey() { | ||
122 | return OKeyPair( Qt::Key_Up, 0 ); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Return an OKeyPair for the Down Arrow Key | ||
127 | * without any modifier Key | ||
128 | */ | ||
129 | OKeyPair OKeyPair::downArrowKey() { | ||
130 | return OKeyPair( Qt::Key_Down, 0 ); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Return an Empty OKeyPair | ||
135 | */ | ||
136 | OKeyPair OKeyPair::emptyKey() { | ||
137 | return OKeyPair(); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * This functions uses the Opie::Core::ODevice::buttons | ||
142 | * for OKeyPairList | ||
143 | * | ||
144 | * @see Opie::Core::ODevice | ||
145 | * @see Opie::Core::ODeviceButton | ||
146 | * @see Opie::Core::ODevice::button | ||
147 | */ | ||
148 | OKeyPair::List OKeyPair::hardwareKeys() { | ||
149 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | ||
150 | OKeyPair::List lst; | ||
151 | |||
152 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | ||
153 | it != but.end(); ++it ) | ||
154 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | ||
155 | |||
156 | |||
157 | return lst; | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * Equals operator. Check if two OKeyPairs have the same key and modifier | ||
162 | * @see operator!= | ||
163 | */ | ||
164 | bool OKeyPair::operator==( const OKeyPair& pair)const { | ||
165 | if ( m_key != pair.m_key ) return false; | ||
166 | if ( m_mod != pair.m_mod ) return false; | ||
167 | |||
168 | return true; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Not equal operator. calls the equal operator internally | ||
173 | */ | ||
174 | bool OKeyPair::operator!=( const OKeyPair& pair)const { | ||
175 | return !(*this == pair); | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * The normal Constructor to create a OKeyConfigItem | ||
181 | * | ||
182 | * You can set the the key paramater of this item but if | ||
183 | * you use this item with the OKeyConfigManager your setting | ||
184 | * will be overwritten. | ||
185 | * You can also specify a QObject and slot which sould get called | ||
186 | * once this item is activated. This slot only works if you | ||
187 | * use the OKeyConfigManager. | ||
188 | * The actual Key is read by load() | ||
189 | * | ||
190 | * \code | ||
191 | * void MySlot::create(){ | ||
192 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | ||
193 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | ||
194 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | ||
195 | * } | ||
196 | * \endcode | ||
197 | * | ||
198 | * @param text The text exposed to the user | ||
199 | * @param config_key The key used in the config | ||
200 | * @param pix A Pixmap associated with this Item | ||
201 | * @param def The OKeyPair used as default | ||
202 | * @param caller The object where the slot exists | ||
203 | * @param slot The slot which should get called | ||
204 | * | ||
205 | */ | ||
206 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | ||
207 | const QPixmap& pix, int id, const OKeyPair& def, | ||
208 | QObject *caller, | ||
209 | const char* slot ) | ||
210 | : m_text( text ), m_config( config_key ), m_pix( pix ), | ||
211 | m_id( id ), m_def( def ), | ||
212 | m_obj( caller ), m_str( slot ) {} | ||
213 | |||
214 | /** | ||
215 | * A special Constructor for converting from an Opie::Core::ODeviceButton | ||
216 | * delivered by Opie::Core::ODevice::buttons() | ||
217 | * There is no Config Key set and both default key and key are set | ||
218 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | ||
219 | * | ||
220 | * @see Opie::Core::ODevice | ||
221 | * @see Opie::Core::ODeviceButton | ||
222 | * @see Opie::Core::ODevice::buttons() | ||
223 | */ | ||
224 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | ||
225 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | ||
226 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | ||
227 | {} | ||
228 | |||
229 | |||
230 | /** | ||
231 | * Destructor | ||
232 | */ | ||
233 | OKeyConfigItem::~OKeyConfigItem() {} | ||
234 | |||
235 | |||
236 | /** | ||
237 | * The text exposed to the user | ||
238 | * | ||
239 | * @see setText | ||
240 | */ | ||
241 | QString OKeyConfigItem::text()const { | ||
242 | return m_text; | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * The pixmap shown to the user for your action/key | ||
247 | * | ||
248 | * @see setPixmap | ||
249 | */ | ||
250 | QPixmap OKeyConfigItem::pixmap()const { | ||
251 | return m_pix; | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Return the OKeyPair this OKeyConfigItem is configured for. | ||
256 | * | ||
257 | * @see setKeyPair | ||
258 | */ | ||
259 | OKeyPair OKeyConfigItem::keyPair()const { | ||
260 | return m_key; | ||
261 | } | ||
262 | |||
263 | /** | ||
264 | * Return the default OKeyPair | ||
265 | * @see setDefaultKeyPair | ||
266 | */ | ||
267 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | ||
268 | return m_def; | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Return the Id you assigned to this item. | ||
274 | * setting is only possible by the constructor | ||
275 | */ | ||
276 | int OKeyConfigItem::id()const{ | ||
277 | return m_id; | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * reutrn the Config Key. Setting it is only possible | ||
282 | * by the constructor | ||
283 | */ | ||
284 | QCString OKeyConfigItem::configKey()const { | ||
285 | return m_config; | ||
286 | } | ||
287 | |||
288 | /** | ||
289 | * @internal | ||
290 | */ | ||
291 | QObject* OKeyConfigItem::object()const{ | ||
292 | return m_obj; | ||
293 | } | ||
294 | |||
295 | /** | ||
296 | * @internal | ||
297 | */ | ||
298 | QCString OKeyConfigItem::slot()const { | ||
299 | return m_str; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * Set the text | ||
304 | * | ||
305 | * @param text Set the Text of this Action to text | ||
306 | * @see text() | ||
307 | */ | ||
308 | void OKeyConfigItem::setText( const QString& text ) { | ||
309 | m_text = text; | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * Set the pixmap of this action | ||
314 | * | ||
315 | * @param pix The Pixmap to set | ||
316 | * @see pixmap() | ||
317 | */ | ||
318 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | ||
319 | m_pix = pix; | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * Set the KeyPair the OKeyConfigItem uses. | ||
324 | * Your set Key could get overwritten if you use | ||
325 | * the manager or GUI to configure the key | ||
326 | * | ||
327 | * @param key Set the OKeyPair used | ||
328 | * @see keyPair() | ||
329 | */ | ||
330 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | ||
331 | m_key = key; | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Set the default KeyPair. | ||
336 | * | ||
337 | * @param key The default keypair | ||
338 | * @see defaultKeyPair() | ||
339 | */ | ||
340 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | ||
341 | m_def = key; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * @internal | ||
346 | */ | ||
347 | void OKeyConfigItem::setConfigKey( const QCString& str) { | ||
348 | m_config = str; | ||
349 | m_config.detach(); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * @internal | ||
354 | */ | ||
355 | void OKeyConfigItem::setId( int id ) { | ||
356 | m_id = id; | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * If the item is not configured isEmpty() will return true | ||
361 | * It is empty if no text is present and no default | ||
362 | * and no configured key | ||
363 | */ | ||
364 | bool OKeyConfigItem::isEmpty()const { | ||
365 | if ( !m_def.isEmpty() ) return false; | ||
366 | if ( !m_key.isEmpty() ) return false; | ||
367 | if ( !m_text.isEmpty() ) return false; | ||
368 | if ( m_id != -1 ) return false; | ||
369 | |||
370 | return true; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Check if the KeyPairs are the same | ||
375 | */ | ||
376 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | ||
377 | /* if ( isEmpty() == conf.isEmpty() ) return true; | ||
378 | else if ( isEmpty() != conf.isEmpty() ) return false; | ||
379 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | ||
380 | */ | ||
381 | |||
382 | if ( m_id != conf.m_id ) return false; | ||
383 | if ( m_obj != conf.m_obj ) return false; | ||
384 | if ( m_text != conf.m_text ) return false; | ||
385 | if ( m_key != conf.m_key ) return false; | ||
386 | if ( m_def != conf.m_def ) return false; | ||
387 | |||
388 | |||
389 | |||
390 | return true; | ||
391 | |||
392 | } | ||
393 | |||
394 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | ||
395 | return !( *this == conf ); | ||
396 | } | ||
397 | |||
398 | /** | ||
399 | * \brief c'tor | ||
400 | * The Constructor for a OKeyConfigManager | ||
401 | * | ||
402 | * You can use this manager in multiple ways. Either make it handle | ||
403 | * QKeyEvents | ||
404 | * | ||
405 | * \code | ||
406 | * Opie::Core::Config conf = oApp->config(); | ||
407 | * Opie::Ui::OKeyPairList blackList; | ||
408 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | ||
409 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | ||
410 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | ||
411 | * false); | ||
412 | * QListView *view = new QListView(); | ||
413 | * manager->handleWidget(view); | ||
414 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | ||
415 | * manager->load(); | ||
416 | * | ||
417 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | ||
418 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | ||
419 | * | ||
420 | * .... | ||
421 | * | ||
422 | * void update(){ | ||
423 | * QDialog diag(true); | ||
424 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | ||
425 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | ||
426 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | ||
427 | * lay->addWidget(wid); | ||
428 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | ||
429 | * wid->save(); | ||
430 | * } | ||
431 | * } | ||
432 | * | ||
433 | * .... | ||
434 | * MyListView::keyPressEvent( QKeyEvent* e ){ | ||
435 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | ||
436 | * if(!item.isEmpty() ){ | ||
437 | * switch(item.id()){ | ||
438 | * case My_Delete_Key: | ||
439 | * break; | ||
440 | * } | ||
441 | * } | ||
442 | * } | ||
443 | * | ||
444 | * \endcode | ||
445 | * | ||
446 | * @param conf The Config where the KeySetting should be stored | ||
447 | * @param group The group where the KeySetting will be stored | ||
448 | * @param black Which keys shouldn't be allowed to handle | ||
449 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | ||
450 | * @param par The parent/owner of this manager | ||
451 | * @param name The name of this object | ||
452 | */ | ||
453 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | ||
454 | const QString& group, | ||
455 | const OKeyPair::List& black, | ||
456 | bool grabkeyboard, QObject* par, | ||
457 | const char* name) | ||
458 | : QObject( par, name ), m_conf( conf ), m_group( group ), | ||
459 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | ||
460 | if ( m_grab ) | ||
461 | QPEApplication::grabKeyboard(); | ||
462 | } | ||
463 | |||
464 | |||
465 | /** | ||
466 | * Destructor | ||
467 | */ | ||
468 | OKeyConfigManager::~OKeyConfigManager() { | ||
469 | if ( m_grab ) | ||
470 | QPEApplication::ungrabKeyboard(); | ||
471 | } | ||
472 | |||
473 | /** | ||
474 | * Load the Configuration from the OConfig | ||
475 | * If a Key is restricted but was in the config we will | ||
476 | * make it be the empty key paur | ||
477 | * We will change the group but restore to the previous. | ||
478 | * | ||
479 | * @see OKeyPair::emptyKey | ||
480 | */ | ||
481 | void OKeyConfigManager::load() { | ||
482 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
483 | |||
484 | /* | ||
485 | * Read each item | ||
486 | */ | ||
487 | int key, mod; | ||
488 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | ||
489 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | ||
490 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | ||
491 | OKeyPair okey( key, mod ); | ||
492 | |||
493 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | ||
494 | (*it).setKeyPair( OKeyPair(key, mod) ); | ||
495 | else | ||
496 | (*it).setKeyPair( OKeyPair::emptyKey() ); | ||
497 | } | ||
498 | delete m_map; m_map = 0; | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * We will save the current configuration | ||
503 | * to the OConfig. We will change the group but restore | ||
504 | * to the previous | ||
505 | */ | ||
506 | void OKeyConfigManager::save() { | ||
507 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
508 | |||
509 | /* | ||
510 | * Write each item | ||
511 | */ | ||
512 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | ||
513 | /* skip empty items */ | ||
514 | if ( (*it).isEmpty() ) | ||
515 | continue; | ||
516 | OKeyPair pair = (*it).keyPair(); | ||
517 | OKeyPair deft = (*it).defaultKeyPair(); | ||
518 | /* | ||
519 | * don't write if it is the default setting | ||
520 | * FIXME allow to remove Keys from config | ||
521 | if ( (pair.keycode() == deft.keycode()) && | ||
522 | (pair.modifier()== deft.modifier() ) ) | ||
523 | return; | ||
524 | */ | ||
525 | |||
526 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | ||
527 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | ||
528 | } | ||
529 | m_conf->write(); | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * This is function uses a QMap internally but you can have the same keycode | ||
534 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | ||
535 | * with same keycode and modifier key. The GUI takes care that a user can't | ||
536 | * cofigure two keys. | ||
537 | * | ||
538 | * Make sure you call e->ignore if you don't want to handle this event | ||
539 | */ | ||
540 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | ||
541 | /* | ||
542 | * Fix Up issues with Qt/E, my keybard, and virtual input | ||
543 | * methods | ||
544 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | ||
545 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | ||
546 | * case ascii | ||
547 | */ | ||
548 | int key, mod; | ||
549 | Opie::Ui::Internal::fixupKeys( key, mod, e ); | ||
550 | |||
551 | OKeyConfigItem::List _keyList = keyList( key ); | ||
552 | if ( _keyList.isEmpty() ) | ||
553 | return OKeyConfigItem(); | ||
554 | |||
555 | OKeyConfigItem item; | ||
556 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | ||
557 | ++it ) { | ||
558 | if ( (*it).keyPair().modifier() == mod ) { | ||
559 | item = *it; | ||
560 | break; | ||
561 | } | ||
562 | |||
563 | } | ||
564 | |||
565 | return item; | ||
566 | } | ||
567 | |||
568 | /** | ||
569 | * Return the associated id of the item or -1 if no item | ||
570 | * matched the key | ||
571 | * | ||
572 | * @see handleKeyEvent | ||
573 | */ | ||
574 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | ||
575 | return handleKeyEvent( ev ).id(); | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * Add Key Config to the List of items | ||
580 | */ | ||
581 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | ||
582 | m_keys.append( item ); | ||
583 | delete m_map; m_map = 0; | ||
584 | } | ||
585 | |||
586 | /** | ||
587 | * Remove the Key from the Config. Internal lists will be destroyed | ||
588 | * and rebuild on demand later | ||
589 | */ | ||
590 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | ||
591 | m_keys.remove( item ); | ||
592 | delete m_map; m_map = 0; | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * Clears the complete list | ||
597 | */ | ||
598 | void OKeyConfigManager::clearKeyConfig() { | ||
599 | m_keys.clear(); | ||
600 | delete m_map; m_map = 0; | ||
601 | } | ||
602 | |||
603 | /** | ||
604 | * | ||
605 | */ | ||
606 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | ||
607 | return m_keys; | ||
608 | } | ||
609 | |||
610 | /** | ||
611 | * Add this OKeyPair to the blackList. | ||
612 | * Internal lists will be destroyed | ||
613 | */ | ||
614 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | ||
615 | m_blackKeys.append( key ); | ||
616 | delete m_map; m_map = 0; | ||
617 | } | ||
618 | |||
619 | |||
620 | /** | ||
621 | * Remove this OKeyPair from the black List | ||
622 | * Internal lists will be destroyed | ||
623 | */ | ||
624 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | ||
625 | m_blackKeys.remove( key ); | ||
626 | delete m_map; m_map = 0; | ||
627 | } | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Clear the blackList | ||
632 | */ | ||
633 | void OKeyConfigManager::clearBlackList() { | ||
634 | m_blackKeys.clear(); | ||
635 | delete m_map; m_map = 0; | ||
636 | } | ||
637 | |||
638 | |||
639 | /** | ||
640 | * Return a copy of the blackList | ||
641 | */ | ||
642 | OKeyPair::List OKeyConfigManager::blackList()const { | ||
643 | return m_blackKeys; | ||
644 | } | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Ask the Manager to handle KeyEvents for you. | ||
649 | * All handled keys will emit a QSignal and return true | ||
650 | * that it handled the keyevent | ||
651 | */ | ||
652 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | ||
653 | wid->installEventFilter( this ); | ||
654 | } | ||
655 | |||
656 | /** | ||
657 | * @internal | ||
658 | */ | ||
659 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | ||
660 | if ( !obj->isWidgetType() ) | ||
661 | return false; | ||
662 | |||
663 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | ||
664 | return false; | ||
665 | |||
666 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | ||
667 | OKeyConfigItem item = handleKeyEvent( key ); | ||
668 | |||
669 | if ( item.isEmpty() ) | ||
670 | return false; | ||
671 | |||
672 | QWidget *wid = static_cast<QWidget*>( obj ); | ||
673 | |||
674 | if ( item.object() && !item.slot().isEmpty() ) { | ||
675 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | ||
676 | item.object(), item.slot().data() ); | ||
677 | emit actionActivated(wid, key); | ||
678 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | ||
679 | item.object(), item.slot().data() ); | ||
680 | } | ||
681 | emit actionActivated( wid, key, item ); | ||
682 | |||
683 | return true; | ||
684 | } | ||
685 | |||
686 | /** | ||
687 | * @internal | ||
688 | */ | ||
689 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | ||
690 | /* | ||
691 | * Create the map if not existing anymore | ||
692 | */ | ||
693 | if ( !m_map ) { | ||
694 | m_map = new OKeyMapConfigPrivate; | ||
695 | /* for every key */ | ||
696 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | ||
697 | it!= m_keys.end(); ++it ) { | ||
698 | |||
699 | bool add = true; | ||
700 | /* see if this key is blocked */ | ||
701 | OKeyPair pair = (*it).keyPair(); | ||
702 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | ||
703 | pairIt != m_blackKeys.end(); ++pairIt ) { | ||
704 | if ( (*pairIt).keycode() == pair.keycode() && | ||
705 | (*pairIt).modifier() == pair.modifier() ) { | ||
706 | add = false; | ||
707 | break; | ||
708 | } | ||
709 | } | ||
710 | /* check if we added it */ | ||
711 | if ( add ) | ||
712 | (*m_map)[pair.keycode()].append( *it ); | ||
713 | } | ||
714 | } | ||
715 | return (*m_map)[keycode]; | ||
716 | } | ||
717 | |||
718 | 20 | ||
719 | namespace Opie { | 21 | namespace Opie { |
720 | namespace Ui { | 22 | namespace Ui { |
721 | namespace Internal { | 23 | namespace Internal { |
722 | 24 | ||
723 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) | 25 | OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) |
724 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { | 26 | : Opie::Ui::OListViewItem( parent ), m_manager( man ) { |
725 | m_origItem = item; | 27 | m_origItem = item; |
726 | setItem( item ); | 28 | setItem( item ); |
727 | } | 29 | } |
728 | OKeyListViewItem::~OKeyListViewItem() {} | 30 | OKeyListViewItem::~OKeyListViewItem() {} |
729 | OKeyConfigItem &OKeyListViewItem::item(){ | 31 | OKeyConfigItem &OKeyListViewItem::item(){ |
730 | return m_item; | 32 | return m_item; |
731 | } | 33 | } |
732 | OKeyConfigItem OKeyListViewItem::origItem() const{ | 34 | OKeyConfigItem OKeyListViewItem::origItem() const{ |
733 | return m_origItem; | 35 | return m_origItem; |
734 | } | 36 | } |
735 | OKeyConfigManager* OKeyListViewItem::manager() { | 37 | OKeyConfigManager* OKeyListViewItem::manager() { |
736 | return m_manager; | 38 | return m_manager; |
737 | } | 39 | } |
738 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { | 40 | void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { |
739 | m_item = item; | 41 | m_item = item; |
740 | setPixmap( 0, m_item.pixmap() ); | 42 | setPixmap( 0, m_item.pixmap() ); |
741 | setText ( 1, m_item.text() ); | 43 | setText ( 1, m_item.text() ); |
742 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 44 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
743 | setText( 2, keyToString( m_item.keyPair() ) ); | 45 | setText( 2, keyToString( m_item.keyPair() ) ); |
744 | 46 | ||
745 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : | 47 | m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : |
746 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); | 48 | setText ( 3, keyToString( m_item.defaultKeyPair() ) ); |
747 | } | 49 | } |
748 | void OKeyListViewItem::updateText() { | 50 | void OKeyListViewItem::updateText() { |
749 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : | 51 | m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : |
750 | setText( 2, keyToString( m_item.keyPair() ) ); | 52 | setText( 2, keyToString( m_item.keyPair() ) ); |
751 | } | 53 | } |
752 | 54 | ||
753 | QString keyToString( const OKeyPair& pair ) { | 55 | QString keyToString( const OKeyPair& pair ) { |
754 | int mod = 0; | 56 | int mod = 0; |
755 | if ( pair.modifier() & Qt::ShiftButton ) | 57 | if ( pair.modifier() & Qt::ShiftButton ) |
756 | mod |= Qt::SHIFT; | 58 | mod |= Qt::SHIFT; |
757 | if ( pair.modifier() & Qt::ControlButton ) | 59 | if ( pair.modifier() & Qt::ControlButton ) |
758 | mod |= Qt::CTRL; | 60 | mod |= Qt::CTRL; |
759 | if ( pair.modifier() & Qt::AltButton ) | 61 | if ( pair.modifier() & Qt::AltButton ) |
760 | mod |= Qt::ALT; | 62 | mod |= Qt::ALT; |
761 | 63 | ||
762 | return QAccel::keyToString( mod + pair.keycode() ); | 64 | return QAccel::keyToString( mod + pair.keycode() ); |
763 | } | 65 | } |
764 | 66 | ||
765 | /* | ||
766 | * the virtual and hardware key events have both issues... | ||
767 | */ | ||
768 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | ||
769 | key = e->key(); | ||
770 | mod = e->state(); | ||
771 | /* | ||
772 | * virtual keyboard | ||
773 | * else change the button mod only | ||
774 | */ | ||
775 | if ( key == 0 ) { | ||
776 | key = e->ascii(); | ||
777 | if ( key > 96 && key < 123) | ||
778 | key -= 32; | ||
779 | }else{ | ||
780 | int new_mod = 0; | ||
781 | if ( mod & 256 ) | ||
782 | new_mod |= Qt::ShiftButton; | ||
783 | else if ( mod & 512 ) | ||
784 | new_mod |= Qt::ControlButton; | ||
785 | else if ( mod & 1024 ) | ||
786 | new_mod |= Qt::AltButton; | ||
787 | |||
788 | mod = new_mod == 0? mod : new_mod; | ||
789 | } | ||
790 | } | ||
791 | |||
792 | struct OKeyConfigWidgetPrivate{ | 67 | struct OKeyConfigWidgetPrivate{ |
793 | OKeyConfigWidgetPrivate(const QString& = QString::null, | 68 | OKeyConfigWidgetPrivate(const QString& = QString::null, |
794 | OKeyConfigManager* = 0); | 69 | OKeyConfigManager* = 0); |
795 | bool operator==( const OKeyConfigWidgetPrivate& ); | 70 | bool operator==( const OKeyConfigWidgetPrivate& ); |
796 | QString name; | 71 | QString name; |
797 | OKeyConfigManager *manager; | 72 | OKeyConfigManager *manager; |
798 | }; | 73 | }; |
799 | 74 | ||
800 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, | 75 | OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, |
801 | OKeyConfigManager* man ) | 76 | OKeyConfigManager* man ) |
802 | : name( _name ), manager( man ){} | 77 | : name( _name ), manager( man ){} |
803 | 78 | ||
804 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { | 79 | bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { |
805 | if ( manager != item.manager) return false; | 80 | if ( manager != item.manager) return false; |
806 | if ( name != item.name ) return false; | 81 | if ( name != item.name ) return false; |
807 | 82 | ||
808 | return true; | 83 | return true; |
809 | } | 84 | } |
810 | 85 | ||
811 | } | 86 | } |
812 | } | 87 | |
813 | } | ||
814 | 88 | ||
815 | 89 | ||
816 | 90 | ||
817 | //////////////////////// | 91 | //////////////////////// |
818 | //////////////////////// | 92 | //////////////////////// |
819 | //////// Widget Starts Here | 93 | //////// Widget Starts Here |
820 | 94 | ||
821 | 95 | ||
822 | 96 | ||
823 | 97 | ||
824 | /** | 98 | /** |
825 | * | 99 | * |
826 | * This is a c'tor. You still need to pass the OKeyConfigManager | 100 | * This is a c'tor. You still need to pass the OKeyConfigManager |
827 | * and then issue a load. | 101 | * and then issue a load. |
828 | * The default mode is Immediate | 102 | * The default mode is Immediate |
829 | * | 103 | * |
830 | */ | 104 | */ |
831 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) | 105 | OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) |
832 | : QWidget( parent, name, fl ) { | 106 | : QWidget( parent, name, fl ) { |
833 | initUi(); | 107 | initUi(); |
834 | } | 108 | } |
835 | 109 | ||
836 | 110 | ||
837 | 111 | ||
838 | /** | 112 | /** |
839 | * c'tor | 113 | * c'tor |
840 | */ | 114 | */ |
841 | OKeyConfigWidget::~OKeyConfigWidget() { | 115 | OKeyConfigWidget::~OKeyConfigWidget() { |
842 | } | 116 | } |
843 | 117 | ||
844 | 118 | ||
845 | /** | 119 | /** |
846 | * @internal | 120 | * @internal |
847 | */ | 121 | */ |
848 | void OKeyConfigWidget::initUi() { | 122 | void OKeyConfigWidget::initUi() { |
849 | QBoxLayout *layout = new QVBoxLayout( this ); | 123 | QBoxLayout *layout = new QVBoxLayout( this ); |
850 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); | 124 | QGridLayout *gridLay = new QGridLayout( 2, 2 ); |
851 | layout->addLayout( gridLay, 10 ); | 125 | layout->addLayout( gridLay, 10 ); |
852 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth | 126 | gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth |
853 | 127 | ||
854 | /* | 128 | /* |
855 | * LISTVIEW with the Keys | 129 | * LISTVIEW with the Keys |
856 | */ | 130 | */ |
857 | m_view = new Opie::Ui::OListView( this ); | 131 | m_view = new Opie::Ui::OListView( this ); |
858 | m_view->setFocus(); | 132 | m_view->setFocus(); |
859 | m_view->setAllColumnsShowFocus( true ); | 133 | m_view->setAllColumnsShowFocus( true ); |
860 | m_view->addColumn( tr("Pixmap") ); | 134 | m_view->addColumn( tr("Pixmap") ); |
861 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); | 135 | m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); |
862 | m_view->addColumn( tr("Key" ) ); | 136 | m_view->addColumn( tr("Key" ) ); |
863 | m_view->addColumn( tr("Default Key" ) ); | 137 | m_view->addColumn( tr("Default Key" ) ); |
864 | m_view->setRootIsDecorated( true ); | 138 | m_view->setRootIsDecorated( true ); |
865 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), | 139 | connect(m_view, SIGNAL(currentChanged(QListViewItem*)), |
866 | this, SLOT(slotListViewItem(QListViewItem*)) ); | 140 | this, SLOT(slotListViewItem(QListViewItem*)) ); |
867 | 141 | ||
868 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); | 142 | gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); |
869 | 143 | ||
870 | /* | 144 | /* |
871 | * GROUP with button info | 145 | * GROUP with button info |
872 | */ | 146 | */ |
873 | 147 | ||
874 | QGroupBox *box = new QGroupBox( this ); | 148 | QGroupBox *box = new QGroupBox( this ); |
875 | box ->setTitle( tr("Shortcut for Selected Action") ); | 149 | box ->setTitle( tr("Shortcut for Selected Action") ); |
876 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); | 150 | box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); |
877 | layout->addWidget( box, 1 ); | 151 | layout->addWidget( box, 1 ); |
878 | 152 | ||
879 | gridLay = new QGridLayout( box, 3, 4 ); | 153 | gridLay = new QGridLayout( box, 3, 4 ); |
880 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); | 154 | gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); |
881 | gridLay->setMargin( 4 ); | 155 | gridLay->setMargin( 4 ); |
882 | 156 | ||
883 | QButtonGroup *gr = new QButtonGroup( box ); | 157 | QButtonGroup *gr = new QButtonGroup( box ); |
884 | gr->hide(); | 158 | gr->hide(); |
885 | gr->setExclusive( true ); | 159 | gr->setExclusive( true ); |
886 | 160 | ||
887 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); | 161 | QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); |
888 | connect( rad, SIGNAL(clicked()), | 162 | connect( rad, SIGNAL(clicked()), |
889 | this, SLOT(slotNoKey()) ); | 163 | this, SLOT(slotNoKey()) ); |
890 | gr->insert( rad, 10 ); | 164 | gr->insert( rad, 10 ); |
891 | gridLay->addWidget( rad, 1, 0 ); | 165 | gridLay->addWidget( rad, 1, 0 ); |
892 | m_none = rad; | 166 | m_none = rad; |
893 | 167 | ||
894 | rad = new QRadioButton( tr("&Default" ), box ); | 168 | rad = new QRadioButton( tr("&Default" ), box ); |
895 | connect( rad, SIGNAL(clicked()), | 169 | connect( rad, SIGNAL(clicked()), |
896 | this, SLOT(slotDefaultKey()) ); | 170 | this, SLOT(slotDefaultKey()) ); |
897 | gr->insert( rad, 11 ); | 171 | gr->insert( rad, 11 ); |
898 | gridLay->addWidget( rad, 1, 1 ); | 172 | gridLay->addWidget( rad, 1, 1 ); |
899 | m_def = rad; | 173 | m_def = rad; |
900 | 174 | ||
901 | rad = new QRadioButton( tr("C&ustom"), box ); | 175 | rad = new QRadioButton( tr("C&ustom"), box ); |
902 | connect( rad, SIGNAL(clicked()), | 176 | connect( rad, SIGNAL(clicked()), |
903 | this, SLOT(slotCustomKey()) ); | 177 | this, SLOT(slotCustomKey()) ); |
904 | gr->insert( rad, 12 ); | 178 | gr->insert( rad, 12 ); |
905 | gridLay->addWidget( rad, 1, 2 ); | 179 | gridLay->addWidget( rad, 1, 2 ); |
906 | m_cus = rad; | 180 | m_cus = rad; |
907 | 181 | ||
908 | m_btn = new QPushButton( tr("Configure Key"), box ); | 182 | m_btn = new QPushButton( tr("Configure Key"), box ); |
909 | gridLay->addWidget( m_btn, 1, 4 ); | 183 | gridLay->addWidget( m_btn, 1, 4 ); |
910 | 184 | ||
911 | m_lbl= new QLabel( tr( "Default: " ), box ); | 185 | m_lbl= new QLabel( tr( "Default: " ), box ); |
912 | gridLay->addWidget( m_lbl, 2, 0 ); | 186 | gridLay->addWidget( m_lbl, 2, 0 ); |
913 | 187 | ||
914 | connect(m_btn, SIGNAL(clicked()), | 188 | connect(m_btn, SIGNAL(clicked()), |
915 | this, SLOT(slotConfigure())); | 189 | this, SLOT(slotConfigure())); |
916 | 190 | ||
917 | m_box = box; | 191 | m_box = box; |
918 | } | 192 | } |
919 | 193 | ||
920 | /** | 194 | /** |
921 | * Set the ChangeMode. | 195 | * Set the ChangeMode. |
922 | * You need to call this function prior to load | 196 | * You need to call this function prior to load |
923 | * If you call this function past load the behaviour is undefined | 197 | * If you call this function past load the behaviour is undefined |
924 | * But caling load again is safe | 198 | * But caling load again is safe |
925 | */ | 199 | */ |
926 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { | 200 | void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { |
927 | m_mode = mode; | 201 | m_mode = mode; |
928 | } | 202 | } |
929 | 203 | ||
930 | 204 | ||
931 | /** | 205 | /** |
932 | * return the current mode | 206 | * return the current mode |
933 | */ | 207 | */ |
934 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { | 208 | OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { |
935 | return m_mode; | 209 | return m_mode; |
936 | } | 210 | } |
937 | 211 | ||
938 | 212 | ||
939 | /** | 213 | /** |
940 | * insert these items before calling load | 214 | * insert these items before calling load |
941 | */ | 215 | */ |
942 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { | 216 | void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { |
943 | Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man ); | 217 | Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man ); |
944 | m_list.append(root); | 218 | m_list.append(root); |
945 | } | 219 | } |
946 | 220 | ||
947 | 221 | ||
948 | /** | 222 | /** |
949 | * loads the items and allows editing them | 223 | * loads the items and allows editing them |
950 | */ | 224 | */ |
951 | void OKeyConfigWidget::load() { | 225 | void OKeyConfigWidget::load() { |
952 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it; | 226 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it; |
953 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 227 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
954 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); | 228 | OListViewItem *item = new OListViewItem( m_view, (*it).name ); |
955 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); | 229 | OKeyConfigItem::List list = (*it).manager->keyConfigList(); |
956 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) | 230 | for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) |
957 | (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item ); | 231 | (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item ); |
958 | 232 | ||
959 | } | 233 | } |
960 | } | 234 | } |
961 | 235 | ||
962 | /** | 236 | /** |
963 | * Saves if in Queue Mode. It'll update the supplied | 237 | * Saves if in Queue Mode. It'll update the supplied |
964 | * OKeyConfigManager objects. | 238 | * OKeyConfigManager objects. |
965 | * If in Queue mode it'll just return | 239 | * If in Queue mode it'll just return |
966 | */ | 240 | */ |
967 | void OKeyConfigWidget::save() { | 241 | void OKeyConfigWidget::save() { |
968 | /* | 242 | /* |
969 | * Iterate over all config items | 243 | * Iterate over all config items |
970 | */ | 244 | */ |
971 | QListViewItemIterator it( m_view ); | 245 | QListViewItemIterator it( m_view ); |
972 | while ( it.current() ) { | 246 | while ( it.current() ) { |
973 | if (it.current()->parent() ) { | 247 | if (it.current()->parent() ) { |
974 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() ); | 248 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() ); |
975 | OKeyConfigManager *man = item->manager(); | 249 | OKeyConfigManager *man = item->manager(); |
976 | man->removeKeyConfig( item->origItem() ); | 250 | man->removeKeyConfig( item->origItem() ); |
977 | man->addKeyConfig( item->item() ); | 251 | man->addKeyConfig( item->item() ); |
978 | } | 252 | } |
979 | ++it; | 253 | ++it; |
980 | } | 254 | } |
981 | 255 | ||
982 | 256 | ||
983 | } | 257 | } |
984 | 258 | ||
985 | 259 | ||
986 | /** | 260 | /** |
987 | * @internal | 261 | * @internal |
988 | */ | 262 | */ |
989 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { | 263 | void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { |
990 | if ( !_item || !_item->parent() ) { | 264 | if ( !_item || !_item->parent() ) { |
991 | m_box->setEnabled( false ); | 265 | m_box->setEnabled( false ); |
992 | m_none->setChecked( true ); | 266 | m_none->setChecked( true ); |
993 | m_btn ->setEnabled( false ); | 267 | m_btn ->setEnabled( false ); |
994 | m_def ->setChecked( false ); | 268 | m_def ->setChecked( false ); |
995 | m_cus ->setChecked( false ); | 269 | m_cus ->setChecked( false ); |
996 | }else{ | 270 | }else{ |
997 | m_box->setEnabled( true ); | 271 | m_box->setEnabled( true ); |
998 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item ); | 272 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item ); |
999 | OKeyConfigItem keyItem= item->item(); | 273 | OKeyConfigItem keyItem= item->item(); |
1000 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); | 274 | m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); |
1001 | if ( keyItem.keyPair().isEmpty() ) { | 275 | if ( keyItem.keyPair().isEmpty() ) { |
1002 | m_none->setChecked( true ); | 276 | m_none->setChecked( true ); |
1003 | m_btn ->setEnabled( false ); | 277 | m_btn ->setEnabled( false ); |
1004 | m_def ->setChecked( false ); | 278 | m_def ->setChecked( false ); |
1005 | m_cus ->setChecked( false ); | 279 | m_cus ->setChecked( false ); |
1006 | }else { | 280 | }else { |
1007 | m_none->setChecked( false ); | 281 | m_none->setChecked( false ); |
1008 | m_cus ->setChecked( true ); | 282 | m_cus ->setChecked( true ); |
1009 | m_btn ->setEnabled( true ); | 283 | m_btn ->setEnabled( true ); |
1010 | m_def ->setChecked( false ); | 284 | m_def ->setChecked( false ); |
1011 | } | 285 | } |
1012 | } | 286 | } |
1013 | } | 287 | } |
1014 | 288 | ||
1015 | void OKeyConfigWidget::slotNoKey() { | 289 | void OKeyConfigWidget::slotNoKey() { |
1016 | m_none->setChecked( true ); | 290 | m_none->setChecked( true ); |
1017 | m_cus ->setChecked( false ); | 291 | m_cus ->setChecked( false ); |
1018 | m_btn ->setEnabled( false ); | 292 | m_btn ->setEnabled( false ); |
1019 | m_def ->setChecked( false ); | 293 | m_def ->setChecked( false ); |
1020 | 294 | ||
1021 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 295 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1022 | return; | 296 | return; |
1023 | 297 | ||
1024 | 298 | ||
1025 | 299 | ||
1026 | /* | 300 | /* |
1027 | * If immediate we need to remove and readd the key | 301 | * If immediate we need to remove and readd the key |
1028 | */ | 302 | */ |
1029 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); | 303 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1030 | updateItem( item, OKeyPair::emptyKey() ); | 304 | updateItem( item, OKeyPair::emptyKey() ); |
1031 | } | 305 | } |
1032 | 306 | ||
1033 | void OKeyConfigWidget::slotDefaultKey() { | 307 | void OKeyConfigWidget::slotDefaultKey() { |
1034 | m_none->setChecked( false ); | 308 | m_none->setChecked( false ); |
1035 | m_cus ->setChecked( false ); | 309 | m_cus ->setChecked( false ); |
1036 | m_btn ->setEnabled( false ); | 310 | m_btn ->setEnabled( false ); |
1037 | m_def ->setChecked( true ); | 311 | m_def ->setChecked( true ); |
1038 | 312 | ||
1039 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 313 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1040 | return; | 314 | return; |
1041 | 315 | ||
1042 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); | 316 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1043 | updateItem( item, item->item().defaultKeyPair() ); | 317 | updateItem( item, item->item().defaultKeyPair() ); |
1044 | } | 318 | } |
1045 | 319 | ||
1046 | void OKeyConfigWidget::slotCustomKey() { | 320 | void OKeyConfigWidget::slotCustomKey() { |
1047 | m_cus ->setChecked( true ); | 321 | m_cus ->setChecked( true ); |
1048 | m_btn ->setEnabled( true ); | 322 | m_btn ->setEnabled( true ); |
1049 | m_def ->setChecked( false ); | 323 | m_def ->setChecked( false ); |
1050 | m_none->setChecked( false ); | 324 | m_none->setChecked( false ); |
1051 | 325 | ||
1052 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 326 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1053 | return; | 327 | return; |
1054 | 328 | ||
1055 | 329 | ||
1056 | } | 330 | } |
1057 | 331 | ||
1058 | void OKeyConfigWidget::slotConfigure() { | 332 | void OKeyConfigWidget::slotConfigure() { |
1059 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) | 333 | if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) |
1060 | return; | 334 | return; |
1061 | 335 | ||
1062 | /* FIXME make use of OModalHelper */ | 336 | /* FIXME make use of OModalHelper */ |
1063 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); | 337 | OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); |
1064 | dlg.setCaption(tr("Configure Key")); | 338 | dlg.setCaption(tr("Configure Key")); |
1065 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); | 339 | connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); |
1066 | 340 | ||
1067 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { | 341 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { |
1068 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); | 342 | Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); |
1069 | updateItem( item, dlg.keyPair() ); | 343 | updateItem( item, dlg.keyPair() ); |
1070 | } | 344 | } |
1071 | 345 | ||
1072 | 346 | ||
1073 | } | 347 | } |
1074 | 348 | ||
1075 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item, | 349 | bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item, |
1076 | const OKeyPair& newItem ) { | 350 | const OKeyPair& newItem ) { |
1077 | OKeyPair::List bList = item->manager()->blackList(); | 351 | OKeyPair::List bList = item->manager()->blackList(); |
1078 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { | 352 | for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { |
1079 | /* black list matched */ | 353 | /* black list matched */ |
1080 | if ( *it == newItem ) { | 354 | if ( *it == newItem ) { |
1081 | QMessageBox::warning( 0, tr("Key is on BlackList" ), | 355 | QMessageBox::warning( 0, tr("Key is on BlackList" ), |
1082 | tr("<qt>The Key you choose is on the black list " | 356 | tr("<qt>The Key you choose is on the black list " |
1083 | "and may not be used with this manager. Please " | 357 | "and may not be used with this manager. Please " |
1084 | "use a different key.</qt>" ) ); | 358 | "use a different key.</qt>" ) ); |
1085 | return false; | 359 | return false; |
1086 | } | 360 | } |
1087 | } | 361 | } |
1088 | /* no we need to check the other items which is dog slow */ | 362 | /* no we need to check the other items which is dog slow */ |
1089 | QListViewItemIterator it( item->parent() ); | 363 | QListViewItemIterator it( item->parent() ); |
1090 | while ( it.current() ) { | 364 | while ( it.current() ) { |
1091 | /* if not our parent and not us */ | 365 | /* if not our parent and not us */ |
1092 | if (it.current()->parent() && it.current() != item) { | 366 | if (it.current()->parent() && it.current() != item) { |
1093 | /* damn already given away*/ | 367 | /* damn already given away*/ |
1094 | if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) { | 368 | if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) { |
1095 | QMessageBox::warning( 0, tr("Key is already assigned" ), | 369 | QMessageBox::warning( 0, tr("Key is already assigned" ), |
1096 | tr("<qt>The Key you choose is already taken by " | 370 | tr("<qt>The Key you choose is already taken by " |
1097 | "a different Item of your config. Please try" | 371 | "a different Item of your config. Please try" |
1098 | "using a different key.</qt>" ) ); | 372 | "using a different key.</qt>" ) ); |
1099 | return false; | 373 | return false; |
1100 | } | 374 | } |
1101 | } | 375 | } |
1102 | ++it; | 376 | ++it; |
1103 | } | 377 | } |
1104 | 378 | ||
1105 | return true; | 379 | return true; |
1106 | } | 380 | } |
1107 | 381 | ||
1108 | void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item, | 382 | void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item, |
1109 | const OKeyPair& newItem) { | 383 | const OKeyPair& newItem) { |
1110 | /* sanity check | 384 | /* sanity check |
1111 | * check against the blacklist of the manager | 385 | * check against the blacklist of the manager |
1112 | * check if another item uses this key which is o(n) at least | 386 | * check if another item uses this key which is o(n) at least |
1113 | */ | 387 | */ |
1114 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) | 388 | if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) |
1115 | return; | 389 | return; |
1116 | 390 | ||
1117 | 391 | ||
1118 | 392 | ||
1119 | /* | 393 | /* |
1120 | * If immediate we need to remove and readd the key | 394 | * If immediate we need to remove and readd the key |
1121 | */ | 395 | */ |
1122 | if ( m_mode == Imediate ) | 396 | if ( m_mode == Imediate ) |
1123 | item->manager()->removeKeyConfig( item->item() ); | 397 | item->manager()->removeKeyConfig( item->item() ); |
1124 | 398 | ||
1125 | item->item().setKeyPair( newItem ); | 399 | item->item().setKeyPair( newItem ); |
1126 | item->updateText(); | 400 | item->updateText(); |
1127 | 401 | ||
1128 | if ( m_mode == Imediate ) | 402 | if ( m_mode == Imediate ) |
1129 | item->manager()->addKeyConfig( item->item() ); | 403 | item->manager()->addKeyConfig( item->item() ); |
1130 | } | 404 | } |
1131 | 405 | ||
1132 | 406 | ||
1133 | 407 | ||
1134 | ///// | 408 | ///// |
1135 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | 409 | OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, |
1136 | bool mod, WFlags fl ) | 410 | bool mod, WFlags fl ) |
1137 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , | 411 | : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , |
1138 | m_key( 0 ), m_mod( 0 ) { | 412 | m_key( 0 ), m_mod( 0 ) { |
1139 | setFocusPolicy( StrongFocus ); | 413 | setFocusPolicy( StrongFocus ); |
1140 | 414 | ||
1141 | QHBoxLayout *lay = new QHBoxLayout( this ); | 415 | QHBoxLayout *lay = new QHBoxLayout( this ); |
1142 | 416 | ||
1143 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); | 417 | QLabel *lbl = new QLabel( tr("Configure Key" ), this ); |
1144 | lay->addWidget( lbl ); | 418 | lay->addWidget( lbl ); |
1145 | lbl->setFocusPolicy( NoFocus ); | 419 | lbl->setFocusPolicy( NoFocus ); |
1146 | 420 | ||
1147 | m_lbl = new QLabel( this ); | 421 | m_lbl = new QLabel( this ); |
1148 | lay->addWidget( m_lbl ); | 422 | lay->addWidget( m_lbl ); |
1149 | m_lbl->setFocusPolicy( NoFocus ); | 423 | m_lbl->setFocusPolicy( NoFocus ); |
1150 | 424 | ||
1151 | m_timer = new QTimer( this ); | 425 | m_timer = new QTimer( this ); |
1152 | connect(m_timer, SIGNAL(timeout()), | 426 | connect(m_timer, SIGNAL(timeout()), |
1153 | this, SLOT(slotTimeUp()) ); | 427 | this, SLOT(slotTimeUp()) ); |
1154 | } | 428 | } |
1155 | 429 | ||
1156 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 430 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1157 | } | 431 | } |
1158 | 432 | ||
1159 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 433 | Opie::Core::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1160 | return m_keyPair; | 434 | return m_keyPair; |
1161 | } | 435 | } |
1162 | 436 | ||
1163 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | 437 | void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { |
1164 | QDialog::keyPressEvent( ev ); | 438 | QDialog::keyPressEvent( ev ); |
1165 | 439 | ||
1166 | if ( ev->isAutoRepeat() ) | 440 | if ( ev->isAutoRepeat() ) |
1167 | return; | 441 | return; |
1168 | 442 | ||
1169 | int mod, key; | 443 | int mod, key; |
1170 | Opie::Ui::Internal::fixupKeys( key,mod, ev ); | 444 | Opie::Core::Internal::fixupKeys( key,mod, ev ); |
1171 | 445 | ||
1172 | /* either we used software keyboard | 446 | /* either we used software keyboard |
1173 | * or we've true support | 447 | * or we've true support |
1174 | */ | 448 | */ |
1175 | if ( !m_virtKey && !ev->key()) { | 449 | if ( !m_virtKey && !ev->key()) { |
1176 | m_virtKey = true; | 450 | m_virtKey = true; |
1177 | m_keyPair = OKeyPair( key, mod ); | 451 | m_keyPair = OKeyPair( key, mod ); |
1178 | }else{ | 452 | }else{ |
1179 | mod = 0; | 453 | mod = 0; |
1180 | switch( key ) { | 454 | switch( key ) { |
1181 | case Qt::Key_Control: | 455 | case Qt::Key_Control: |
1182 | mod = Qt::ControlButton; | 456 | mod = Qt::ControlButton; |
1183 | break; | 457 | break; |
1184 | case Qt::Key_Shift: | 458 | case Qt::Key_Shift: |
1185 | mod = Qt::ShiftButton; | 459 | mod = Qt::ShiftButton; |
1186 | break; | 460 | break; |
1187 | case Qt::Key_Alt: | 461 | case Qt::Key_Alt: |
1188 | mod = Qt::AltButton; | 462 | mod = Qt::AltButton; |
1189 | break; | 463 | break; |
1190 | default: | 464 | default: |
1191 | break; | 465 | break; |
1192 | } | 466 | } |
1193 | if (mod ) { | 467 | if (mod ) { |
1194 | m_mod |= mod; | 468 | m_mod |= mod; |
1195 | key = 0; | 469 | key = 0; |
1196 | }else | 470 | }else |
1197 | m_key = key; | 471 | m_key = key; |
1198 | 472 | ||
1199 | if ( ( !mod || m_key || key ) && !m_timer->isActive() ) | 473 | if ( ( !mod || m_key || key ) && !m_timer->isActive() ) |
1200 | m_timer->start( 150, true ); | 474 | m_timer->start( 150, true ); |
1201 | 475 | ||
1202 | m_keyPair = OKeyPair( m_key, m_mod ); | 476 | m_keyPair = OKeyPair( m_key, m_mod ); |
1203 | } | 477 | } |
1204 | 478 | ||
1205 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); | 479 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); |
1206 | 480 | ||
1207 | } | 481 | } |
1208 | 482 | ||
1209 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { | 483 | void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { |
1210 | m_timer->stop(); | 484 | m_timer->stop(); |
1211 | QDialog::keyPressEvent( ev ); | 485 | QDialog::keyPressEvent( ev ); |
1212 | 486 | ||
1213 | if ( ev->isAutoRepeat() ) | 487 | if ( ev->isAutoRepeat() ) |
1214 | return; | 488 | return; |
1215 | 489 | ||
1216 | 490 | ||
1217 | if ( m_virtKey && !ev->key()) { | 491 | if ( m_virtKey && !ev->key()) { |
1218 | m_virtKey = false; | 492 | m_virtKey = false; |
1219 | slotTimeUp(); | 493 | slotTimeUp(); |
1220 | }else { | 494 | }else { |
1221 | int mod = 0; | 495 | int mod = 0; |
1222 | int key = ev->key(); | 496 | int key = ev->key(); |
1223 | switch( key ) { | 497 | switch( key ) { |
1224 | case Qt::Key_Control: | 498 | case Qt::Key_Control: |
1225 | mod = Qt::ControlButton; | 499 | mod = Qt::ControlButton; |
1226 | break; | 500 | break; |
1227 | case Qt::Key_Shift: | 501 | case Qt::Key_Shift: |
1228 | mod = Qt::ShiftButton; | 502 | mod = Qt::ShiftButton; |
1229 | break; | 503 | break; |
1230 | case Qt::Key_Alt: | 504 | case Qt::Key_Alt: |
1231 | mod = Qt::AltButton; | 505 | mod = Qt::AltButton; |
1232 | break; | 506 | break; |
1233 | default: | 507 | default: |
1234 | break; | 508 | break; |
1235 | } | 509 | } |
1236 | if (mod ) | 510 | if (mod ) |
1237 | m_mod &= ~mod; | 511 | m_mod &= ~mod; |
1238 | else | 512 | else |
1239 | m_key = key; | 513 | m_key = key; |
1240 | m_keyPair = OKeyPair( m_key, m_mod ); | 514 | m_keyPair = OKeyPair( m_key, m_mod ); |
1241 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); | 515 | m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); |
1242 | } | 516 | } |
1243 | } | 517 | } |
1244 | 518 | ||
1245 | 519 | ||
1246 | void OKeyChooserConfigDialog::slotTimeUp() { | 520 | void OKeyChooserConfigDialog::slotTimeUp() { |
1247 | m_mod = m_key = 0; | 521 | m_mod = m_key = 0; |
1248 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); | 522 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); |
1249 | } | 523 | } |
524 | |||
525 | |||
526 | } | ||
527 | } | ||
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index bb8eb6c..d11054c 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -1,322 +1,137 @@ | |||
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_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/okeyconfigmanager.h> |
11 | #include <opie2/odevice.h> | ||
12 | 11 | ||
13 | #include <qstring.h> | ||
14 | #include <qpixmap.h> | ||
15 | #include <qcstring.h> | ||
16 | #include <qhbox.h> | 12 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 13 | |
18 | 14 | ||
19 | class QKeyEvent; | 15 | class QKeyEvent; |
20 | class QLabel; | 16 | class QLabel; |
21 | class QPushButton; | 17 | class QPushButton; |
22 | class QListViewItem; | 18 | class QListViewItem; |
23 | class QRadioButton; | 19 | class QRadioButton; |
24 | class QTimer; | 20 | class QTimer; |
25 | 21 | ||
26 | namespace Opie { | 22 | namespace Opie { |
27 | namespace Ui { | 23 | namespace Ui { |
28 | namespace Internal { | 24 | namespace Internal { |
29 | class OKeyConfigWidgetPrivate; | 25 | class OKeyConfigWidgetPrivate; |
30 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; | 26 | typedef QValueList<OKeyConfigWidgetPrivate> OKeyConfigWidgetPrivateList; |
31 | class OKeyListViewItem; | 27 | class OKeyListViewItem; |
32 | } | 28 | } |
33 | class OListViewItem; | 29 | class OListViewItem; |
34 | class OListView; | 30 | class OListView; |
35 | 31 | ||
36 | /** | ||
37 | * \brief small class representing a Key with possible modifiers | ||
38 | * This class holds information about key code and possible | ||
39 | * modifier state. That is the lowest level of the key input | ||
40 | * functions. | ||
41 | * There are also static methods to get special keys. | ||
42 | * OKeyPair will be used with \see OKeyConfigItem | ||
43 | * | ||
44 | * @since 1.2 | ||
45 | */ | ||
46 | class OKeyPair { | ||
47 | public: | ||
48 | typedef QValueList<OKeyPair> List; | ||
49 | OKeyPair( int key = -1, int modifier = -1); | ||
50 | ~OKeyPair(); | ||
51 | |||
52 | bool operator==( const OKeyPair& )const; | ||
53 | bool operator!=( const OKeyPair& )const; | ||
54 | |||
55 | bool isEmpty()const; | ||
56 | |||
57 | int keycode()const; | ||
58 | int modifier()const; | ||
59 | |||
60 | void setKeycode( int ); | ||
61 | void setModifier( int ); | ||
62 | |||
63 | static OKeyPair returnKey(); | ||
64 | static OKeyPair leftArrowKey(); | ||
65 | static OKeyPair rightArrowKey(); | ||
66 | static OKeyPair upArrowKey(); | ||
67 | static OKeyPair downArrowKey(); | ||
68 | static OKeyPair emptyKey(); | ||
69 | static OKeyPair::List hardwareKeys(); | ||
70 | |||
71 | private: | ||
72 | int m_key; | ||
73 | int m_mod; | ||
74 | class Private; | ||
75 | Private* d; | ||
76 | }; | ||
77 | |||
78 | /** | ||
79 | * A class to represent an OKeyPair. | ||
80 | * It consists out of a Text exposed to the user, Config Key Item, | ||
81 | * Pixmap, A default OKeyPair and the set OKeyPair. | ||
82 | * You can also pass an id to it | ||
83 | * | ||
84 | * @since 1.1.2 | ||
85 | */ | ||
86 | class OKeyConfigItem { | ||
87 | friend class OKeyConfigManager; | ||
88 | public: | ||
89 | typedef QValueList<OKeyConfigItem> List; | ||
90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | ||
91 | const QPixmap& symbol = QPixmap(), | ||
92 | int id = -1, | ||
93 | const OKeyPair& def = OKeyPair::emptyKey(), | ||
94 | QObject *caller = 0, const char* slot = 0); | ||
95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | ||
96 | ~OKeyConfigItem(); | ||
97 | |||
98 | bool operator==( const OKeyConfigItem& )const; | ||
99 | bool operator!=( const OKeyConfigItem& )const; | ||
100 | |||
101 | QString text()const; | ||
102 | QPixmap pixmap()const; | ||
103 | int id()const; | ||
104 | |||
105 | |||
106 | |||
107 | OKeyPair keyPair()const; | ||
108 | OKeyPair defaultKeyPair()const; | ||
109 | QCString configKey()const; | ||
110 | |||
111 | |||
112 | void setText( const QString& text ); | ||
113 | void setPixmap( const QPixmap& ); | ||
114 | void setKeyPair( const OKeyPair& ); | ||
115 | void setDefaultKeyPair( const OKeyPair& ); | ||
116 | |||
117 | bool isEmpty()const; | ||
118 | |||
119 | protected: | ||
120 | QObject *object()const; | ||
121 | QCString slot()const; | ||
122 | void setId( int id ); | ||
123 | void setConfigKey( const QCString& ); | ||
124 | |||
125 | private: | ||
126 | QString m_text; | ||
127 | QCString m_config; | ||
128 | QPixmap m_pix; | ||
129 | int m_id; | ||
130 | OKeyPair m_key; | ||
131 | OKeyPair m_def; | ||
132 | QObject *m_obj; | ||
133 | QCString m_str; | ||
134 | class Private; | ||
135 | Private *d; | ||
136 | }; | ||
137 | |||
138 | |||
139 | |||
140 | /** | ||
141 | * \brief A manager to load and save Key Actions and get notified | ||
142 | * This is the Manager for KeyActions. | ||
143 | * You can say from which config and group to read data, to grab the | ||
144 | * keyboard to handle hardware keys, you can supply a blacklist of | ||
145 | * keys which should not be used by allowed to be used. | ||
146 | * You can even pass this manager to a Widget to do the configuration for you. | ||
147 | * You need to add OKeyConfigItem for your keys and then issue a load() to | ||
148 | * read the Key information. | ||
149 | * You can either handle the QKeyEvent yourself and ask this class if it is | ||
150 | * handled by your action and let give you the action. Or you can install | ||
151 | * the event filter and get a signal. | ||
152 | * You need to load ans save yourself! | ||
153 | * | ||
154 | * @since 1.1.2 | ||
155 | */ | ||
156 | class OKeyConfigManager : public QObject { | ||
157 | Q_OBJECT | ||
158 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | ||
159 | public: | ||
160 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | ||
161 | const QString& group = QString::null, | ||
162 | const OKeyPair::List &block = OKeyPair::List(), | ||
163 | bool grabkeyboard = false, QObject * par = 0, | ||
164 | const char* name = 0 ); | ||
165 | ~OKeyConfigManager(); | ||
166 | |||
167 | void load(); | ||
168 | void save(); | ||
169 | |||
170 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | ||
171 | int handleKeyEventId( QKeyEvent* ); | ||
172 | |||
173 | void addKeyConfig( const OKeyConfigItem& ); | ||
174 | void removeKeyConfig( const OKeyConfigItem& ); | ||
175 | void clearKeyConfig(); | ||
176 | |||
177 | void addToBlackList( const OKeyPair& ); | ||
178 | void removeFromBlackList( const OKeyPair& ); | ||
179 | void clearBlackList(); | ||
180 | OKeyPair::List blackList()const; | ||
181 | |||
182 | void handleWidget( QWidget* ); | ||
183 | |||
184 | bool eventFilter( QObject*, QEvent* ); | ||
185 | |||
186 | OKeyConfigItem::List keyConfigList()const; | ||
187 | signals: | ||
188 | /** | ||
189 | * The Signals are triggered on KeyPress and KeyRelease! | ||
190 | * You can check the isDown of the QKeyEvent | ||
191 | * @see QKeyEvent | ||
192 | */ | ||
193 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | ||
194 | |||
195 | /** | ||
196 | * This Signal correspondents to the OKeyConfigItem slot | ||
197 | * and object | ||
198 | * | ||
199 | * @see OKeyConfigItem::slot | ||
200 | * @see OKeyConfigItem::object | ||
201 | */ | ||
202 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
203 | |||
204 | private: | ||
205 | OKeyConfigItem::List keyList( int ); | ||
206 | OKeyConfigItem::List m_keys; | ||
207 | QValueList<QWidget*> m_widgets; | ||
208 | Opie::Core::OConfig *m_conf; | ||
209 | QString m_group; | ||
210 | OKeyPair::List m_blackKeys; | ||
211 | bool m_grab : 1; | ||
212 | OKeyMapConfigPrivate *m_map; | ||
213 | class Private; | ||
214 | Private *d; | ||
215 | }; | ||
216 | |||
217 | 32 | ||
218 | /** | 33 | /** |
219 | * With this Widget you can let the Keyboard Shortcuts | 34 | * With this Widget you can let the Keyboard Shortcuts |
220 | * be configured by the user. | 35 | * be configured by the user. |
221 | * There are two ways you can use this widget. Either in a tab were | 36 | * There are two ways you can use this widget. Either in a tab were |
222 | * all changes are immediately getting into effect or in a queue | 37 | * all changes are immediately getting into effect or in a queue |
223 | * were you ask for saving. Save won't write the data but only set | 38 | * were you ask for saving. Save won't write the data but only set |
224 | * it to the OKeyConfigManager | 39 | * it to the OKeyConfigManager |
225 | * | 40 | * |
226 | * @since 1.2 | 41 | * @since 1.2 |
227 | */ | 42 | */ |
228 | class OKeyConfigWidget : public QWidget { | 43 | class OKeyConfigWidget : public QWidget { |
229 | Q_OBJECT | 44 | Q_OBJECT |
230 | 45 | ||
231 | public: | 46 | public: |
232 | /** | 47 | /** |
233 | * Immediate Apply the change directly to the underlying OKeyConfigManager | 48 | * Immediate Apply the change directly to the underlying OKeyConfigManager |
234 | * Queue Save all items and then apply when you save() | 49 | * Queue Save all items and then apply when you save() |
235 | */ | 50 | */ |
236 | enum ChangeMode { Imediate, Queue }; | 51 | enum ChangeMode { Imediate, Queue }; |
237 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 52 | OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
238 | ~OKeyConfigWidget(); | 53 | ~OKeyConfigWidget(); |
239 | 54 | ||
240 | void setChangeMode( enum ChangeMode ); | 55 | void setChangeMode( enum ChangeMode ); |
241 | ChangeMode changeMode()const; | 56 | ChangeMode changeMode()const; |
242 | 57 | ||
243 | void insert( const QString& name, OKeyConfigManager* ); | 58 | void insert( const QString& name, Opie::Core::OKeyConfigManager* ); |
244 | 59 | ||
245 | void load(); | 60 | void load(); |
246 | void save(); | 61 | void save(); |
247 | 62 | ||
248 | private slots: | 63 | private slots: |
249 | void slotListViewItem( QListViewItem* ); | 64 | void slotListViewItem( QListViewItem* ); |
250 | void slotNoKey(); | 65 | void slotNoKey(); |
251 | void slotDefaultKey(); | 66 | void slotDefaultKey(); |
252 | void slotCustomKey(); | 67 | void slotCustomKey(); |
253 | void slotConfigure(); | 68 | void slotConfigure(); |
254 | 69 | ||
255 | private: | 70 | private: |
256 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, | 71 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, |
257 | const OKeyPair& newItem ); | 72 | const Opie::Core::OKeyPair& newItem ); |
258 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, | 73 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, |
259 | const OKeyPair& newItem); | 74 | const Opie::Core::OKeyPair& newItem); |
260 | void initUi(); | 75 | void initUi(); |
261 | Opie::Ui::OListView *m_view; | 76 | Opie::Ui::OListView *m_view; |
262 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; | 77 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; |
263 | QLabel *m_lbl; | 78 | QLabel *m_lbl; |
264 | QPushButton *m_btn; | 79 | QPushButton *m_btn; |
265 | QRadioButton *m_def, *m_cus, *m_none; | 80 | QRadioButton *m_def, *m_cus, *m_none; |
266 | QWidget* m_box; | 81 | QWidget* m_box; |
267 | ChangeMode m_mode; | 82 | ChangeMode m_mode; |
268 | class Private; | 83 | class Private; |
269 | Private *d; | 84 | Private *d; |
270 | }; | 85 | }; |
271 | 86 | ||
272 | 87 | ||
273 | /** | 88 | /** |
274 | * This is a small dialog that allows you to | 89 | * This is a small dialog that allows you to |
275 | * capture a key sequence. | 90 | * capture a key sequence. |
276 | * If you want it to close after a key was captured you | 91 | * If you want it to close after a key was captured you |
277 | * can use this code snippet. | 92 | * can use this code snippet. |
278 | * | 93 | * |
279 | * \code | 94 | * \code |
280 | * OKeyChooserConfigDialog diag(0,0,true); | 95 | * OKeyChooserConfigDialog diag(0,0,true); |
281 | * connect(&diag,SIGNAL(keyCaptured()), | 96 | * connect(&diag,SIGNAL(keyCaptured()), |
282 | * this,SLOT(accept())); | 97 | * this,SLOT(accept())); |
283 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ | 98 | * if( QPEApplication::execDialog(&diag) == QDialog::Accept ){ |
284 | * take_the_key_and_do_something | 99 | * take_the_key_and_do_something |
285 | * } | 100 | * } |
286 | * | 101 | * |
287 | * \endcode | 102 | * \endcode |
288 | * | 103 | * |
289 | */ | 104 | */ |
290 | class OKeyChooserConfigDialog : public QDialog { | 105 | class OKeyChooserConfigDialog : public QDialog { |
291 | Q_OBJECT | 106 | Q_OBJECT |
292 | public: | 107 | public: |
293 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 108 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
294 | ~OKeyChooserConfigDialog(); | 109 | ~OKeyChooserConfigDialog(); |
295 | 110 | ||
296 | OKeyPair keyPair()const; | 111 | Opie::Core::OKeyPair keyPair()const; |
297 | 112 | ||
298 | protected: | 113 | protected: |
299 | void keyPressEvent( QKeyEvent* ); | 114 | void keyPressEvent( QKeyEvent* ); |
300 | void keyReleaseEvent( QKeyEvent* ); | 115 | void keyReleaseEvent( QKeyEvent* ); |
301 | 116 | ||
302 | signals: | 117 | signals: |
303 | void keyCaptured(); | 118 | void keyCaptured(); |
304 | 119 | ||
305 | private slots: | 120 | private slots: |
306 | void slotTimeUp(); | 121 | void slotTimeUp(); |
307 | 122 | ||
308 | private: | 123 | private: |
309 | QTimer *m_timer; | 124 | QTimer *m_timer; |
310 | QLabel *m_lbl; | 125 | QLabel *m_lbl; |
311 | bool m_virtKey : 1; | 126 | bool m_virtKey : 1; |
312 | OKeyPair m_keyPair; | 127 | Opie::Core::OKeyPair m_keyPair; |
313 | int m_key, m_mod; | 128 | int m_key, m_mod; |
314 | class Private; | 129 | class Private; |
315 | Private *d; | 130 | Private *d; |
316 | }; | 131 | }; |
317 | 132 | ||
318 | } | 133 | } |
319 | } | 134 | } |
320 | 135 | ||
321 | 136 | ||
322 | #endif | 137 | #endif |
diff --git a/libopie2/opieui/okeyconfigwidget_p.h b/libopie2/opieui/okeyconfigwidget_p.h index 7690846..4dece4d 100644 --- a/libopie2/opieui/okeyconfigwidget_p.h +++ b/libopie2/opieui/okeyconfigwidget_p.h | |||
@@ -1,33 +1,35 @@ | |||
1 | /* | 1 | /* |
2 | * Only Internal implemented in the same .cpp file anyway | 2 | * Only Internal implemented in the same .cpp file anyway |
3 | */ | 3 | */ |
4 | #include <opie2/olistview.h> | 4 | #include <opie2/olistview.h> |
5 | 5 | ||
6 | #include <opie2/okeyconfigmanager_p.h> | ||
6 | 7 | ||
7 | namespace Opie { | 8 | namespace Opie { |
8 | namespace Ui { | 9 | namespace Ui { |
9 | namespace Internal { | 10 | namespace Internal { |
10 | static QString keyToString( const OKeyPair& ); | 11 | static QString keyToString( const Opie::Core::OKeyPair& ); |
11 | static void fixupKeys( int&, int&, QKeyEvent* ); | ||
12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { | 12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { |
13 | public: | 13 | public: |
14 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); | 14 | OKeyListViewItem( const Opie::Core::OKeyConfigItem& item, |
15 | Opie::Core::OKeyConfigManager*, | ||
16 | Opie::Ui::OListViewItem* parent); | ||
15 | ~OKeyListViewItem(); | 17 | ~OKeyListViewItem(); |
16 | 18 | ||
17 | void setDefault(); | 19 | void setDefault(); |
18 | 20 | ||
19 | OKeyConfigItem& item(); | 21 | Opie::Core::OKeyConfigItem& item(); |
20 | OKeyConfigItem origItem()const; | 22 | Opie::Core::OKeyConfigItem origItem()const; |
21 | void setItem( const OKeyConfigItem& item ); | 23 | void setItem( const Opie::Core::OKeyConfigItem& item ); |
22 | void updateText(); | 24 | void updateText(); |
23 | 25 | ||
24 | OKeyConfigManager *manager(); | 26 | Opie::Core::OKeyConfigManager *manager(); |
25 | private: | 27 | private: |
26 | OKeyConfigItem m_item; | 28 | Opie::Core::OKeyConfigItem m_item; |
27 | OKeyConfigItem m_origItem; | 29 | Opie::Core::OKeyConfigItem m_origItem; |
28 | OKeyConfigManager* m_manager; | 30 | Opie::Core::OKeyConfigManager* m_manager; |
29 | 31 | ||
30 | }; | 32 | }; |
31 | } | 33 | } |
32 | } | 34 | } |
33 | } | 35 | } |