incsearchwidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qcombobox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qtooltip.h>
00028 #include <qwhatsthis.h>
00029
00030 #include <kdialog.h>
00031 #include <klineedit.h>
00032 #include <klocale.h>
00033
00034 #include "incsearchwidget.h"
00035
00036 IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
00037 : QWidget( parent, name )
00038 {
00039 setCaption( i18n( "Incremental Search" ) );
00040
00041 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
00042
00043 QLabel *label = new QLabel( i18n( "Search:" ), this );
00044 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
00045 layout->addWidget( label );
00046
00047 mSearchText = new KLineEdit( this );
00048 QWhatsThis::add( mSearchText, i18n( "The incremental search<p>Enter some text here will start the search for the contact, which matches the search pattern best. The part of the contact, which will be used for matching, depends on the field selection." ) );
00049 label->setBuddy( mSearchText );
00050 layout->addWidget( mSearchText );
00051
00052 mFieldCombo = new QComboBox( false, this );
00053 layout->addWidget( mFieldCombo );
00054
00055 QToolTip::add( mFieldCombo, i18n( "Select incremental search field" ) );
00056 QWhatsThis::add( mFieldCombo, i18n( "Here you can choose the field, which shall be used for incremental search." ) );
00057
00058 resize( QSize(420, 50).expandedTo( sizeHint() ) );
00059
00060 connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
00061 SLOT( announceDoSearch() ) );
00062 connect( mSearchText, SIGNAL( returnPressed() ),
00063 SLOT( announceDoSearch() ) );
00064 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
00065 SLOT( announceDoSearch() ) );
00066 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
00067 SLOT( announceFieldChanged() ) );
00068
00069 setFocusProxy( mSearchText );
00070 }
00071
00072 IncSearchWidget::~IncSearchWidget()
00073 {
00074 }
00075
00076 void IncSearchWidget::announceDoSearch()
00077 {
00078 emit doSearch( mSearchText->text() );
00079 }
00080
00081 void IncSearchWidget::announceFieldChanged()
00082 {
00083 emit fieldChanged();
00084 }
00085
00086 void IncSearchWidget::setFields( const KABC::Field::List &list )
00087 {
00088 mFieldCombo->clear();
00089 mFieldCombo->insertItem( i18n( "All Fields" ) );
00090
00091 KABC::Field::List::ConstIterator it;
00092 for ( it = list.begin(); it != list.end(); ++it )
00093 mFieldCombo->insertItem( (*it)->label() );
00094
00095 mFieldList = list;
00096
00097 announceDoSearch();
00098 announceFieldChanged();
00099 }
00100
00101 KABC::Field::List IncSearchWidget::fields() const
00102 {
00103 return mFieldList;
00104 }
00105
00106 KABC::Field *IncSearchWidget::currentField()const
00107 {
00108 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
00109 return 0;
00110 else
00111 return mFieldList[ mFieldCombo->currentItem() - 1 ];
00112 }
00113
00114 void IncSearchWidget::setCurrentItem( int pos )
00115 {
00116 mFieldCombo->setCurrentItem( pos );
00117 announceFieldChanged();
00118 }
00119
00120 int IncSearchWidget::currentItem() const
00121 {
00122 return mFieldCombo->currentItem();
00123 }
00124
00125 #include "incsearchwidget.moc"
This file is part of the documentation for kaddressbook Library Version 3.2.2.