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.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 4babf67..a7bf6c9 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -6,48 +6,49 @@
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 <qdragobject.h> 24#include <qdragobject.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qiconview.h> 26#include <qiconview.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qapplication.h>
30 31
31#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
32#include <kabc/addressee.h> 33#include <kabc/addressee.h>
33#include <kconfig.h> 34#include <kconfig.h>
34#include <kdebug.h> 35#include <kdebug.h>
35#include <klocale.h> 36#include <klocale.h>
36 37
37#include "kabprefs.h" 38#include "kabprefs.h"
38#include "viewmanager.h" 39#include "viewmanager.h"
39 40
40#include "kaddressbookcardview.h" 41#include "kaddressbookcardview.h"
41 42
42#ifndef KAB_EMBEDDED 43#ifndef KAB_EMBEDDED
43extern "C" { 44extern "C" {
44 void *init_libkaddrbk_cardview() 45 void *init_libkaddrbk_cardview()
45 { 46 {
46 return ( new CardViewFactory ); 47 return ( new CardViewFactory );
47 } 48 }
48} 49}
49#endif //KAB_EMBEDDED 50#endif //KAB_EMBEDDED
50 51
51//////////////////////////////// 52////////////////////////////////
52// AddresseeCardViewItem (internal class) 53// AddresseeCardViewItem (internal class)
53class AddresseeCardViewItem : public CardViewItem 54class AddresseeCardViewItem : public CardViewItem
@@ -148,48 +149,59 @@ KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
148 mShowEmptyFields = false; 149 mShowEmptyFields = false;
149 150
150 // Init the GUI 151 // Init the GUI
151 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 152 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
152 153
153 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 154 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
154 mCardView->setSelectionMode(CardView::Extended); 155 mCardView->setSelectionMode(CardView::Extended);
155 layout->addWidget(mCardView); 156 layout->addWidget(mCardView);
156 157
157 // Connect up the signals 158 // Connect up the signals
158 connect(mCardView, SIGNAL(executed(CardViewItem *)), 159 connect(mCardView, SIGNAL(executed(CardViewItem *)),
159 this, SLOT(addresseeExecuted(CardViewItem *))); 160 this, SLOT(addresseeExecuted(CardViewItem *)));
160 connect(mCardView, SIGNAL(selectionChanged()), 161 connect(mCardView, SIGNAL(selectionChanged()),
161 this, SLOT(addresseeSelected())); 162 this, SLOT(addresseeSelected()));
162 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 163 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
163 this, SIGNAL(dropped(QDropEvent*))); 164 this, SIGNAL(dropped(QDropEvent*)));
164 connect(mCardView, SIGNAL(startAddresseeDrag()), 165 connect(mCardView, SIGNAL(startAddresseeDrag()),
165 this, SIGNAL(startDrag())); 166 this, SIGNAL(startDrag()));
166} 167}
167 168
168KAddressBookCardView::~KAddressBookCardView() 169KAddressBookCardView::~KAddressBookCardView()
169{ 170{
170} 171}
171 172
173void KAddressBookCardView::scrollUP()
174{
175 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
176 QApplication::postEvent( mCardView, ev );
177
178}
179void KAddressBookCardView::scrollDOWN()
180{
181 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
182 QApplication::postEvent( mCardView, ev );
183}
172void KAddressBookCardView::readConfig(KConfig *config) 184void KAddressBookCardView::readConfig(KConfig *config)
173{ 185{
174 KAddressBookView::readConfig(config); 186 KAddressBookView::readConfig(config);
175 187
176 // costum colors? 188 // costum colors?
177 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 189 if ( config->readBoolEntry( "EnableCustomColors", false ) )
178 { 190 {
179 QPalette p( mCardView->palette() ); 191 QPalette p( mCardView->palette() );
180 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 192 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
181 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 193 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
182 c = p.color(QPalette::Normal, QColorGroup::Text ); 194 c = p.color(QPalette::Normal, QColorGroup::Text );
183 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 195 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
184 c = p.color(QPalette::Normal, QColorGroup::Button ); 196 c = p.color(QPalette::Normal, QColorGroup::Button );
185 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 197 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
186 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 198 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
187 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 199 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
188 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 200 c = p.color(QPalette::Normal, QColorGroup::Highlight );
189 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 201 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
190 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 202 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
191 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 203 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
192 mCardView->viewport()->setPalette( p ); 204 mCardView->viewport()->setPalette( p );
193 } 205 }
194 else 206 else
195 { 207 {
@@ -269,50 +281,54 @@ void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
269 new AddresseeCardViewItem(fields(), mShowEmptyFields, 281 new AddresseeCardViewItem(fields(), mShowEmptyFields,
270 addressBook(), *it, mCardView); 282 addressBook(), *it, mCardView);
271 283
272 } 284 }
273 } else { 285 } else {
274 KABC::Field::List fieldList = fields(); 286 KABC::Field::List fieldList = fields();
275 KABC::Field::List::ConstIterator fieldIt; 287 KABC::Field::List::ConstIterator fieldIt;
276 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 288 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
277 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 289 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
278#if QT_VERSION >= 300 290#if QT_VERSION >= 300
279 if (re.search((*fieldIt)->value( *it ).lower()) != -1) 291 if (re.search((*fieldIt)->value( *it ).lower()) != -1)
280#else 292#else
281 if (re.match((*fieldIt)->value( *it ).lower()) != -1) 293 if (re.match((*fieldIt)->value( *it ).lower()) != -1)
282#endif 294#endif
283 { 295 {
284 new AddresseeCardViewItem(fields(), mShowEmptyFields, 296 new AddresseeCardViewItem(fields(), mShowEmptyFields,
285 addressBook(), *it, mCardView); 297 addressBook(), *it, mCardView);
286 continue; 298 continue;
287 } 299 }
288 } 300 }
289 } 301 }
290 } 302 }
291 mCardView->viewport()->setUpdatesEnabled( true ); 303 mCardView->viewport()->setUpdatesEnabled( true );
292 mCardView->viewport()->update(); 304 mCardView->viewport()->update();
293 // by default nothing is selected 305 if ( mCardView->firstItem() ) {
294 emit selected(QString::null); 306 mCardView->setCurrentItem ( mCardView->firstItem() );
307 mCardView->setSelected ( mCardView->firstItem() , true );
308 }
309 else
310 emit selected(QString::null);
295} 311}
296QStringList KAddressBookCardView::selectedUids() 312QStringList KAddressBookCardView::selectedUids()
297{ 313{
298 QStringList uidList; 314 QStringList uidList;
299 CardViewItem *item; 315 CardViewItem *item;
300 AddresseeCardViewItem *aItem; 316 AddresseeCardViewItem *aItem;
301 317
302 for (item = mCardView->firstItem(); item; item = item->nextItem()) 318 for (item = mCardView->firstItem(); item; item = item->nextItem())
303 { 319 {
304 if (item->isSelected()) 320 if (item->isSelected())
305 { 321 {
306#ifndef KAB_EMBEDDED 322#ifndef KAB_EMBEDDED
307 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 323 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
308#else //KAB_EMBEDDED 324#else //KAB_EMBEDDED
309 aItem = (AddresseeCardViewItem*)(item); 325 aItem = (AddresseeCardViewItem*)(item);
310#endif //KAB_EMBEDDED 326#endif //KAB_EMBEDDED
311 if (aItem) 327 if (aItem)
312 uidList << aItem->addressee().uid(); 328 uidList << aItem->addressee().uid();
313 } 329 }
314 } 330 }
315 331
316 return uidList; 332 return uidList;
317} 333}
318 334