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