-rw-r--r-- | libopie2/qt3/opieui/ocombobox.cpp | 5 | ||||
-rw-r--r-- | libopie2/qt3/opieui/oeditlistbox.cpp | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp index a1dd5f5..8dbda8f 100644 --- a/libopie2/qt3/opieui/ocombobox.cpp +++ b/libopie2/qt3/opieui/ocombobox.cpp | |||
@@ -131,385 +131,388 @@ void OComboBox::setAutoCompletion( bool autocomplete ) | |||
131 | { | 131 | { |
132 | if ( autocomplete ) | 132 | if ( autocomplete ) |
133 | { | 133 | { |
134 | d->olineEdit->setCompletionMode( OGlobalSettings::CompletionAuto ); | 134 | d->olineEdit->setCompletionMode( OGlobalSettings::CompletionAuto ); |
135 | setCompletionMode( OGlobalSettings::CompletionAuto ); | 135 | setCompletionMode( OGlobalSettings::CompletionAuto ); |
136 | } | 136 | } |
137 | else | 137 | else |
138 | { | 138 | { |
139 | d->olineEdit->setCompletionMode( OGlobalSettings::completionMode() ); | 139 | d->olineEdit->setCompletionMode( OGlobalSettings::completionMode() ); |
140 | setCompletionMode( OGlobalSettings::completionMode() ); | 140 | setCompletionMode( OGlobalSettings::completionMode() ); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | void OComboBox::setContextMenuEnabled( bool showMenu ) | 145 | void OComboBox::setContextMenuEnabled( bool showMenu ) |
146 | { | 146 | { |
147 | if( d->olineEdit ) | 147 | if( d->olineEdit ) |
148 | { | 148 | { |
149 | d->olineEdit->setContextMenuEnabled( showMenu ); | 149 | d->olineEdit->setContextMenuEnabled( showMenu ); |
150 | m_bEnableMenu = showMenu; | 150 | m_bEnableMenu = showMenu; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | /* | 154 | /* |
155 | void OComboBox::setURLDropsEnabled( bool enable ) | 155 | void OComboBox::setURLDropsEnabled( bool enable ) |
156 | { | 156 | { |
157 | if ( d->olineEdit ) | 157 | if ( d->olineEdit ) |
158 | d->olineEdit->setURLDropsEnabled( enable ); | 158 | d->olineEdit->setURLDropsEnabled( enable ); |
159 | } | 159 | } |
160 | 160 | ||
161 | bool OComboBox::isURLDropsEnabled() const | 161 | bool OComboBox::isURLDropsEnabled() const |
162 | { | 162 | { |
163 | return d->olineEdit && d->olineEdit->isURLDropsEnabled(); | 163 | return d->olineEdit && d->olineEdit->isURLDropsEnabled(); |
164 | } | 164 | } |
165 | */ | 165 | */ |
166 | 166 | ||
167 | void OComboBox::setCompletedText( const QString& text, bool marked ) | 167 | void OComboBox::setCompletedText( const QString& text, bool marked ) |
168 | { | 168 | { |
169 | if ( d->olineEdit ) | 169 | if ( d->olineEdit ) |
170 | d->olineEdit->setCompletedText( text, marked ); | 170 | d->olineEdit->setCompletedText( text, marked ); |
171 | } | 171 | } |
172 | 172 | ||
173 | void OComboBox::setCompletedText( const QString& text ) | 173 | void OComboBox::setCompletedText( const QString& text ) |
174 | { | 174 | { |
175 | if ( d->olineEdit ) | 175 | if ( d->olineEdit ) |
176 | d->olineEdit->setCompletedText( text ); | 176 | d->olineEdit->setCompletedText( text ); |
177 | } | 177 | } |
178 | 178 | ||
179 | void OComboBox::makeCompletion( const QString& text ) | 179 | void OComboBox::makeCompletion( const QString& text ) |
180 | { | 180 | { |
181 | if( d->olineEdit ) | 181 | if( d->olineEdit ) |
182 | d->olineEdit->makeCompletion( text ); | 182 | d->olineEdit->makeCompletion( text ); |
183 | 183 | ||
184 | else // read-only combo completion | 184 | else // read-only combo completion |
185 | { | 185 | { |
186 | if( text.isNull() || !listBox() ) | 186 | if( text.isNull() || !listBox() ) |
187 | return; | 187 | return; |
188 | 188 | ||
189 | int index = listBox()->index( listBox()->findItem( text ) ); | 189 | int index = listBox()->index( listBox()->findItem( text ) ); |
190 | if( index >= 0 ) { | 190 | if( index >= 0 ) { |
191 | setCurrentItem( index ); | 191 | setCurrentItem( index ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void OComboBox::rotateText( OCompletionBase::KeyBindingType type ) | 196 | void OComboBox::rotateText( OCompletionBase::KeyBindingType type ) |
197 | { | 197 | { |
198 | if ( d->olineEdit ) | 198 | if ( d->olineEdit ) |
199 | d->olineEdit->rotateText( type ); | 199 | d->olineEdit->rotateText( type ); |
200 | } | 200 | } |
201 | 201 | ||
202 | bool OComboBox::eventFilter( QObject* o, QEvent* ev ) | 202 | bool OComboBox::eventFilter( QObject* o, QEvent* ev ) |
203 | { | 203 | { |
204 | QLineEdit *edit = lineEdit(); | 204 | QLineEdit *edit = lineEdit(); |
205 | 205 | ||
206 | int type = ev->type(); | 206 | int type = ev->type(); |
207 | 207 | ||
208 | if ( o == edit ) | 208 | if ( o == edit ) |
209 | { | 209 | { |
210 | //OCursor::autoHideEventFilter( edit, ev ); | 210 | //OCursor::autoHideEventFilter( edit, ev ); |
211 | 211 | ||
212 | if ( type == QEvent::KeyPress ) | 212 | if ( type == QEvent::KeyPress ) |
213 | { | 213 | { |
214 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); | 214 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); |
215 | 215 | ||
216 | if ( e->key() == Key_Return || e->key() == Key_Enter) | 216 | if ( e->key() == Key_Return || e->key() == Key_Enter) |
217 | { | 217 | { |
218 | // On Return pressed event, emit both | 218 | // On Return pressed event, emit both |
219 | // returnPressed(const QString&) and returnPressed() signals | 219 | // returnPressed(const QString&) and returnPressed() signals |
220 | emit returnPressed(); | 220 | emit returnPressed(); |
221 | emit returnPressed( currentText() ); | 221 | emit returnPressed( currentText() ); |
222 | if ( d->olineEdit && d->olineEdit->completionBox(false) && | 222 | if ( d->olineEdit && d->olineEdit->completionBox(false) && |
223 | d->olineEdit->completionBox()->isVisible() ) | 223 | d->olineEdit->completionBox()->isVisible() ) |
224 | d->olineEdit->completionBox()->hide(); | 224 | d->olineEdit->completionBox()->hide(); |
225 | 225 | ||
226 | return m_trapReturnKey; | 226 | return m_trapReturnKey; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | // wheel-scrolling changes the current item | 232 | // wheel-scrolling changes the current item |
233 | if ( type == QEvent::Wheel ) { | 233 | if ( type == QEvent::Wheel ) { |
234 | if ( !listBox() || listBox()->isHidden() ) { | 234 | if ( !listBox() || listBox()->isHidden() ) { |
235 | QWheelEvent *e = static_cast<QWheelEvent*>( ev ); | 235 | QWheelEvent *e = static_cast<QWheelEvent*>( ev ); |
236 | static const int WHEEL_DELTA = 120; | 236 | static const int WHEEL_DELTA = 120; |
237 | int skipItems = e->delta() / WHEEL_DELTA; | 237 | int skipItems = e->delta() / WHEEL_DELTA; |
238 | if ( e->state() & ControlButton ) // fast skipping | 238 | if ( e->state() & ControlButton ) // fast skipping |
239 | skipItems *= 10; | 239 | skipItems *= 10; |
240 | 240 | ||
241 | int newItem = currentItem() - skipItems; | 241 | int newItem = currentItem() - skipItems; |
242 | 242 | ||
243 | if ( newItem < 0 ) | 243 | if ( newItem < 0 ) |
244 | newItem = 0; | 244 | newItem = 0; |
245 | else if ( newItem >= count() ) | 245 | else if ( newItem >= count() ) |
246 | newItem = count() -1; | 246 | newItem = count() -1; |
247 | 247 | ||
248 | setCurrentItem( newItem ); | 248 | setCurrentItem( newItem ); |
249 | if ( !text( newItem ).isNull() ) | 249 | if ( !text( newItem ).isNull() ) |
250 | emit activated( text( newItem ) ); | 250 | emit activated( text( newItem ) ); |
251 | emit activated( newItem ); | 251 | emit activated( newItem ); |
252 | e->accept(); | 252 | e->accept(); |
253 | return true; | 253 | return true; |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | return QComboBox::eventFilter( o, ev ); | 257 | return QComboBox::eventFilter( o, ev ); |
258 | } | 258 | } |
259 | 259 | ||
260 | void OComboBox::setTrapReturnKey( bool grab ) | 260 | void OComboBox::setTrapReturnKey( bool grab ) |
261 | { | 261 | { |
262 | m_trapReturnKey = grab; | 262 | m_trapReturnKey = grab; |
263 | } | 263 | } |
264 | 264 | ||
265 | bool OComboBox::trapReturnKey() const | 265 | bool OComboBox::trapReturnKey() const |
266 | { | 266 | { |
267 | return m_trapReturnKey; | 267 | return m_trapReturnKey; |
268 | } | 268 | } |
269 | 269 | ||
270 | /* | 270 | /* |
271 | void OComboBox::setEditURL( const OURL& url ) | 271 | void OComboBox::setEditURL( const OURL& url ) |
272 | { | 272 | { |
273 | QComboBox::setEditText( url.prettyURL() ); | 273 | QComboBox::setEditText( url.prettyURL() ); |
274 | } | 274 | } |
275 | 275 | ||
276 | void OComboBox::insertURL( const OURL& url, int index ) | 276 | void OComboBox::insertURL( const OURL& url, int index ) |
277 | { | 277 | { |
278 | QComboBox::insertItem( url.prettyURL(), index ); | 278 | QComboBox::insertItem( url.prettyURL(), index ); |
279 | } | 279 | } |
280 | 280 | ||
281 | void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index ) | 281 | void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index ) |
282 | { | 282 | { |
283 | QComboBox::insertItem( pixmap, url.prettyURL(), index ); | 283 | QComboBox::insertItem( pixmap, url.prettyURL(), index ); |
284 | } | 284 | } |
285 | 285 | ||
286 | void OComboBox::changeURL( const OURL& url, int index ) | 286 | void OComboBox::changeURL( const OURL& url, int index ) |
287 | { | 287 | { |
288 | QComboBox::changeItem( url.prettyURL(), index ); | 288 | QComboBox::changeItem( url.prettyURL(), index ); |
289 | } | 289 | } |
290 | 290 | ||
291 | void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index ) | 291 | void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index ) |
292 | { | 292 | { |
293 | QComboBox::changeItem( pixmap, url.prettyURL(), index ); | 293 | QComboBox::changeItem( pixmap, url.prettyURL(), index ); |
294 | } | 294 | } |
295 | */ | 295 | */ |
296 | 296 | ||
297 | 297 | ||
298 | void OComboBox::setCompletedItems( const QStringList& items ) | 298 | void OComboBox::setCompletedItems( const QStringList& items ) |
299 | { | 299 | { |
300 | if ( d->olineEdit ) | 300 | if ( d->olineEdit ) |
301 | d->olineEdit->setCompletedItems( items ); | 301 | d->olineEdit->setCompletedItems( items ); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | OCompletionBox * OComboBox::completionBox( bool create ) | 305 | OCompletionBox * OComboBox::completionBox( bool create ) |
306 | { | 306 | { |
307 | if ( d->olineEdit ) | 307 | if ( d->olineEdit ) |
308 | return d->olineEdit->completionBox( create ); | 308 | return d->olineEdit->completionBox( create ); |
309 | return 0; | 309 | return 0; |
310 | } | 310 | } |
311 | 311 | ||
312 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding | 312 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding |
313 | void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow ) | 313 | void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow ) |
314 | { | 314 | { |
315 | QComboBox::create( id, initializeWindow, destroyOldWindow ); | 315 | QComboBox::create( id, initializeWindow, destroyOldWindow ); |
316 | //OCursor::setAutoHideCursor( lineEdit(), true, true ); | 316 | //OCursor::setAutoHideCursor( lineEdit(), true, true ); |
317 | } | 317 | } |
318 | 318 | ||
319 | void OComboBox::setLineEdit( OLineEdit *edit ) | 319 | void OComboBox::setLineEdit( OLineEdit *edit ) |
320 | { | 320 | { |
321 | #if QT_VERSION > 290 | 321 | #if QT_VERSION > 290 |
322 | QComboBox::setLineEdit( edit ); | 322 | QComboBox::setLineEdit( edit ); |
323 | d->olineEdit = dynamic_cast<OLineEdit*>( edit ); | 323 | if ( !edit->inherits( "OLineEdit" ) ) |
324 | d->olineEdit = 0; | ||
325 | else | ||
326 | d->olineEdit = static_cast<OLineEdit*>( edit ); | ||
324 | setDelegate( d->olineEdit ); | 327 | setDelegate( d->olineEdit ); |
325 | 328 | ||
326 | // forward some signals. We only emit returnPressed() ourselves. | 329 | // forward some signals. We only emit returnPressed() ourselves. |
327 | if ( d->olineEdit ) { | 330 | if ( d->olineEdit ) { |
328 | connect( d->olineEdit, SIGNAL( completion( const QString& )), | 331 | connect( d->olineEdit, SIGNAL( completion( const QString& )), |
329 | SIGNAL( completion( const QString& )) ); | 332 | SIGNAL( completion( const QString& )) ); |
330 | connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )), | 333 | connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )), |
331 | SIGNAL( substringCompletion( const QString& )) ); | 334 | SIGNAL( substringCompletion( const QString& )) ); |
332 | connect( d->olineEdit, | 335 | connect( d->olineEdit, |
333 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )), | 336 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )), |
334 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )) ); | 337 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )) ); |
335 | connect( d->olineEdit, | 338 | connect( d->olineEdit, |
336 | SIGNAL( completionModeChanged( OGlobalSettings::Completion )), | 339 | SIGNAL( completionModeChanged( OGlobalSettings::Completion )), |
337 | SIGNAL( completionModeChanged( OGlobalSettings::Completion))); | 340 | SIGNAL( completionModeChanged( OGlobalSettings::Completion))); |
338 | 341 | ||
339 | connect( d->olineEdit, | 342 | connect( d->olineEdit, |
340 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )), | 343 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )), |
341 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )) ); | 344 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )) ); |
342 | } | 345 | } |
343 | #else | 346 | #else |
344 | #warning OComboBox is not fully functional with Qt2 | 347 | #warning OComboBox is not fully functional with Qt2 |
345 | #endif | 348 | #endif |
346 | } | 349 | } |
347 | 350 | ||
348 | // Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 | 351 | // Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 |
349 | void OComboBox::deleteWordForward() | 352 | void OComboBox::deleteWordForward() |
350 | { | 353 | { |
351 | lineEdit()->cursorWordForward(TRUE); | 354 | lineEdit()->cursorWordForward(TRUE); |
352 | #if QT_VERSION > 290 | 355 | #if QT_VERSION > 290 |
353 | if ( lineEdit()->hasSelectedText() ) | 356 | if ( lineEdit()->hasSelectedText() ) |
354 | #else | 357 | #else |
355 | if ( lineEdit()->hasMarkedText() ) | 358 | if ( lineEdit()->hasMarkedText() ) |
356 | #endif | 359 | #endif |
357 | { | 360 | { |
358 | lineEdit()->del(); | 361 | lineEdit()->del(); |
359 | } | 362 | } |
360 | } | 363 | } |
361 | 364 | ||
362 | void OComboBox::deleteWordBack() | 365 | void OComboBox::deleteWordBack() |
363 | { | 366 | { |
364 | lineEdit()->cursorWordBackward(TRUE); | 367 | lineEdit()->cursorWordBackward(TRUE); |
365 | #if QT_VERSION > 290 | 368 | #if QT_VERSION > 290 |
366 | if ( lineEdit()->hasSelectedText() ) | 369 | if ( lineEdit()->hasSelectedText() ) |
367 | #else | 370 | #else |
368 | if ( lineEdit()->hasMarkedText() ) | 371 | if ( lineEdit()->hasMarkedText() ) |
369 | #endif | 372 | #endif |
370 | { | 373 | { |
371 | lineEdit()->del(); | 374 | lineEdit()->del(); |
372 | } | 375 | } |
373 | } | 376 | } |
374 | 377 | ||
375 | void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) | 378 | void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) |
376 | { | 379 | { |
377 | int sel = -1; | 380 | int sel = -1; |
378 | for (int i = 0; i < count(); ++i) | 381 | for (int i = 0; i < count(); ++i) |
379 | if (text(i) == item) | 382 | if (text(i) == item) |
380 | { | 383 | { |
381 | sel = i; | 384 | sel = i; |
382 | break; | 385 | break; |
383 | } | 386 | } |
384 | if (sel == -1 && insert) | 387 | if (sel == -1 && insert) |
385 | { | 388 | { |
386 | insertItem(item, index); | 389 | insertItem(item, index); |
387 | if (index >= 0) | 390 | if (index >= 0) |
388 | sel = index; | 391 | sel = index; |
389 | else | 392 | else |
390 | sel = count() - 1; | 393 | sel = count() - 1; |
391 | } | 394 | } |
392 | setCurrentItem(sel); | 395 | setCurrentItem(sel); |
393 | } | 396 | } |
394 | 397 | ||
395 | void OComboBox::setCurrentItem(int index) | 398 | void OComboBox::setCurrentItem(int index) |
396 | { | 399 | { |
397 | QComboBox::setCurrentItem(index); | 400 | QComboBox::setCurrentItem(index); |
398 | } | 401 | } |
399 | 402 | ||
400 | 403 | ||
401 | /*====================================================================================== | 404 | /*====================================================================================== |
402 | * OHistoryCombo | 405 | * OHistoryCombo |
403 | *======================================================================================*/ | 406 | *======================================================================================*/ |
404 | 407 | ||
405 | // we are always read-write | 408 | // we are always read-write |
406 | OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) | 409 | OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) |
407 | : OComboBox( true, parent, name ) | 410 | : OComboBox( true, parent, name ) |
408 | { | 411 | { |
409 | init( true ); // using completion | 412 | init( true ); // using completion |
410 | } | 413 | } |
411 | 414 | ||
412 | // we are always read-write | 415 | // we are always read-write |
413 | OHistoryCombo::OHistoryCombo( bool useCompletion, | 416 | OHistoryCombo::OHistoryCombo( bool useCompletion, |
414 | QWidget *parent, const char *name ) | 417 | QWidget *parent, const char *name ) |
415 | : OComboBox( true, parent, name ) | 418 | : OComboBox( true, parent, name ) |
416 | { | 419 | { |
417 | init( useCompletion ); | 420 | init( useCompletion ); |
418 | } | 421 | } |
419 | 422 | ||
420 | void OHistoryCombo::init( bool useCompletion ) | 423 | void OHistoryCombo::init( bool useCompletion ) |
421 | { | 424 | { |
422 | if ( useCompletion ) | 425 | if ( useCompletion ) |
423 | completionObject()->setOrder( OCompletion::Weighted ); | 426 | completionObject()->setOrder( OCompletion::Weighted ); |
424 | 427 | ||
425 | setInsertionPolicy( NoInsertion ); | 428 | setInsertionPolicy( NoInsertion ); |
426 | myIterateIndex = -1; | 429 | myIterateIndex = -1; |
427 | myRotated = false; | 430 | myRotated = false; |
428 | myPixProvider = 0L; | 431 | myPixProvider = 0L; |
429 | 432 | ||
430 | connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), | 433 | connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), |
431 | SLOT(addContextMenuItems(QPopupMenu*)) ); | 434 | SLOT(addContextMenuItems(QPopupMenu*)) ); |
432 | connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); | 435 | connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); |
433 | connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); | 436 | connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); |
434 | } | 437 | } |
435 | 438 | ||
436 | OHistoryCombo::~OHistoryCombo() | 439 | OHistoryCombo::~OHistoryCombo() |
437 | { | 440 | { |
438 | delete myPixProvider; | 441 | delete myPixProvider; |
439 | } | 442 | } |
440 | 443 | ||
441 | void OHistoryCombo::setHistoryItems( QStringList items, | 444 | void OHistoryCombo::setHistoryItems( QStringList items, |
442 | bool setCompletionList ) | 445 | bool setCompletionList ) |
443 | { | 446 | { |
444 | OComboBox::clear(); | 447 | OComboBox::clear(); |
445 | 448 | ||
446 | // limit to maxCount() | 449 | // limit to maxCount() |
447 | while ( (int) items.count() > maxCount() && !items.isEmpty() ) | 450 | while ( (int) items.count() > maxCount() && !items.isEmpty() ) |
448 | items.remove( items.begin() ); | 451 | items.remove( items.begin() ); |
449 | 452 | ||
450 | insertItems( items ); | 453 | insertItems( items ); |
451 | 454 | ||
452 | if ( setCompletionList && useCompletion() ) { | 455 | if ( setCompletionList && useCompletion() ) { |
453 | // we don't have any weighting information here ;( | 456 | // we don't have any weighting information here ;( |
454 | OCompletion *comp = completionObject(); | 457 | OCompletion *comp = completionObject(); |
455 | comp->setOrder( OCompletion::Insertion ); | 458 | comp->setOrder( OCompletion::Insertion ); |
456 | comp->setItems( items ); | 459 | comp->setItems( items ); |
457 | comp->setOrder( OCompletion::Weighted ); | 460 | comp->setOrder( OCompletion::Weighted ); |
458 | } | 461 | } |
459 | 462 | ||
460 | clearEdit(); | 463 | clearEdit(); |
461 | } | 464 | } |
462 | 465 | ||
463 | QStringList OHistoryCombo::historyItems() const | 466 | QStringList OHistoryCombo::historyItems() const |
464 | { | 467 | { |
465 | QStringList list; | 468 | QStringList list; |
466 | for ( int i = 0; i < count(); i++ ) | 469 | for ( int i = 0; i < count(); i++ ) |
467 | list.append( text( i ) ); | 470 | list.append( text( i ) ); |
468 | 471 | ||
469 | return list; | 472 | return list; |
470 | } | 473 | } |
471 | 474 | ||
472 | void OHistoryCombo::clearHistory() | 475 | void OHistoryCombo::clearHistory() |
473 | { | 476 | { |
474 | OComboBox::clear(); | 477 | OComboBox::clear(); |
475 | if ( useCompletion() ) | 478 | if ( useCompletion() ) |
476 | completionObject()->clear(); | 479 | completionObject()->clear(); |
477 | } | 480 | } |
478 | 481 | ||
479 | void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) | 482 | void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) |
480 | { | 483 | { |
481 | if ( menu &&!lineEdit()->text().isEmpty()) | 484 | if ( menu &&!lineEdit()->text().isEmpty()) |
482 | { | 485 | { |
483 | menu->insertSeparator(); | 486 | menu->insertSeparator(); |
484 | menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); | 487 | menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); |
485 | } | 488 | } |
486 | } | 489 | } |
487 | 490 | ||
488 | void OHistoryCombo::addToHistory( const QString& item ) | 491 | void OHistoryCombo::addToHistory( const QString& item ) |
489 | { | 492 | { |
490 | if ( item.isEmpty() || (count() > 0 && item == text(0) )) | 493 | if ( item.isEmpty() || (count() > 0 && item == text(0) )) |
491 | return; | 494 | return; |
492 | 495 | ||
493 | // remove all existing items before adding | 496 | // remove all existing items before adding |
494 | if ( !duplicatesEnabled() ) { | 497 | if ( !duplicatesEnabled() ) { |
495 | for ( int i = 0; i < count(); i++ ) { | 498 | for ( int i = 0; i < count(); i++ ) { |
496 | if ( text( i ) == item ) | 499 | if ( text( i ) == item ) |
497 | removeItem( i ); | 500 | removeItem( i ); |
498 | } | 501 | } |
499 | } | 502 | } |
500 | 503 | ||
501 | // now add the item | 504 | // now add the item |
502 | if ( myPixProvider ) | 505 | if ( myPixProvider ) |
503 | //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); | 506 | //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); |
504 | insertItem( myPixProvider->pixmapFor(item, 16), item, 0); | 507 | insertItem( myPixProvider->pixmapFor(item, 16), item, 0); |
505 | else | 508 | else |
506 | insertItem( item, 0 ); | 509 | insertItem( item, 0 ); |
507 | 510 | ||
508 | int last; | 511 | int last; |
509 | QString rmItem; | 512 | QString rmItem; |
510 | 513 | ||
511 | bool useComp = useCompletion(); | 514 | bool useComp = useCompletion(); |
512 | while ( count() > maxCount() && count() > 0 ) { | 515 | while ( count() > maxCount() && count() > 0 ) { |
513 | // remove the last item, as long as we are longer than maxCount() | 516 | // remove the last item, as long as we are longer than maxCount() |
514 | // remove the removed item from the completionObject if it isn't | 517 | // remove the removed item from the completionObject if it isn't |
515 | // anymore available at all in the combobox. | 518 | // anymore available at all in the combobox. |
diff --git a/libopie2/qt3/opieui/oeditlistbox.cpp b/libopie2/qt3/opieui/oeditlistbox.cpp index 3c53552..0e95274 100644 --- a/libopie2/qt3/opieui/oeditlistbox.cpp +++ b/libopie2/qt3/opieui/oeditlistbox.cpp | |||
@@ -222,195 +222,196 @@ void OEditListBox::moveItemUp() | |||
222 | m_listBox->takeItem(selItem); | 222 | m_listBox->takeItem(selItem); |
223 | m_listBox->insertItem(selItem, selIndex-1); | 223 | m_listBox->insertItem(selItem, selIndex-1); |
224 | m_listBox->setCurrentItem(selIndex - 1); | 224 | m_listBox->setCurrentItem(selIndex - 1); |
225 | 225 | ||
226 | emit changed(); | 226 | emit changed(); |
227 | } | 227 | } |
228 | 228 | ||
229 | void OEditListBox::moveItemDown() | 229 | void OEditListBox::moveItemDown() |
230 | { | 230 | { |
231 | if (!m_listBox->isEnabled()) | 231 | if (!m_listBox->isEnabled()) |
232 | { | 232 | { |
233 | //ONotifyClient::beep(); | 233 | //ONotifyClient::beep(); |
234 | return; | 234 | return; |
235 | } | 235 | } |
236 | 236 | ||
237 | unsigned int selIndex = m_listBox->currentItem(); | 237 | unsigned int selIndex = m_listBox->currentItem(); |
238 | if (selIndex == m_listBox->count() - 1) | 238 | if (selIndex == m_listBox->count() - 1) |
239 | { | 239 | { |
240 | //ONotifyClient::beep(); | 240 | //ONotifyClient::beep(); |
241 | return; | 241 | return; |
242 | } | 242 | } |
243 | 243 | ||
244 | QListBoxItem *selItem = m_listBox->item(selIndex); | 244 | QListBoxItem *selItem = m_listBox->item(selIndex); |
245 | m_listBox->takeItem(selItem); | 245 | m_listBox->takeItem(selItem); |
246 | m_listBox->insertItem(selItem, selIndex+1); | 246 | m_listBox->insertItem(selItem, selIndex+1); |
247 | m_listBox->setCurrentItem(selIndex + 1); | 247 | m_listBox->setCurrentItem(selIndex + 1); |
248 | 248 | ||
249 | emit changed(); | 249 | emit changed(); |
250 | } | 250 | } |
251 | 251 | ||
252 | void OEditListBox::addItem() | 252 | void OEditListBox::addItem() |
253 | { | 253 | { |
254 | // when m_checkAtEntering is true, the add-button is disabled, but this | 254 | // when m_checkAtEntering is true, the add-button is disabled, but this |
255 | // slot can still be called through Key_Return/Key_Enter. So we guard | 255 | // slot can still be called through Key_Return/Key_Enter. So we guard |
256 | // against this. | 256 | // against this. |
257 | if ( !servNewButton || !servNewButton->isEnabled() ) | 257 | if ( !servNewButton || !servNewButton->isEnabled() ) |
258 | return; | 258 | return; |
259 | 259 | ||
260 | const QString& currentTextLE=m_lineEdit->text(); | 260 | const QString& currentTextLE=m_lineEdit->text(); |
261 | bool alreadyInList(false); | 261 | bool alreadyInList(false); |
262 | //if we didn't check for dupes at the inserting we have to do it now | 262 | //if we didn't check for dupes at the inserting we have to do it now |
263 | if (!d->m_checkAtEntering) | 263 | if (!d->m_checkAtEntering) |
264 | { | 264 | { |
265 | // first check current item instead of dumb iterating the entire list | 265 | // first check current item instead of dumb iterating the entire list |
266 | if ( m_listBox->currentText() == currentTextLE ) | 266 | if ( m_listBox->currentText() == currentTextLE ) |
267 | alreadyInList = true; | 267 | alreadyInList = true; |
268 | else | 268 | else |
269 | { | 269 | { |
270 | #if QT_VERSION > 290 | 270 | #if QT_VERSION > 290 |
271 | StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive ); | 271 | StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive ); |
272 | alreadyInList =(m_listBox->findItem(currentTextLE, mode) != 0); | 272 | alreadyInList =(m_listBox->findItem(currentTextLE, mode) != 0); |
273 | #else | 273 | #else |
274 | alreadyInList =(m_listBox->findItem(currentTextLE) != 0); | 274 | alreadyInList =(m_listBox->findItem(currentTextLE) != 0); |
275 | #endif | 275 | #endif |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | if ( servNewButton ) | 279 | if ( servNewButton ) |
280 | servNewButton->setEnabled(false); | 280 | servNewButton->setEnabled(false); |
281 | 281 | ||
282 | bool block = m_lineEdit->signalsBlocked(); | 282 | bool block = m_lineEdit->signalsBlocked(); |
283 | m_lineEdit->blockSignals(true); | 283 | m_lineEdit->blockSignals(true); |
284 | m_lineEdit->clear(); | 284 | m_lineEdit->clear(); |
285 | m_lineEdit->blockSignals(block); | 285 | m_lineEdit->blockSignals(block); |
286 | 286 | ||
287 | m_listBox->setSelected(currentItem(), false); | 287 | m_listBox->setSelected(currentItem(), false); |
288 | 288 | ||
289 | if (!alreadyInList) | 289 | if (!alreadyInList) |
290 | { | 290 | { |
291 | block = m_listBox->signalsBlocked(); | 291 | block = m_listBox->signalsBlocked(); |
292 | m_listBox->blockSignals( true ); | 292 | m_listBox->blockSignals( true ); |
293 | m_listBox->insertItem(currentTextLE); | 293 | m_listBox->insertItem(currentTextLE); |
294 | m_listBox->blockSignals( block ); | 294 | m_listBox->blockSignals( block ); |
295 | emit changed(); | 295 | emit changed(); |
296 | emit added( currentTextLE ); | 296 | emit added( currentTextLE ); |
297 | } | 297 | } |
298 | } | 298 | } |
299 | 299 | ||
300 | int OEditListBox::currentItem() const | 300 | int OEditListBox::currentItem() const |
301 | { | 301 | { |
302 | int nr = m_listBox->currentItem(); | 302 | int nr = m_listBox->currentItem(); |
303 | #if QT_VERSION > 290 | 303 | #if QT_VERSION > 290 |
304 | if(nr >= 0 && !m_listBox->item(nr)->isSelected()) return -1; | 304 | if(nr >= 0 && !m_listBox->item(nr)->isSelected()) return -1; |
305 | #else | 305 | #else |
306 | if(nr >= 0 && !m_listBox->isSelected(m_listBox->item(nr))) return -1; | 306 | if(nr >= 0 && !m_listBox->isSelected(m_listBox->item(nr))) return -1; |
307 | #endif | 307 | #endif |
308 | return nr; | 308 | return nr; |
309 | } | 309 | } |
310 | 310 | ||
311 | void OEditListBox::removeItem() | 311 | void OEditListBox::removeItem() |
312 | { | 312 | { |
313 | int selected = m_listBox->currentItem(); | 313 | int selected = m_listBox->currentItem(); |
314 | 314 | ||
315 | if ( selected >= 0 ) | 315 | if ( selected >= 0 ) |
316 | { | 316 | { |
317 | QString removedText = m_listBox->currentText(); | 317 | QString removedText = m_listBox->currentText(); |
318 | 318 | ||
319 | m_listBox->removeItem( selected ); | 319 | m_listBox->removeItem( selected ); |
320 | if ( count() > 0 ) | 320 | if ( count() > 0 ) |
321 | m_listBox->setSelected( QMIN( selected, count() - 1 ), true ); | 321 | m_listBox->setSelected( QMIN( selected, count() - 1 ), true ); |
322 | 322 | ||
323 | emit changed(); | 323 | emit changed(); |
324 | emit removed( removedText ); | 324 | emit removed( removedText ); |
325 | } | 325 | } |
326 | 326 | ||
327 | if ( servRemoveButton && m_listBox->currentItem() == -1 ) | 327 | if ( servRemoveButton && m_listBox->currentItem() == -1 ) |
328 | servRemoveButton->setEnabled(false); | 328 | servRemoveButton->setEnabled(false); |
329 | } | 329 | } |
330 | 330 | ||
331 | void OEditListBox::enableMoveButtons(int index) | 331 | void OEditListBox::enableMoveButtons(int index) |
332 | { | 332 | { |
333 | // Update the lineEdit when we select a different line. | 333 | // Update the lineEdit when we select a different line. |
334 | if(currentText() != m_lineEdit->text()) | 334 | if(currentText() != m_lineEdit->text()) |
335 | m_lineEdit->setText(currentText()); | 335 | m_lineEdit->setText(currentText()); |
336 | 336 | ||
337 | bool moveEnabled = servUpButton && servDownButton; | 337 | bool moveEnabled = servUpButton && servDownButton; |
338 | 338 | ||
339 | if (moveEnabled ) | 339 | if (moveEnabled ) |
340 | { | 340 | { |
341 | if (m_listBox->count() <= 1) | 341 | if (m_listBox->count() <= 1) |
342 | { | 342 | { |
343 | servUpButton->setEnabled(false); | 343 | servUpButton->setEnabled(false); |
344 | servDownButton->setEnabled(false); | 344 | servDownButton->setEnabled(false); |
345 | } | 345 | } |
346 | else if ((uint) index == (m_listBox->count() - 1)) | 346 | else if ((uint) index == (m_listBox->count() - 1)) |
347 | { | 347 | { |
348 | servUpButton->setEnabled(true); | 348 | servUpButton->setEnabled(true); |
349 | servDownButton->setEnabled(false); | 349 | servDownButton->setEnabled(false); |
350 | } | 350 | } |
351 | else if (index == 0) | 351 | else if (index == 0) |
352 | { | 352 | { |
353 | servUpButton->setEnabled(false); | 353 | servUpButton->setEnabled(false); |
354 | servDownButton->setEnabled(true); | 354 | servDownButton->setEnabled(true); |
355 | } | 355 | } |
356 | else | 356 | else |
357 | { | 357 | { |
358 | servUpButton->setEnabled(true); | 358 | servUpButton->setEnabled(true); |
359 | servDownButton->setEnabled(true); | 359 | servDownButton->setEnabled(true); |
360 | } | 360 | } |
361 | } | 361 | } |
362 | 362 | ||
363 | if ( servRemoveButton ) | 363 | if ( servRemoveButton ) |
364 | servRemoveButton->setEnabled(true); | 364 | servRemoveButton->setEnabled(true); |
365 | } | 365 | } |
366 | 366 | ||
367 | void OEditListBox::clear() | 367 | void OEditListBox::clear() |
368 | { | 368 | { |
369 | m_lineEdit->clear(); | 369 | m_lineEdit->clear(); |
370 | m_listBox->clear(); | 370 | m_listBox->clear(); |
371 | emit changed(); | 371 | emit changed(); |
372 | } | 372 | } |
373 | 373 | ||
374 | void OEditListBox::insertStringList(const QStringList& list, int index) | 374 | void OEditListBox::insertStringList(const QStringList& list, int index) |
375 | { | 375 | { |
376 | m_listBox->insertStringList(list,index); | 376 | m_listBox->insertStringList(list,index); |
377 | } | 377 | } |
378 | 378 | ||
379 | void OEditListBox::insertStrList(const QStrList* list, int index) | 379 | void OEditListBox::insertStrList(const QStrList* list, int index) |
380 | { | 380 | { |
381 | m_listBox->insertStrList(list,index); | 381 | m_listBox->insertStrList(list,index); |
382 | } | 382 | } |
383 | 383 | ||
384 | void OEditListBox::insertStrList(const QStrList& list, int index) | 384 | void OEditListBox::insertStrList(const QStrList& list, int index) |
385 | { | 385 | { |
386 | m_listBox->insertStrList(list,index); | 386 | m_listBox->insertStrList(list,index); |
387 | } | 387 | } |
388 | 388 | ||
389 | void OEditListBox::insertStrList(const char ** list, int numStrings, int index) | 389 | void OEditListBox::insertStrList(const char ** list, int numStrings, int index) |
390 | { | 390 | { |
391 | m_listBox->insertStrList(list,numStrings,index); | 391 | m_listBox->insertStrList(list,numStrings,index); |
392 | } | 392 | } |
393 | 393 | ||
394 | QStringList OEditListBox::items() const | 394 | QStringList OEditListBox::items() const |
395 | { | 395 | { |
396 | QStringList list; | 396 | QStringList list; |
397 | for ( uint i = 0; i < m_listBox->count(); i++ ) | 397 | for ( uint i = 0; i < m_listBox->count(); i++ ) |
398 | list.append( m_listBox->text( i )); | 398 | list.append( m_listBox->text( i )); |
399 | 399 | ||
400 | return list; | 400 | return list; |
401 | } | 401 | } |
402 | 402 | ||
403 | void OEditListBox::virtual_hook( int, void* ) | 403 | void OEditListBox::virtual_hook( int, void* ) |
404 | { /*BASE::virtual_hook( id, data );*/ } | 404 | { /*BASE::virtual_hook( id, data );*/ } |
405 | 405 | ||
406 | 406 | ||
407 | /*====================================================================================== | 407 | /*====================================================================================== |
408 | * CustomEditor | 408 | * CustomEditor |
409 | *======================================================================================*/ | 409 | *======================================================================================*/ |
410 | 410 | ||
411 | OEditListBox::CustomEditor::CustomEditor( OComboBox *combo ) | 411 | OEditListBox::CustomEditor::CustomEditor( OComboBox *combo ) |
412 | { | 412 | { |
413 | m_representationWidget = combo; | 413 | m_representationWidget = combo; |
414 | m_lineEdit = dynamic_cast<OLineEdit*>( combo->lineEdit() ); | 414 | assert( combo->lineEdit()->inherits( "OLineEdit" ) ); |
415 | assert( m_lineEdit ); | 415 | m_lineEdit = static_cast<OLineEdit*>( combo->lineEdit() ); |
416 | |||
416 | } | 417 | } |