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