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 <qapplication.h>
00025 #include <qcombobox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qtoolbutton.h>
00029 #include <qtooltip.h>
00030 #include <qwhatsthis.h>
00031
00032 #include <kdialog.h>
00033 #include <kiconloader.h>
00034 #include <klineedit.h>
00035 #include <klocale.h>
00036
00037 #include "incsearchwidget.h"
00038
00039 IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
00040 : QWidget( parent, name )
00041 {
00042 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
00043
00044 QToolButton *button = new QToolButton( this );
00045 button->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
00046 button->setPixmap( SmallIcon( QApplication::reverseLayout() ? "clear_left" : "locationbar_erase" ) );
00047 QToolTip::add( button, i18n( "Reset" ) );
00048 layout->addWidget( button );
00049
00050 QLabel *label = new QLabel( i18n( "Search:" ), this, "kde toolbar widget" );
00051 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
00052 layout->addWidget( label );
00053
00054 mSearchText = new KLineEdit( this );
00055 mSearchText->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
00056 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." ) );
00057 label->setBuddy( mSearchText );
00058 layout->addWidget( mSearchText );
00059
00060 label = new QLabel( i18n( "as in 'Search in:'", "&in:" ), this, "kde toolbar widget" );
00061 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
00062 layout->addWidget( label );
00063
00064 mFieldCombo = new QComboBox( false, this );
00065 layout->addWidget( mFieldCombo );
00066 label->setBuddy(mFieldCombo);
00067
00068 QToolTip::add( mFieldCombo, i18n( "Select incremental search field" ) );
00069 QWhatsThis::add( mFieldCombo, i18n( "Here you can choose the field, which shall be used for incremental search." ) );
00070
00071 connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
00072 SLOT( announceDoSearch() ) );
00073 connect( mSearchText, SIGNAL( returnPressed() ),
00074 SLOT( announceDoSearch() ) );
00075 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
00076 SLOT( announceDoSearch() ) );
00077 connect( button, SIGNAL( clicked() ), SIGNAL( doReset() ) );
00078 connect( button, SIGNAL( clicked() ),
00079 mSearchText, SLOT( clear() ) );
00080 connect( button, SIGNAL( clicked() ),
00081 SLOT( announceDoSearch() ) );
00082
00083 initFields();
00084
00085 setFocusProxy( mSearchText );
00086 }
00087
00088 IncSearchWidget::~IncSearchWidget()
00089 {
00090 }
00091
00092 void IncSearchWidget::announceDoSearch()
00093 {
00094 emit doSearch( mSearchText->text() );
00095 }
00096
00097 void IncSearchWidget::initFields()
00098 {
00099 mFieldList = KABC::Field::allFields();
00100
00101 mFieldCombo->clear();
00102 mFieldCombo->insertItem( i18n( "All Fields" ) );
00103
00104 KABC::Field::List::ConstIterator it;
00105 for ( it = mFieldList.begin(); it != mFieldList.end(); ++it )
00106 mFieldCombo->insertItem( (*it)->label() );
00107
00108 announceDoSearch();
00109 }
00110
00111 KABC::Field *IncSearchWidget::currentField() const
00112 {
00113 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
00114 return 0;
00115 else
00116 return mFieldList[ mFieldCombo->currentItem() - 1 ];
00117 }
00118
00119 void IncSearchWidget::setCurrentItem( int pos )
00120 {
00121 mFieldCombo->setCurrentItem( pos );
00122 }
00123
00124 int IncSearchWidget::currentItem() const
00125 {
00126 return mFieldCombo->currentItem();
00127 }
00128
00129 #include "incsearchwidget.moc"
This file is part of the documentation for kaddressbook Library Version 3.3.2.