kaddressbook Library API Documentation

incsearchwidget.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 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; // for error or 'use all fields' 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"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:08 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003