summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp
index 1991381..56f4746 100644
--- a/libopie2/opieui/okeyconfigwidget.cpp
+++ b/libopie2/opieui/okeyconfigwidget.cpp
@@ -1,527 +1,527 @@
1#include "okeyconfigwidget.h" 1#include "okeyconfigwidget.h"
2#include "okeyconfigwidget_p.h" 2#include "okeyconfigwidget_p.h"
3 3
4 4
5#include <qgroupbox.h> 5#include <qgroupbox.h>
6#include <qradiobutton.h> 6#include <qradiobutton.h>
7#include <qpushbutton.h> 7#include <qpushbutton.h>
8#include <qbuttongroup.h> 8#include <qbuttongroup.h>
9#include <qmessagebox.h> 9#include <qmessagebox.h>
10#include <qaccel.h> 10#include <qaccel.h>
11#include <qlayout.h> 11#include <qlayout.h>
12#include <qlabel.h> 12#include <qlabel.h>
13 13
14/* non gui */ 14/* non gui */
15#include <qtimer.h> 15#include <qtimer.h>
16 16
17using Opie::Core::OKeyConfigItem; 17using Opie::Core::OKeyConfigItem;
18using Opie::Core::OKeyPair; 18using Opie::Core::OKeyPair;
19using Opie::Core::OKeyConfigManager; 19using Opie::Core::OKeyConfigManager;
20 20
21namespace Opie { 21namespace Opie {
22namespace Ui { 22namespace Ui {
23namespace Internal { 23namespace Internal {
24 24
25 OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent) 25 OKeyListViewItem::OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager* man, OListViewItem* parent)
26 : Opie::Ui::OListViewItem( parent ), m_manager( man ) { 26 : Opie::Ui::OListViewItem( parent ), m_manager( man ) {
27 m_origItem = item; 27 m_origItem = item;
28 setItem( item ); 28 setItem( item );
29 } 29 }
30 OKeyListViewItem::~OKeyListViewItem() {} 30 OKeyListViewItem::~OKeyListViewItem() {}
31 OKeyConfigItem &OKeyListViewItem::item(){ 31 OKeyConfigItem &OKeyListViewItem::item(){
32 return m_item; 32 return m_item;
33 } 33 }
34 OKeyConfigItem OKeyListViewItem::origItem() const{ 34 OKeyConfigItem OKeyListViewItem::origItem() const{
35 return m_origItem; 35 return m_origItem;
36 } 36 }
37 OKeyConfigManager* OKeyListViewItem::manager() { 37 OKeyConfigManager* OKeyListViewItem::manager() {
38 return m_manager; 38 return m_manager;
39 } 39 }
40 void OKeyListViewItem::setItem( const OKeyConfigItem& item ) { 40 void OKeyListViewItem::setItem( const OKeyConfigItem& item ) {
41 m_item = item; 41 m_item = item;
42 setPixmap( 0, m_item.pixmap() ); 42 setPixmap( 0, m_item.pixmap() );
43 setText ( 1, m_item.text() ); 43 setText ( 1, m_item.text() );
44 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : 44 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) :
45 setText( 2, keyToString( m_item.keyPair() ) ); 45 setText( 2, keyToString( m_item.keyPair() ) );
46 46
47 m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) : 47 m_item.defaultKeyPair().isEmpty() ? setText( 3, QObject::tr( "None" ) ) :
48 setText ( 3, keyToString( m_item.defaultKeyPair() ) ); 48 setText ( 3, keyToString( m_item.defaultKeyPair() ) );
49 } 49 }
50 void OKeyListViewItem::updateText() { 50 void OKeyListViewItem::updateText() {
51 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) : 51 m_item.keyPair().isEmpty() ? setText( 2, QObject::tr( "None" ) ) :
52 setText( 2, keyToString( m_item.keyPair() ) ); 52 setText( 2, keyToString( m_item.keyPair() ) );
53 } 53 }
54 54
55 QString keyToString( const OKeyPair& pair ) { 55 QString keyToString( const OKeyPair& pair ) {
56 int mod = 0; 56 int mod = 0;
57 if ( pair.modifier() & Qt::ShiftButton ) 57 if ( pair.modifier() & Qt::ShiftButton )
58 mod |= Qt::SHIFT; 58 mod |= Qt::SHIFT;
59 if ( pair.modifier() & Qt::ControlButton ) 59 if ( pair.modifier() & Qt::ControlButton )
60 mod |= Qt::CTRL; 60 mod |= Qt::CTRL;
61 if ( pair.modifier() & Qt::AltButton ) 61 if ( pair.modifier() & Qt::AltButton )
62 mod |= Qt::ALT; 62 mod |= Qt::ALT;
63 63
64 return QAccel::keyToString( mod + pair.keycode() ); 64 return QAccel::keyToString( mod + pair.keycode() );
65 } 65 }
66 66
67 struct OKeyConfigWidgetPrivate{ 67 struct OKeyConfigWidgetPrivate{
68 OKeyConfigWidgetPrivate(const QString& = QString::null, 68 OKeyConfigWidgetPrivate(const QString& = QString::null,
69 OKeyConfigManager* = 0); 69 OKeyConfigManager* = 0);
70 bool operator==( const OKeyConfigWidgetPrivate& ); 70 bool operator==( const OKeyConfigWidgetPrivate& );
71 QString name; 71 QString name;
72 OKeyConfigManager *manager; 72 OKeyConfigManager *manager;
73 }; 73 };
74 74
75 OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name, 75 OKeyConfigWidgetPrivate::OKeyConfigWidgetPrivate( const QString& _name,
76 OKeyConfigManager* man ) 76 OKeyConfigManager* man )
77 : name( _name ), manager( man ){} 77 : name( _name ), manager( man ){}
78 78
79 bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) { 79 bool OKeyConfigWidgetPrivate::operator==( const OKeyConfigWidgetPrivate& item) {
80 if ( manager != item.manager) return false; 80 if ( manager != item.manager) return false;
81 if ( name != item.name ) return false; 81 if ( name != item.name ) return false;
82 82
83 return true; 83 return true;
84 } 84 }
85 85
86} 86}
87 87
88 88
89 89
90 90
91//////////////////////// 91////////////////////////
92//////////////////////// 92////////////////////////
93//////// Widget Starts Here 93//////// Widget Starts Here
94 94
95 95
96 96
97 97
98/** 98/**
99 * 99 *
100 * This is a c'tor. You still need to pass the OKeyConfigManager 100 * This is a c'tor. You still need to pass the OKeyConfigManager
101 * and then issue a load. 101 * and then issue a load.
102 * The default mode is Immediate 102 * The default mode is Immediate
103 * 103 *
104 */ 104 */
105OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl ) 105OKeyConfigWidget::OKeyConfigWidget( QWidget* parent, const char *name, WFlags fl )
106 : QWidget( parent, name, fl ) { 106 : QWidget( parent, name, fl ) {
107 initUi(); 107 initUi();
108} 108}
109 109
110 110
111 111
112/** 112/**
113 * c'tor 113 * c'tor
114 */ 114 */
115OKeyConfigWidget::~OKeyConfigWidget() { 115OKeyConfigWidget::~OKeyConfigWidget() {
116} 116}
117 117
118 118
119/** 119/**
120 * @internal 120 * @internal
121 */ 121 */
122void OKeyConfigWidget::initUi() { 122void OKeyConfigWidget::initUi() {
123 QBoxLayout *layout = new QVBoxLayout( this ); 123 QBoxLayout *layout = new QVBoxLayout( this );
124 QGridLayout *gridLay = new QGridLayout( 2, 2 ); 124 QGridLayout *gridLay = new QGridLayout( 2, 2 );
125 layout->addLayout( gridLay, 10 ); 125 layout->addLayout( gridLay, 10 );
126 gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth 126 gridLay->setRowStretch( 1, 10 ); // let only the ListView strecth
127 127
128/* 128/*
129 * LISTVIEW with the Keys 129 * LISTVIEW with the Keys
130 */ 130 */
131 m_view = new Opie::Ui::OListView( this ); 131 m_view = new Opie::Ui::OListView( this );
132 m_view->setFocus(); 132 m_view->setFocus();
133 m_view->setAllColumnsShowFocus( true ); 133 m_view->setAllColumnsShowFocus( true );
134 m_view->addColumn( tr("Pixmap") ); 134 m_view->addColumn( tr("Pixmap") );
135 m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) ); 135 m_view->addColumn( tr("Name","Name of the Action in the ListView Header" ) );
136 m_view->addColumn( tr("Key" ) ); 136 m_view->addColumn( tr("Key" ) );
137 m_view->addColumn( tr("Default Key" ) ); 137 m_view->addColumn( tr("Default Key" ) );
138 m_view->setRootIsDecorated( true ); 138 m_view->setRootIsDecorated( true );
139 connect(m_view, SIGNAL(currentChanged(QListViewItem*)), 139 connect(m_view, SIGNAL(currentChanged(QListViewItem*)),
140 this, SLOT(slotListViewItem(QListViewItem*)) ); 140 this, SLOT(slotListViewItem(QListViewItem*)) );
141 141
142 gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 ); 142 gridLay->addMultiCellWidget( m_view, 1, 1, 0, 1 );
143 143
144/* 144/*
145 * GROUP with button info 145 * GROUP with button info
146 */ 146 */
147 147
148 QGroupBox *box = new QGroupBox( this ); 148 QGroupBox *box = new QGroupBox( this );
149 box ->setTitle( tr("Shortcut for Selected Action") ); 149 box ->setTitle( tr("Shortcut for Selected Action") );
150 box ->setFrameStyle( QFrame::Box | QFrame::Sunken ); 150 box ->setFrameStyle( QFrame::Box | QFrame::Sunken );
151 layout->addWidget( box, 1 ); 151 layout->addWidget( box, 1 );
152 152
153 gridLay = new QGridLayout( box, 3, 4 ); 153 gridLay = new QGridLayout( box, 3, 4 );
154 gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() ); 154 gridLay->addRowSpacing( 0, fontMetrics().lineSpacing() );
155 gridLay->setMargin( 4 ); 155 gridLay->setMargin( 4 );
156 156
157 QButtonGroup *gr = new QButtonGroup( box ); 157 QButtonGroup *gr = new QButtonGroup( box );
158 gr->hide(); 158 gr->hide();
159 gr->setExclusive( true ); 159 gr->setExclusive( true );
160 160
161 QRadioButton *rad = new QRadioButton( tr( "&None" ), box ); 161 QRadioButton *rad = new QRadioButton( tr( "&None" ), box );
162 connect( rad, SIGNAL(clicked()), 162 connect( rad, SIGNAL(clicked()),
163 this, SLOT(slotNoKey()) ); 163 this, SLOT(slotNoKey()) );
164 gr->insert( rad, 10 ); 164 gr->insert( rad, 10 );
165 gridLay->addWidget( rad, 1, 0 ); 165 gridLay->addWidget( rad, 1, 0 );
166 m_none = rad; 166 m_none = rad;
167 167
168 rad = new QRadioButton( tr("&Default" ), box ); 168 rad = new QRadioButton( tr("&Default" ), box );
169 connect( rad, SIGNAL(clicked()), 169 connect( rad, SIGNAL(clicked()),
170 this, SLOT(slotDefaultKey()) ); 170 this, SLOT(slotDefaultKey()) );
171 gr->insert( rad, 11 ); 171 gr->insert( rad, 11 );
172 gridLay->addWidget( rad, 1, 1 ); 172 gridLay->addWidget( rad, 1, 1 );
173 m_def = rad; 173 m_def = rad;
174 174
175 rad = new QRadioButton( tr("C&ustom"), box ); 175 rad = new QRadioButton( tr("C&ustom"), box );
176 connect( rad, SIGNAL(clicked()), 176 connect( rad, SIGNAL(clicked()),
177 this, SLOT(slotCustomKey()) ); 177 this, SLOT(slotCustomKey()) );
178 gr->insert( rad, 12 ); 178 gr->insert( rad, 12 );
179 gridLay->addWidget( rad, 1, 2 ); 179 gridLay->addWidget( rad, 1, 2 );
180 m_cus = rad; 180 m_cus = rad;
181 181
182 m_btn = new QPushButton( tr("Configure Key"), box ); 182 m_btn = new QPushButton( tr("Configure Key"), box );
183 gridLay->addWidget( m_btn, 1, 4 ); 183 gridLay->addWidget( m_btn, 1, 3 );
184 184
185 m_lbl= new QLabel( tr( "Default: " ), box ); 185 m_lbl= new QLabel( tr( "Default: " ), box );
186 gridLay->addWidget( m_lbl, 2, 0 ); 186 gridLay->addMultiCellWidget( m_lbl, 2, 2, 0, 3 );
187 187
188 connect(m_btn, SIGNAL(clicked()), 188 connect(m_btn, SIGNAL(clicked()),
189 this, SLOT(slotConfigure())); 189 this, SLOT(slotConfigure()));
190 190
191 m_box = box; 191 m_box = box;
192} 192}
193 193
194/** 194/**
195 * Set the ChangeMode. 195 * Set the ChangeMode.
196 * You need to call this function prior to load 196 * You need to call this function prior to load
197 * If you call this function past load the behaviour is undefined 197 * If you call this function past load the behaviour is undefined
198 * But caling load again is safe 198 * But caling load again is safe
199 */ 199 */
200void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) { 200void OKeyConfigWidget::setChangeMode( enum ChangeMode mode) {
201 m_mode = mode; 201 m_mode = mode;
202} 202}
203 203
204 204
205/** 205/**
206 * return the current mode 206 * return the current mode
207 */ 207 */
208OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const { 208OKeyConfigWidget::ChangeMode OKeyConfigWidget::changeMode()const {
209 return m_mode; 209 return m_mode;
210} 210}
211 211
212 212
213/** 213/**
214 * insert these items before calling load 214 * insert these items before calling load
215 */ 215 */
216void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) { 216void OKeyConfigWidget::insert( const QString& str, OKeyConfigManager* man ) {
217 Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man ); 217 Opie::Ui::Internal::OKeyConfigWidgetPrivate root( str, man );
218 m_list.append(root); 218 m_list.append(root);
219} 219}
220 220
221 221
222/** 222/**
223 * loads the items and allows editing them 223 * loads the items and allows editing them
224 */ 224 */
225void OKeyConfigWidget::load() { 225void OKeyConfigWidget::load() {
226 Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it; 226 Opie::Ui::Internal::OKeyConfigWidgetPrivateList::Iterator it;
227 for ( it = m_list.begin(); it != m_list.end(); ++it ) { 227 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
228 OListViewItem *item = new OListViewItem( m_view, (*it).name ); 228 OListViewItem *item = new OListViewItem( m_view, (*it).name );
229 OKeyConfigItem::List list = (*it).manager->keyConfigList(); 229 OKeyConfigItem::List list = (*it).manager->keyConfigList();
230 for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt ) 230 for (OKeyConfigItem::List::Iterator keyIt = list.begin(); keyIt != list.end();++keyIt )
231 (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item ); 231 (void )new Opie::Ui::Internal::OKeyListViewItem(*keyIt, (*it).manager, item );
232 232
233 } 233 }
234} 234}
235 235
236/** 236/**
237 * Saves if in Queue Mode. It'll update the supplied 237 * Saves if in Queue Mode. It'll update the supplied
238 * OKeyConfigManager objects. 238 * OKeyConfigManager objects.
239 * If in Queue mode it'll just return 239 * If in Queue mode it'll just return
240 */ 240 */
241void OKeyConfigWidget::save() { 241void OKeyConfigWidget::save() {
242 /* 242 /*
243 * Iterate over all config items 243 * Iterate over all config items
244 */ 244 */
245 QListViewItemIterator it( m_view ); 245 QListViewItemIterator it( m_view );
246 while ( it.current() ) { 246 while ( it.current() ) {
247 if (it.current()->parent() ) { 247 if (it.current()->parent() ) {
248 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() ); 248 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( it.current() );
249 OKeyConfigManager *man = item->manager(); 249 OKeyConfigManager *man = item->manager();
250 man->removeKeyConfig( item->origItem() ); 250 man->removeKeyConfig( item->origItem() );
251 man->addKeyConfig( item->item() ); 251 man->addKeyConfig( item->item() );
252 } 252 }
253 ++it; 253 ++it;
254 } 254 }
255 255
256 256
257} 257}
258 258
259 259
260/** 260/**
261 * @internal 261 * @internal
262 */ 262 */
263void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) { 263void OKeyConfigWidget::slotListViewItem( QListViewItem* _item) {
264 if ( !_item || !_item->parent() ) { 264 if ( !_item || !_item->parent() ) {
265 m_box->setEnabled( false ); 265 m_box->setEnabled( false );
266 m_none->setChecked( true ); 266 m_none->setChecked( true );
267 m_btn ->setEnabled( false ); 267 m_btn ->setEnabled( false );
268 m_def ->setChecked( false ); 268 m_def ->setChecked( false );
269 m_cus ->setChecked( false ); 269 m_cus ->setChecked( false );
270 }else{ 270 }else{
271 m_box->setEnabled( true ); 271 m_box->setEnabled( true );
272 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item ); 272 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>( _item );
273 OKeyConfigItem keyItem= item->item(); 273 OKeyConfigItem keyItem= item->item();
274 m_lbl->setText( tr("Default: " )+ item->text( 3 ) ); 274 m_lbl->setText( tr("Default: " )+ item->text( 3 ) );
275 if ( keyItem.keyPair().isEmpty() ) { 275 if ( keyItem.keyPair().isEmpty() ) {
276 m_none->setChecked( true ); 276 m_none->setChecked( true );
277 m_btn ->setEnabled( false ); 277 m_btn ->setEnabled( false );
278 m_def ->setChecked( false ); 278 m_def ->setChecked( false );
279 m_cus ->setChecked( false ); 279 m_cus ->setChecked( false );
280 }else { 280 }else {
281 m_none->setChecked( false ); 281 m_none->setChecked( false );
282 m_cus ->setChecked( true ); 282 m_cus ->setChecked( true );
283 m_btn ->setEnabled( true ); 283 m_btn ->setEnabled( true );
284 m_def ->setChecked( false ); 284 m_def ->setChecked( false );
285 } 285 }
286 } 286 }
287} 287}
288 288
289void OKeyConfigWidget::slotNoKey() { 289void OKeyConfigWidget::slotNoKey() {
290 m_none->setChecked( true ); 290 m_none->setChecked( true );
291 m_cus ->setChecked( false ); 291 m_cus ->setChecked( false );
292 m_btn ->setEnabled( false ); 292 m_btn ->setEnabled( false );
293 m_def ->setChecked( false ); 293 m_def ->setChecked( false );
294 294
295 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 295 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
296 return; 296 return;
297 297
298 298
299 299
300 /* 300 /*
301 * If immediate we need to remove and readd the key 301 * If immediate we need to remove and readd the key
302 */ 302 */
303 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); 303 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem());
304 updateItem( item, OKeyPair::emptyKey() ); 304 updateItem( item, OKeyPair::emptyKey() );
305} 305}
306 306
307void OKeyConfigWidget::slotDefaultKey() { 307void OKeyConfigWidget::slotDefaultKey() {
308 m_none->setChecked( false ); 308 m_none->setChecked( false );
309 m_cus ->setChecked( false ); 309 m_cus ->setChecked( false );
310 m_btn ->setEnabled( false ); 310 m_btn ->setEnabled( false );
311 m_def ->setChecked( true ); 311 m_def ->setChecked( true );
312 312
313 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 313 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
314 return; 314 return;
315 315
316 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); 316 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem());
317 updateItem( item, item->item().defaultKeyPair() ); 317 updateItem( item, item->item().defaultKeyPair() );
318} 318}
319 319
320void OKeyConfigWidget::slotCustomKey() { 320void OKeyConfigWidget::slotCustomKey() {
321 m_cus ->setChecked( true ); 321 m_cus ->setChecked( true );
322 m_btn ->setEnabled( true ); 322 m_btn ->setEnabled( true );
323 m_def ->setChecked( false ); 323 m_def ->setChecked( false );
324 m_none->setChecked( false ); 324 m_none->setChecked( false );
325 325
326 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 326 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
327 return; 327 return;
328 328
329 329
330} 330}
331 331
332void OKeyConfigWidget::slotConfigure() { 332void OKeyConfigWidget::slotConfigure() {
333 if ( !m_view->currentItem() || !m_view->currentItem()->parent() ) 333 if ( !m_view->currentItem() || !m_view->currentItem()->parent() )
334 return; 334 return;
335 335
336 /* FIXME make use of OModalHelper */ 336 /* FIXME make use of OModalHelper */
337 OKeyChooserConfigDialog dlg( this, "Dialog Name", true ); 337 OKeyChooserConfigDialog dlg( this, "Dialog Name", true );
338 dlg.setCaption(tr("Configure Key")); 338 dlg.setCaption(tr("Configure Key"));
339 connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) ); 339 connect(&dlg, SIGNAL(keyCaptured()), &dlg, SLOT(accept()) );
340 340
341 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { 341 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) {
342 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem()); 342 Opie::Ui::Internal::OKeyListViewItem *item = static_cast<Opie::Ui::Internal::OKeyListViewItem*>(m_view->currentItem());
343 updateItem( item, dlg.keyPair() ); 343 updateItem( item, dlg.keyPair() );
344 } 344 }
345 345
346 346
347} 347}
348 348
349bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item, 349bool OKeyConfigWidget::sanityCheck( Opie::Ui::Internal::OKeyListViewItem* item,
350 const OKeyPair& newItem ) { 350 const OKeyPair& newItem ) {
351 OKeyPair::List bList = item->manager()->blackList(); 351 OKeyPair::List bList = item->manager()->blackList();
352 for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) { 352 for ( OKeyPair::List::Iterator it = bList.begin(); it != bList.end(); ++it ) {
353 /* black list matched */ 353 /* black list matched */
354 if ( *it == newItem ) { 354 if ( *it == newItem ) {
355 QMessageBox::warning( 0, tr("Key is on BlackList" ), 355 QMessageBox::warning( 0, tr("Key is on BlackList" ),
356 tr("<qt>The Key you choose is on the black list " 356 tr("<qt>The Key you choose is on the black list "
357 "and may not be used with this manager. Please " 357 "and may not be used with this manager. Please "
358 "use a different key.</qt>" ) ); 358 "use a different key.</qt>" ) );
359 return false; 359 return false;
360 } 360 }
361 } 361 }
362 /* no we need to check the other items which is dog slow */ 362 /* no we need to check the other items which is dog slow */
363 QListViewItemIterator it( item->parent() ); 363 QListViewItemIterator it( item->parent() );
364 while ( it.current() ) { 364 while ( it.current() ) {
365 /* if not our parent and not us */ 365 /* if not our parent and not us */
366 if (it.current()->parent() && it.current() != item) { 366 if (it.current()->parent() && it.current() != item) {
367 /* damn already given away*/ 367 /* damn already given away*/
368 if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) { 368 if ( newItem == static_cast<Opie::Ui::Internal::OKeyListViewItem*>(it.current() )->item().keyPair() ) {
369 QMessageBox::warning( 0, tr("Key is already assigned" ), 369 QMessageBox::warning( 0, tr("Key is already assigned" ),
370 tr("<qt>The Key you choose is already taken by " 370 tr("<qt>The Key you choose is already taken by "
371 "a different Item of your config. Please try" 371 "a different Item of your config. Please try"
372 "using a different key.</qt>" ) ); 372 "using a different key.</qt>" ) );
373 return false; 373 return false;
374 } 374 }
375 } 375 }
376 ++it; 376 ++it;
377 } 377 }
378 378
379 return true; 379 return true;
380} 380}
381 381
382void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item, 382void OKeyConfigWidget::updateItem( Opie::Ui::Internal::OKeyListViewItem *item,
383 const OKeyPair& newItem) { 383 const OKeyPair& newItem) {
384 /* sanity check 384 /* sanity check
385 * check against the blacklist of the manager 385 * check against the blacklist of the manager
386 * check if another item uses this key which is o(n) at least 386 * check if another item uses this key which is o(n) at least
387 */ 387 */
388 if ( !newItem.isEmpty() && !sanityCheck(item, newItem )) 388 if ( !newItem.isEmpty() && !sanityCheck(item, newItem ))
389 return; 389 return;
390 390
391 391
392 392
393 /* 393 /*
394 * If immediate we need to remove and readd the key 394 * If immediate we need to remove and readd the key
395 */ 395 */
396 if ( m_mode == Imediate ) 396 if ( m_mode == Imediate )
397 item->manager()->removeKeyConfig( item->item() ); 397 item->manager()->removeKeyConfig( item->item() );
398 398
399 item->item().setKeyPair( newItem ); 399 item->item().setKeyPair( newItem );
400 item->updateText(); 400 item->updateText();
401 401
402 if ( m_mode == Imediate ) 402 if ( m_mode == Imediate )
403 item->manager()->addKeyConfig( item->item() ); 403 item->manager()->addKeyConfig( item->item() );
404} 404}
405 405
406 406
407 407
408///// 408/////
409OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, 409OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam,
410 bool mod, WFlags fl ) 410 bool mod, WFlags fl )
411 : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) , 411 : QDialog( par, nam, mod, fl ), m_virtKey( false ), m_keyPair( OKeyPair::emptyKey() ) ,
412 m_key( 0 ), m_mod( 0 ) { 412 m_key( 0 ), m_mod( 0 ) {
413 setFocusPolicy( StrongFocus ); 413 setFocusPolicy( StrongFocus );
414 414
415 QHBoxLayout *lay = new QHBoxLayout( this ); 415 QHBoxLayout *lay = new QHBoxLayout( this );
416 416
417 QLabel *lbl = new QLabel( tr("Configure Key" ), this ); 417 QLabel *lbl = new QLabel( tr("Configure Key" ), this );
418 lay->addWidget( lbl ); 418 lay->addWidget( lbl );
419 lbl->setFocusPolicy( NoFocus ); 419 lbl->setFocusPolicy( NoFocus );
420 420
421 m_lbl = new QLabel( this ); 421 m_lbl = new QLabel( this );
422 lay->addWidget( m_lbl ); 422 lay->addWidget( m_lbl );
423 m_lbl->setFocusPolicy( NoFocus ); 423 m_lbl->setFocusPolicy( NoFocus );
424 424
425 m_timer = new QTimer( this ); 425 m_timer = new QTimer( this );
426 connect(m_timer, SIGNAL(timeout()), 426 connect(m_timer, SIGNAL(timeout()),
427 this, SLOT(slotTimeUp()) ); 427 this, SLOT(slotTimeUp()) );
428} 428}
429 429
430OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { 430OKeyChooserConfigDialog::~OKeyChooserConfigDialog() {
431} 431}
432 432
433Opie::Core::OKeyPair OKeyChooserConfigDialog::keyPair()const{ 433Opie::Core::OKeyPair OKeyChooserConfigDialog::keyPair()const{
434 return m_keyPair; 434 return m_keyPair;
435} 435}
436 436
437void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { 437void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) {
438 QDialog::keyPressEvent( ev ); 438 QDialog::keyPressEvent( ev );
439 439
440 if ( ev->isAutoRepeat() ) 440 if ( ev->isAutoRepeat() )
441 return; 441 return;
442 442
443 int mod, key; 443 int mod, key;
444 Opie::Core::Internal::fixupKeys( key,mod, ev ); 444 Opie::Core::Internal::fixupKeys( key,mod, ev );
445 445
446 /* either we used software keyboard 446 /* either we used software keyboard
447 * or we've true support 447 * or we've true support
448 */ 448 */
449 if ( !m_virtKey && !ev->key()) { 449 if ( !m_virtKey && !ev->key()) {
450 m_virtKey = true; 450 m_virtKey = true;
451 m_keyPair = OKeyPair( key, mod ); 451 m_keyPair = OKeyPair( key, mod );
452 }else{ 452 }else{
453 mod = 0; 453 mod = 0;
454 switch( key ) { 454 switch( key ) {
455 case Qt::Key_Control: 455 case Qt::Key_Control:
456 mod = Qt::ControlButton; 456 mod = Qt::ControlButton;
457 break; 457 break;
458 case Qt::Key_Shift: 458 case Qt::Key_Shift:
459 mod = Qt::ShiftButton; 459 mod = Qt::ShiftButton;
460 break; 460 break;
461 case Qt::Key_Alt: 461 case Qt::Key_Alt:
462 mod = Qt::AltButton; 462 mod = Qt::AltButton;
463 break; 463 break;
464 default: 464 default:
465 break; 465 break;
466 } 466 }
467 if (mod ) { 467 if (mod ) {
468 m_mod |= mod; 468 m_mod |= mod;
469 key = 0; 469 key = 0;
470 }else 470 }else
471 m_key = key; 471 m_key = key;
472 472
473 if ( ( !mod || m_key || key ) && !m_timer->isActive() ) 473 if ( ( !mod || m_key || key ) && !m_timer->isActive() )
474 m_timer->start( 150, true ); 474 m_timer->start( 150, true );
475 475
476 m_keyPair = OKeyPair( m_key, m_mod ); 476 m_keyPair = OKeyPair( m_key, m_mod );
477 } 477 }
478 478
479 m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); 479 m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) );
480 480
481} 481}
482 482
483void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) { 483void OKeyChooserConfigDialog::keyReleaseEvent( QKeyEvent* ev ) {
484 m_timer->stop(); 484 m_timer->stop();
485 QDialog::keyPressEvent( ev ); 485 QDialog::keyPressEvent( ev );
486 486
487 if ( ev->isAutoRepeat() ) 487 if ( ev->isAutoRepeat() )
488 return; 488 return;
489 489
490 490
491 if ( m_virtKey && !ev->key()) { 491 if ( m_virtKey && !ev->key()) {
492 m_virtKey = false; 492 m_virtKey = false;
493 slotTimeUp(); 493 slotTimeUp();
494 }else { 494 }else {
495 int mod = 0; 495 int mod = 0;
496 int key = ev->key(); 496 int key = ev->key();
497 switch( key ) { 497 switch( key ) {
498 case Qt::Key_Control: 498 case Qt::Key_Control:
499 mod = Qt::ControlButton; 499 mod = Qt::ControlButton;
500 break; 500 break;
501 case Qt::Key_Shift: 501 case Qt::Key_Shift:
502 mod = Qt::ShiftButton; 502 mod = Qt::ShiftButton;
503 break; 503 break;
504 case Qt::Key_Alt: 504 case Qt::Key_Alt:
505 mod = Qt::AltButton; 505 mod = Qt::AltButton;
506 break; 506 break;
507 default: 507 default:
508 break; 508 break;
509 } 509 }
510 if (mod ) 510 if (mod )
511 m_mod &= ~mod; 511 m_mod &= ~mod;
512 else 512 else
513 m_key = key; 513 m_key = key;
514 m_keyPair = OKeyPair( m_key, m_mod ); 514 m_keyPair = OKeyPair( m_key, m_mod );
515 m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) ); 515 m_lbl->setText( Opie::Ui::Internal::keyToString( m_keyPair ) );
516 } 516 }
517} 517}
518 518
519 519
520void OKeyChooserConfigDialog::slotTimeUp() { 520void OKeyChooserConfigDialog::slotTimeUp() {
521 m_mod = m_key = 0; 521 m_mod = m_key = 0;
522 QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); 522 QTimer::singleShot(0, this, SIGNAL(keyCaptured()) );
523} 523}
524 524
525 525
526} 526}
527} 527}