summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/kaddressbookcardview.cpp
Unidiff
Diffstat (limited to 'kaddressbook/views/kaddressbookcardview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp53
1 files changed, 52 insertions, 1 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
@@ -94,48 +94,49 @@ class AddresseeCardViewItem : public CardViewItem
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
108AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 108AddresseeCardView::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
114AddresseeCardView::~AddresseeCardView() 114AddresseeCardView::~AddresseeCardView()
115{ 115{
116} 116}
117 117
118
118void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 119void 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
124qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 125qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
125#endif //KAB_EMBEDDED 126#endif //KAB_EMBEDDED
126} 127}
127 128
128void AddresseeCardView::dropEvent(QDropEvent *e) 129void AddresseeCardView::dropEvent(QDropEvent *e)
129{ 130{
130 emit addresseeDropped(e); 131 emit addresseeDropped(e);
131} 132}
132 133
133void AddresseeCardView::startDrag() 134void AddresseeCardView::startDrag()
134{ 135{
135 emit startAddresseeDrag(); 136 emit startAddresseeDrag();
136} 137}
137 138
138 139
139/////////////////////////////// 140///////////////////////////////
140// KAddressBookCardView 141// KAddressBookCardView
141 142
@@ -219,49 +220,99 @@ void KAddressBookCardView::readConfig(KConfig *config)
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
238void KAddressBookCardView::writeConfig( KConfig *config ) 239void 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}
243 244void 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);
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}
244QStringList KAddressBookCardView::selectedUids() 295QStringList 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
267void KAddressBookCardView::refresh(QString uid) 318void KAddressBookCardView::refresh(QString uid)