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