24 #include <tqapplication.h>
25 #include <tqcombobox.h>
29 #include <tqtoolbutton.h>
30 #include <tqtooltip.h>
31 #include <tqwhatsthis.h>
34 #include <kiconloader.h>
35 #include <klineedit.h>
36 #include <tdelocale.h>
38 #include "incsearchwidget.h"
40 IncSearchWidget::IncSearchWidget( TQWidget *parent,
const char *name )
41 : TQWidget( parent, name )
43 TQHBoxLayout *layout =
new TQHBoxLayout(
this, 2, KDialog::spacingHint() );
45 TQToolButton *button =
new TQToolButton(
this );
46 button->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum );
47 button->setPixmap( SmallIcon( TQApplication::reverseLayout() ?
"clear_left" :
"locationbar_erase" ) );
48 button->setAccel( TQKeySequence( CTRL+ALT+Key_S ) );
49 button->setAutoRaise(
true );
50 TQToolTip::add( button, i18n(
"Reset" ) );
51 layout->addWidget( button );
53 TQLabel *label =
new TQLabel( i18n(
"Search:" ),
this,
"tde toolbar widget" );
54 label->setAlignment( TQLabel::AlignVCenter | TQLabel::AlignRight );
55 layout->addWidget( label );
57 mSearchText =
new KLineEdit(
this );
58 mSearchText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Preferred );
59 TQWhatsThis::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." ) );
60 label->setBuddy( mSearchText );
61 layout->addWidget( mSearchText );
63 label =
new TQLabel( i18n(
"as in 'Search in:'",
"&in:" ),
this,
"tde toolbar widget" );
64 label->setAlignment( TQLabel::AlignVCenter | TQLabel::AlignRight );
65 layout->addWidget( label );
67 mFieldCombo =
new TQComboBox(
false,
this );
68 layout->addWidget( mFieldCombo );
69 label->setBuddy(mFieldCombo);
71 TQToolTip::add( mFieldCombo, i18n(
"Select incremental search field" ) );
72 TQWhatsThis::add( mFieldCombo, i18n(
"Here you can choose the field, which shall be used for incremental search." ) );
74 mInputTimer =
new TQTimer(
this );
76 connect( mInputTimer, TQ_SIGNAL( timeout() ),
77 TQ_SLOT( timeout() ) );
78 connect( mSearchText, TQ_SIGNAL( textChanged(
const TQString& ) ),
79 TQ_SLOT( announceDoSearch() ) );
80 connect( mSearchText, TQ_SIGNAL( returnPressed() ),
81 TQ_SLOT( announceDoSearch() ) );
82 connect( mFieldCombo, TQ_SIGNAL( activated(
const TQString& ) ),
83 TQ_SLOT( announceDoSearch() ) );
84 connect( button, TQ_SIGNAL( clicked() ),
85 mSearchText, TQ_SLOT( clear() ) );
86 connect( button, TQ_SIGNAL( clicked() ),
87 TQ_SLOT( announceDoSearch() ) );
91 mSearchText->installEventFilter(
this );
93 setFocusProxy( mSearchText );
96 IncSearchWidget::~IncSearchWidget()
100 void IncSearchWidget::announceDoSearch()
102 if ( mInputTimer->isActive() )
105 mInputTimer->start( 0,
true );
108 void IncSearchWidget::timeout()
110 emit doSearch( mSearchText->text() );
113 void IncSearchWidget::initFields()
115 mFieldList = TDEABC::Field::allFields();
117 mFieldCombo->clear();
118 mFieldCombo->insertItem( i18n(
"Visible Fields" ) );
119 mFieldCombo->insertItem( i18n(
"All Fields" ) );
121 TDEABC::Field::List::ConstIterator it;
122 for ( it = mFieldList.begin(); it != mFieldList.end(); ++it )
123 mFieldCombo->insertItem( (*it)->label() );
128 TDEABC::Field::List IncSearchWidget::currentFields()
const
130 TDEABC::Field::List fieldList;
132 if ( mFieldCombo->currentItem() == 0 )
133 fieldList = mViewFields;
134 else if ( mFieldCombo->currentItem() > 1 )
135 fieldList.append( mFieldList[ mFieldCombo->currentItem() - 2 ] );
140 void IncSearchWidget::setCurrentItem(
int pos )
142 mFieldCombo->setCurrentItem( pos );
145 int IncSearchWidget::currentItem()
const
147 return mFieldCombo->currentItem();
150 void IncSearchWidget::setViewFields(
const TDEABC::Field::List &fields )
152 mViewFields = fields;
155 void IncSearchWidget::clear()
157 mSearchText->clear();
160 void IncSearchWidget::keyPressEvent( TQKeyEvent *event )
162 if ( event->key() == TQt::Key_Up ) {
165 }
else if ( event->key() == TQt::Key_Down ) {
171 #include "incsearchwidget.moc"