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