author | zautrix <zautrix> | 2005-03-29 13:52:41 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-29 13:52:41 (UTC) |
commit | 7046b36fb5dd14598ece00b575554eba2956ef84 (patch) (unidiff) | |
tree | 934579f9f61f09563dfcbfef207d314d510d57ea /kaddressbook/incsearchwidget.cpp | |
parent | 894717798a8d129f4b991a2fe856d2f1e8e9624a (diff) | |
download | kdepimpi-7046b36fb5dd14598ece00b575554eba2956ef84.zip kdepimpi-7046b36fb5dd14598ece00b575554eba2956ef84.tar.gz kdepimpi-7046b36fb5dd14598ece00b575554eba2956ef84.tar.bz2 |
kapi fixes
Diffstat (limited to 'kaddressbook/incsearchwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/incsearchwidget.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index dd2121a..cd198c4 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp | |||
@@ -21,148 +21,154 @@ | |||
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 | ||
38 | IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) | 38 | IncSearchWidget::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 | //mSearchText->setMaximumWidth(60); |
60 | 60 | ||
61 | 61 | ||
62 | mFieldCombo = new QComboBox( false, this ); | 62 | mFieldCombo = new QComboBox( false, this ); |
63 | layout->addWidget( mFieldCombo ); | 63 | layout->addWidget( mFieldCombo ); |
64 | mFieldCombo->setMaximumHeight( 34 ); | 64 | mFieldCombo->setMaximumHeight( 34 ); |
65 | QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); | 65 | QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); |
66 | 66 | ||
67 | // #ifndef KAB_EMBEDDED | 67 | // #ifndef KAB_EMBEDDED |
68 | // resize( QSize(420, 50).expandedTo( sizeHint() ) ); | 68 | // resize( QSize(420, 50).expandedTo( sizeHint() ) ); |
69 | // #else //KAB_EMBEDDED | 69 | // #else //KAB_EMBEDDED |
70 | // resize( QSize(30, 10).expandedTo( sizeHint() ) ); | 70 | // resize( QSize(30, 10).expandedTo( sizeHint() ) ); |
71 | // #endif //KAB_EMBEDDED | 71 | // #endif //KAB_EMBEDDED |
72 | 72 | ||
73 | 73 | ||
74 | // 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 |
75 | connect( mSearchText, SIGNAL( textChanged( const QString& ) ), | 75 | connect( mSearchText, SIGNAL( textChanged( const QString& ) ), |
76 | SLOT( announceDoSearch2() ) ); | 76 | SLOT( announceDoSearch2() ) ); |
77 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), | 77 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), |
78 | SLOT( announceDoSearch2() ) ); | 78 | SLOT( announceDoSearch2() ) ); |
79 | 79 | ||
80 | connect( mSearchText, SIGNAL( returnPressed() ), | 80 | connect( mSearchText, SIGNAL( returnPressed() ), |
81 | SLOT( announceDoSearch() ) ); | 81 | SLOT( announceDoSearch() ) ); |
82 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), | 82 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), |
83 | SLOT( announceFieldChanged() ) ); | 83 | SLOT( announceFieldChanged() ) ); |
84 | 84 | ||
85 | 85 | ||
86 | 86 | ||
87 | connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() )); | 87 | connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() )); |
88 | connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() )); | 88 | connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() )); |
89 | 89 | ||
90 | 90 | ||
91 | setFocusProxy( mSearchText ); | 91 | setFocusProxy( mSearchText ); |
92 | } | 92 | } |
93 | 93 | ||
94 | IncSearchWidget::~IncSearchWidget() | 94 | IncSearchWidget::~IncSearchWidget() |
95 | { | 95 | { |
96 | 96 | ||
97 | } | 97 | } |
98 | void IncSearchWidget::announceDoSearch2() | 98 | void IncSearchWidget::announceDoSearch2() |
99 | { | 99 | { |
100 | if ( KABPrefs::instance()->mSearchWithReturn ) | 100 | if ( KABPrefs::instance()->mSearchWithReturn ) |
101 | return; | 101 | return; |
102 | emit doSearch( mSearchText->text() ); | 102 | emit doSearch( mSearchText->text() ); |
103 | //qDebug("emit dosreach "); | 103 | //qDebug("emit dosreach "); |
104 | } | 104 | } |
105 | 105 | ||
106 | void IncSearchWidget::announceDoSearch() | 106 | void IncSearchWidget::announceDoSearch() |
107 | { | 107 | { |
108 | 108 | ||
109 | emit doSearch( mSearchText->text() ); | 109 | emit doSearch( mSearchText->text() ); |
110 | // qDebug("emit dosreach "); | 110 | // qDebug("emit dosreach "); |
111 | } | 111 | } |
112 | 112 | ||
113 | void IncSearchWidget::announceFieldChanged() | 113 | void IncSearchWidget::announceFieldChanged() |
114 | { | 114 | { |
115 | emit fieldChanged(); | 115 | emit fieldChanged(); |
116 | } | 116 | } |
117 | 117 | void IncSearchWidget::setSize() | |
118 | { | ||
119 | if ( KABPrefs::instance()->mHideSearchOnSwitch && QApplication::desktop()->width() == 480) { | ||
120 | mFieldCombo->setMaximumWidth( 40 ); | ||
121 | mSearchText->setMaximumWidth( 30 ); | ||
122 | } else { | ||
123 | QFontMetrics fm ( mFieldCombo->font() ); | ||
124 | int wid = fm.width(i18n( "All Fields" ) ); | ||
125 | int max = wid; | ||
126 | mFieldCombo->setMaximumWidth( wid+60 ); | ||
127 | mSearchText->setMaximumWidth( 1024 ); | ||
128 | } | ||
129 | } | ||
118 | void IncSearchWidget::setFields( const KABC::Field::List &list ) | 130 | void IncSearchWidget::setFields( const KABC::Field::List &list ) |
119 | { | 131 | { |
120 | 132 | ||
121 | mFieldCombo->clear(); | 133 | mFieldCombo->clear(); |
122 | mFieldCombo->insertItem( i18n( "All Fields" ) ); | 134 | mFieldCombo->insertItem( i18n( "All Fields" ) ); |
123 | QFontMetrics fm ( mFieldCombo->font() ); | 135 | |
124 | int wid = fm.width(i18n( "All Fields" ) ); | ||
125 | int max = wid; | ||
126 | |||
127 | KABC::Field::List::ConstIterator it; | 136 | KABC::Field::List::ConstIterator it; |
128 | for ( it = list.begin(); it != list.end(); ++it ) { | 137 | for ( it = list.begin(); it != list.end(); ++it ) { |
129 | mFieldCombo->insertItem( (*it)->label() ); | 138 | mFieldCombo->insertItem( (*it)->label() ); |
130 | // wid = fm.width((*it)->label() ); | ||
131 | //if ( wid > max ) | ||
132 | // max = wid; | ||
133 | } | 139 | } |
134 | 140 | ||
135 | mFieldList = list; | 141 | mFieldList = list; |
136 | 142 | ||
137 | announceDoSearch(); | 143 | announceDoSearch(); |
138 | announceFieldChanged(); | 144 | announceFieldChanged(); |
139 | mFieldCombo->setMaximumWidth( wid+60 ); | 145 | setSize(); |
140 | } | 146 | } |
141 | 147 | ||
142 | KABC::Field::List IncSearchWidget::fields() const | 148 | KABC::Field::List IncSearchWidget::fields() const |
143 | { | 149 | { |
144 | return mFieldList; | 150 | return mFieldList; |
145 | } | 151 | } |
146 | 152 | ||
147 | KABC::Field *IncSearchWidget::currentField()const | 153 | KABC::Field *IncSearchWidget::currentField()const |
148 | { | 154 | { |
149 | if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) | 155 | if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) |
150 | return 0; // for error or 'use all fields' | 156 | return 0; // for error or 'use all fields' |
151 | else | 157 | else |
152 | return mFieldList[ mFieldCombo->currentItem() - 1 ]; | 158 | return mFieldList[ mFieldCombo->currentItem() - 1 ]; |
153 | } | 159 | } |
154 | 160 | ||
155 | void IncSearchWidget::setCurrentItem( int pos ) | 161 | void IncSearchWidget::setCurrentItem( int pos ) |
156 | { | 162 | { |
157 | mFieldCombo->setCurrentItem( pos ); | 163 | mFieldCombo->setCurrentItem( pos ); |
158 | announceFieldChanged(); | 164 | announceFieldChanged(); |
159 | } | 165 | } |
160 | 166 | ||
161 | int IncSearchWidget::currentItem() const | 167 | int IncSearchWidget::currentItem() const |
162 | { | 168 | { |
163 | 169 | ||
164 | return mFieldCombo->currentItem(); | 170 | return mFieldCombo->currentItem(); |
165 | } | 171 | } |
166 | #ifndef KAB_EMBEDDED | 172 | #ifndef KAB_EMBEDDED |
167 | #include "incsearchwidget.moc" | 173 | #include "incsearchwidget.moc" |
168 | #endif //KAB_EMBEDDED | 174 | #endif //KAB_EMBEDDED |