-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,5 +1,6 @@ | |||
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 | ** |
@@ -31,6 +32,41 @@ | |||
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"); |
@@ -249,7 +285,7 @@ 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" |
@@ -286,6 +322,26 @@ void CategoryCombo::slotValueChanged( int ) | |||
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 ), |
@@ -296,6 +352,11 @@ CategorySelect::CategorySelect( QWidget *parent, const char *name,int width) | |||
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) |
@@ -308,6 +369,13 @@ CategorySelect::CategorySelect( const QArray<int> &vl, | |||
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, |
@@ -319,11 +387,17 @@ CategorySelect::CategorySelect( const QArray<int> &vl, | |||
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() )){ |
@@ -357,6 +431,10 @@ void CategorySelect::slotDialog() | |||
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 ) { |
@@ -376,12 +454,28 @@ void CategorySelect::slotNewCat( int newUid ) | |||
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 ) |
@@ -406,23 +500,31 @@ void CategorySelect::init(int width) | |||
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 ) { |
@@ -434,6 +536,9 @@ void CategorySelect::setRemoveCategoryEdit( bool remove ) | |||
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; |
@@ -445,6 +550,9 @@ void CategorySelect::setAllCategories( bool add ) | |||
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(); |