summaryrefslogtreecommitdiffabout
path: root/kaddressbook/incsearchwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/incsearchwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/incsearchwidget.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp
index 78eaf65..dd2121a 100644
--- a/kaddressbook/incsearchwidget.cpp
+++ b/kaddressbook/incsearchwidget.cpp
@@ -1,167 +1,168 @@
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> 33#include <kglobal.h>
34#include "kabprefs.h" 34#include "kabprefs.h"
35 35
36#include "incsearchwidget.h" 36#include "incsearchwidget.h"
37 37
38IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) 38IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
39 : QWidget( parent, name ) 39 : QWidget( parent, name )
40{ 40{
41#ifndef KAB_EMBEDDED 41#ifndef KAB_EMBEDDED
42//US setCaption( i18n( "Incremental Search" ) ); 42//US setCaption( i18n( "Incremental Search" ) );
43#endif //KAB_EMBEDDED 43#endif //KAB_EMBEDDED
44 44
45 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); 45 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
46 46
47#ifdef DESKTOP_VERSION 47#ifdef DESKTOP_VERSION
48 QLabel *label = new QLabel( i18n( "Search:" ), this ); 48 QLabel *label = new QLabel( i18n( "Search:" ), this );
49 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); 49 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
50 layout->addWidget( label ); 50 layout->addWidget( label );
51#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
52 52
53 mSearchText = new KLineEdit( this ); 53 mSearchText = new KLineEdit( this );
54 layout->addWidget( mSearchText ); 54 layout->addWidget( mSearchText );
55// #ifdef KAB_EMBEDDED 55// #ifdef KAB_EMBEDDED
56// if (KGlobal::getOrientation() == KGlobal::Portrait) 56// if (KGlobal::getOrientation() == KGlobal::Portrait)
57// mSearchText->setMaximumWidth(30); 57// mSearchText->setMaximumWidth(30);
58// #endif //KAB_EMBEDDED 58// #endif //KAB_EMBEDDED
59 //mSearchText->setMaximumWidth(60);
59 60
60 61
61 mFieldCombo = new QComboBox( false, this ); 62 mFieldCombo = new QComboBox( false, this );
62 layout->addWidget( mFieldCombo ); 63 layout->addWidget( mFieldCombo );
63 mFieldCombo->setMaximumHeight( 34 ); 64 mFieldCombo->setMaximumHeight( 34 );
64 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); 65 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) );
65 66
66// #ifndef KAB_EMBEDDED 67// #ifndef KAB_EMBEDDED
67// resize( QSize(420, 50).expandedTo( sizeHint() ) ); 68// resize( QSize(420, 50).expandedTo( sizeHint() ) );
68// #else //KAB_EMBEDDED 69// #else //KAB_EMBEDDED
69// resize( QSize(30, 10).expandedTo( sizeHint() ) ); 70// resize( QSize(30, 10).expandedTo( sizeHint() ) );
70// #endif //KAB_EMBEDDED 71// #endif //KAB_EMBEDDED
71 72
72 73
73 // for performance reasons, we do a search on the pda only after return is pressed 74 // for performance reasons, we do a search on the pda only after return is pressed
74 connect( mSearchText, SIGNAL( textChanged( const QString& ) ), 75 connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
75 SLOT( announceDoSearch2() ) ); 76 SLOT( announceDoSearch2() ) );
76 connect( mFieldCombo, SIGNAL( activated( const QString& ) ), 77 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
77 SLOT( announceDoSearch2() ) ); 78 SLOT( announceDoSearch2() ) );
78 79
79 connect( mSearchText, SIGNAL( returnPressed() ), 80 connect( mSearchText, SIGNAL( returnPressed() ),
80 SLOT( announceDoSearch() ) ); 81 SLOT( announceDoSearch() ) );
81 connect( mFieldCombo, SIGNAL( activated( const QString& ) ), 82 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
82 SLOT( announceFieldChanged() ) ); 83 SLOT( announceFieldChanged() ) );
83 84
84 85
85 86
86 connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() )); 87 connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() ));
87 connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() )); 88 connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() ));
88 89
89 90
90 setFocusProxy( mSearchText ); 91 setFocusProxy( mSearchText );
91} 92}
92 93
93IncSearchWidget::~IncSearchWidget() 94IncSearchWidget::~IncSearchWidget()
94{ 95{
95 96
96} 97}
97void IncSearchWidget::announceDoSearch2() 98void IncSearchWidget::announceDoSearch2()
98{ 99{
99 if ( KABPrefs::instance()->mSearchWithReturn ) 100 if ( KABPrefs::instance()->mSearchWithReturn )
100 return; 101 return;
101 emit doSearch( mSearchText->text() ); 102 emit doSearch( mSearchText->text() );
102 //qDebug("emit dosreach "); 103 //qDebug("emit dosreach ");
103} 104}
104 105
105void IncSearchWidget::announceDoSearch() 106void IncSearchWidget::announceDoSearch()
106{ 107{
107 108
108 emit doSearch( mSearchText->text() ); 109 emit doSearch( mSearchText->text() );
109 // qDebug("emit dosreach "); 110 // qDebug("emit dosreach ");
110} 111}
111 112
112void IncSearchWidget::announceFieldChanged() 113void IncSearchWidget::announceFieldChanged()
113{ 114{
114 emit fieldChanged(); 115 emit fieldChanged();
115} 116}
116 117
117void IncSearchWidget::setFields( const KABC::Field::List &list ) 118void IncSearchWidget::setFields( const KABC::Field::List &list )
118{ 119{
119 120
120 mFieldCombo->clear(); 121 mFieldCombo->clear();
121 mFieldCombo->insertItem( i18n( "All Fields" ) ); 122 mFieldCombo->insertItem( i18n( "All Fields" ) );
122 QFontMetrics fm ( mFieldCombo->font() ); 123 QFontMetrics fm ( mFieldCombo->font() );
123 int wid = fm.width(i18n( "All Fields" ) ); 124 int wid = fm.width(i18n( "All Fields" ) );
124 int max = wid; 125 int max = wid;
125 126
126 KABC::Field::List::ConstIterator it; 127 KABC::Field::List::ConstIterator it;
127 for ( it = list.begin(); it != list.end(); ++it ) { 128 for ( it = list.begin(); it != list.end(); ++it ) {
128 mFieldCombo->insertItem( (*it)->label() ); 129 mFieldCombo->insertItem( (*it)->label() );
129 // wid = fm.width((*it)->label() ); 130 // wid = fm.width((*it)->label() );
130 //if ( wid > max ) 131 //if ( wid > max )
131 // max = wid; 132 // max = wid;
132 } 133 }
133 134
134 mFieldList = list; 135 mFieldList = list;
135 136
136 announceDoSearch(); 137 announceDoSearch();
137 announceFieldChanged(); 138 announceFieldChanged();
138 mFieldCombo->setMaximumWidth( wid+60 ); 139 mFieldCombo->setMaximumWidth( wid+60 );
139} 140}
140 141
141KABC::Field::List IncSearchWidget::fields() const 142KABC::Field::List IncSearchWidget::fields() const
142{ 143{
143 return mFieldList; 144 return mFieldList;
144} 145}
145 146
146KABC::Field *IncSearchWidget::currentField()const 147KABC::Field *IncSearchWidget::currentField()const
147{ 148{
148 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) 149 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
149 return 0; // for error or 'use all fields' 150 return 0; // for error or 'use all fields'
150 else 151 else
151 return mFieldList[ mFieldCombo->currentItem() - 1 ]; 152 return mFieldList[ mFieldCombo->currentItem() - 1 ];
152} 153}
153 154
154void IncSearchWidget::setCurrentItem( int pos ) 155void IncSearchWidget::setCurrentItem( int pos )
155{ 156{
156 mFieldCombo->setCurrentItem( pos ); 157 mFieldCombo->setCurrentItem( pos );
157 announceFieldChanged(); 158 announceFieldChanged();
158} 159}
159 160
160int IncSearchWidget::currentItem() const 161int IncSearchWidget::currentItem() const
161{ 162{
162 163
163 return mFieldCombo->currentItem(); 164 return mFieldCombo->currentItem();
164} 165}
165#ifndef KAB_EMBEDDED 166#ifndef KAB_EMBEDDED
166#include "incsearchwidget.moc" 167#include "incsearchwidget.moc"
167#endif //KAB_EMBEDDED 168#endif //KAB_EMBEDDED