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