-rw-r--r-- | library/categoryselect.cpp | 114 |
1 files changed, 111 insertions, 3 deletions
diff --git a/library/categoryselect.cpp b/library/categoryselect.cpp index 21b3f91..8473aeb 100644 --- a/library/categoryselect.cpp +++ b/library/categoryselect.cpp | |||
@@ -1,8 +1,9 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2003 zecke introduce a needed symbol | ||
3 | ** | 4 | ** |
4 | ** This file is part of Qtopia Environment. | 5 | ** This file is part of Qtopia Environment. |
5 | ** | 6 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
@@ -28,12 +29,47 @@ | |||
28 | 29 | ||
29 | #include "categorywidget.h" | 30 | #include "categorywidget.h" |
30 | #include "categoryselect.h" | 31 | #include "categoryselect.h" |
31 | 32 | ||
32 | #include <stdlib.h> | 33 | #include <stdlib.h> |
33 | 34 | ||
35 | |||
36 | /*! \enum CategorySelect::SelectorWidget | ||
37 | Chooses a type of widget to use as the selection widget. | ||
38 | |||
39 | \value ComboBox | ||
40 | \value ListView | ||
41 | */ | ||
42 | |||
43 | /*! | ||
44 | \class CategorySelect | ||
45 | \brief The CategorySelect widget allows users to select Categories with a | ||
46 | combobox interface. | ||
47 | |||
48 | CategorySelect is useful to provide a QComboBox of Categories for | ||
49 | filtering (such as in the Contacts table view) or to allow the user | ||
50 | to select multiple Categories. The allCategories variable sets | ||
51 | whether the CategorySelect is in filtering or selecting mode. | ||
52 | |||
53 | In filtering mode, the All and Unfiled categories are added. The | ||
54 | |||
55 | In selecting mode, the CategorySelect may either be a QComboBox and | ||
56 | a QToolButton or a QListView with checkable items depending on the | ||
57 | screen size. | ||
58 | |||
59 | CategorySelect automatically updates itself if Categories has been | ||
60 | changed elsewhere in the environment. | ||
61 | |||
62 | Signals and slots are provided to notify the application of the users | ||
63 | selections. A QToolButton is also provided so that users can edit the | ||
64 | Categories manually. | ||
65 | |||
66 | \ingroup qtopiaemb | ||
67 | */ | ||
68 | |||
69 | |||
34 | static QString categoryEdittingFileName() | 70 | static QString categoryEdittingFileName() |
35 | { | 71 | { |
36 | QString str = getenv("HOME"); | 72 | QString str = getenv("HOME"); |
37 | str +="/.cateditting"; | 73 | str +="/.cateditting"; |
38 | return str; | 74 | return str; |
39 | } | 75 | } |
@@ -246,13 +282,13 @@ CategoryCombo::~CategoryCombo() | |||
246 | } | 282 | } |
247 | 283 | ||
248 | int CategoryCombo::currentCategory() const | 284 | int CategoryCombo::currentCategory() const |
249 | { | 285 | { |
250 | int returnMe; | 286 | int returnMe; |
251 | returnMe = currentItem(); | 287 | returnMe = currentItem(); |
252 | 288 | ||
253 | if ( returnMe == (int)d->mAppCats.count() ) | 289 | if ( returnMe == (int)d->mAppCats.count() ) |
254 | returnMe = -1; | 290 | returnMe = -1; |
255 | else if ( returnMe > (int)d->mAppCats.count() ) // only happen on "All" | 291 | else if ( returnMe > (int)d->mAppCats.count() ) // only happen on "All" |
256 | returnMe = -2; | 292 | returnMe = -2; |
257 | else | 293 | else |
258 | returnMe = d->mAppCats[returnMe]; | 294 | returnMe = d->mAppCats[returnMe]; |
@@ -283,50 +319,88 @@ void CategoryCombo::setCurrentText( const QString &str ) | |||
283 | 319 | ||
284 | void CategoryCombo::slotValueChanged( int ) | 320 | void CategoryCombo::slotValueChanged( int ) |
285 | { | 321 | { |
286 | emit sigCatChanged( currentCategory() ); | 322 | emit sigCatChanged( currentCategory() ); |
287 | } | 323 | } |
288 | 324 | ||
325 | /*! | ||
326 | Constructs a category selector with parent \a parent, name \a name. | ||
327 | |||
328 | This constructor is provided to make Opie compatible with Sharp ROM. | ||
329 | */ | ||
330 | CategorySelect::CategorySelect( QWidget* parent, const char* name ) | ||
331 | : QHBox( parent, name ), | ||
332 | cmbCat( 0 ), | ||
333 | cmdCat( 0 ), | ||
334 | d( 0 ) | ||
335 | { | ||
336 | d = new CategorySelectPrivate(); | ||
337 | init(0); // default argument | ||
338 | } | ||
339 | /*! | ||
340 | Constructs a category selector with parent \a parent, name \a name and | ||
341 | fixed width \a width. | ||
342 | |||
343 | This constructor is provided to make integration with Qt Designer easier. | ||
344 | */ | ||
289 | CategorySelect::CategorySelect( QWidget *parent, const char *name,int width) | 345 | CategorySelect::CategorySelect( QWidget *parent, const char *name,int width) |
290 | : QHBox( parent, name ), | 346 | : QHBox( parent, name ), |
291 | cmbCat( 0 ), | 347 | cmbCat( 0 ), |
292 | cmdCat( 0 ), | 348 | cmdCat( 0 ), |
293 | d( 0 ) | 349 | d( 0 ) |
294 | { | 350 | { |
295 | d = new CategorySelectPrivate(); | 351 | d = new CategorySelectPrivate(); |
296 | init(width); | 352 | init(width); |
297 | } | 353 | } |
298 | 354 | ||
355 | /*! | ||
356 | \overload | ||
357 | This constructor accepts an array \a vl of integers representing Categories. | ||
358 | \a appName is used as the visible name string. | ||
359 | */ | ||
299 | CategorySelect::CategorySelect( const QArray<int> &vl, | 360 | CategorySelect::CategorySelect( const QArray<int> &vl, |
300 | const QString &appName, QWidget *parent, | 361 | const QString &appName, QWidget *parent, |
301 | const char *name ,int width) | 362 | const char *name ,int width) |
302 | : QHBox( parent, name ) | 363 | : QHBox( parent, name ) |
303 | { | 364 | { |
304 | d = new CategorySelectPrivate( vl ); | 365 | d = new CategorySelectPrivate( vl ); |
305 | 366 | ||
306 | init(width); | 367 | init(width); |
307 | 368 | ||
308 | setCategories( vl, appName, appName ); | 369 | setCategories( vl, appName, appName ); |
309 | } | 370 | } |
310 | 371 | ||
372 | /*! | ||
373 | \overload | ||
374 | |||
375 | This constructor accepts an array \a vl of integers representing Categories. | ||
376 | \a visibleName is the string used when the name of this widget is required | ||
377 | to be displayed. \a width is an integer used as the fixed width of the widget. | ||
378 | */ | ||
311 | CategorySelect::CategorySelect( const QArray<int> &vl, | 379 | CategorySelect::CategorySelect( const QArray<int> &vl, |
312 | const QString &appName, | 380 | const QString &appName, |
313 | const QString &visibleName, | 381 | const QString &visibleName, |
314 | QWidget *parent, const char *name , int width) | 382 | QWidget *parent, const char *name , int width) |
315 | : QHBox( parent, name ) | 383 | : QHBox( parent, name ) |
316 | { | 384 | { |
317 | d = new CategorySelectPrivate( vl ); | 385 | d = new CategorySelectPrivate( vl ); |
318 | init(width); | 386 | init(width); |
319 | setCategories( vl, appName, visibleName ); | 387 | setCategories( vl, appName, visibleName ); |
320 | } | 388 | } |
321 | 389 | ||
390 | /*! | ||
391 | Destructs a CategorySelect widget. | ||
392 | */ | ||
322 | CategorySelect::~CategorySelect() | 393 | CategorySelect::~CategorySelect() |
323 | { | 394 | { |
324 | delete d; | 395 | delete d; |
325 | } | 396 | } |
326 | 397 | ||
398 | /*! | ||
399 | This slot is called when the user pushes the button to edit Categories. | ||
400 | */ | ||
327 | void CategorySelect::slotDialog() | 401 | void CategorySelect::slotDialog() |
328 | { | 402 | { |
329 | if (QFile::exists( categoryEdittingFileName() )){ | 403 | if (QFile::exists( categoryEdittingFileName() )){ |
330 | QMessageBox::warning(this,tr("Error"), | 404 | QMessageBox::warning(this,tr("Error"), |
331 | tr("Sorry, another application is\nediting categories.") ); | 405 | tr("Sorry, another application is\nediting categories.") ); |
332 | return; | 406 | return; |
@@ -354,12 +428,16 @@ void CategorySelect::slotDialog() | |||
354 | } | 428 | } |
355 | 429 | ||
356 | f.close(); | 430 | f.close(); |
357 | QFile::remove( categoryEdittingFileName() ); | 431 | QFile::remove( categoryEdittingFileName() ); |
358 | } | 432 | } |
359 | 433 | ||
434 | |||
435 | /*! | ||
436 | This slot is called when a new Category is available. | ||
437 | */ | ||
360 | void CategorySelect::slotNewCat( int newUid ) | 438 | void CategorySelect::slotNewCat( int newUid ) |
361 | { | 439 | { |
362 | if ( newUid != -1 ) { | 440 | if ( newUid != -1 ) { |
363 | bool alreadyIn = false; | 441 | bool alreadyIn = false; |
364 | for ( uint it = 0; it < d->mRec.count(); ++it ) { | 442 | for ( uint it = 0; it < d->mRec.count(); ++it ) { |
365 | if ( d->mRec[it] == newUid ) { | 443 | if ( d->mRec[it] == newUid ) { |
@@ -373,18 +451,34 @@ void CategorySelect::slotNewCat( int newUid ) | |||
373 | } | 451 | } |
374 | } else | 452 | } else |
375 | d->mRec.resize(0); // now Unfiled. | 453 | d->mRec.resize(0); // now Unfiled. |
376 | emit signalSelected( currentCategory() ); | 454 | emit signalSelected( currentCategory() ); |
377 | } | 455 | } |
378 | 456 | ||
457 | /*! | ||
458 | \overload | ||
459 | |||
460 | Resets the CategorySelect to select the \a vlCats for | ||
461 | the Categories assoicated with \a appName. | ||
462 | |||
463 | This function should only be called if <i>filtering</i> | ||
464 | on Categories and not selecting and therefore possibly | ||
465 | allowing the user to edit Categories. | ||
466 | */ | ||
379 | QString CategorySelect::setCategories( const QArray<int> &rec, | 467 | QString CategorySelect::setCategories( const QArray<int> &rec, |
380 | const QString &appName ) | 468 | const QString &appName ) |
381 | { | 469 | { |
382 | return setCategories( rec, appName, appName ); | 470 | return setCategories( rec, appName, appName ); |
383 | } | 471 | } |
384 | 472 | ||
473 | /*! | ||
474 | Resets the CategorySelect to select the \a vlCats for | ||
475 | the Categories assoicated with \a appName and displays | ||
476 | the \a visibleName if the user is selecting and therefore editing | ||
477 | new Categories. | ||
478 | */ | ||
385 | QString CategorySelect::setCategories( const QArray<int> &rec, | 479 | QString CategorySelect::setCategories( const QArray<int> &rec, |
386 | const QString &appName, | 480 | const QString &appName, |
387 | const QString &visibleName ) | 481 | const QString &visibleName ) |
388 | { | 482 | { |
389 | d->mVisibleName = visibleName; | 483 | d->mVisibleName = visibleName; |
390 | mStrAppName = appName; | 484 | mStrAppName = appName; |
@@ -403,50 +497,64 @@ void CategorySelect::init(int width) | |||
403 | cmdCat->setTextLabel( "...", FALSE ); | 497 | cmdCat->setTextLabel( "...", FALSE ); |
404 | cmdCat->setUsesTextLabel( true ); | 498 | cmdCat->setUsesTextLabel( true ); |
405 | cmdCat->setMaximumSize( cmdCat->sizeHint() ); | 499 | cmdCat->setMaximumSize( cmdCat->sizeHint() ); |
406 | cmdCat->setFocusPolicy( TabFocus ); | 500 | cmdCat->setFocusPolicy( TabFocus ); |
407 | } | 501 | } |
408 | 502 | ||
409 | 503 | /*! | |
504 | Return the value of the currently selected category. | ||
505 | */ | ||
410 | int CategorySelect::currentCategory() const | 506 | int CategorySelect::currentCategory() const |
411 | { | 507 | { |
412 | return cmbCat->currentCategory(); | 508 | return cmbCat->currentCategory(); |
413 | } | 509 | } |
414 | 510 | ||
511 | |||
415 | void CategorySelect::setCurrentCategory( int newCatUid ) | 512 | void CategorySelect::setCurrentCategory( int newCatUid ) |
416 | { | 513 | { |
417 | cmbCat->setCurrentCategory( newCatUid ); | 514 | cmbCat->setCurrentCategory( newCatUid ); |
418 | } | 515 | } |
419 | 516 | ||
420 | 517 | /*! | |
518 | Returns a shallow copy of the categories in this CategorySelect. | ||
519 | */ | ||
421 | const QArray<int> &CategorySelect::currentCategories() const | 520 | const QArray<int> &CategorySelect::currentCategories() const |
422 | { | 521 | { |
423 | return d->mRec; | 522 | return d->mRec; |
424 | } | 523 | } |
425 | 524 | ||
525 | /*! | ||
526 | Hides the edit section of the CategorySelect widget if \a remove is TRUE. | ||
527 | */ | ||
426 | void CategorySelect::setRemoveCategoryEdit( bool remove ) | 528 | void CategorySelect::setRemoveCategoryEdit( bool remove ) |
427 | { | 529 | { |
428 | if ( remove ) { | 530 | if ( remove ) { |
429 | cmdCat->setEnabled( FALSE ); | 531 | cmdCat->setEnabled( FALSE ); |
430 | cmdCat->hide(); | 532 | cmdCat->hide(); |
431 | } else { | 533 | } else { |
432 | cmdCat->setEnabled( TRUE ); | 534 | cmdCat->setEnabled( TRUE ); |
433 | cmdCat->show(); | 535 | cmdCat->show(); |
434 | } | 536 | } |
435 | } | 537 | } |
436 | 538 | ||
539 | /*! | ||
540 | Changes this CategorySelect to the All category if \a all is TRUE. | ||
541 | */ | ||
437 | void CategorySelect::setAllCategories( bool add ) | 542 | void CategorySelect::setAllCategories( bool add ) |
438 | { | 543 | { |
439 | d->usingAll = add; | 544 | d->usingAll = add; |
440 | if ( add ) { | 545 | if ( add ) { |
441 | cmbCat->insertItem( tr( "All" ), cmbCat->count() ); | 546 | cmbCat->insertItem( tr( "All" ), cmbCat->count() ); |
442 | cmbCat->setCurrentItem( cmbCat->count() - 1 ); | 547 | cmbCat->setCurrentItem( cmbCat->count() - 1 ); |
443 | } else | 548 | } else |
444 | cmbCat->removeItem( cmbCat->count() - 1 ); | 549 | cmbCat->removeItem( cmbCat->count() - 1 ); |
445 | } | 550 | } |
446 | 551 | ||
447 | // 01.12.21 added | 552 | // 01.12.21 added |
553 | /*! | ||
554 | Sets the fixed width of the widget to \a width. | ||
555 | */ | ||
448 | void CategorySelect::setFixedWidth(int width) | 556 | void CategorySelect::setFixedWidth(int width) |
449 | { | 557 | { |
450 | width -= cmdCat->width(); | 558 | width -= cmdCat->width(); |
451 | cmbCat->setFixedWidth(width); | 559 | cmbCat->setFixedWidth(width); |
452 | } | 560 | } |