24 #include <tqapplication.h>
25 #include <tqiconview.h>
27 #include <tqstringlist.h>
29 #include <tdeabc/addressbook.h>
30 #include <tdeabc/addressee.h>
31 #include <tdeconfig.h>
33 #include <tdeglobal.h>
34 #include <kiconloader.h>
35 #include <tdelocale.h>
40 #include "kaddressbookiconview.h"
42 class IconViewFactory :
public ViewFactory
45 KAddressBookView *view( KAB::Core *core, TQWidget *parent,
const char *name )
50 TQString type()
const {
return I18N_NOOP(
"Icon" ); }
52 TQString description()
const {
return i18n(
"Icons represent contacts. Very simple view." ); }
56 void *init_libkaddrbk_iconview()
58 return (
new IconViewFactory );
62 AddresseeIconView::AddresseeIconView( TQWidget *parent,
const char *name )
63 : TDEIconView( parent, name )
65 setSelectionMode( TQIconView::Extended );
66 setResizeMode( TQIconView::Adjust );
67 setWordWrapIconText(
true );
69 setItemsMovable(
false );
70 setSorting(
true,
true );
71 setMode( TDEIconView::Select );
73 connect(
this, TQ_SIGNAL( dropped( TQDropEvent*,
const TQValueList<TQIconDragItem>& ) ),
74 this, TQ_SLOT( itemDropped( TQDropEvent*,
const TQValueList<TQIconDragItem>& ) ) );
77 AddresseeIconView::~AddresseeIconView()
81 void AddresseeIconView::itemDropped( TQDropEvent *event,
const TQValueList<TQIconDragItem>& )
83 emit addresseeDropped( event );
86 TQDragObject *AddresseeIconView::dragObject()
88 emit startAddresseeDrag();
95 class AddresseeIconViewItem :
public TDEIconViewItem
98 AddresseeIconViewItem(
const TDEABC::Field::List&, TDEABC::AddressBook *doc,
99 const TDEABC::Addressee &addr, TQIconView *parent )
100 : TDEIconViewItem( parent ), mDocument( doc ), mAddressee( addr )
105 const TDEABC::Addressee &addressee()
const {
return mAddressee; }
109 mAddressee = mDocument->findByUid( mAddressee.uid() );
111 if ( !mAddressee.isEmpty() )
112 setText( mAddressee.givenName() +
" " + mAddressee.familyName() );
115 TQPixmap defaultIcon( TDEGlobal::iconLoader()->loadIcon(
"x-office-address-book", TDEIcon::Desktop ) );
116 TDEABC::Picture pic = mAddressee.photo();
117 if ( pic.data().isNull() )
118 pic = mAddressee.logo();
120 if ( pic.isIntern() && !pic.data().isNull() ) {
121 TQImage img = pic.data();
122 if ( img.width() > img.height() )
123 icon = img.scaleWidth( 32 );
125 icon = img.scaleHeight( 32 );
133 TDEABC::AddressBook *mDocument;
134 TDEABC::Addressee mAddressee;
138 KAddressBookIconView::KAddressBookIconView( KAB::Core *core,
139 TQWidget *parent,
const char *name)
142 TQVBoxLayout *layout =
new TQVBoxLayout( viewWidget() );
144 mIconView =
new AddresseeIconView( viewWidget(),
"mIconView" );
145 layout->addWidget( mIconView );
148 connect( mIconView, TQ_SIGNAL( executed( TQIconViewItem* ) ),
149 this, TQ_SLOT( addresseeExecuted( TQIconViewItem* ) ) );
150 connect( mIconView, TQ_SIGNAL( selectionChanged() ),
151 this, TQ_SLOT( addresseeSelected() ) );
152 connect( mIconView, TQ_SIGNAL( addresseeDropped( TQDropEvent* ) ),
153 this, TQ_SIGNAL( dropped( TQDropEvent* ) ) );
154 connect( mIconView, TQ_SIGNAL( startAddresseeDrag() ),
155 this, TQ_SIGNAL( startDrag() ) );
156 connect( mIconView, TQ_SIGNAL( contextMenuRequested( TQIconViewItem*,
const TQPoint& ) ),
157 this, TQ_SLOT( rmbClicked( TQIconViewItem*,
const TQPoint& ) ) );
160 KAddressBookIconView::~KAddressBookIconView()
167 return TDEABC::Field::allFields()[ 2 ];
174 disconnect( mIconView, TQ_SIGNAL(
executed( TQIconViewItem* ) ),
175 this, TQ_SLOT( addresseeExecuted( TQIconViewItem* ) ) );
177 if ( KABPrefs::instance()->honorSingleClick() )
178 connect( mIconView, TQ_SIGNAL(
executed( TQIconViewItem* ) ),
179 this, TQ_SLOT( addresseeExecuted( TQIconViewItem* ) ) );
181 connect( mIconView, TQ_SIGNAL( doubleClicked( TQIconViewItem* ) ),
182 this, TQ_SLOT( addresseeExecuted( TQIconViewItem* ) ) );
187 TQStringList uidList;
188 TQIconViewItem *item;
189 AddresseeIconViewItem *aItem;
191 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
192 if ( item->isSelected() ) {
193 aItem =
dynamic_cast<AddresseeIconViewItem*
>( item );
195 uidList << aItem->addressee().uid();
202 void KAddressBookIconView::refresh(
const TQString &uid )
204 TQIconViewItem *item;
205 AddresseeIconViewItem *aItem;
207 if ( uid.isEmpty() ) {
212 const TDEABC::Addressee::List addresseeList(
addressees() );
213 TDEABC::Addressee::List::ConstIterator it( addresseeList.begin() );
214 const TDEABC::Addressee::List::ConstIterator endIt( addresseeList.end() );
215 for ( ; it != endIt; ++it )
216 aItem =
new AddresseeIconViewItem(
fields(),
core()->addressBook(), *it, mIconView );
218 mIconView->arrangeItemsInGrid(
true );
220 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
221 AddresseeIconViewItem* aivi =
dynamic_cast<AddresseeIconViewItem*
>( item );
222 mIconList.append( aivi );
227 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
228 aItem =
dynamic_cast<AddresseeIconViewItem*
>( item );
229 if ( aItem && (aItem->addressee().uid() == uid) ) {
231 mIconView->arrangeItemsInGrid(
true );
236 refresh( TQString() );
240 void KAddressBookIconView::setSelected(
const TQString &uid,
bool selected )
242 TQIconViewItem *item;
243 AddresseeIconViewItem *aItem;
245 if ( uid.isEmpty() ) {
249 for ( item = mIconView->firstItem(); item && !found; item = item->nextItem() ) {
251 aItem =
dynamic_cast<AddresseeIconViewItem*
>( item );
252 if ( aItem && (aItem->addressee().uid() == uid) ) {
253 mIconView->setSelected( aItem,
selected );
254 mIconView->ensureItemVisible( aItem );
261 void KAddressBookIconView::setFirstSelected(
bool selected )
263 if ( mIconView->firstItem() ) {
264 mIconView->setSelected( mIconView->firstItem(),
selected );
265 mIconView->ensureItemVisible( mIconView->firstItem() );
269 void KAddressBookIconView::addresseeExecuted( TQIconViewItem *item )
271 AddresseeIconViewItem *aItem =
dynamic_cast<AddresseeIconViewItem*
>( item );
274 emit
executed( aItem->addressee().uid() );
277 void KAddressBookIconView::addresseeSelected()
279 TQIconViewItem *item;
280 AddresseeIconViewItem *aItem;
283 for ( item = mIconView->firstItem(); item && !found; item = item->nextItem() ) {
284 if ( item->isSelected() ) {
285 aItem =
dynamic_cast<AddresseeIconViewItem*
>( item );
287 emit
selected( aItem->addressee().uid() );
297 void KAddressBookIconView::rmbClicked( TQIconViewItem*,
const TQPoint &point )
302 void KAddressBookIconView::scrollUp()
304 TQApplication::postEvent( mIconView,
new TQKeyEvent( TQEvent::KeyPress, TQt::Key_Up, 0, 0 ) );
307 void KAddressBookIconView::scrollDown()
309 TQApplication::postEvent( mIconView,
new TQKeyEvent( TQEvent::KeyPress, TQt::Key_Down, 0, 0 ) );
312 #include "kaddressbookiconview.moc"
This is an example kaddressbook view that is implemented using TDEIconView.
virtual void readConfig(TDEConfig *config)
Called whenever this view should read the config.
virtual TQStringList selectedUids()
Must be overloaded in subclasses.
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.
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.