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