24 #include <tqapplication.h>
25 #include <tqdragobject.h>
27 #include <tqiconview.h>
29 #include <tqstringlist.h>
31 #include <tdeabc/addressbook.h>
32 #include <tdeabc/addressee.h>
33 #include <tdeconfig.h>
35 #include <tdelocale.h>
38 #include "configurecardviewdialog.h"
41 #include "kaddressbookcardview.h"
43 class CardViewFactory :
public ViewFactory
46 KAddressBookView *view( KAB::Core *core, TQWidget *parent,
const char *name )
51 TQString type()
const {
return I18N_NOOP(
"Card"); }
53 TQString description()
const {
return i18n(
"Rolodex style cards represent contacts." ); }
56 const char *name = 0 )
63 void *init_libkaddrbk_cardview()
65 return (
new CardViewFactory );
72 AddresseeCardViewItem(
const TDEABC::Field::List &fields,
74 TDEABC::AddressBook *doc,
const TDEABC::Addressee &addr,
77 mFields( fields ), mShowEmptyFields( showEmptyFields ),
78 mDocument( doc ), mAddressee( addr )
80 if ( mFields.isEmpty() )
81 mFields = TDEABC::Field::defaultFields();
86 const TDEABC::Addressee &addressee()
const {
return mAddressee; }
90 mAddressee = mDocument->findByUid( mAddressee.uid() );
92 if ( !mAddressee.isEmpty() ) {
95 TDEABC::Field::List::ConstIterator it( mFields.begin() );
96 const TDEABC::Field::List::ConstIterator endIt( mFields.end() );
97 for ( ; it != endIt; ++it ) {
104 insertField( (*it)->label(), (*it)->value( mAddressee ) );
112 TDEABC::Field::List mFields;
113 bool mShowEmptyFields;
114 TDEABC::AddressBook *mDocument;
115 TDEABC::Addressee mAddressee;
119 AddresseeCardView::AddresseeCardView( TQWidget *parent,
const char *name )
122 setAcceptDrops(
true );
125 AddresseeCardView::~AddresseeCardView()
129 void AddresseeCardView::dragEnterEvent( TQDragEnterEvent *event )
131 if ( TQTextDrag::canDecode( event ) )
135 void AddresseeCardView::dropEvent( TQDropEvent *event )
137 emit addresseeDropped( event );
140 void AddresseeCardView::startDrag()
142 emit startAddresseeDrag();
146 KAddressBookCardView::KAddressBookCardView( KAB::Core *core,
147 TQWidget *parent,
const char *name )
150 mShowEmptyFields =
false;
152 TQVBoxLayout *layout =
new TQVBoxLayout( viewWidget() );
154 mCardView =
new AddresseeCardView( viewWidget(),
"mCardView" );
155 mCardView->setSelectionMode( CardView::Extended );
156 layout->addWidget( mCardView );
159 connect( mCardView, TQ_SIGNAL( executed(
CardViewItem* ) ),
161 connect( mCardView, TQ_SIGNAL( selectionChanged() ),
162 this, TQ_SLOT( addresseeSelected() ) );
163 connect( mCardView, TQ_SIGNAL( addresseeDropped( TQDropEvent* ) ),
164 this, TQ_SIGNAL( dropped( TQDropEvent* ) ) );
165 connect( mCardView, TQ_SIGNAL( startAddresseeDrag() ),
166 this, TQ_SIGNAL( startDrag() ) );
167 connect( mCardView, TQ_SIGNAL( contextMenuRequested(
CardViewItem*,
const TQPoint& ) ),
168 this, TQ_SLOT( rmbClicked(
CardViewItem*,
const TQPoint& ) ) );
171 KAddressBookCardView::~KAddressBookCardView()
178 return TDEABC::Field::allFields()[ 0 ];
186 if ( config->readBoolEntry(
"EnableCustomColors",
false ) ) {
187 TQPalette p( mCardView->palette() );
188 TQColor c = p.color( TQPalette::Active, TQColorGroup::Base );
189 p.setColor( TQPalette::Active, TQColorGroup::Base, config->readColorEntry(
"BackgroundColor", &c ) );
190 c = p.color( TQPalette::Active, TQColorGroup::Text );
191 p.setColor( TQPalette::Active, TQColorGroup::Text, config->readColorEntry(
"TextColor", &c ) );
192 c = p.color( TQPalette::Active, TQColorGroup::Button );
193 p.setColor( TQPalette::Active, TQColorGroup::Button, config->readColorEntry(
"HeaderColor", &c ) );
194 c = p.color( TQPalette::Active, TQColorGroup::ButtonText );
195 p.setColor( TQPalette::Active, TQColorGroup::ButtonText, config->readColorEntry(
"HeaderTextColor", &c ) );
196 c = p.color( TQPalette::Active, TQColorGroup::Highlight );
197 p.setColor( TQPalette::Active, TQColorGroup::Highlight, config->readColorEntry(
"HighlightColor", &c ) );
198 c = p.color( TQPalette::Active, TQColorGroup::HighlightedText );
199 p.setColor( TQPalette::Active, TQColorGroup::HighlightedText, config->readColorEntry(
"HighlightedTextColor", &c ) );
200 mCardView->viewport()->setPalette( p );
203 mCardView->viewport()->setPalette( mCardView->palette() );
208 if ( config->readBoolEntry(
"EnableCustomFonts",
false ) ) {
209 mCardView->setFont( config->readFontEntry(
"TextFont", &f ) );
211 mCardView->setHeaderFont( config->readFontEntry(
"HeaderFont", &f ) );
213 mCardView->setFont( f );
215 mCardView->setHeaderFont( f );
218 mCardView->setDrawCardBorder( config->readBoolEntry(
"DrawBorder",
true ) );
219 mCardView->setDrawColSeparators( config->readBoolEntry(
"DrawSeparators",
true ) );
220 mCardView->setDrawFieldLabels( config->readBoolEntry(
"DrawFieldLabels",
false ) );
221 mShowEmptyFields = config->readBoolEntry(
"ShowEmptyFields",
false );
223 mCardView->setShowEmptyFields( mShowEmptyFields );
225 mCardView->setItemWidth( config->readNumEntry(
"ItemWidth", 200 ) );
226 mCardView->setItemMargin( config->readNumEntry(
"ItemMargin", 0 ) );
227 mCardView->setItemSpacing( config->readNumEntry(
"ItemSpacing", 10 ) );
228 mCardView->setSeparatorWidth( config->readNumEntry(
"SeparatorWidth", 2 ) );
233 if ( KABPrefs::instance()->honorSingleClick() )
237 connect( mCardView, TQ_SIGNAL( doubleClicked(
CardViewItem* ) ),
243 config->writeEntry(
"ItemWidth", mCardView->itemWidth() );
249 TQStringList uidList;
251 AddresseeCardViewItem *aItem;
253 for ( item = mCardView->firstItem(); item; item = item->
nextItem() ) {
255 aItem =
dynamic_cast<AddresseeCardViewItem*
>( item );
257 uidList << aItem->addressee().uid();
264 void KAddressBookCardView::refresh(
const TQString &uid )
267 AddresseeCardViewItem *aItem;
269 if ( uid.isEmpty() ) {
271 mCardView->viewport()->setUpdatesEnabled(
false );
274 const TDEABC::Addressee::List addresseeList(
addressees() );
275 TDEABC::Addressee::List::ConstIterator it( addresseeList.begin() );
276 const TDEABC::Addressee::List::ConstIterator endIt( addresseeList.end() );
277 for ( ; it != endIt; ++it ) {
278 aItem =
new AddresseeCardViewItem(
fields(), mShowEmptyFields,
279 core()->addressBook(), *it, mCardView );
281 mCardView->viewport()->setUpdatesEnabled(
true );
282 mCardView->viewport()->update();
289 for ( item = mCardView->firstItem(); item && !found; item = item->
nextItem() ) {
290 aItem =
dynamic_cast<AddresseeCardViewItem*
>( item );
291 if ( aItem && (aItem->addressee().uid() == uid) ) {
299 void KAddressBookCardView::setSelected(
const TQString &uid,
bool selected )
302 AddresseeCardViewItem *aItem;
304 if ( uid.isEmpty() ) {
308 for ( item = mCardView->firstItem(); item && !found; item = item->
nextItem() ) {
309 aItem =
dynamic_cast<AddresseeCardViewItem*
>( item );
311 if ( aItem && (aItem->addressee().uid() == uid) ) {
312 mCardView->setSelected( aItem,
selected );
313 mCardView->ensureItemVisible( item );
320 void KAddressBookCardView::setFirstSelected(
bool selected )
322 if ( mCardView->firstItem() ) {
323 mCardView->setSelected( mCardView->firstItem(),
selected );
324 mCardView->ensureItemVisible( mCardView->firstItem() );
328 void KAddressBookCardView::addresseeExecuted(
CardViewItem *item )
330 AddresseeCardViewItem *aItem =
dynamic_cast<AddresseeCardViewItem*
>( item );
332 emit
executed( aItem->addressee().uid() );
335 void KAddressBookCardView::addresseeSelected()
338 AddresseeCardViewItem *aItem;
341 for ( item = mCardView->firstItem(); item && !found; item = item->
nextItem() ) {
343 aItem =
dynamic_cast<AddresseeCardViewItem*
>( item );
345 emit
selected( aItem->addressee().uid() );
355 void KAddressBookCardView::rmbClicked(
CardViewItem*,
const TQPoint &point )
360 void KAddressBookCardView::scrollUp()
362 TQApplication::postEvent( mCardView,
new TQKeyEvent( TQEvent::KeyPress, TQt::Key_Up, 0, 0 ) );
365 void KAddressBookCardView::scrollDown()
367 TQApplication::postEvent( mCardView,
new TQKeyEvent( TQEvent::KeyPress, TQt::Key_Down, 0, 0 ) );
370 #include "kaddressbookcardview.moc"
Represents a single card (item) in the card view.
CardViewItem * nextItem() const
void clearFields()
Removes all the fields from this card.
void setCaption(const TQString &caption)
Sets the caption of the card.
void insertField(const TQString &label, const TQString &value)
Adds a field to the card.
The CardView is a method of displaying data in cards.
This view uses the CardView class to create a card view.
virtual void readConfig(TDEConfig *config)
Called whenever this view should read the config.
virtual TQStringList selectedUids()
Must be overloaded in subclasses.
virtual void writeConfig(TDEConfig *config)
Called whenever this view should write the config.
virtual TDEABC::Field * sortField() const
Base class for all views in kaddressbook.
void popup(const TQPoint &point)
Call this slot to popup a rmb menu.
void selected(const TQString &uid)
This signal should be emitted by a subclass whenever an addressee is selected.
virtual void writeConfig(TDEConfig *)
Called whenever this view should write the config.
void executed(const TQString &uid)
This signal should be emitted by a subclass whenever an addressee is executed.
TDEABC::Addressee::List addressees()
Returns a list of the addressees that should be displayed.
virtual void readConfig(TDEConfig *config)
Called whenever this view should read the config.
TDEABC::Field::List fields() const
Returns a list of the fields that should be displayed.