Diffstat (limited to 'kaddressbook/views/kaddressbookcardview.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index 239429f..49c0691 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp | |||
@@ -70,96 +70,97 @@ class AddresseeCardViewItem : public CardViewItem | |||
70 | 70 | ||
71 | void refresh() | 71 | void refresh() |
72 | { | 72 | { |
73 | // Update our addressee, since it may have changed elsewhere | 73 | // Update our addressee, since it may have changed elsewhere |
74 | mAddressee = mDocument->findByUid(mAddressee.uid()); | 74 | mAddressee = mDocument->findByUid(mAddressee.uid()); |
75 | 75 | ||
76 | if (!mAddressee.isEmpty()) | 76 | if (!mAddressee.isEmpty()) |
77 | { | 77 | { |
78 | clearFields(); | 78 | clearFields(); |
79 | 79 | ||
80 | // Try all the selected fields until we find one with text. | 80 | // Try all the selected fields until we find one with text. |
81 | // This will limit the number of unlabeled icons in the view | 81 | // This will limit the number of unlabeled icons in the view |
82 | KABC::Field::List::Iterator iter; | 82 | KABC::Field::List::Iterator iter; |
83 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) | 83 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) |
84 | { | 84 | { |
85 | // insert empty fields or not? not doing so saves a bit of memory and CPU | 85 | // insert empty fields or not? not doing so saves a bit of memory and CPU |
86 | // (during geometry calculations), but prevents having equally | 86 | // (during geometry calculations), but prevents having equally |
87 | // wide label columns in all cards, unless CardViewItem/CardView search | 87 | // wide label columns in all cards, unless CardViewItem/CardView search |
88 | // globally for the widest label. (anders) | 88 | // globally for the widest label. (anders) |
89 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) | 89 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) |
90 | insertField((*iter)->label(), (*iter)->value( mAddressee )); | 90 | insertField((*iter)->label(), (*iter)->value( mAddressee )); |
91 | } | 91 | } |
92 | 92 | ||
93 | // We might want to make this the first field. hmm... -mpilone | 93 | // We might want to make this the first field. hmm... -mpilone |
94 | setCaption( mAddressee.realName() ); | 94 | setCaption( mAddressee.realName() ); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | private: | 98 | private: |
99 | KABC::Field::List mFields; | 99 | KABC::Field::List mFields; |
100 | bool mShowEmptyFields; | 100 | bool mShowEmptyFields; |
101 | KABC::AddressBook *mDocument; | 101 | KABC::AddressBook *mDocument; |
102 | KABC::Addressee mAddressee; | 102 | KABC::Addressee mAddressee; |
103 | }; | 103 | }; |
104 | 104 | ||
105 | /////////////////////////////// | 105 | /////////////////////////////// |
106 | // AddresseeCardView | 106 | // AddresseeCardView |
107 | 107 | ||
108 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) | 108 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) |
109 | : CardView(parent, name) | 109 | : CardView(parent, name) |
110 | { | 110 | { |
111 | setAcceptDrops(true); | 111 | setAcceptDrops(true); |
112 | } | 112 | } |
113 | 113 | ||
114 | AddresseeCardView::~AddresseeCardView() | 114 | AddresseeCardView::~AddresseeCardView() |
115 | { | 115 | { |
116 | } | 116 | } |
117 | 117 | ||
118 | |||
118 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) | 119 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) |
119 | { | 120 | { |
120 | #ifndef KAB_EMBEDDED | 121 | #ifndef KAB_EMBEDDED |
121 | if (QTextDrag::canDecode(e)) | 122 | if (QTextDrag::canDecode(e)) |
122 | e->accept(); | 123 | e->accept(); |
123 | #else //KAB_EMBEDDED | 124 | #else //KAB_EMBEDDED |
124 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); | 125 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); |
125 | #endif //KAB_EMBEDDED | 126 | #endif //KAB_EMBEDDED |
126 | } | 127 | } |
127 | 128 | ||
128 | void AddresseeCardView::dropEvent(QDropEvent *e) | 129 | void AddresseeCardView::dropEvent(QDropEvent *e) |
129 | { | 130 | { |
130 | emit addresseeDropped(e); | 131 | emit addresseeDropped(e); |
131 | } | 132 | } |
132 | 133 | ||
133 | void AddresseeCardView::startDrag() | 134 | void AddresseeCardView::startDrag() |
134 | { | 135 | { |
135 | emit startAddresseeDrag(); | 136 | emit startAddresseeDrag(); |
136 | } | 137 | } |
137 | 138 | ||
138 | 139 | ||
139 | /////////////////////////////// | 140 | /////////////////////////////// |
140 | // KAddressBookCardView | 141 | // KAddressBookCardView |
141 | 142 | ||
142 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, | 143 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, |
143 | QWidget *parent, const char *name ) | 144 | QWidget *parent, const char *name ) |
144 | : KAddressBookView( ab, parent, name ) | 145 | : KAddressBookView( ab, parent, name ) |
145 | { | 146 | { |
146 | mShowEmptyFields = false; | 147 | mShowEmptyFields = false; |
147 | 148 | ||
148 | // Init the GUI | 149 | // Init the GUI |
149 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 150 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); |
150 | 151 | ||
151 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); | 152 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); |
152 | mCardView->setSelectionMode(CardView::Extended); | 153 | mCardView->setSelectionMode(CardView::Extended); |
153 | layout->addWidget(mCardView); | 154 | layout->addWidget(mCardView); |
154 | 155 | ||
155 | // Connect up the signals | 156 | // Connect up the signals |
156 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 157 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
157 | this, SLOT(addresseeExecuted(CardViewItem *))); | 158 | this, SLOT(addresseeExecuted(CardViewItem *))); |
158 | connect(mCardView, SIGNAL(selectionChanged()), | 159 | connect(mCardView, SIGNAL(selectionChanged()), |
159 | this, SLOT(addresseeSelected())); | 160 | this, SLOT(addresseeSelected())); |
160 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), | 161 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), |
161 | this, SIGNAL(dropped(QDropEvent*))); | 162 | this, SIGNAL(dropped(QDropEvent*))); |
162 | connect(mCardView, SIGNAL(startAddresseeDrag()), | 163 | connect(mCardView, SIGNAL(startAddresseeDrag()), |
163 | this, SIGNAL(startDrag())); | 164 | this, SIGNAL(startDrag())); |
164 | } | 165 | } |
165 | 166 | ||
@@ -195,97 +196,147 @@ void KAddressBookCardView::readConfig(KConfig *config) | |||
195 | mCardView->viewport()->setPalette( mCardView->palette() ); | 196 | mCardView->viewport()->setPalette( mCardView->palette() ); |
196 | } | 197 | } |
197 | 198 | ||
198 | //custom fonts? | 199 | //custom fonts? |
199 | QFont f( font() ); | 200 | QFont f( font() ); |
200 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 201 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
201 | { | 202 | { |
202 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); | 203 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); |
203 | f.setBold( true ); | 204 | f.setBold( true ); |
204 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 205 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
205 | } | 206 | } |
206 | else | 207 | else |
207 | { | 208 | { |
208 | mCardView->setFont( f ); | 209 | mCardView->setFont( f ); |
209 | f.setBold( true ); | 210 | f.setBold( true ); |
210 | mCardView->setHeaderFont( f ); | 211 | mCardView->setHeaderFont( f ); |
211 | } | 212 | } |
212 | 213 | ||
213 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); | 214 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); |
214 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", | 215 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", |
215 | true)); | 216 | true)); |
216 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); | 217 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); |
217 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); | 218 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); |
218 | 219 | ||
219 | mCardView->setShowEmptyFields( mShowEmptyFields ); | 220 | mCardView->setShowEmptyFields( mShowEmptyFields ); |
220 | 221 | ||
221 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); | 222 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); |
222 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); | 223 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); |
223 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); | 224 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); |
224 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); | 225 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); |
225 | 226 | ||
226 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), | 227 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), |
227 | this, SLOT(addresseeExecuted(CardViewItem *))); | 228 | this, SLOT(addresseeExecuted(CardViewItem *))); |
228 | 229 | ||
229 | if (KABPrefs::instance()->mHonorSingleClick) | 230 | if (KABPrefs::instance()->mHonorSingleClick) |
230 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 231 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
231 | this, SLOT(addresseeExecuted(CardViewItem *))); | 232 | this, SLOT(addresseeExecuted(CardViewItem *))); |
232 | else | 233 | else |
233 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | 234 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), |
234 | this, SLOT(addresseeExecuted(CardViewItem *))); | 235 | this, SLOT(addresseeExecuted(CardViewItem *))); |
235 | 236 | ||
236 | } | 237 | } |
237 | 238 | ||
238 | void KAddressBookCardView::writeConfig( KConfig *config ) | 239 | void KAddressBookCardView::writeConfig( KConfig *config ) |
239 | { | 240 | { |
240 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); | 241 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); |
241 | KAddressBookView::writeConfig( config ); | 242 | KAddressBookView::writeConfig( config ); |
242 | } | 243 | } |
244 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) | ||
245 | { | ||
246 | mCardView->clear(); | ||
247 | if ( s.isEmpty() || s == "*" ) { | ||
248 | refresh(); | ||
249 | return; | ||
250 | } | ||
251 | QString pattern = s.lower()+"*"; | ||
252 | QRegExp re; | ||
253 | re.setWildcard(true); // most people understand these better. | ||
254 | re.setCaseSensitive(false); | ||
255 | re.setPattern( pattern ); | ||
256 | if (!re.isValid()) | ||
257 | return; | ||
258 | mCardView->viewport()->setUpdatesEnabled( false ); | ||
259 | KABC::Addressee::List addresseeList = addressees(); | ||
260 | KABC::Addressee::List::Iterator it; | ||
261 | if ( field ) { | ||
262 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | ||
263 | #if QT_VERSION >= 300 | ||
264 | if (re.search(field->value( *it ).lower()) != -1) | ||
265 | #else | ||
266 | if (re.match(field->value( *it ).lower()) != -1) | ||
267 | #endif | ||
268 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | ||
269 | addressBook(), *it, mCardView); | ||
243 | 270 | ||
271 | } | ||
272 | } else { | ||
273 | KABC::Field::List fieldList = fields(); | ||
274 | KABC::Field::List::ConstIterator fieldIt; | ||
275 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | ||
276 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | ||
277 | #if QT_VERSION >= 300 | ||
278 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | ||
279 | #else | ||
280 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | ||
281 | #endif | ||
282 | { | ||
283 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | ||
284 | addressBook(), *it, mCardView); | ||
285 | continue; | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | mCardView->viewport()->setUpdatesEnabled( true ); | ||
291 | mCardView->viewport()->update(); | ||
292 | // by default nothing is selected | ||
293 | emit selected(QString::null); | ||
294 | } | ||
244 | QStringList KAddressBookCardView::selectedUids() | 295 | QStringList KAddressBookCardView::selectedUids() |
245 | { | 296 | { |
246 | QStringList uidList; | 297 | QStringList uidList; |
247 | CardViewItem *item; | 298 | CardViewItem *item; |
248 | AddresseeCardViewItem *aItem; | 299 | AddresseeCardViewItem *aItem; |
249 | 300 | ||
250 | for (item = mCardView->firstItem(); item; item = item->nextItem()) | 301 | for (item = mCardView->firstItem(); item; item = item->nextItem()) |
251 | { | 302 | { |
252 | if (item->isSelected()) | 303 | if (item->isSelected()) |
253 | { | 304 | { |
254 | #ifndef KAB_EMBEDDED | 305 | #ifndef KAB_EMBEDDED |
255 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 306 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
256 | #else //KAB_EMBEDDED | 307 | #else //KAB_EMBEDDED |
257 | aItem = (AddresseeCardViewItem*)(item); | 308 | aItem = (AddresseeCardViewItem*)(item); |
258 | #endif //KAB_EMBEDDED | 309 | #endif //KAB_EMBEDDED |
259 | if (aItem) | 310 | if (aItem) |
260 | uidList << aItem->addressee().uid(); | 311 | uidList << aItem->addressee().uid(); |
261 | } | 312 | } |
262 | } | 313 | } |
263 | 314 | ||
264 | return uidList; | 315 | return uidList; |
265 | } | 316 | } |
266 | 317 | ||
267 | void KAddressBookCardView::refresh(QString uid) | 318 | void KAddressBookCardView::refresh(QString uid) |
268 | { | 319 | { |
269 | CardViewItem *item; | 320 | CardViewItem *item; |
270 | AddresseeCardViewItem *aItem; | 321 | AddresseeCardViewItem *aItem; |
271 | 322 | ||
272 | if (uid.isNull()) | 323 | if (uid.isNull()) |
273 | { | 324 | { |
274 | // Rebuild the view | 325 | // Rebuild the view |
275 | mCardView->viewport()->setUpdatesEnabled( false ); | 326 | mCardView->viewport()->setUpdatesEnabled( false ); |
276 | mCardView->clear(); | 327 | mCardView->clear(); |
277 | 328 | ||
278 | KABC::Addressee::List addresseeList = addressees(); | 329 | KABC::Addressee::List addresseeList = addressees(); |
279 | KABC::Addressee::List::Iterator iter; | 330 | KABC::Addressee::List::Iterator iter; |
280 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) | 331 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) |
281 | { | 332 | { |
282 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, | 333 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, |
283 | addressBook(), *iter, mCardView); | 334 | addressBook(), *iter, mCardView); |
284 | } | 335 | } |
285 | mCardView->viewport()->setUpdatesEnabled( true ); | 336 | mCardView->viewport()->setUpdatesEnabled( true ); |
286 | mCardView->viewport()->update(); | 337 | mCardView->viewport()->update(); |
287 | 338 | ||
288 | // by default nothing is selected | 339 | // by default nothing is selected |
289 | emit selected(QString::null); | 340 | emit selected(QString::null); |
290 | } | 341 | } |
291 | else | 342 | else |