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