00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "categoryfilterimpl.h"
00031
00032
00033 #include <qpe/qpeapplication.h>
00034
00035
00036 #include <qgroupbox.h>
00037 #include <qlayout.h>
00038 #include <qlistbox.h>
00039 #include <qstring.h>
00040
00041
00042 CategoryFilterImpl :: CategoryFilterImpl(const QString &categories, const QString &selectedCategories, QWidget *parent, const char *name )
00043 : QDialog( parent, name, true )
00044 {
00045 setCaption( tr( "Category Filter" ) );
00046
00047 QVBoxLayout *layout = new QVBoxLayout( this );
00048 layout->setMargin( 2 );
00049 layout->setSpacing( 4 );
00050
00051 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Select one or more groups" ), this );
00052 grpbox->layout()->setSpacing( 2 );
00053 grpbox->layout()->setMargin( 4 );
00054 layout->addWidget( grpbox );
00055
00056 QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() );
00057
00058 lstCategories = new QListBox( grpbox );
00059 lstCategories->setSelectionMode( QListBox::Multi );
00060 grplayout->addWidget( lstCategories );
00061
00062
00063 int start = 1;
00064
00065 QString item;
00066 int end;
00067 QString finditem;
00068 do
00069 {
00070 end = categories.find( "#", start );
00071 item = categories.mid( start, end - start );
00072 if ( item != "" )
00073 {
00074 lstCategories->insertItem( item );
00075 finditem = QString( "#%1#" ).arg( item );
00076 if ( selectedCategories.find( finditem ) != -1 )
00077 lstCategories->setSelected( lstCategories->count()-1, true );
00078 }
00079
00080 start = end + 1;
00081 }
00082 while ( start < (int)categories.length() );
00083
00084 lstCategories->sort( true );
00085
00086 QPEApplication::showDialog( this );
00087 }
00088
00089 CategoryFilterImpl :: ~CategoryFilterImpl()
00090 {}
00091
00092 QString CategoryFilterImpl :: getSelectedFilter()
00093 {
00094
00095 QString ret = "#";
00096
00097 for ( int i = 0 ; i < (int)lstCategories->count() ; ++i )
00098 {
00099 if ( lstCategories->isSelected( i ) )
00100 {
00101 ret.append( lstCategories->text( i ) );
00102 ret.append( "#" );
00103 }
00104 }
00105
00106 if ( ret == "#" )
00107 ret = "";
00108 return ret;
00109 }