summaryrefslogtreecommitdiffabout
path: root/kaddressbook/incsearchwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/incsearchwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/incsearchwidget.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp
index 2ffa357..3533427 100644
--- a/kaddressbook/incsearchwidget.cpp
+++ b/kaddressbook/incsearchwidget.cpp
@@ -1,150 +1,161 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlayout.h> 25#include <qlayout.h>
26#include <qtooltip.h> 26#include <qtooltip.h>
27#include <qcombobox.h> 27#include <qcombobox.h>
28 28
29#include <kdialog.h> 29#include <kdialog.h>
30#include <klineedit.h> 30#include <klineedit.h>
31#include <klocale.h> 31#include <klocale.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kglobal.h>
34#include "kabprefs.h"
33 35
34#include "incsearchwidget.h" 36#include "incsearchwidget.h"
35 37
36IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) 38IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
37 : QWidget( parent, name ) 39 : QWidget( parent, name )
38{ 40{
39#ifndef KAB_EMBEDDED 41#ifndef KAB_EMBEDDED
40//US setCaption( i18n( "Incremental Search" ) ); 42//US setCaption( i18n( "Incremental Search" ) );
41#endif //KAB_EMBEDDED 43#endif //KAB_EMBEDDED
42 44
43 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); 45 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
44 46
45#ifdef DESKTOP_VERSION 47#ifdef DESKTOP_VERSION
46 QLabel *label = new QLabel( i18n( "Search:" ), this ); 48 QLabel *label = new QLabel( i18n( "Search:" ), this );
47 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); 49 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
48 layout->addWidget( label ); 50 layout->addWidget( label );
49#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
50 52
51 mSearchText = new KLineEdit( this ); 53 mSearchText = new KLineEdit( this );
52 layout->addWidget( mSearchText ); 54 layout->addWidget( mSearchText );
53// #ifdef KAB_EMBEDDED 55// #ifdef KAB_EMBEDDED
54// if (KGlobal::getOrientation() == KGlobal::Portrait) 56// if (KGlobal::getOrientation() == KGlobal::Portrait)
55// mSearchText->setMaximumWidth(30); 57// mSearchText->setMaximumWidth(30);
56// #endif //KAB_EMBEDDED 58// #endif //KAB_EMBEDDED
57 59
58 60
59 mFieldCombo = new QComboBox( false, this ); 61 mFieldCombo = new QComboBox( false, this );
60 layout->addWidget( mFieldCombo ); 62 layout->addWidget( mFieldCombo );
61 mFieldCombo->setMaximumHeight( 34 ); 63 mFieldCombo->setMaximumHeight( 34 );
62 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); 64 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) );
63 65
64// #ifndef KAB_EMBEDDED 66// #ifndef KAB_EMBEDDED
65// resize( QSize(420, 50).expandedTo( sizeHint() ) ); 67// resize( QSize(420, 50).expandedTo( sizeHint() ) );
66// #else //KAB_EMBEDDED 68// #else //KAB_EMBEDDED
67// resize( QSize(30, 10).expandedTo( sizeHint() ) ); 69// resize( QSize(30, 10).expandedTo( sizeHint() ) );
68// #endif //KAB_EMBEDDED 70// #endif //KAB_EMBEDDED
69 71
70#ifdef DESKTOP_VERSION 72
71 // for performance reasons, we do a search on the pda only after return is pressed 73 // for performance reasons, we do a search on the pda only after return is pressed
72 connect( mSearchText, SIGNAL( textChanged( const QString& ) ), 74 connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
73 SLOT( announceDoSearch() ) ); 75 SLOT( announceDoSearch2() ) );
74 connect( mFieldCombo, SIGNAL( activated( const QString& ) ), 76 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
75 SLOT( announceDoSearch() ) ); 77 SLOT( announceDoSearch2() ) );
76#endif 78
77 connect( mSearchText, SIGNAL( returnPressed() ), 79 connect( mSearchText, SIGNAL( returnPressed() ),
78 SLOT( announceDoSearch() ) ); 80 SLOT( announceDoSearch() ) );
79 connect( mFieldCombo, SIGNAL( activated( const QString& ) ), 81 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
80 SLOT( announceFieldChanged() ) ); 82 SLOT( announceFieldChanged() ) );
81 83
82 setFocusProxy( mSearchText ); 84 setFocusProxy( mSearchText );
83} 85}
84 86
85IncSearchWidget::~IncSearchWidget() 87IncSearchWidget::~IncSearchWidget()
86{ 88{
87 89
88} 90}
91void IncSearchWidget::announceDoSearch2()
92{
93 if ( KABPrefs::instance()->mSearchWithReturn )
94 return;
95 emit doSearch( mSearchText->text() );
96 //qDebug("emit dosreach ");
97}
89 98
90void IncSearchWidget::announceDoSearch() 99void IncSearchWidget::announceDoSearch()
91{ 100{
101
92 emit doSearch( mSearchText->text() ); 102 emit doSearch( mSearchText->text() );
103 // qDebug("emit dosreach ");
93} 104}
94 105
95void IncSearchWidget::announceFieldChanged() 106void IncSearchWidget::announceFieldChanged()
96{ 107{
97 emit fieldChanged(); 108 emit fieldChanged();
98} 109}
99 110
100void IncSearchWidget::setFields( const KABC::Field::List &list ) 111void IncSearchWidget::setFields( const KABC::Field::List &list )
101{ 112{
102 113
103 mFieldCombo->clear(); 114 mFieldCombo->clear();
104 mFieldCombo->insertItem( i18n( "All Fields" ) ); 115 mFieldCombo->insertItem( i18n( "All Fields" ) );
105 QFontMetrics fm ( mFieldCombo->font() ); 116 QFontMetrics fm ( mFieldCombo->font() );
106 int wid = fm.width(i18n( "All Fields" ) ); 117 int wid = fm.width(i18n( "All Fields" ) );
107 int max = wid; 118 int max = wid;
108 119
109 KABC::Field::List::ConstIterator it; 120 KABC::Field::List::ConstIterator it;
110 for ( it = list.begin(); it != list.end(); ++it ) { 121 for ( it = list.begin(); it != list.end(); ++it ) {
111 mFieldCombo->insertItem( (*it)->label() ); 122 mFieldCombo->insertItem( (*it)->label() );
112 // wid = fm.width((*it)->label() ); 123 // wid = fm.width((*it)->label() );
113 //if ( wid > max ) 124 //if ( wid > max )
114 // max = wid; 125 // max = wid;
115 } 126 }
116 127
117 mFieldList = list; 128 mFieldList = list;
118 129
119 announceDoSearch(); 130 announceDoSearch();
120 announceFieldChanged(); 131 announceFieldChanged();
121 mFieldCombo->setMaximumWidth( wid+60 ); 132 mFieldCombo->setMaximumWidth( wid+60 );
122} 133}
123 134
124KABC::Field::List IncSearchWidget::fields() const 135KABC::Field::List IncSearchWidget::fields() const
125{ 136{
126 return mFieldList; 137 return mFieldList;
127} 138}
128 139
129KABC::Field *IncSearchWidget::currentField()const 140KABC::Field *IncSearchWidget::currentField()const
130{ 141{
131 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) 142 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
132 return 0; // for error or 'use all fields' 143 return 0; // for error or 'use all fields'
133 else 144 else
134 return mFieldList[ mFieldCombo->currentItem() - 1 ]; 145 return mFieldList[ mFieldCombo->currentItem() - 1 ];
135} 146}
136 147
137void IncSearchWidget::setCurrentItem( int pos ) 148void IncSearchWidget::setCurrentItem( int pos )
138{ 149{
139 mFieldCombo->setCurrentItem( pos ); 150 mFieldCombo->setCurrentItem( pos );
140 announceFieldChanged(); 151 announceFieldChanged();
141} 152}
142 153
143int IncSearchWidget::currentItem() const 154int IncSearchWidget::currentItem() const
144{ 155{
145 156
146 return mFieldCombo->currentItem(); 157 return mFieldCombo->currentItem();
147} 158}
148#ifndef KAB_EMBEDDED 159#ifndef KAB_EMBEDDED
149#include "incsearchwidget.moc" 160#include "incsearchwidget.moc"
150#endif //KAB_EMBEDDED 161#endif //KAB_EMBEDDED