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 <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; // for error or 'use all fields' 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"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:51:13 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003