-rw-r--r-- | libopie2/qt3/opieui/ocombobox.cpp | 20 | ||||
-rw-r--r-- | libopie2/qt3/opieui/ocompletionbox.cpp | 10 | ||||
-rw-r--r-- | libopie2/qt3/opieui/ojanuswidget.cpp | 10 | ||||
-rw-r--r-- | libopie2/qt3/opieui/olineedit.cpp | 24 |
4 files changed, 32 insertions, 32 deletions
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp index 8dbda8f..bd330e0 100644 --- a/libopie2/qt3/opieui/ocombobox.cpp +++ b/libopie2/qt3/opieui/ocombobox.cpp | |||
@@ -139,398 +139,398 @@ void OComboBox::setAutoCompletion( bool autocomplete ) | |||
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 | if ( !edit->inherits( "OLineEdit" ) ) | 323 | if ( !edit->inherits( "OLineEdit" ) ) |
324 | d->olineEdit = 0; | 324 | d->olineEdit = 0; |
325 | else | 325 | else |
326 | d->olineEdit = static_cast<OLineEdit*>( edit ); | 326 | d->olineEdit = static_cast<OLineEdit*>( edit ); |
327 | setDelegate( d->olineEdit ); | 327 | setDelegate( d->olineEdit ); |
328 | 328 | ||
329 | // forward some signals. We only emit returnPressed() ourselves. | 329 | // forward some signals. We only emit returnPressed() ourselves. |
330 | if ( d->olineEdit ) { | 330 | if ( d->olineEdit ) { |
331 | connect( d->olineEdit, SIGNAL( completion( const QString& )), | 331 | connect( d->olineEdit, SIGNAL( completion(const QString&)), |
332 | SIGNAL( completion( const QString& )) ); | 332 | SIGNAL( completion(const QString&)) ); |
333 | connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )), | 333 | connect( d->olineEdit, SIGNAL( substringCompletion(const QString&)), |
334 | SIGNAL( substringCompletion( const QString& )) ); | 334 | SIGNAL( substringCompletion(const QString&)) ); |
335 | connect( d->olineEdit, | 335 | connect( d->olineEdit, |
336 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )), | 336 | SIGNAL( textRotation(OCompletionBase::KeyBindingType)), |
337 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )) ); | 337 | SIGNAL( textRotation(OCompletionBase::KeyBindingType)) ); |
338 | connect( d->olineEdit, | 338 | connect( d->olineEdit, |
339 | SIGNAL( completionModeChanged( OGlobalSettings::Completion )), | 339 | SIGNAL( completionModeChanged(OGlobalSettings::Completion)), |
340 | SIGNAL( completionModeChanged( OGlobalSettings::Completion))); | 340 | SIGNAL( completionModeChanged(OGlobalSettings::Completion))); |
341 | 341 | ||
342 | connect( d->olineEdit, | 342 | connect( d->olineEdit, |
343 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )), | 343 | SIGNAL( aboutToShowContextMenu(QPopupMenu*)), |
344 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )) ); | 344 | SIGNAL( aboutToShowContextMenu(QPopupMenu*)) ); |
345 | } | 345 | } |
346 | #else | 346 | #else |
347 | #warning OComboBox is not fully functional with Qt2 | 347 | #warning OComboBox is not fully functional with Qt2 |
348 | #endif | 348 | #endif |
349 | } | 349 | } |
350 | 350 | ||
351 | // Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 | 351 | // Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 |
352 | void OComboBox::deleteWordForward() | 352 | void OComboBox::deleteWordForward() |
353 | { | 353 | { |
354 | lineEdit()->cursorWordForward(TRUE); | 354 | lineEdit()->cursorWordForward(TRUE); |
355 | #if QT_VERSION > 290 | 355 | #if QT_VERSION > 290 |
356 | if ( lineEdit()->hasSelectedText() ) | 356 | if ( lineEdit()->hasSelectedText() ) |
357 | #else | 357 | #else |
358 | if ( lineEdit()->hasMarkedText() ) | 358 | if ( lineEdit()->hasMarkedText() ) |
359 | #endif | 359 | #endif |
360 | { | 360 | { |
361 | lineEdit()->del(); | 361 | lineEdit()->del(); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | 364 | ||
365 | void OComboBox::deleteWordBack() | 365 | void OComboBox::deleteWordBack() |
366 | { | 366 | { |
367 | lineEdit()->cursorWordBackward(TRUE); | 367 | lineEdit()->cursorWordBackward(TRUE); |
368 | #if QT_VERSION > 290 | 368 | #if QT_VERSION > 290 |
369 | if ( lineEdit()->hasSelectedText() ) | 369 | if ( lineEdit()->hasSelectedText() ) |
370 | #else | 370 | #else |
371 | if ( lineEdit()->hasMarkedText() ) | 371 | if ( lineEdit()->hasMarkedText() ) |
372 | #endif | 372 | #endif |
373 | { | 373 | { |
374 | lineEdit()->del(); | 374 | lineEdit()->del(); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) | 378 | void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) |
379 | { | 379 | { |
380 | int sel = -1; | 380 | int sel = -1; |
381 | for (int i = 0; i < count(); ++i) | 381 | for (int i = 0; i < count(); ++i) |
382 | if (text(i) == item) | 382 | if (text(i) == item) |
383 | { | 383 | { |
384 | sel = i; | 384 | sel = i; |
385 | break; | 385 | break; |
386 | } | 386 | } |
387 | if (sel == -1 && insert) | 387 | if (sel == -1 && insert) |
388 | { | 388 | { |
389 | insertItem(item, index); | 389 | insertItem(item, index); |
390 | if (index >= 0) | 390 | if (index >= 0) |
391 | sel = index; | 391 | sel = index; |
392 | else | 392 | else |
393 | sel = count() - 1; | 393 | sel = count() - 1; |
394 | } | 394 | } |
395 | setCurrentItem(sel); | 395 | setCurrentItem(sel); |
396 | } | 396 | } |
397 | 397 | ||
398 | void OComboBox::setCurrentItem(int index) | 398 | void OComboBox::setCurrentItem(int index) |
399 | { | 399 | { |
400 | QComboBox::setCurrentItem(index); | 400 | QComboBox::setCurrentItem(index); |
401 | } | 401 | } |
402 | 402 | ||
403 | 403 | ||
404 | /*====================================================================================== | 404 | /*====================================================================================== |
405 | * OHistoryCombo | 405 | * OHistoryCombo |
406 | *======================================================================================*/ | 406 | *======================================================================================*/ |
407 | 407 | ||
408 | // we are always read-write | 408 | // we are always read-write |
409 | OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) | 409 | OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) |
410 | : OComboBox( true, parent, name ) | 410 | : OComboBox( true, parent, name ) |
411 | { | 411 | { |
412 | init( true ); // using completion | 412 | init( true ); // using completion |
413 | } | 413 | } |
414 | 414 | ||
415 | // we are always read-write | 415 | // we are always read-write |
416 | OHistoryCombo::OHistoryCombo( bool useCompletion, | 416 | OHistoryCombo::OHistoryCombo( bool useCompletion, |
417 | QWidget *parent, const char *name ) | 417 | QWidget *parent, const char *name ) |
418 | : OComboBox( true, parent, name ) | 418 | : OComboBox( true, parent, name ) |
419 | { | 419 | { |
420 | init( useCompletion ); | 420 | init( useCompletion ); |
421 | } | 421 | } |
422 | 422 | ||
423 | void OHistoryCombo::init( bool useCompletion ) | 423 | void OHistoryCombo::init( bool useCompletion ) |
424 | { | 424 | { |
425 | if ( useCompletion ) | 425 | if ( useCompletion ) |
426 | completionObject()->setOrder( OCompletion::Weighted ); | 426 | completionObject()->setOrder( OCompletion::Weighted ); |
427 | 427 | ||
428 | setInsertionPolicy( NoInsertion ); | 428 | setInsertionPolicy( NoInsertion ); |
429 | myIterateIndex = -1; | 429 | myIterateIndex = -1; |
430 | myRotated = false; | 430 | myRotated = false; |
431 | myPixProvider = 0L; | 431 | myPixProvider = 0L; |
432 | 432 | ||
433 | connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), | 433 | connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), |
434 | SLOT(addContextMenuItems(QPopupMenu*)) ); | 434 | SLOT(addContextMenuItems(QPopupMenu*)) ); |
435 | connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); | 435 | connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); |
436 | connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); | 436 | connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); |
437 | } | 437 | } |
438 | 438 | ||
439 | OHistoryCombo::~OHistoryCombo() | 439 | OHistoryCombo::~OHistoryCombo() |
440 | { | 440 | { |
441 | delete myPixProvider; | 441 | delete myPixProvider; |
442 | } | 442 | } |
443 | 443 | ||
444 | void OHistoryCombo::setHistoryItems( QStringList items, | 444 | void OHistoryCombo::setHistoryItems( QStringList items, |
445 | bool setCompletionList ) | 445 | bool setCompletionList ) |
446 | { | 446 | { |
447 | OComboBox::clear(); | 447 | OComboBox::clear(); |
448 | 448 | ||
449 | // limit to maxCount() | 449 | // limit to maxCount() |
450 | while ( (int) items.count() > maxCount() && !items.isEmpty() ) | 450 | while ( (int) items.count() > maxCount() && !items.isEmpty() ) |
451 | items.remove( items.begin() ); | 451 | items.remove( items.begin() ); |
452 | 452 | ||
453 | insertItems( items ); | 453 | insertItems( items ); |
454 | 454 | ||
455 | if ( setCompletionList && useCompletion() ) { | 455 | if ( setCompletionList && useCompletion() ) { |
456 | // we don't have any weighting information here ;( | 456 | // we don't have any weighting information here ;( |
457 | OCompletion *comp = completionObject(); | 457 | OCompletion *comp = completionObject(); |
458 | comp->setOrder( OCompletion::Insertion ); | 458 | comp->setOrder( OCompletion::Insertion ); |
459 | comp->setItems( items ); | 459 | comp->setItems( items ); |
460 | comp->setOrder( OCompletion::Weighted ); | 460 | comp->setOrder( OCompletion::Weighted ); |
461 | } | 461 | } |
462 | 462 | ||
463 | clearEdit(); | 463 | clearEdit(); |
464 | } | 464 | } |
465 | 465 | ||
466 | QStringList OHistoryCombo::historyItems() const | 466 | QStringList OHistoryCombo::historyItems() const |
467 | { | 467 | { |
468 | QStringList list; | 468 | QStringList list; |
469 | for ( int i = 0; i < count(); i++ ) | 469 | for ( int i = 0; i < count(); i++ ) |
470 | list.append( text( i ) ); | 470 | list.append( text( i ) ); |
471 | 471 | ||
472 | return list; | 472 | return list; |
473 | } | 473 | } |
474 | 474 | ||
475 | void OHistoryCombo::clearHistory() | 475 | void OHistoryCombo::clearHistory() |
476 | { | 476 | { |
477 | OComboBox::clear(); | 477 | OComboBox::clear(); |
478 | if ( useCompletion() ) | 478 | if ( useCompletion() ) |
479 | completionObject()->clear(); | 479 | completionObject()->clear(); |
480 | } | 480 | } |
481 | 481 | ||
482 | void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) | 482 | void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) |
483 | { | 483 | { |
484 | if ( menu &&!lineEdit()->text().isEmpty()) | 484 | if ( menu &&!lineEdit()->text().isEmpty()) |
485 | { | 485 | { |
486 | menu->insertSeparator(); | 486 | menu->insertSeparator(); |
487 | menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); | 487 | menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | void OHistoryCombo::addToHistory( const QString& item ) | 491 | void OHistoryCombo::addToHistory( const QString& item ) |
492 | { | 492 | { |
493 | if ( item.isEmpty() || (count() > 0 && item == text(0) )) | 493 | if ( item.isEmpty() || (count() > 0 && item == text(0) )) |
494 | return; | 494 | return; |
495 | 495 | ||
496 | // remove all existing items before adding | 496 | // remove all existing items before adding |
497 | if ( !duplicatesEnabled() ) { | 497 | if ( !duplicatesEnabled() ) { |
498 | for ( int i = 0; i < count(); i++ ) { | 498 | for ( int i = 0; i < count(); i++ ) { |
499 | if ( text( i ) == item ) | 499 | if ( text( i ) == item ) |
500 | removeItem( i ); | 500 | removeItem( i ); |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | // now add the item | 504 | // now add the item |
505 | if ( myPixProvider ) | 505 | if ( myPixProvider ) |
506 | //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); | 506 | //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); |
507 | insertItem( myPixProvider->pixmapFor(item, 16), item, 0); | 507 | insertItem( myPixProvider->pixmapFor(item, 16), item, 0); |
508 | else | 508 | else |
509 | insertItem( item, 0 ); | 509 | insertItem( item, 0 ); |
510 | 510 | ||
511 | int last; | 511 | int last; |
512 | QString rmItem; | 512 | QString rmItem; |
513 | 513 | ||
514 | bool useComp = useCompletion(); | 514 | bool useComp = useCompletion(); |
515 | while ( count() > maxCount() && count() > 0 ) { | 515 | while ( count() > maxCount() && count() > 0 ) { |
516 | // 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() |
517 | // remove the removed item from the completionObject if it isn't | 517 | // remove the removed item from the completionObject if it isn't |
518 | // anymore available at all in the combobox. | 518 | // anymore available at all in the combobox. |
519 | last = count() - 1; | 519 | last = count() - 1; |
520 | rmItem = text( last ); | 520 | rmItem = text( last ); |
521 | removeItem( last ); | 521 | removeItem( last ); |
522 | if ( useComp && !contains( rmItem ) ) | 522 | if ( useComp && !contains( rmItem ) ) |
523 | completionObject()->removeItem( rmItem ); | 523 | completionObject()->removeItem( rmItem ); |
524 | } | 524 | } |
525 | 525 | ||
526 | if ( useComp ) | 526 | if ( useComp ) |
527 | completionObject()->addItem( item ); | 527 | completionObject()->addItem( item ); |
528 | } | 528 | } |
529 | 529 | ||
530 | bool OHistoryCombo::removeFromHistory( const QString& item ) | 530 | bool OHistoryCombo::removeFromHistory( const QString& item ) |
531 | { | 531 | { |
532 | if ( item.isEmpty() ) | 532 | if ( item.isEmpty() ) |
533 | return false; | 533 | return false; |
534 | 534 | ||
535 | bool removed = false; | 535 | bool removed = false; |
536 | QString temp = currentText(); | 536 | QString temp = currentText(); |
diff --git a/libopie2/qt3/opieui/ocompletionbox.cpp b/libopie2/qt3/opieui/ocompletionbox.cpp index b594b8e..b36123e 100644 --- a/libopie2/qt3/opieui/ocompletionbox.cpp +++ b/libopie2/qt3/opieui/ocompletionbox.cpp | |||
@@ -1,269 +1,269 @@ | |||
1 | /* | 1 | /* |
2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
3 | is part of the Copyright (C) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> | 3 | is part of the Copyright (C) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> |
4 | Opie Project Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 4 | Opie Project Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
5 | Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org> | 5 | Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org> |
6 | =. | 6 | =. |
7 | .=l. Originally part of the KDE Project | 7 | .=l. Originally part of the KDE Project |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qevent.h> | 34 | #include <qevent.h> |
35 | #include <qstyle.h> | 35 | #include <qstyle.h> |
36 | 36 | ||
37 | #include <opie2/ocompletionbox.h> | 37 | #include <opie2/ocompletionbox.h> |
38 | 38 | ||
39 | #define OListBox QListBox | 39 | #define OListBox QListBox |
40 | 40 | ||
41 | class OCompletionBox::OCompletionBoxPrivate | 41 | class OCompletionBox::OCompletionBoxPrivate |
42 | { | 42 | { |
43 | public: | 43 | public: |
44 | QWidget *m_parent; // necessary to set the focus back | 44 | QWidget *m_parent; // necessary to set the focus back |
45 | QString cancelText; | 45 | QString cancelText; |
46 | bool tabHandling; | 46 | bool tabHandling; |
47 | bool down_workaround; | 47 | bool down_workaround; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | OCompletionBox::OCompletionBox( QWidget *parent, const char *name ) | 50 | OCompletionBox::OCompletionBox( QWidget *parent, const char *name ) |
51 | :OListBox( parent, name, WType_Popup ) | 51 | :OListBox( parent, name, WType_Popup ) |
52 | { | 52 | { |
53 | d = new OCompletionBoxPrivate; | 53 | d = new OCompletionBoxPrivate; |
54 | d->m_parent = parent; | 54 | d->m_parent = parent; |
55 | d->tabHandling = true; | 55 | d->tabHandling = true; |
56 | d->down_workaround = false; | 56 | d->down_workaround = false; |
57 | 57 | ||
58 | setColumnMode( 1 ); | 58 | setColumnMode( 1 ); |
59 | setLineWidth( 1 ); | 59 | setLineWidth( 1 ); |
60 | setFrameStyle( QFrame::Box | QFrame::Plain ); | 60 | setFrameStyle( QFrame::Box | QFrame::Plain ); |
61 | 61 | ||
62 | if ( parent ) | 62 | if ( parent ) |
63 | setFocusProxy( parent ); | 63 | setFocusProxy( parent ); |
64 | else | 64 | else |
65 | setFocusPolicy( NoFocus ); | 65 | setFocusPolicy( NoFocus ); |
66 | 66 | ||
67 | setVScrollBarMode( Auto ); | 67 | setVScrollBarMode( Auto ); |
68 | setHScrollBarMode( AlwaysOff ); | 68 | setHScrollBarMode( AlwaysOff ); |
69 | 69 | ||
70 | connect( this, SIGNAL( doubleClicked( QListBoxItem * )), | 70 | connect( this, SIGNAL( doubleClicked(QListBoxItem*)), |
71 | SLOT( slotActivated( QListBoxItem * )) ); | 71 | SLOT( slotActivated(QListBoxItem*)) ); |
72 | 72 | ||
73 | // grmbl, just QListBox workarounds :[ Thanks Volker. | 73 | // grmbl, just QListBox workarounds :[ Thanks Volker. |
74 | connect( this, SIGNAL( currentChanged( QListBoxItem * )), | 74 | connect( this, SIGNAL( currentChanged(QListBoxItem*)), |
75 | SLOT( slotCurrentChanged() )); | 75 | SLOT( slotCurrentChanged() )); |
76 | connect( this, SIGNAL( clicked( QListBoxItem * )), | 76 | connect( this, SIGNAL( clicked(QListBoxItem*)), |
77 | SLOT( slotItemClicked( QListBoxItem * )) ); | 77 | SLOT( slotItemClicked(QListBoxItem*)) ); |
78 | } | 78 | } |
79 | 79 | ||
80 | OCompletionBox::~OCompletionBox() | 80 | OCompletionBox::~OCompletionBox() |
81 | { | 81 | { |
82 | d->m_parent = 0L; | 82 | d->m_parent = 0L; |
83 | delete d; | 83 | delete d; |
84 | } | 84 | } |
85 | 85 | ||
86 | QStringList OCompletionBox::items() const | 86 | QStringList OCompletionBox::items() const |
87 | { | 87 | { |
88 | QStringList list; | 88 | QStringList list; |
89 | for ( uint i = 0; i < count(); i++ ) { | 89 | for ( uint i = 0; i < count(); i++ ) { |
90 | list.append( text( i ) ); | 90 | list.append( text( i ) ); |
91 | } | 91 | } |
92 | return list; | 92 | return list; |
93 | } | 93 | } |
94 | 94 | ||
95 | void OCompletionBox::slotActivated( QListBoxItem *item ) | 95 | void OCompletionBox::slotActivated( QListBoxItem *item ) |
96 | { | 96 | { |
97 | if ( !item ) | 97 | if ( !item ) |
98 | return; | 98 | return; |
99 | 99 | ||
100 | hide(); | 100 | hide(); |
101 | emit activated( item->text() ); | 101 | emit activated( item->text() ); |
102 | } | 102 | } |
103 | 103 | ||
104 | bool OCompletionBox::eventFilter( QObject *o, QEvent *e ) | 104 | bool OCompletionBox::eventFilter( QObject *o, QEvent *e ) |
105 | { | 105 | { |
106 | int type = e->type(); | 106 | int type = e->type(); |
107 | 107 | ||
108 | if ( o == d->m_parent ) { | 108 | if ( o == d->m_parent ) { |
109 | if ( isVisible() ) { | 109 | if ( isVisible() ) { |
110 | if ( type == QEvent::KeyPress ) { | 110 | if ( type == QEvent::KeyPress ) { |
111 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); | 111 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); |
112 | switch ( ev->key() ) { | 112 | switch ( ev->key() ) { |
113 | case Key_BackTab: | 113 | case Key_BackTab: |
114 | if ( d->tabHandling ) { | 114 | if ( d->tabHandling ) { |
115 | up(); | 115 | up(); |
116 | ev->accept(); | 116 | ev->accept(); |
117 | return true; | 117 | return true; |
118 | } | 118 | } |
119 | break; | 119 | break; |
120 | case Key_Tab: | 120 | case Key_Tab: |
121 | if ( d->tabHandling ) { | 121 | if ( d->tabHandling ) { |
122 | down(); // Only on TAB!! | 122 | down(); // Only on TAB!! |
123 | ev->accept(); | 123 | ev->accept(); |
124 | return true; | 124 | return true; |
125 | } | 125 | } |
126 | break; | 126 | break; |
127 | case Key_Down: | 127 | case Key_Down: |
128 | down(); | 128 | down(); |
129 | ev->accept(); | 129 | ev->accept(); |
130 | return true; | 130 | return true; |
131 | case Key_Up: | 131 | case Key_Up: |
132 | up(); | 132 | up(); |
133 | ev->accept(); | 133 | ev->accept(); |
134 | return true; | 134 | return true; |
135 | case Key_Prior: | 135 | case Key_Prior: |
136 | pageUp(); | 136 | pageUp(); |
137 | ev->accept(); | 137 | ev->accept(); |
138 | return true; | 138 | return true; |
139 | case Key_Next: | 139 | case Key_Next: |
140 | pageDown(); | 140 | pageDown(); |
141 | ev->accept(); | 141 | ev->accept(); |
142 | return true; | 142 | return true; |
143 | case Key_Escape: | 143 | case Key_Escape: |
144 | cancelled(); | 144 | cancelled(); |
145 | ev->accept(); | 145 | ev->accept(); |
146 | return true; | 146 | return true; |
147 | case Key_Enter: | 147 | case Key_Enter: |
148 | case Key_Return: | 148 | case Key_Return: |
149 | if ( ev->state() & ShiftButton ) { | 149 | if ( ev->state() & ShiftButton ) { |
150 | hide(); | 150 | hide(); |
151 | ev->accept(); // Consume the Enter event | 151 | ev->accept(); // Consume the Enter event |
152 | return true; | 152 | return true; |
153 | } | 153 | } |
154 | break; | 154 | break; |
155 | default: | 155 | default: |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | else if ( type == QEvent::AccelOverride ) { | 159 | else if ( type == QEvent::AccelOverride ) { |
160 | // Override any acceleartors that match | 160 | // Override any acceleartors that match |
161 | // the key sequences we use here... | 161 | // the key sequences we use here... |
162 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); | 162 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); |
163 | switch ( ev->key() ) { | 163 | switch ( ev->key() ) { |
164 | case Key_Tab: | 164 | case Key_Tab: |
165 | case Key_BackTab: | 165 | case Key_BackTab: |
166 | case Key_Down: | 166 | case Key_Down: |
167 | case Key_Up: | 167 | case Key_Up: |
168 | case Key_Prior: | 168 | case Key_Prior: |
169 | case Key_Next: | 169 | case Key_Next: |
170 | case Key_Escape: | 170 | case Key_Escape: |
171 | case Key_Enter: | 171 | case Key_Enter: |
172 | case Key_Return: | 172 | case Key_Return: |
173 | ev->accept(); | 173 | ev->accept(); |
174 | return true; | 174 | return true; |
175 | break; | 175 | break; |
176 | default: | 176 | default: |
177 | break; | 177 | break; |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | // parent loses focus or gets a click -> we hide | 181 | // parent loses focus or gets a click -> we hide |
182 | else if ( type == QEvent::FocusOut || type == QEvent::Resize || | 182 | else if ( type == QEvent::FocusOut || type == QEvent::Resize || |
183 | type == QEvent::Close || type == QEvent::Hide || | 183 | type == QEvent::Close || type == QEvent::Hide || |
184 | type == QEvent::Move ) { | 184 | type == QEvent::Move ) { |
185 | hide(); | 185 | hide(); |
186 | } | 186 | } |
187 | else if ( type == QEvent::Move ) | 187 | else if ( type == QEvent::Move ) |
188 | move( d->m_parent->mapToGlobal(QPoint(0, d->m_parent->height()))); | 188 | move( d->m_parent->mapToGlobal(QPoint(0, d->m_parent->height()))); |
189 | else if ( type == QEvent::Resize ) | 189 | else if ( type == QEvent::Resize ) |
190 | resize( sizeHint() ); | 190 | resize( sizeHint() ); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | // any mouse-click on something else than "this" makes us hide | 194 | // any mouse-click on something else than "this" makes us hide |
195 | else if ( type == QEvent::MouseButtonPress ) { | 195 | else if ( type == QEvent::MouseButtonPress ) { |
196 | QMouseEvent *ev = static_cast<QMouseEvent *>( e ); | 196 | QMouseEvent *ev = static_cast<QMouseEvent *>( e ); |
197 | if ( !rect().contains( ev->pos() )) // this widget | 197 | if ( !rect().contains( ev->pos() )) // this widget |
198 | hide(); | 198 | hide(); |
199 | } | 199 | } |
200 | 200 | ||
201 | return OListBox::eventFilter( o, e ); | 201 | return OListBox::eventFilter( o, e ); |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | void OCompletionBox::popup() | 205 | void OCompletionBox::popup() |
206 | { | 206 | { |
207 | if ( count() == 0 ) | 207 | if ( count() == 0 ) |
208 | hide(); | 208 | hide(); |
209 | else { | 209 | else { |
210 | ensureCurrentVisible(); | 210 | ensureCurrentVisible(); |
211 | bool block = signalsBlocked(); | 211 | bool block = signalsBlocked(); |
212 | blockSignals( true ); | 212 | blockSignals( true ); |
213 | setCurrentItem( 0 ); | 213 | setCurrentItem( 0 ); |
214 | blockSignals( block ); | 214 | blockSignals( block ); |
215 | clearSelection(); | 215 | clearSelection(); |
216 | if ( !isVisible() ) | 216 | if ( !isVisible() ) |
217 | show(); | 217 | show(); |
218 | else if ( size().height() < sizeHint().height() ) | 218 | else if ( size().height() < sizeHint().height() ) |
219 | resize( sizeHint() ); | 219 | resize( sizeHint() ); |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | void OCompletionBox::show() | 223 | void OCompletionBox::show() |
224 | { | 224 | { |
225 | resize( sizeHint() ); | 225 | resize( sizeHint() ); |
226 | 226 | ||
227 | if ( d->m_parent ) | 227 | if ( d->m_parent ) |
228 | { | 228 | { |
229 | //QDesktopWidget *screen = QApplication::desktop(); | 229 | //QDesktopWidget *screen = QApplication::desktop(); |
230 | QWidget *screen = QApplication::desktop(); | 230 | QWidget *screen = QApplication::desktop(); |
231 | 231 | ||
232 | QPoint orig = d->m_parent->mapToGlobal( QPoint(0, d->m_parent->height()) ); | 232 | QPoint orig = d->m_parent->mapToGlobal( QPoint(0, d->m_parent->height()) ); |
233 | int x = orig.x(); | 233 | int x = orig.x(); |
234 | int y = orig.y(); | 234 | int y = orig.y(); |
235 | 235 | ||
236 | if ( x + width() > screen->width() ) | 236 | if ( x + width() > screen->width() ) |
237 | x = screen->width() - width(); | 237 | x = screen->width() - width(); |
238 | if (y + height() > screen->height() ) | 238 | if (y + height() > screen->height() ) |
239 | y = y - height() - d->m_parent->height(); | 239 | y = y - height() - d->m_parent->height(); |
240 | 240 | ||
241 | move( x, y); | 241 | move( x, y); |
242 | qApp->installEventFilter( this ); | 242 | qApp->installEventFilter( this ); |
243 | } | 243 | } |
244 | 244 | ||
245 | // ### we shouldn't need to call this, but without this, the scrollbars | 245 | // ### we shouldn't need to call this, but without this, the scrollbars |
246 | // are pretty b0rked. | 246 | // are pretty b0rked. |
247 | //triggerUpdate( true ); | 247 | //triggerUpdate( true ); |
248 | 248 | ||
249 | OListBox::show(); | 249 | OListBox::show(); |
250 | } | 250 | } |
251 | 251 | ||
252 | void OCompletionBox::hide() | 252 | void OCompletionBox::hide() |
253 | { | 253 | { |
254 | if ( d->m_parent ) | 254 | if ( d->m_parent ) |
255 | qApp->removeEventFilter( this ); | 255 | qApp->removeEventFilter( this ); |
256 | d->cancelText = QString::null; | 256 | d->cancelText = QString::null; |
257 | OListBox::hide(); | 257 | OListBox::hide(); |
258 | } | 258 | } |
259 | 259 | ||
260 | QSize OCompletionBox::sizeHint() const | 260 | QSize OCompletionBox::sizeHint() const |
261 | { | 261 | { |
262 | int ih = itemHeight(); | 262 | int ih = itemHeight(); |
263 | int h = QMIN( 15 * ih, (int) count() * ih ) +1; | 263 | int h = QMIN( 15 * ih, (int) count() * ih ) +1; |
264 | h = QMAX( h, OListBox::minimumSizeHint().height() ); | 264 | h = QMAX( h, OListBox::minimumSizeHint().height() ); |
265 | 265 | ||
266 | int w = (d->m_parent) ? d->m_parent->width() : OListBox::minimumSizeHint().width(); | 266 | int w = (d->m_parent) ? d->m_parent->width() : OListBox::minimumSizeHint().width(); |
267 | w = QMAX( OListBox::minimumSizeHint().width(), w ); | 267 | w = QMAX( OListBox::minimumSizeHint().width(), w ); |
268 | return QSize( w, h ); | 268 | return QSize( w, h ); |
269 | } | 269 | } |
diff --git a/libopie2/qt3/opieui/ojanuswidget.cpp b/libopie2/qt3/opieui/ojanuswidget.cpp index 0a037ff..063e393 100644 --- a/libopie2/qt3/opieui/ojanuswidget.cpp +++ b/libopie2/qt3/opieui/ojanuswidget.cpp | |||
@@ -1,355 +1,355 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Originally part of the KDE project | 4 | Originally part of the KDE project |
5 | (C) 1999-2000 Espen Sand (espensa@online.no) | 5 | (C) 1999-2000 Espen Sand (espensa@online.no) |
6 | =. | 6 | =. |
7 | .=l. | 7 | .=l. |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | /* QT */ | 33 | /* QT */ |
34 | 34 | ||
35 | #include <qbitmap.h> | 35 | #include <qbitmap.h> |
36 | #include <qgrid.h> | 36 | #include <qgrid.h> |
37 | #include <qhbox.h> | 37 | #include <qhbox.h> |
38 | #include <qheader.h> | 38 | #include <qheader.h> |
39 | #include <qlabel.h> | 39 | #include <qlabel.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | #include <qpixmap.h> | 42 | #include <qpixmap.h> |
43 | #include <qlistview.h> | 43 | #include <qlistview.h> |
44 | #include <qsplitter.h> | 44 | #include <qsplitter.h> |
45 | #include <qtabwidget.h> | 45 | #include <qtabwidget.h> |
46 | #include <qvbox.h> | 46 | #include <qvbox.h> |
47 | #include <qwidgetstack.h> | 47 | #include <qwidgetstack.h> |
48 | #include <qpainter.h> | 48 | #include <qpainter.h> |
49 | #include <qtimer.h> | 49 | #include <qtimer.h> |
50 | #include <qstyle.h> | 50 | #include <qstyle.h> |
51 | 51 | ||
52 | /* OPIE */ | 52 | /* OPIE */ |
53 | 53 | ||
54 | #include <opie2/odialog.h> | 54 | #include <opie2/odialog.h> |
55 | #include <opie2/oseparator.h> | 55 | #include <opie2/oseparator.h> |
56 | #include <opie2/ojanuswidget.h> | 56 | #include <opie2/ojanuswidget.h> |
57 | 57 | ||
58 | /*====================================================================================== | 58 | /*====================================================================================== |
59 | * IconListItem | 59 | * IconListItem |
60 | *======================================================================================*/ | 60 | *======================================================================================*/ |
61 | 61 | ||
62 | class OJanusWidget::IconListItem : public QListBoxItem | 62 | class OJanusWidget::IconListItem : public QListBoxItem |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | IconListItem( QListBox *listbox, const QPixmap &pixmap, | 65 | IconListItem( QListBox *listbox, const QPixmap &pixmap, |
66 | const QString &text ); | 66 | const QString &text ); |
67 | virtual int height( const QListBox *lb ) const; | 67 | virtual int height( const QListBox *lb ) const; |
68 | virtual int width( const QListBox *lb ) const; | 68 | virtual int width( const QListBox *lb ) const; |
69 | int expandMinimumWidth( int width ); | 69 | int expandMinimumWidth( int width ); |
70 | 70 | ||
71 | protected: | 71 | protected: |
72 | const QPixmap &defaultPixmap(); | 72 | const QPixmap &defaultPixmap(); |
73 | void paint( QPainter *painter ); | 73 | void paint( QPainter *painter ); |
74 | 74 | ||
75 | private: | 75 | private: |
76 | QPixmap mPixmap; | 76 | QPixmap mPixmap; |
77 | int mMinimumWidth; | 77 | int mMinimumWidth; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | template class QPtrList<QListViewItem>; | 80 | template class QPtrList<QListViewItem>; |
81 | 81 | ||
82 | /*====================================================================================== | 82 | /*====================================================================================== |
83 | * OJanusWidget | 83 | * OJanusWidget |
84 | *======================================================================================*/ | 84 | *======================================================================================*/ |
85 | 85 | ||
86 | OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face ) | 86 | OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face ) |
87 | : QWidget( parent, name, 0 ), | 87 | : QWidget( parent, name, 0 ), |
88 | mValid(false), mPageList(0), | 88 | mValid(false), mPageList(0), |
89 | mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), | 89 | mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), |
90 | mShowIconsInTreeList(false), d(0) | 90 | mShowIconsInTreeList(false), d(0) |
91 | { | 91 | { |
92 | QVBoxLayout *topLayout = new QVBoxLayout( this ); | 92 | QVBoxLayout *topLayout = new QVBoxLayout( this ); |
93 | 93 | ||
94 | if( mFace == TreeList || mFace == IconList ) | 94 | if( mFace == TreeList || mFace == IconList ) |
95 | { | 95 | { |
96 | mPageList = new QPtrList<QWidget>; | 96 | mPageList = new QPtrList<QWidget>; |
97 | mTitleList = new QStringList(); | 97 | mTitleList = new QStringList(); |
98 | 98 | ||
99 | QFrame *page; | 99 | QFrame *page; |
100 | if( mFace == TreeList ) | 100 | if( mFace == TreeList ) |
101 | { | 101 | { |
102 | QSplitter *splitter = new QSplitter( this ); | 102 | QSplitter *splitter = new QSplitter( this ); |
103 | topLayout->addWidget( splitter, 10 ); | 103 | topLayout->addWidget( splitter, 10 ); |
104 | mTreeListResizeMode = QSplitter::KeepSize; | 104 | mTreeListResizeMode = QSplitter::KeepSize; |
105 | 105 | ||
106 | mTreeList = new QListView( splitter ); | 106 | mTreeList = new QListView( splitter ); |
107 | mTreeList->addColumn( QString::fromLatin1("") ); | 107 | mTreeList->addColumn( QString::fromLatin1("") ); |
108 | mTreeList->header()->hide(); | 108 | mTreeList->header()->hide(); |
109 | mTreeList->setRootIsDecorated(true); | 109 | mTreeList->setRootIsDecorated(true); |
110 | mTreeList->setSorting( -1 ); | 110 | mTreeList->setSorting( -1 ); |
111 | connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); | 111 | connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); |
112 | connect( mTreeList, SIGNAL(clicked(QListViewItem *)), SLOT(slotItemClicked(QListViewItem *))); | 112 | connect( mTreeList, SIGNAL(clicked(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*))); |
113 | 113 | ||
114 | // | 114 | // |
115 | // Page area. Title at top with a separator below and a pagestack using | 115 | // Page area. Title at top with a separator below and a pagestack using |
116 | // all available space at bottom. | 116 | // all available space at bottom. |
117 | // | 117 | // |
118 | QFrame *p = new QFrame( splitter ); | 118 | QFrame *p = new QFrame( splitter ); |
119 | 119 | ||
120 | QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); | 120 | QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); |
121 | hbox->addSpacing( ODialog::spacingHint() ); | 121 | hbox->addSpacing( ODialog::spacingHint() ); |
122 | 122 | ||
123 | page = new QFrame( p ); | 123 | page = new QFrame( p ); |
124 | hbox->addWidget( page, 10 ); | 124 | hbox->addWidget( page, 10 ); |
125 | } | 125 | } |
126 | else | 126 | else |
127 | { | 127 | { |
128 | QHBoxLayout *hbox = new QHBoxLayout( topLayout ); | 128 | QHBoxLayout *hbox = new QHBoxLayout( topLayout ); |
129 | mIconList = new IconListBox( this ); | 129 | mIconList = new IconListBox( this ); |
130 | 130 | ||
131 | QFont listFont( mIconList->font() ); | 131 | QFont listFont( mIconList->font() ); |
132 | listFont.setBold( true ); | 132 | listFont.setBold( true ); |
133 | mIconList->setFont( listFont ); | 133 | mIconList->setFont( listFont ); |
134 | 134 | ||
135 | mIconList->verticalScrollBar()->installEventFilter( this ); | 135 | mIconList->verticalScrollBar()->installEventFilter( this ); |
136 | hbox->addWidget( mIconList ); | 136 | hbox->addWidget( mIconList ); |
137 | connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); | 137 | connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); |
138 | hbox->addSpacing( ODialog::spacingHint() ); | 138 | hbox->addSpacing( ODialog::spacingHint() ); |
139 | page = new QFrame( this ); | 139 | page = new QFrame( this ); |
140 | hbox->addWidget( page, 10 ); | 140 | hbox->addWidget( page, 10 ); |
141 | } | 141 | } |
142 | 142 | ||
143 | // | 143 | // |
144 | // Rest of page area. Title at top with a separator below and a | 144 | // Rest of page area. Title at top with a separator below and a |
145 | // pagestack using all available space at bottom. | 145 | // pagestack using all available space at bottom. |
146 | // | 146 | // |
147 | 147 | ||
148 | QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() ); | 148 | QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() ); |
149 | 149 | ||
150 | mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" ); | 150 | mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" ); |
151 | vbox->addWidget( mTitleLabel ); | 151 | vbox->addWidget( mTitleLabel ); |
152 | 152 | ||
153 | QFont titleFont( mTitleLabel->font() ); | 153 | QFont titleFont( mTitleLabel->font() ); |
154 | titleFont.setBold( true ); | 154 | titleFont.setBold( true ); |
155 | mTitleLabel->setFont( titleFont ); | 155 | mTitleLabel->setFont( titleFont ); |
156 | 156 | ||
157 | mTitleSep = new OSeparator( page ); | 157 | mTitleSep = new OSeparator( page ); |
158 | mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); | 158 | mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); |
159 | vbox->addWidget( mTitleSep ); | 159 | vbox->addWidget( mTitleSep ); |
160 | 160 | ||
161 | mPageStack = new QWidgetStack( page ); | 161 | mPageStack = new QWidgetStack( page ); |
162 | connect(mPageStack, SIGNAL(aboutToShow(QWidget *)), | 162 | connect(mPageStack, SIGNAL(aboutToShow(QWidget*)), |
163 | this, SIGNAL(aboutToShowPage(QWidget *))); | 163 | this, SIGNAL(aboutToShowPage(QWidget*))); |
164 | vbox->addWidget( mPageStack, 10 ); | 164 | vbox->addWidget( mPageStack, 10 ); |
165 | } | 165 | } |
166 | else if( mFace == Tabbed ) | 166 | else if( mFace == Tabbed ) |
167 | { | 167 | { |
168 | mPageList = new QPtrList<QWidget>; | 168 | mPageList = new QPtrList<QWidget>; |
169 | 169 | ||
170 | mTabControl = new QTabWidget( this ); | 170 | mTabControl = new QTabWidget( this ); |
171 | mTabControl->setMargin (ODialog::marginHint()); | 171 | mTabControl->setMargin (ODialog::marginHint()); |
172 | topLayout->addWidget( mTabControl, 10 ); | 172 | topLayout->addWidget( mTabControl, 10 ); |
173 | } | 173 | } |
174 | else if( mFace == Swallow ) | 174 | else if( mFace == Swallow ) |
175 | { | 175 | { |
176 | mSwallowPage = new QWidget( this ); | 176 | mSwallowPage = new QWidget( this ); |
177 | topLayout->addWidget( mSwallowPage, 10 ); | 177 | topLayout->addWidget( mSwallowPage, 10 ); |
178 | } | 178 | } |
179 | else | 179 | else |
180 | { | 180 | { |
181 | mFace = Plain; | 181 | mFace = Plain; |
182 | mPlainPage = new QFrame( this ); | 182 | mPlainPage = new QFrame( this ); |
183 | topLayout->addWidget( mPlainPage, 10 ); | 183 | topLayout->addWidget( mPlainPage, 10 ); |
184 | } | 184 | } |
185 | 185 | ||
186 | /* FIXME: Revise for Opie | 186 | /* FIXME: Revise for Opie |
187 | if ( kapp ) | 187 | if ( kapp ) |
188 | connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); | 188 | connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); |
189 | */ | 189 | */ |
190 | 190 | ||
191 | mValid = true; | 191 | mValid = true; |
192 | 192 | ||
193 | setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. | 193 | setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | OJanusWidget::~OJanusWidget() | 197 | OJanusWidget::~OJanusWidget() |
198 | { | 198 | { |
199 | delete mPageList; | 199 | delete mPageList; |
200 | mPageList = 0; | 200 | mPageList = 0; |
201 | delete mTitleList; | 201 | delete mTitleList; |
202 | mTitleList = 0; | 202 | mTitleList = 0; |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | bool OJanusWidget::isValid() const | 206 | bool OJanusWidget::isValid() const |
207 | { | 207 | { |
208 | return( mValid ); | 208 | return( mValid ); |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | QFrame *OJanusWidget::plainPage() | 212 | QFrame *OJanusWidget::plainPage() |
213 | { | 213 | { |
214 | return( mPlainPage ); | 214 | return( mPlainPage ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | int OJanusWidget::face() const | 218 | int OJanusWidget::face() const |
219 | { | 219 | { |
220 | return( mFace ); | 220 | return( mFace ); |
221 | } | 221 | } |
222 | 222 | ||
223 | QWidget *OJanusWidget::FindParent() | 223 | QWidget *OJanusWidget::FindParent() |
224 | { | 224 | { |
225 | if( mFace == Tabbed ) { | 225 | if( mFace == Tabbed ) { |
226 | return mTabControl; | 226 | return mTabControl; |
227 | } | 227 | } |
228 | else { | 228 | else { |
229 | return this; | 229 | return this; |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header, | 233 | QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header, |
234 | const QPixmap &pixmap ) | 234 | const QPixmap &pixmap ) |
235 | { | 235 | { |
236 | if( mValid == false ) | 236 | if( mValid == false ) |
237 | { | 237 | { |
238 | qDebug( "addPage: Invalid object" ); | 238 | qDebug( "addPage: Invalid object" ); |
239 | return( 0 ); | 239 | return( 0 ); |
240 | } | 240 | } |
241 | 241 | ||
242 | QFrame *page = new QFrame( FindParent(), "page" ); | 242 | QFrame *page = new QFrame( FindParent(), "page" ); |
243 | addPageWidget( page, items, header, pixmap ); | 243 | addPageWidget( page, items, header, pixmap ); |
244 | 244 | ||
245 | return page; | 245 | return page; |
246 | } | 246 | } |
247 | 247 | ||
248 | void OJanusWidget::pageGone( QObject *obj ) | 248 | void OJanusWidget::pageGone( QObject *obj ) |
249 | { | 249 | { |
250 | removePage( static_cast<QWidget*>( obj ) ); | 250 | removePage( static_cast<QWidget*>( obj ) ); |
251 | } | 251 | } |
252 | 252 | ||
253 | void OJanusWidget::slotReopen( QListViewItem * item ) | 253 | void OJanusWidget::slotReopen( QListViewItem * item ) |
254 | { | 254 | { |
255 | if( item ) | 255 | if( item ) |
256 | item->setOpen( true ); | 256 | item->setOpen( true ); |
257 | } | 257 | } |
258 | 258 | ||
259 | QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header, | 259 | QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header, |
260 | const QPixmap &pixmap ) | 260 | const QPixmap &pixmap ) |
261 | { | 261 | { |
262 | QStringList items; | 262 | QStringList items; |
263 | items << itemName; | 263 | items << itemName; |
264 | return addPage(items, header, pixmap); | 264 | return addPage(items, header, pixmap); |
265 | } | 265 | } |
266 | 266 | ||
267 | 267 | ||
268 | 268 | ||
269 | QVBox *OJanusWidget::addVBoxPage( const QStringList &items, | 269 | QVBox *OJanusWidget::addVBoxPage( const QStringList &items, |
270 | const QString &header, | 270 | const QString &header, |
271 | const QPixmap &pixmap ) | 271 | const QPixmap &pixmap ) |
272 | { | 272 | { |
273 | if( mValid == false ) | 273 | if( mValid == false ) |
274 | { | 274 | { |
275 | qDebug( "addPage: Invalid object" ); | 275 | qDebug( "addPage: Invalid object" ); |
276 | return( 0 ); | 276 | return( 0 ); |
277 | } | 277 | } |
278 | 278 | ||
279 | QVBox *page = new QVBox(FindParent() , "page" ); | 279 | QVBox *page = new QVBox(FindParent() , "page" ); |
280 | page->setSpacing( ODialog::spacingHint() ); | 280 | page->setSpacing( ODialog::spacingHint() ); |
281 | addPageWidget( page, items, header, pixmap ); | 281 | addPageWidget( page, items, header, pixmap ); |
282 | 282 | ||
283 | return page; | 283 | return page; |
284 | } | 284 | } |
285 | 285 | ||
286 | QVBox *OJanusWidget::addVBoxPage( const QString &itemName, | 286 | QVBox *OJanusWidget::addVBoxPage( const QString &itemName, |
287 | const QString &header, | 287 | const QString &header, |
288 | const QPixmap &pixmap ) | 288 | const QPixmap &pixmap ) |
289 | { | 289 | { |
290 | QStringList items; | 290 | QStringList items; |
291 | items << itemName; | 291 | items << itemName; |
292 | return addVBoxPage(items, header, pixmap); | 292 | return addVBoxPage(items, header, pixmap); |
293 | } | 293 | } |
294 | 294 | ||
295 | QHBox *OJanusWidget::addHBoxPage( const QStringList &items, | 295 | QHBox *OJanusWidget::addHBoxPage( const QStringList &items, |
296 | const QString &header, | 296 | const QString &header, |
297 | const QPixmap &pixmap ) | 297 | const QPixmap &pixmap ) |
298 | { | 298 | { |
299 | if( mValid == false ) { | 299 | if( mValid == false ) { |
300 | qDebug( "addPage: Invalid object" ); | 300 | qDebug( "addPage: Invalid object" ); |
301 | return( 0 ); | 301 | return( 0 ); |
302 | } | 302 | } |
303 | 303 | ||
304 | QHBox *page = new QHBox(FindParent(), "page"); | 304 | QHBox *page = new QHBox(FindParent(), "page"); |
305 | page->setSpacing( ODialog::spacingHint() ); | 305 | page->setSpacing( ODialog::spacingHint() ); |
306 | addPageWidget( page, items, header, pixmap ); | 306 | addPageWidget( page, items, header, pixmap ); |
307 | 307 | ||
308 | return page; | 308 | return page; |
309 | } | 309 | } |
310 | 310 | ||
311 | QHBox *OJanusWidget::addHBoxPage( const QString &itemName, | 311 | QHBox *OJanusWidget::addHBoxPage( const QString &itemName, |
312 | const QString &header, | 312 | const QString &header, |
313 | const QPixmap &pixmap ) | 313 | const QPixmap &pixmap ) |
314 | { | 314 | { |
315 | QStringList items; | 315 | QStringList items; |
316 | items << itemName; | 316 | items << itemName; |
317 | return addHBoxPage(items, header, pixmap); | 317 | return addHBoxPage(items, header, pixmap); |
318 | } | 318 | } |
319 | 319 | ||
320 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, | 320 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, |
321 | const QStringList &items, | 321 | const QStringList &items, |
322 | const QString &header, | 322 | const QString &header, |
323 | const QPixmap &pixmap ) | 323 | const QPixmap &pixmap ) |
324 | { | 324 | { |
325 | if( mValid == false ) | 325 | if( mValid == false ) |
326 | { | 326 | { |
327 | qDebug( "addPage: Invalid object" ); | 327 | qDebug( "addPage: Invalid object" ); |
328 | return( 0 ); | 328 | return( 0 ); |
329 | } | 329 | } |
330 | 330 | ||
331 | QGrid *page = new QGrid( n, dir, FindParent(), "page" ); | 331 | QGrid *page = new QGrid( n, dir, FindParent(), "page" ); |
332 | page->setSpacing( ODialog::spacingHint() ); | 332 | page->setSpacing( ODialog::spacingHint() ); |
333 | addPageWidget( page, items, header, pixmap ); | 333 | addPageWidget( page, items, header, pixmap ); |
334 | 334 | ||
335 | return page; | 335 | return page; |
336 | } | 336 | } |
337 | 337 | ||
338 | 338 | ||
339 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, | 339 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, |
340 | const QString &itemName, | 340 | const QString &itemName, |
341 | const QString &header, | 341 | const QString &header, |
342 | const QPixmap &pixmap ) | 342 | const QPixmap &pixmap ) |
343 | { | 343 | { |
344 | QStringList items; | 344 | QStringList items; |
345 | items << itemName; | 345 | items << itemName; |
346 | return addGridPage(n, dir, items, header, pixmap); | 346 | return addGridPage(n, dir, items, header, pixmap); |
347 | } | 347 | } |
348 | 348 | ||
349 | void OJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) | 349 | void OJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) |
350 | { | 350 | { |
351 | bool isTop = true; | 351 | bool isTop = true; |
352 | QListViewItem *curTop = 0, *child, *last, *newChild; | 352 | QListViewItem *curTop = 0, *child, *last, *newChild; |
353 | unsigned int index = 1; | 353 | unsigned int index = 1; |
354 | QStringList curPath; | 354 | QStringList curPath; |
355 | 355 | ||
@@ -674,387 +674,387 @@ int OJanusWidget::activePageIndex() const | |||
674 | 674 | ||
675 | 675 | ||
676 | int OJanusWidget::pageIndex( QWidget *widget ) const | 676 | int OJanusWidget::pageIndex( QWidget *widget ) const |
677 | { | 677 | { |
678 | if( widget == 0 ) | 678 | if( widget == 0 ) |
679 | { | 679 | { |
680 | return( -1 ); | 680 | return( -1 ); |
681 | } | 681 | } |
682 | else if( mFace == TreeList || mFace == IconList ) | 682 | else if( mFace == TreeList || mFace == IconList ) |
683 | { | 683 | { |
684 | return( mPageList->findRef( widget ) ); | 684 | return( mPageList->findRef( widget ) ); |
685 | } | 685 | } |
686 | else if( mFace == Tabbed ) | 686 | else if( mFace == Tabbed ) |
687 | { | 687 | { |
688 | // | 688 | // |
689 | // The user gets the real page widget with addVBoxPage(), addHBoxPage() | 689 | // The user gets the real page widget with addVBoxPage(), addHBoxPage() |
690 | // and addGridPage() but not with addPage() which returns a child of | 690 | // and addGridPage() but not with addPage() which returns a child of |
691 | // the toplevel page. addPage() returns a QFrame so I check for that. | 691 | // the toplevel page. addPage() returns a QFrame so I check for that. |
692 | // | 692 | // |
693 | if( widget->isA("QFrame") ) | 693 | if( widget->isA("QFrame") ) |
694 | { | 694 | { |
695 | return( mPageList->findRef( widget->parentWidget() ) ); | 695 | return( mPageList->findRef( widget->parentWidget() ) ); |
696 | } | 696 | } |
697 | else | 697 | else |
698 | { | 698 | { |
699 | return( mPageList->findRef( widget ) ); | 699 | return( mPageList->findRef( widget ) ); |
700 | } | 700 | } |
701 | } | 701 | } |
702 | else | 702 | else |
703 | { | 703 | { |
704 | return( -1 ); | 704 | return( -1 ); |
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | void OJanusWidget::slotFontChanged() | 708 | void OJanusWidget::slotFontChanged() |
709 | { | 709 | { |
710 | #ifdef FIXME | 710 | #ifdef FIXME |
711 | 711 | ||
712 | if ( mTitleLabel != 0 ) | 712 | if ( mTitleLabel != 0 ) |
713 | { | 713 | { |
714 | mTitleLabel->setFont( KGlobalSettings::generalFont() ); | 714 | mTitleLabel->setFont( KGlobalSettings::generalFont() ); |
715 | QFont titleFont( mTitleLabel->font() ); | 715 | QFont titleFont( mTitleLabel->font() ); |
716 | titleFont.setBold( true ); | 716 | titleFont.setBold( true ); |
717 | mTitleLabel->setFont( titleFont ); | 717 | mTitleLabel->setFont( titleFont ); |
718 | } | 718 | } |
719 | #endif | 719 | #endif |
720 | 720 | ||
721 | if( mFace == IconList ) | 721 | if( mFace == IconList ) |
722 | { | 722 | { |
723 | QFont listFont( mIconList->font() ); | 723 | QFont listFont( mIconList->font() ); |
724 | listFont.setBold( true ); | 724 | listFont.setBold( true ); |
725 | mIconList->setFont( listFont ); | 725 | mIconList->setFont( listFont ); |
726 | mIconList->invalidateHeight(); | 726 | mIconList->invalidateHeight(); |
727 | mIconList->invalidateWidth(); | 727 | mIconList->invalidateWidth(); |
728 | } | 728 | } |
729 | } | 729 | } |
730 | 730 | ||
731 | // makes the treelist behave like the list of kcontrol | 731 | // makes the treelist behave like the list of kcontrol |
732 | void OJanusWidget::slotItemClicked(QListViewItem *it) | 732 | void OJanusWidget::slotItemClicked(QListViewItem *it) |
733 | { | 733 | { |
734 | if(it && (it->childCount()>0)) | 734 | if(it && (it->childCount()>0)) |
735 | it->setOpen(!it->isOpen()); | 735 | it->setOpen(!it->isOpen()); |
736 | } | 736 | } |
737 | 737 | ||
738 | void OJanusWidget::setFocus() | 738 | void OJanusWidget::setFocus() |
739 | { | 739 | { |
740 | if( mValid == false ) { return; } | 740 | if( mValid == false ) { return; } |
741 | if( mFace == TreeList ) | 741 | if( mFace == TreeList ) |
742 | { | 742 | { |
743 | mTreeList->setFocus(); | 743 | mTreeList->setFocus(); |
744 | } | 744 | } |
745 | if( mFace == IconList ) | 745 | if( mFace == IconList ) |
746 | { | 746 | { |
747 | mIconList->setFocus(); | 747 | mIconList->setFocus(); |
748 | } | 748 | } |
749 | else if( mFace == Tabbed ) | 749 | else if( mFace == Tabbed ) |
750 | { | 750 | { |
751 | mTabControl->setFocus(); | 751 | mTabControl->setFocus(); |
752 | } | 752 | } |
753 | else if( mFace == Swallow ) | 753 | else if( mFace == Swallow ) |
754 | { | 754 | { |
755 | mSwallowPage->setFocus(); | 755 | mSwallowPage->setFocus(); |
756 | } | 756 | } |
757 | else if( mFace == Plain ) | 757 | else if( mFace == Plain ) |
758 | { | 758 | { |
759 | mPlainPage->setFocus(); | 759 | mPlainPage->setFocus(); |
760 | } | 760 | } |
761 | } | 761 | } |
762 | 762 | ||
763 | 763 | ||
764 | QSize OJanusWidget::minimumSizeHint() const | 764 | QSize OJanusWidget::minimumSizeHint() const |
765 | { | 765 | { |
766 | if( mFace == TreeList || mFace == IconList ) | 766 | if( mFace == TreeList || mFace == IconList ) |
767 | { | 767 | { |
768 | QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 ); | 768 | QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 ); |
769 | QSize s2(0,0); | 769 | QSize s2(0,0); |
770 | QSize s3(0,0); | 770 | QSize s3(0,0); |
771 | QSize s4( mPageStack->sizeHint() ); | 771 | QSize s4( mPageStack->sizeHint() ); |
772 | 772 | ||
773 | if( mFace == TreeList ) | 773 | if( mFace == TreeList ) |
774 | { | 774 | { |
775 | #if QT_VERSION < 300 | 775 | #if QT_VERSION < 300 |
776 | s1.rwidth() += style().splitterWidth(); | 776 | s1.rwidth() += style().splitterWidth(); |
777 | #else | 777 | #else |
778 | s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); | 778 | s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); |
779 | #endif | 779 | #endif |
780 | s2 = mTreeList->minimumSize(); | 780 | s2 = mTreeList->minimumSize(); |
781 | } | 781 | } |
782 | else | 782 | else |
783 | { | 783 | { |
784 | mIconList->updateMinimumHeight(); | 784 | mIconList->updateMinimumHeight(); |
785 | mIconList->updateWidth(); | 785 | mIconList->updateWidth(); |
786 | s2 = mIconList->minimumSize(); | 786 | s2 = mIconList->minimumSize(); |
787 | } | 787 | } |
788 | 788 | ||
789 | if( mTitleLabel->isVisible() == true ) | 789 | if( mTitleLabel->isVisible() == true ) |
790 | { | 790 | { |
791 | s3 += mTitleLabel->sizeHint(); | 791 | s3 += mTitleLabel->sizeHint(); |
792 | s3.rheight() += mTitleSep->minimumSize().height(); | 792 | s3.rheight() += mTitleSep->minimumSize().height(); |
793 | } | 793 | } |
794 | 794 | ||
795 | // | 795 | // |
796 | // Select the tallest item. It has only effect in IconList mode | 796 | // Select the tallest item. It has only effect in IconList mode |
797 | // | 797 | // |
798 | int h1 = s1.rheight() + s3.rheight() + s4.height(); | 798 | int h1 = s1.rheight() + s3.rheight() + s4.height(); |
799 | int h2 = QMAX( h1, s2.rheight() ); | 799 | int h2 = QMAX( h1, s2.rheight() ); |
800 | 800 | ||
801 | return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); | 801 | return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); |
802 | } | 802 | } |
803 | else if( mFace == Tabbed ) | 803 | else if( mFace == Tabbed ) |
804 | { | 804 | { |
805 | return( mTabControl->sizeHint() ); | 805 | return( mTabControl->sizeHint() ); |
806 | } | 806 | } |
807 | else if( mFace == Swallow ) | 807 | else if( mFace == Swallow ) |
808 | { | 808 | { |
809 | return( mSwallowPage->minimumSize() ); | 809 | return( mSwallowPage->minimumSize() ); |
810 | } | 810 | } |
811 | else if( mFace == Plain ) | 811 | else if( mFace == Plain ) |
812 | { | 812 | { |
813 | return( mPlainPage->sizeHint() ); | 813 | return( mPlainPage->sizeHint() ); |
814 | } | 814 | } |
815 | else | 815 | else |
816 | { | 816 | { |
817 | return( QSize( 100, 100 ) ); // Should never happen though. | 817 | return( QSize( 100, 100 ) ); // Should never happen though. |
818 | } | 818 | } |
819 | 819 | ||
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | QSize OJanusWidget::sizeHint() const | 823 | QSize OJanusWidget::sizeHint() const |
824 | { | 824 | { |
825 | return( minimumSizeHint() ); | 825 | return( minimumSizeHint() ); |
826 | } | 826 | } |
827 | 827 | ||
828 | 828 | ||
829 | void OJanusWidget::setTreeListAutoResize( bool state ) | 829 | void OJanusWidget::setTreeListAutoResize( bool state ) |
830 | { | 830 | { |
831 | if( mFace == TreeList ) | 831 | if( mFace == TreeList ) |
832 | { | 832 | { |
833 | mTreeListResizeMode = state == false ? | 833 | mTreeListResizeMode = state == false ? |
834 | QSplitter::KeepSize : QSplitter::Stretch; | 834 | QSplitter::KeepSize : QSplitter::Stretch; |
835 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); | 835 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); |
836 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); | 836 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); |
837 | } | 837 | } |
838 | } | 838 | } |
839 | 839 | ||
840 | 840 | ||
841 | void OJanusWidget::setIconListAllVisible( bool state ) | 841 | void OJanusWidget::setIconListAllVisible( bool state ) |
842 | { | 842 | { |
843 | if( mFace == IconList ) | 843 | if( mFace == IconList ) |
844 | { | 844 | { |
845 | mIconList->setShowAll( state ); | 845 | mIconList->setShowAll( state ); |
846 | } | 846 | } |
847 | } | 847 | } |
848 | 848 | ||
849 | void OJanusWidget::setShowIconsInTreeList( bool state ) | 849 | void OJanusWidget::setShowIconsInTreeList( bool state ) |
850 | { | 850 | { |
851 | mShowIconsInTreeList = state; | 851 | mShowIconsInTreeList = state; |
852 | } | 852 | } |
853 | 853 | ||
854 | void OJanusWidget::setRootIsDecorated( bool state ) | 854 | void OJanusWidget::setRootIsDecorated( bool state ) |
855 | { | 855 | { |
856 | if( mFace == TreeList ) { | 856 | if( mFace == TreeList ) { |
857 | mTreeList->setRootIsDecorated(state); | 857 | mTreeList->setRootIsDecorated(state); |
858 | } | 858 | } |
859 | } | 859 | } |
860 | 860 | ||
861 | void OJanusWidget::unfoldTreeList( bool persist ) | 861 | void OJanusWidget::unfoldTreeList( bool persist ) |
862 | { | 862 | { |
863 | if( mFace == TreeList ) | 863 | if( mFace == TreeList ) |
864 | { | 864 | { |
865 | if( persist ) | 865 | if( persist ) |
866 | connect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); | 866 | connect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); |
867 | else | 867 | else |
868 | disconnect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); | 868 | disconnect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); |
869 | 869 | ||
870 | for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) | 870 | for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) |
871 | item->setOpen( true ); | 871 | item->setOpen( true ); |
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | void OJanusWidget::showEvent( QShowEvent * ) | 875 | void OJanusWidget::showEvent( QShowEvent * ) |
876 | { | 876 | { |
877 | if( mFace == TreeList ) | 877 | if( mFace == TreeList ) |
878 | { | 878 | { |
879 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); | 879 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); |
880 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); | 880 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); |
881 | } | 881 | } |
882 | } | 882 | } |
883 | 883 | ||
884 | 884 | ||
885 | // | 885 | // |
886 | // 2000-13-02 Espen Sand | 886 | // 2000-13-02 Espen Sand |
887 | // It should be obvious that this eventfilter must only be | 887 | // It should be obvious that this eventfilter must only be |
888 | // be installed on the vertical scrollbar of the mIconList. | 888 | // be installed on the vertical scrollbar of the mIconList. |
889 | // | 889 | // |
890 | bool OJanusWidget::eventFilter( QObject *o, QEvent *e ) | 890 | bool OJanusWidget::eventFilter( QObject *o, QEvent *e ) |
891 | { | 891 | { |
892 | if( e->type() == QEvent::Show ) | 892 | if( e->type() == QEvent::Show ) |
893 | { | 893 | { |
894 | IconListItem *item = (IconListItem*)mIconList->item(0); | 894 | IconListItem *item = (IconListItem*)mIconList->item(0); |
895 | if( item != 0 ) | 895 | if( item != 0 ) |
896 | { | 896 | { |
897 | int lw = item->width( mIconList ); | 897 | int lw = item->width( mIconList ); |
898 | int sw = mIconList->verticalScrollBar()->sizeHint().width(); | 898 | int sw = mIconList->verticalScrollBar()->sizeHint().width(); |
899 | mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); | 899 | mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); |
900 | } | 900 | } |
901 | } | 901 | } |
902 | else if( e->type() == QEvent::Hide ) | 902 | else if( e->type() == QEvent::Hide ) |
903 | { | 903 | { |
904 | IconListItem *item = (IconListItem*)mIconList->item(0); | 904 | IconListItem *item = (IconListItem*)mIconList->item(0); |
905 | if( item != 0 ) | 905 | if( item != 0 ) |
906 | { | 906 | { |
907 | int lw = item->width( mIconList ); | 907 | int lw = item->width( mIconList ); |
908 | mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); | 908 | mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); |
909 | } | 909 | } |
910 | } | 910 | } |
911 | return QWidget::eventFilter( o, e ); | 911 | return QWidget::eventFilter( o, e ); |
912 | } | 912 | } |
913 | 913 | ||
914 | 914 | ||
915 | 915 | ||
916 | // | 916 | // |
917 | // Code for the icon list box | 917 | // Code for the icon list box |
918 | // | 918 | // |
919 | 919 | ||
920 | 920 | ||
921 | OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, | 921 | OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, |
922 | WFlags f ) | 922 | WFlags f ) |
923 | :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false), | 923 | :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false), |
924 | mWidthValid(false) | 924 | mWidthValid(false) |
925 | { | 925 | { |
926 | } | 926 | } |
927 | 927 | ||
928 | 928 | ||
929 | void OJanusWidget::IconListBox::updateMinimumHeight() | 929 | void OJanusWidget::IconListBox::updateMinimumHeight() |
930 | { | 930 | { |
931 | if( mShowAll == true && mHeightValid == false ) | 931 | if( mShowAll == true && mHeightValid == false ) |
932 | { | 932 | { |
933 | int h = frameWidth()*2; | 933 | int h = frameWidth()*2; |
934 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 934 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
935 | { | 935 | { |
936 | h += i->height( this ); | 936 | h += i->height( this ); |
937 | } | 937 | } |
938 | setMinimumHeight( h ); | 938 | setMinimumHeight( h ); |
939 | mHeightValid = true; | 939 | mHeightValid = true; |
940 | } | 940 | } |
941 | } | 941 | } |
942 | 942 | ||
943 | 943 | ||
944 | void OJanusWidget::IconListBox::updateWidth() | 944 | void OJanusWidget::IconListBox::updateWidth() |
945 | { | 945 | { |
946 | if( mWidthValid == false ) | 946 | if( mWidthValid == false ) |
947 | { | 947 | { |
948 | int maxWidth = 10; | 948 | int maxWidth = 10; |
949 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 949 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
950 | { | 950 | { |
951 | int w = ((IconListItem *)i)->width(this); | 951 | int w = ((IconListItem *)i)->width(this); |
952 | maxWidth = QMAX( w, maxWidth ); | 952 | maxWidth = QMAX( w, maxWidth ); |
953 | } | 953 | } |
954 | 954 | ||
955 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 955 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
956 | { | 956 | { |
957 | ((IconListItem *)i)->expandMinimumWidth( maxWidth ); | 957 | ((IconListItem *)i)->expandMinimumWidth( maxWidth ); |
958 | } | 958 | } |
959 | 959 | ||
960 | if( verticalScrollBar()->isVisible() ) | 960 | if( verticalScrollBar()->isVisible() ) |
961 | { | 961 | { |
962 | maxWidth += verticalScrollBar()->sizeHint().width(); | 962 | maxWidth += verticalScrollBar()->sizeHint().width(); |
963 | } | 963 | } |
964 | 964 | ||
965 | setFixedWidth( maxWidth + frameWidth()*2 ); | 965 | setFixedWidth( maxWidth + frameWidth()*2 ); |
966 | mWidthValid = true; | 966 | mWidthValid = true; |
967 | } | 967 | } |
968 | } | 968 | } |
969 | 969 | ||
970 | 970 | ||
971 | void OJanusWidget::IconListBox::invalidateHeight() | 971 | void OJanusWidget::IconListBox::invalidateHeight() |
972 | { | 972 | { |
973 | mHeightValid = false; | 973 | mHeightValid = false; |
974 | } | 974 | } |
975 | 975 | ||
976 | 976 | ||
977 | void OJanusWidget::IconListBox::invalidateWidth() | 977 | void OJanusWidget::IconListBox::invalidateWidth() |
978 | { | 978 | { |
979 | mWidthValid = false; | 979 | mWidthValid = false; |
980 | } | 980 | } |
981 | 981 | ||
982 | 982 | ||
983 | void OJanusWidget::IconListBox::setShowAll( bool showAll ) | 983 | void OJanusWidget::IconListBox::setShowAll( bool showAll ) |
984 | { | 984 | { |
985 | mShowAll = showAll; | 985 | mShowAll = showAll; |
986 | mHeightValid = false; | 986 | mHeightValid = false; |
987 | } | 987 | } |
988 | 988 | ||
989 | 989 | ||
990 | 990 | ||
991 | OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, | 991 | OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, |
992 | const QString &text ) | 992 | const QString &text ) |
993 | : QListBoxItem( listbox ) | 993 | : QListBoxItem( listbox ) |
994 | { | 994 | { |
995 | mPixmap = pixmap; | 995 | mPixmap = pixmap; |
996 | if( mPixmap.isNull() == true ) | 996 | if( mPixmap.isNull() == true ) |
997 | { | 997 | { |
998 | mPixmap = defaultPixmap(); | 998 | mPixmap = defaultPixmap(); |
999 | } | 999 | } |
1000 | setText( text ); | 1000 | setText( text ); |
1001 | mMinimumWidth = 0; | 1001 | mMinimumWidth = 0; |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | 1004 | ||
1005 | int OJanusWidget::IconListItem::expandMinimumWidth( int width ) | 1005 | int OJanusWidget::IconListItem::expandMinimumWidth( int width ) |
1006 | { | 1006 | { |
1007 | mMinimumWidth = QMAX( mMinimumWidth, width ); | 1007 | mMinimumWidth = QMAX( mMinimumWidth, width ); |
1008 | return( mMinimumWidth ); | 1008 | return( mMinimumWidth ); |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | 1011 | ||
1012 | const QPixmap &OJanusWidget::IconListItem::defaultPixmap() | 1012 | const QPixmap &OJanusWidget::IconListItem::defaultPixmap() |
1013 | { | 1013 | { |
1014 | static QPixmap *pix=0; | 1014 | static QPixmap *pix=0; |
1015 | if( pix == 0 ) | 1015 | if( pix == 0 ) |
1016 | { | 1016 | { |
1017 | pix = new QPixmap( 32, 32 ); | 1017 | pix = new QPixmap( 32, 32 ); |
1018 | QPainter p( pix ); | 1018 | QPainter p( pix ); |
1019 | p.eraseRect( 0, 0, pix->width(), pix->height() ); | 1019 | p.eraseRect( 0, 0, pix->width(), pix->height() ); |
1020 | p.setPen( Qt::red ); | 1020 | p.setPen( Qt::red ); |
1021 | p.drawRect ( 0, 0, pix->width(), pix->height() ); | 1021 | p.drawRect ( 0, 0, pix->width(), pix->height() ); |
1022 | p.end(); | 1022 | p.end(); |
1023 | 1023 | ||
1024 | QBitmap mask( pix->width(), pix->height(), true ); | 1024 | QBitmap mask( pix->width(), pix->height(), true ); |
1025 | mask.fill( Qt::black ); | 1025 | mask.fill( Qt::black ); |
1026 | p.begin( &mask ); | 1026 | p.begin( &mask ); |
1027 | p.setPen( Qt::white ); | 1027 | p.setPen( Qt::white ); |
1028 | p.drawRect ( 0, 0, pix->width(), pix->height() ); | 1028 | p.drawRect ( 0, 0, pix->width(), pix->height() ); |
1029 | p.end(); | 1029 | p.end(); |
1030 | 1030 | ||
1031 | pix->setMask( mask ); | 1031 | pix->setMask( mask ); |
1032 | } | 1032 | } |
1033 | return( *pix ); | 1033 | return( *pix ); |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | void OJanusWidget::IconListItem::paint( QPainter *painter ) | 1037 | void OJanusWidget::IconListItem::paint( QPainter *painter ) |
1038 | { | 1038 | { |
1039 | QFontMetrics fm = painter->fontMetrics(); | 1039 | QFontMetrics fm = painter->fontMetrics(); |
1040 | //int wt = fm.boundingRect(text()).width(); | 1040 | //int wt = fm.boundingRect(text()).width(); |
1041 | int wp = mPixmap.width(); | 1041 | int wp = mPixmap.width(); |
1042 | int ht = fm.lineSpacing(); | 1042 | int ht = fm.lineSpacing(); |
1043 | int hp = mPixmap.height(); | 1043 | int hp = mPixmap.height(); |
1044 | 1044 | ||
1045 | painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); | 1045 | painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); |
1046 | if( text().isEmpty() == false ) | 1046 | if( text().isEmpty() == false ) |
1047 | { | 1047 | { |
1048 | painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); | 1048 | painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); |
1049 | } | 1049 | } |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | int OJanusWidget::IconListItem::height( const QListBox *lb ) const | 1052 | int OJanusWidget::IconListItem::height( const QListBox *lb ) const |
1053 | { | 1053 | { |
1054 | if( text().isEmpty() == true ) | 1054 | if( text().isEmpty() == true ) |
1055 | { | 1055 | { |
1056 | return( mPixmap.height() ); | 1056 | return( mPixmap.height() ); |
1057 | } | 1057 | } |
1058 | else | 1058 | else |
1059 | { | 1059 | { |
1060 | return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); | 1060 | return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); |
diff --git a/libopie2/qt3/opieui/olineedit.cpp b/libopie2/qt3/opieui/olineedit.cpp index 9cb0cff..6f66fc7 100644 --- a/libopie2/qt3/opieui/olineedit.cpp +++ b/libopie2/qt3/opieui/olineedit.cpp | |||
@@ -258,472 +258,472 @@ void OLineEdit::keyPressEvent( QKeyEvent *e ) | |||
258 | if ( echoMode() == QLineEdit::Normal && | 258 | if ( echoMode() == QLineEdit::Normal && |
259 | completionMode() != OGlobalSettings::CompletionNone ) | 259 | completionMode() != OGlobalSettings::CompletionNone ) |
260 | { | 260 | { |
261 | KeyBindingMap keys = getKeyBindings(); | 261 | KeyBindingMap keys = getKeyBindings(); |
262 | OGlobalSettings::Completion mode = completionMode(); | 262 | OGlobalSettings::Completion mode = completionMode(); |
263 | bool noModifier = (e->state() == NoButton || e->state()== ShiftButton); | 263 | bool noModifier = (e->state() == NoButton || e->state()== ShiftButton); |
264 | 264 | ||
265 | if ( (mode == OGlobalSettings::CompletionAuto || | 265 | if ( (mode == OGlobalSettings::CompletionAuto || |
266 | mode == OGlobalSettings::CompletionMan) && noModifier ) | 266 | mode == OGlobalSettings::CompletionMan) && noModifier ) |
267 | { | 267 | { |
268 | QString keycode = e->text(); | 268 | QString keycode = e->text(); |
269 | if ( !keycode.isNull() && keycode.unicode()->isPrint() ) | 269 | if ( !keycode.isNull() && keycode.unicode()->isPrint() ) |
270 | { | 270 | { |
271 | QLineEdit::keyPressEvent ( e ); | 271 | QLineEdit::keyPressEvent ( e ); |
272 | QString txt = text(); | 272 | QString txt = text(); |
273 | int len = txt.length(); | 273 | int len = txt.length(); |
274 | #if QT_VERSION > 290 | 274 | #if QT_VERSION > 290 |
275 | if ( !hasSelectedText() && len && cursorPosition() == len ) | 275 | if ( !hasSelectedText() && len && cursorPosition() == len ) |
276 | #else | 276 | #else |
277 | if ( !hasMarkedText() && len && cursorPosition() == len ) | 277 | if ( !hasMarkedText() && len && cursorPosition() == len ) |
278 | #endif | 278 | #endif |
279 | { | 279 | { |
280 | if ( emitSignals() ) | 280 | if ( emitSignals() ) |
281 | emit completion( txt ); | 281 | emit completion( txt ); |
282 | if ( handleSignals() ) | 282 | if ( handleSignals() ) |
283 | makeCompletion( txt ); | 283 | makeCompletion( txt ); |
284 | e->accept(); | 284 | e->accept(); |
285 | } | 285 | } |
286 | return; | 286 | return; |
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | else if ( mode == OGlobalSettings::CompletionPopup && noModifier ) | 290 | else if ( mode == OGlobalSettings::CompletionPopup && noModifier ) |
291 | { | 291 | { |
292 | qDebug( "OLineEdit::keyPressEvent() - global settings = CompletionPopup & noModifier" ); | 292 | qDebug( "OLineEdit::keyPressEvent() - global settings = CompletionPopup & noModifier" ); |
293 | 293 | ||
294 | QString old_txt = text(); | 294 | QString old_txt = text(); |
295 | QLineEdit::keyPressEvent ( e ); | 295 | QLineEdit::keyPressEvent ( e ); |
296 | QString txt = text(); | 296 | QString txt = text(); |
297 | int len = txt.length(); | 297 | int len = txt.length(); |
298 | QString keycode = e->text(); | 298 | QString keycode = e->text(); |
299 | 299 | ||
300 | 300 | ||
301 | if ( txt != old_txt && len && cursorPosition() == len && | 301 | if ( txt != old_txt && len && cursorPosition() == len && |
302 | ( (!keycode.isNull() && keycode.unicode()->isPrint()) || | 302 | ( (!keycode.isNull() && keycode.unicode()->isPrint()) || |
303 | e->key() == Key_Backspace ) ) | 303 | e->key() == Key_Backspace ) ) |
304 | { | 304 | { |
305 | if ( emitSignals() ) | 305 | if ( emitSignals() ) |
306 | emit completion( txt ); // emit when requested... | 306 | emit completion( txt ); // emit when requested... |
307 | if ( handleSignals() ) | 307 | if ( handleSignals() ) |
308 | makeCompletion( txt ); // handle when requested... | 308 | makeCompletion( txt ); // handle when requested... |
309 | e->accept(); | 309 | e->accept(); |
310 | } | 310 | } |
311 | else if (!len && d->completionBox && d->completionBox->isVisible()) | 311 | else if (!len && d->completionBox && d->completionBox->isVisible()) |
312 | d->completionBox->hide(); | 312 | d->completionBox->hide(); |
313 | 313 | ||
314 | return; | 314 | return; |
315 | } | 315 | } |
316 | 316 | ||
317 | /*else if ( mode == OGlobalSettings::CompletionShell ) | 317 | /*else if ( mode == OGlobalSettings::CompletionShell ) |
318 | { | 318 | { |
319 | // Handles completion. | 319 | // Handles completion. |
320 | KShortcut cut; | 320 | KShortcut cut; |
321 | if ( keys[TextCompletion].isNull() ) | 321 | if ( keys[TextCompletion].isNull() ) |
322 | cut = KStdAccel::shortcut(KStdAccel::TextCompletion); | 322 | cut = KStdAccel::shortcut(KStdAccel::TextCompletion); |
323 | else | 323 | else |
324 | cut = keys[TextCompletion]; | 324 | cut = keys[TextCompletion]; |
325 | 325 | ||
326 | if ( cut.contains( key ) ) | 326 | if ( cut.contains( key ) ) |
327 | { | 327 | { |
328 | // Emit completion if the completion mode is CompletionShell | 328 | // Emit completion if the completion mode is CompletionShell |
329 | // and the cursor is at the end of the string. | 329 | // and the cursor is at the end of the string. |
330 | QString txt = text(); | 330 | QString txt = text(); |
331 | int len = txt.length(); | 331 | int len = txt.length(); |
332 | if ( cursorPosition() == len && len != 0 ) | 332 | if ( cursorPosition() == len && len != 0 ) |
333 | { | 333 | { |
334 | if ( emitSignals() ) | 334 | if ( emitSignals() ) |
335 | emit completion( txt ); | 335 | emit completion( txt ); |
336 | if ( handleSignals() ) | 336 | if ( handleSignals() ) |
337 | makeCompletion( txt ); | 337 | makeCompletion( txt ); |
338 | return; | 338 | return; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | else if ( d->completionBox ) | 341 | else if ( d->completionBox ) |
342 | d->completionBox->hide(); | 342 | d->completionBox->hide(); |
343 | } | 343 | } |
344 | 344 | ||
345 | // handle rotation | 345 | // handle rotation |
346 | if ( mode != OGlobalSettings::CompletionNone ) | 346 | if ( mode != OGlobalSettings::CompletionNone ) |
347 | { | 347 | { |
348 | // Handles previous match | 348 | // Handles previous match |
349 | KShortcut cut; | 349 | KShortcut cut; |
350 | if ( keys[PrevCompletionMatch].isNull() ) | 350 | if ( keys[PrevCompletionMatch].isNull() ) |
351 | cut = KStdAccel::shortcut(KStdAccel::PrevCompletion); | 351 | cut = KStdAccel::shortcut(KStdAccel::PrevCompletion); |
352 | else | 352 | else |
353 | cut = keys[PrevCompletionMatch]; | 353 | cut = keys[PrevCompletionMatch]; |
354 | 354 | ||
355 | if ( cut.contains( key ) ) | 355 | if ( cut.contains( key ) ) |
356 | { | 356 | { |
357 | if ( emitSignals() ) | 357 | if ( emitSignals() ) |
358 | emit textRotation( OCompletionBase::PrevCompletionMatch ); | 358 | emit textRotation( OCompletionBase::PrevCompletionMatch ); |
359 | if ( handleSignals() ) | 359 | if ( handleSignals() ) |
360 | rotateText( OCompletionBase::PrevCompletionMatch ); | 360 | rotateText( OCompletionBase::PrevCompletionMatch ); |
361 | return; | 361 | return; |
362 | } | 362 | } |
363 | 363 | ||
364 | // Handles next match | 364 | // Handles next match |
365 | if ( keys[NextCompletionMatch].isNull() ) | 365 | if ( keys[NextCompletionMatch].isNull() ) |
366 | cut = KStdAccel::key(KStdAccel::NextCompletion); | 366 | cut = KStdAccel::key(KStdAccel::NextCompletion); |
367 | else | 367 | else |
368 | cut = keys[NextCompletionMatch]; | 368 | cut = keys[NextCompletionMatch]; |
369 | 369 | ||
370 | if ( cut.contains( key ) ) | 370 | if ( cut.contains( key ) ) |
371 | { | 371 | { |
372 | if ( emitSignals() ) | 372 | if ( emitSignals() ) |
373 | emit textRotation( OCompletionBase::NextCompletionMatch ); | 373 | emit textRotation( OCompletionBase::NextCompletionMatch ); |
374 | if ( handleSignals() ) | 374 | if ( handleSignals() ) |
375 | rotateText( OCompletionBase::NextCompletionMatch ); | 375 | rotateText( OCompletionBase::NextCompletionMatch ); |
376 | return; | 376 | return; |
377 | } | 377 | } |
378 | } | 378 | } |
379 | 379 | ||
380 | // substring completion | 380 | // substring completion |
381 | if ( compObj() ) | 381 | if ( compObj() ) |
382 | { | 382 | { |
383 | KShortcut cut; | 383 | KShortcut cut; |
384 | if ( keys[SubstringCompletion].isNull() ) | 384 | if ( keys[SubstringCompletion].isNull() ) |
385 | cut = KStdAccel::shortcut(KStdAccel::SubstringCompletion); | 385 | cut = KStdAccel::shortcut(KStdAccel::SubstringCompletion); |
386 | else | 386 | else |
387 | cut = keys[SubstringCompletion]; | 387 | cut = keys[SubstringCompletion]; |
388 | 388 | ||
389 | if ( cut.contains( key ) ) | 389 | if ( cut.contains( key ) ) |
390 | { | 390 | { |
391 | if ( emitSignals() ) | 391 | if ( emitSignals() ) |
392 | emit substringCompletion( text() ); | 392 | emit substringCompletion( text() ); |
393 | if ( handleSignals() ) | 393 | if ( handleSignals() ) |
394 | { | 394 | { |
395 | setCompletedItems( compObj()->substringCompletion(text())); | 395 | setCompletedItems( compObj()->substringCompletion(text())); |
396 | e->accept(); | 396 | e->accept(); |
397 | } | 397 | } |
398 | return; | 398 | return; |
399 | } | 399 | } |
400 | } */ | 400 | } */ |
401 | } | 401 | } |
402 | 402 | ||
403 | // Let QLineEdit handle any other keys events. | 403 | // Let QLineEdit handle any other keys events. |
404 | QLineEdit::keyPressEvent ( e ); | 404 | QLineEdit::keyPressEvent ( e ); |
405 | } | 405 | } |
406 | 406 | ||
407 | void OLineEdit::mouseDoubleClickEvent( QMouseEvent* e ) | 407 | void OLineEdit::mouseDoubleClickEvent( QMouseEvent* e ) |
408 | { | 408 | { |
409 | if ( e->button() == Qt::LeftButton ) | 409 | if ( e->button() == Qt::LeftButton ) |
410 | { | 410 | { |
411 | possibleTripleClick=true; | 411 | possibleTripleClick=true; |
412 | QTimer::singleShot( QApplication::doubleClickInterval(),this, | 412 | QTimer::singleShot( QApplication::doubleClickInterval(),this, |
413 | SLOT(tripleClickTimeout()) ); | 413 | SLOT(tripleClickTimeout()) ); |
414 | } | 414 | } |
415 | QLineEdit::mouseDoubleClickEvent( e ); | 415 | QLineEdit::mouseDoubleClickEvent( e ); |
416 | } | 416 | } |
417 | 417 | ||
418 | void OLineEdit::mousePressEvent( QMouseEvent* e ) | 418 | void OLineEdit::mousePressEvent( QMouseEvent* e ) |
419 | { | 419 | { |
420 | if ( possibleTripleClick && e->button() == Qt::LeftButton ) | 420 | if ( possibleTripleClick && e->button() == Qt::LeftButton ) |
421 | { | 421 | { |
422 | selectAll(); | 422 | selectAll(); |
423 | return; | 423 | return; |
424 | } | 424 | } |
425 | QLineEdit::mousePressEvent( e ); | 425 | QLineEdit::mousePressEvent( e ); |
426 | } | 426 | } |
427 | 427 | ||
428 | void OLineEdit::tripleClickTimeout() | 428 | void OLineEdit::tripleClickTimeout() |
429 | { | 429 | { |
430 | possibleTripleClick=false; | 430 | possibleTripleClick=false; |
431 | } | 431 | } |
432 | 432 | ||
433 | QPopupMenu *OLineEdit::createPopupMenu() | 433 | QPopupMenu *OLineEdit::createPopupMenu() |
434 | { | 434 | { |
435 | // Return if popup menu is not enabled !! | 435 | // Return if popup menu is not enabled !! |
436 | if ( !m_bEnableMenu ) | 436 | if ( !m_bEnableMenu ) |
437 | return 0; | 437 | return 0; |
438 | 438 | ||
439 | #if QT_VERSION > 290 | 439 | #if QT_VERSION > 290 |
440 | QPopupMenu *popup = QLineEdit::createPopupMenu(); | 440 | QPopupMenu *popup = QLineEdit::createPopupMenu(); |
441 | #else | 441 | #else |
442 | QPopupMenu *popup = new QPopupMenu(); | 442 | QPopupMenu *popup = new QPopupMenu(); |
443 | #warning OLineEdit is not fully functional on Qt2 | 443 | #warning OLineEdit is not fully functional on Qt2 |
444 | #endif | 444 | #endif |
445 | 445 | ||
446 | // completion object is present. | 446 | // completion object is present. |
447 | if ( compObj() ) | 447 | if ( compObj() ) |
448 | { | 448 | { |
449 | QPopupMenu *subMenu = new QPopupMenu( popup ); | 449 | QPopupMenu *subMenu = new QPopupMenu( popup ); |
450 | connect( subMenu, SIGNAL( activated( int ) ), | 450 | connect( subMenu, SIGNAL( activated(int) ), |
451 | this, SLOT( completionMenuActivated( int ) ) ); | 451 | this, SLOT( completionMenuActivated(int) ) ); |
452 | 452 | ||
453 | popup->insertSeparator(); | 453 | popup->insertSeparator(); |
454 | //popup->insertItem( SmallIconSet("completion"), i18n("Text Completion"), | 454 | //popup->insertItem( SmallIconSet("completion"), i18n("Text Completion"), |
455 | // subMenu ); | 455 | // subMenu ); |
456 | 456 | ||
457 | popup->insertItem( tr("Text Completion"), subMenu ); | 457 | popup->insertItem( tr("Text Completion"), subMenu ); |
458 | 458 | ||
459 | subMenu->insertItem( tr("None"), NoCompletion ); | 459 | subMenu->insertItem( tr("None"), NoCompletion ); |
460 | subMenu->insertItem( tr("Manual"), ShellCompletion ); | 460 | subMenu->insertItem( tr("Manual"), ShellCompletion ); |
461 | subMenu->insertItem( tr("Automatic"), AutoCompletion ); | 461 | subMenu->insertItem( tr("Automatic"), AutoCompletion ); |
462 | subMenu->insertItem( tr("Dropdown List"), PopupCompletion ); | 462 | subMenu->insertItem( tr("Dropdown List"), PopupCompletion ); |
463 | subMenu->insertItem( tr("Short Automatic"), SemiAutoCompletion ); | 463 | subMenu->insertItem( tr("Short Automatic"), SemiAutoCompletion ); |
464 | 464 | ||
465 | //subMenu->setAccel( KStdAccel::completion(), ShellCompletion ); | 465 | //subMenu->setAccel( KStdAccel::completion(), ShellCompletion ); |
466 | subMenu->setAccel( Key_Tab, ShellCompletion ); | 466 | subMenu->setAccel( Key_Tab, ShellCompletion ); |
467 | 467 | ||
468 | OGlobalSettings::Completion mode = completionMode(); | 468 | OGlobalSettings::Completion mode = completionMode(); |
469 | subMenu->setItemChecked( NoCompletion, | 469 | subMenu->setItemChecked( NoCompletion, |
470 | mode == OGlobalSettings::CompletionNone ); | 470 | mode == OGlobalSettings::CompletionNone ); |
471 | subMenu->setItemChecked( ShellCompletion, | 471 | subMenu->setItemChecked( ShellCompletion, |
472 | mode == OGlobalSettings::CompletionShell ); | 472 | mode == OGlobalSettings::CompletionShell ); |
473 | subMenu->setItemChecked( PopupCompletion, | 473 | subMenu->setItemChecked( PopupCompletion, |
474 | mode == OGlobalSettings::CompletionPopup ); | 474 | mode == OGlobalSettings::CompletionPopup ); |
475 | subMenu->setItemChecked( AutoCompletion, | 475 | subMenu->setItemChecked( AutoCompletion, |
476 | mode == OGlobalSettings::CompletionAuto ); | 476 | mode == OGlobalSettings::CompletionAuto ); |
477 | subMenu->setItemChecked( SemiAutoCompletion, | 477 | subMenu->setItemChecked( SemiAutoCompletion, |
478 | mode == OGlobalSettings::CompletionMan ); | 478 | mode == OGlobalSettings::CompletionMan ); |
479 | if ( mode != OGlobalSettings::completionMode() ) | 479 | if ( mode != OGlobalSettings::completionMode() ) |
480 | { | 480 | { |
481 | subMenu->insertSeparator(); | 481 | subMenu->insertSeparator(); |
482 | subMenu->insertItem( tr("Default"), Default ); | 482 | subMenu->insertItem( tr("Default"), Default ); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | // ### do we really need this? Yes, Please do not remove! This | 485 | // ### do we really need this? Yes, Please do not remove! This |
486 | // allows applications to extend the popup menu without having to | 486 | // allows applications to extend the popup menu without having to |
487 | // inherit from this class! (DA) | 487 | // inherit from this class! (DA) |
488 | emit aboutToShowContextMenu( popup ); | 488 | emit aboutToShowContextMenu( popup ); |
489 | 489 | ||
490 | return popup; | 490 | return popup; |
491 | } | 491 | } |
492 | 492 | ||
493 | void OLineEdit::completionMenuActivated( int id ) | 493 | void OLineEdit::completionMenuActivated( int id ) |
494 | { | 494 | { |
495 | OGlobalSettings::Completion oldMode = completionMode(); | 495 | OGlobalSettings::Completion oldMode = completionMode(); |
496 | 496 | ||
497 | switch ( id ) | 497 | switch ( id ) |
498 | { | 498 | { |
499 | case Default: | 499 | case Default: |
500 | setCompletionMode( OGlobalSettings::completionMode() ); break; | 500 | setCompletionMode( OGlobalSettings::completionMode() ); break; |
501 | case NoCompletion: | 501 | case NoCompletion: |
502 | setCompletionMode( OGlobalSettings::CompletionNone ); break; | 502 | setCompletionMode( OGlobalSettings::CompletionNone ); break; |
503 | case AutoCompletion: | 503 | case AutoCompletion: |
504 | setCompletionMode( OGlobalSettings::CompletionAuto ); break; | 504 | setCompletionMode( OGlobalSettings::CompletionAuto ); break; |
505 | case SemiAutoCompletion: | 505 | case SemiAutoCompletion: |
506 | setCompletionMode( OGlobalSettings::CompletionMan ); break; | 506 | setCompletionMode( OGlobalSettings::CompletionMan ); break; |
507 | case ShellCompletion: | 507 | case ShellCompletion: |
508 | setCompletionMode( OGlobalSettings::CompletionShell ); break; | 508 | setCompletionMode( OGlobalSettings::CompletionShell ); break; |
509 | case PopupCompletion: | 509 | case PopupCompletion: |
510 | setCompletionMode( OGlobalSettings::CompletionPopup ); break; | 510 | setCompletionMode( OGlobalSettings::CompletionPopup ); break; |
511 | default: return; | 511 | default: return; |
512 | } | 512 | } |
513 | 513 | ||
514 | if ( oldMode != completionMode() ) | 514 | if ( oldMode != completionMode() ) |
515 | { | 515 | { |
516 | if ( oldMode == OGlobalSettings::CompletionPopup && | 516 | if ( oldMode == OGlobalSettings::CompletionPopup && |
517 | d->completionBox && d->completionBox->isVisible() ) | 517 | d->completionBox && d->completionBox->isVisible() ) |
518 | d->completionBox->hide(); | 518 | d->completionBox->hide(); |
519 | emit completionModeChanged( completionMode() ); | 519 | emit completionModeChanged( completionMode() ); |
520 | } | 520 | } |
521 | } | 521 | } |
522 | 522 | ||
523 | /*void OLineEdit::dropEvent(QDropEvent *e) | 523 | /*void OLineEdit::dropEvent(QDropEvent *e) |
524 | { | 524 | { |
525 | KURL::List urlList; | 525 | KURL::List urlList; |
526 | if( d->handleURLDrops && KURLDrag::decode( e, urlList ) ) | 526 | if( d->handleURLDrops && KURLDrag::decode( e, urlList ) ) |
527 | { | 527 | { |
528 | QString dropText = text(); | 528 | QString dropText = text(); |
529 | KURL::List::ConstIterator it; | 529 | KURL::List::ConstIterator it; |
530 | for( it = urlList.begin() ; it != urlList.end() ; ++it ) | 530 | for( it = urlList.begin() ; it != urlList.end() ; ++it ) |
531 | { | 531 | { |
532 | if(!dropText.isEmpty()) | 532 | if(!dropText.isEmpty()) |
533 | dropText+=' '; | 533 | dropText+=' '; |
534 | 534 | ||
535 | dropText += (*it).prettyURL(); | 535 | dropText += (*it).prettyURL(); |
536 | } | 536 | } |
537 | 537 | ||
538 | validateAndSet( dropText, dropText.length(), 0, 0); | 538 | validateAndSet( dropText, dropText.length(), 0, 0); |
539 | 539 | ||
540 | e->accept(); | 540 | e->accept(); |
541 | } | 541 | } |
542 | else | 542 | else |
543 | QLineEdit::dropEvent(e); | 543 | QLineEdit::dropEvent(e); |
544 | }*/ | 544 | }*/ |
545 | 545 | ||
546 | bool OLineEdit::eventFilter( QObject* o, QEvent* ev ) | 546 | bool OLineEdit::eventFilter( QObject* o, QEvent* ev ) |
547 | { | 547 | { |
548 | if( o == this ) | 548 | if( o == this ) |
549 | { | 549 | { |
550 | //OCursor::autoHideEventFilter( this, ev ); | 550 | //OCursor::autoHideEventFilter( this, ev ); |
551 | if ( ev->type() == QEvent::AccelOverride ) | 551 | if ( ev->type() == QEvent::AccelOverride ) |
552 | { | 552 | { |
553 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); | 553 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); |
554 | // if (overrideAccel (e)) | 554 | // if (overrideAccel (e)) |
555 | // { | 555 | // { |
556 | // e->accept(); | 556 | // e->accept(); |
557 | // return true; | 557 | // return true; |
558 | // } | 558 | // } |
559 | } | 559 | } |
560 | else if( ev->type() == QEvent::KeyPress ) | 560 | else if( ev->type() == QEvent::KeyPress ) |
561 | { | 561 | { |
562 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); | 562 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); |
563 | 563 | ||
564 | if( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) | 564 | if( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) |
565 | { | 565 | { |
566 | bool trap = d->completionBox && d->completionBox->isVisible(); | 566 | bool trap = d->completionBox && d->completionBox->isVisible(); |
567 | 567 | ||
568 | // Qt will emit returnPressed() itself if we return false | 568 | // Qt will emit returnPressed() itself if we return false |
569 | if ( d->grabReturnKeyEvents || trap ) | 569 | if ( d->grabReturnKeyEvents || trap ) |
570 | emit QLineEdit::returnPressed(); | 570 | emit QLineEdit::returnPressed(); |
571 | 571 | ||
572 | emit returnPressed( displayText() ); | 572 | emit returnPressed( displayText() ); |
573 | 573 | ||
574 | if ( trap ) | 574 | if ( trap ) |
575 | d->completionBox->hide(); | 575 | d->completionBox->hide(); |
576 | 576 | ||
577 | // Eat the event if the user asked for it, or if a completionbox was visible | 577 | // Eat the event if the user asked for it, or if a completionbox was visible |
578 | return d->grabReturnKeyEvents || trap; | 578 | return d->grabReturnKeyEvents || trap; |
579 | } | 579 | } |
580 | } | 580 | } |
581 | } | 581 | } |
582 | return QLineEdit::eventFilter( o, ev ); | 582 | return QLineEdit::eventFilter( o, ev ); |
583 | } | 583 | } |
584 | 584 | ||
585 | 585 | ||
586 | void OLineEdit::setURLDropsEnabled(bool enable) | 586 | void OLineEdit::setURLDropsEnabled(bool enable) |
587 | { | 587 | { |
588 | d->handleURLDrops=enable; | 588 | d->handleURLDrops=enable; |
589 | } | 589 | } |
590 | 590 | ||
591 | bool OLineEdit::isURLDropsEnabled() const | 591 | bool OLineEdit::isURLDropsEnabled() const |
592 | { | 592 | { |
593 | return d->handleURLDrops; | 593 | return d->handleURLDrops; |
594 | } | 594 | } |
595 | 595 | ||
596 | void OLineEdit::setTrapReturnKey( bool grab ) | 596 | void OLineEdit::setTrapReturnKey( bool grab ) |
597 | { | 597 | { |
598 | d->grabReturnKeyEvents = grab; | 598 | d->grabReturnKeyEvents = grab; |
599 | } | 599 | } |
600 | 600 | ||
601 | bool OLineEdit::trapReturnKey() const | 601 | bool OLineEdit::trapReturnKey() const |
602 | { | 602 | { |
603 | return d->grabReturnKeyEvents; | 603 | return d->grabReturnKeyEvents; |
604 | } | 604 | } |
605 | 605 | ||
606 | /*void OLineEdit::setURL( const KURL& url ) | 606 | /*void OLineEdit::setURL( const KURL& url ) |
607 | { | 607 | { |
608 | QLineEdit::setText( url.prettyURL() ); | 608 | QLineEdit::setText( url.prettyURL() ); |
609 | }*/ | 609 | }*/ |
610 | 610 | ||
611 | void OLineEdit::makeCompletionBox() | 611 | void OLineEdit::makeCompletionBox() |
612 | { | 612 | { |
613 | if ( d->completionBox ) | 613 | if ( d->completionBox ) |
614 | return; | 614 | return; |
615 | 615 | ||
616 | d->completionBox = new OCompletionBox( this, "completion box" ); | 616 | d->completionBox = new OCompletionBox( this, "completion box" ); |
617 | if ( handleSignals() ) | 617 | if ( handleSignals() ) |
618 | { | 618 | { |
619 | connect( d->completionBox, SIGNAL(highlighted( const QString& )), | 619 | connect( d->completionBox, SIGNAL(highlighted(const QString&)), |
620 | SLOT(setText( const QString& )) ); | 620 | SLOT(setText(const QString&)) ); |
621 | connect( d->completionBox, SIGNAL(userCancelled( const QString& )), | 621 | connect( d->completionBox, SIGNAL(userCancelled(const QString&)), |
622 | SLOT(setText( const QString& )) ); | 622 | SLOT(setText(const QString&)) ); |
623 | 623 | ||
624 | // Nice lil' hacklet ;) KComboBox doesn't know when the completionbox | 624 | // Nice lil' hacklet ;) KComboBox doesn't know when the completionbox |
625 | // is created (childEvent() is even more hacky, IMHO), so we simply | 625 | // is created (childEvent() is even more hacky, IMHO), so we simply |
626 | // forward the completionbox' activated signal from here. | 626 | // forward the completionbox' activated signal from here. |
627 | if ( parentWidget() && parentWidget()->inherits("KComboBox") ) | 627 | if ( parentWidget() && parentWidget()->inherits("KComboBox") ) |
628 | connect( d->completionBox, SIGNAL( activated( const QString& )), | 628 | connect( d->completionBox, SIGNAL( activated(const QString&)), |
629 | parentWidget(), SIGNAL( activated( const QString & ))); | 629 | parentWidget(), SIGNAL( activated(const QString&))); |
630 | } | 630 | } |
631 | } | 631 | } |
632 | 632 | ||
633 | /*bool OLineEdit::overrideAccel (const QKeyEvent* e) | 633 | /*bool OLineEdit::overrideAccel (const QKeyEvent* e) |
634 | { | 634 | { |
635 | KShortcut scKey; | 635 | KShortcut scKey; |
636 | 636 | ||
637 | KKey key( e ); | 637 | KKey key( e ); |
638 | KeyBindingMap keys = getKeyBindings(); | 638 | KeyBindingMap keys = getKeyBindings(); |
639 | 639 | ||
640 | if (keys[TextCompletion].isNull()) | 640 | if (keys[TextCompletion].isNull()) |
641 | scKey = KStdAccel::shortcut(KStdAccel::TextCompletion); | 641 | scKey = KStdAccel::shortcut(KStdAccel::TextCompletion); |
642 | else | 642 | else |
643 | scKey = keys[TextCompletion]; | 643 | scKey = keys[TextCompletion]; |
644 | 644 | ||
645 | if (scKey.contains( key )) | 645 | if (scKey.contains( key )) |
646 | return true; | 646 | return true; |
647 | 647 | ||
648 | if (keys[NextCompletionMatch].isNull()) | 648 | if (keys[NextCompletionMatch].isNull()) |
649 | scKey = KStdAccel::shortcut(KStdAccel::NextCompletion); | 649 | scKey = KStdAccel::shortcut(KStdAccel::NextCompletion); |
650 | else | 650 | else |
651 | scKey = keys[NextCompletionMatch]; | 651 | scKey = keys[NextCompletionMatch]; |
652 | 652 | ||
653 | if (scKey.contains( key )) | 653 | if (scKey.contains( key )) |
654 | return true; | 654 | return true; |
655 | 655 | ||
656 | if (keys[PrevCompletionMatch].isNull()) | 656 | if (keys[PrevCompletionMatch].isNull()) |
657 | scKey = KStdAccel::shortcut(KStdAccel::PrevCompletion); | 657 | scKey = KStdAccel::shortcut(KStdAccel::PrevCompletion); |
658 | else | 658 | else |
659 | scKey = keys[PrevCompletionMatch]; | 659 | scKey = keys[PrevCompletionMatch]; |
660 | 660 | ||
661 | if (scKey.contains( key )) | 661 | if (scKey.contains( key )) |
662 | return true; | 662 | return true; |
663 | 663 | ||
664 | if (KStdAccel::deleteWordBack().contains( key )) | 664 | if (KStdAccel::deleteWordBack().contains( key )) |
665 | return true; | 665 | return true; |
666 | if (KStdAccel::deleteWordForward().contains( key )) | 666 | if (KStdAccel::deleteWordForward().contains( key )) |
667 | return true; | 667 | return true; |
668 | 668 | ||
669 | if (d->completionBox && d->completionBox->isVisible ()) | 669 | if (d->completionBox && d->completionBox->isVisible ()) |
670 | if (e->key () == Key_Backtab) | 670 | if (e->key () == Key_Backtab) |
671 | return true; | 671 | return true; |
672 | 672 | ||
673 | return false; | 673 | return false; |
674 | }*/ | 674 | }*/ |
675 | 675 | ||
676 | void OLineEdit::setCompletedItems( const QStringList& items ) | 676 | void OLineEdit::setCompletedItems( const QStringList& items ) |
677 | { | 677 | { |
678 | QString txt = text(); | 678 | QString txt = text(); |
679 | if ( !items.isEmpty() && | 679 | if ( !items.isEmpty() && |
680 | !(items.count() == 1 && txt == items.first()) ) | 680 | !(items.count() == 1 && txt == items.first()) ) |
681 | { | 681 | { |
682 | if ( !d->completionBox ) | 682 | if ( !d->completionBox ) |
683 | makeCompletionBox(); | 683 | makeCompletionBox(); |
684 | 684 | ||
685 | if ( !txt.isEmpty() ) | 685 | if ( !txt.isEmpty() ) |
686 | d->completionBox->setCancelledText( txt ); | 686 | d->completionBox->setCancelledText( txt ); |
687 | d->completionBox->setItems( items ); | 687 | d->completionBox->setItems( items ); |
688 | d->completionBox->popup(); | 688 | d->completionBox->popup(); |
689 | } | 689 | } |
690 | else | 690 | else |
691 | { | 691 | { |
692 | if ( d->completionBox && d->completionBox->isVisible() ) | 692 | if ( d->completionBox && d->completionBox->isVisible() ) |
693 | d->completionBox->hide(); | 693 | d->completionBox->hide(); |
694 | } | 694 | } |
695 | } | 695 | } |
696 | 696 | ||
697 | OCompletionBox * OLineEdit::completionBox( bool create ) | 697 | OCompletionBox * OLineEdit::completionBox( bool create ) |
698 | { | 698 | { |
699 | if ( create ) | 699 | if ( create ) |
700 | makeCompletionBox(); | 700 | makeCompletionBox(); |
701 | 701 | ||
702 | return d->completionBox; | 702 | return d->completionBox; |
703 | } | 703 | } |
704 | 704 | ||
705 | void OLineEdit::setCompletionObject( OCompletion* comp, bool hsig ) | 705 | void OLineEdit::setCompletionObject( OCompletion* comp, bool hsig ) |
706 | { | 706 | { |
707 | OCompletion *oldComp = compObj(); | 707 | OCompletion *oldComp = compObj(); |
708 | if ( oldComp && handleSignals() ) | 708 | if ( oldComp && handleSignals() ) |
709 | disconnect( oldComp, SIGNAL( matches( const QStringList& )), | 709 | disconnect( oldComp, SIGNAL( matches(const QStringList&)), |
710 | this, SLOT( setCompletedItems( const QStringList& ))); | 710 | this, SLOT( setCompletedItems(const QStringList&))); |
711 | 711 | ||
712 | if ( comp && hsig ) | 712 | if ( comp && hsig ) |
713 | connect( comp, SIGNAL( matches( const QStringList& )), | 713 | connect( comp, SIGNAL( matches(const QStringList&)), |
714 | this, SLOT( setCompletedItems( const QStringList& ))); | 714 | this, SLOT( setCompletedItems(const QStringList&))); |
715 | 715 | ||
716 | OCompletionBase::setCompletionObject( comp, hsig ); | 716 | OCompletionBase::setCompletionObject( comp, hsig ); |
717 | } | 717 | } |
718 | 718 | ||
719 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding | 719 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding |
720 | void OLineEdit::create( WId id, bool initializeWindow, bool destroyOldWindow ) | 720 | void OLineEdit::create( WId id, bool initializeWindow, bool destroyOldWindow ) |
721 | { | 721 | { |
722 | QLineEdit::create( id, initializeWindow, destroyOldWindow ); | 722 | QLineEdit::create( id, initializeWindow, destroyOldWindow ); |
723 | //OCursor::setAutoHideCursor( this, true, true ); | 723 | //OCursor::setAutoHideCursor( this, true, true ); |
724 | } | 724 | } |
725 | 725 | ||
726 | void OLineEdit::clear() | 726 | void OLineEdit::clear() |
727 | { | 727 | { |
728 | setText( QString::null ); | 728 | setText( QString::null ); |
729 | } | 729 | } |