25 #include <tqiconset.h>
27 #include <tqdragobject.h>
28 #include <tqcombobox.h>
29 #include <tqpainter.h>
33 #include <tdelocale.h>
34 #include <tdeglobalsettings.h>
36 #include <tdeconfig.h>
37 #include <tdeapplication.h>
39 #include <tdeabc/addressbook.h>
40 #include <tdeabc/addressee.h>
41 #include <tdeimproxy.h>
43 #include "kaddressbooktableview.h"
45 #include "contactlistview.h"
50 DynamicTip::DynamicTip( ContactListView *parent)
55 void DynamicTip::maybeTip(
const TQPoint &pos )
57 if (!parentWidget()->inherits(
"ContactListView" ))
60 ContactListView *plv = (ContactListView*)parentWidget();
64 TQPoint posVp = plv->viewport()->pos();
66 TQListViewItem *lvi = plv->itemAt( pos - posVp );
70 ContactListViewItem *plvi =
dynamic_cast< ContactListViewItem*
>(lvi);
75 TQRect r = plv->itemRect( lvi );
76 r.moveBy( posVp.x(), posVp.y() );
81 TDEABC::Addressee a = plvi->addressee();
85 s += i18n(
"label: value",
"%1: %2").arg(a.formattedNameLabel())
86 .arg(a.formattedName());
89 s += i18n(
"label: value",
"%1: %2").arg(a.organizationLabel())
90 .arg(a.organization());
92 TQString notes = a.note().stripWhiteSpace();
93 if ( !notes.isEmpty() ) {
95 s +=
'\n' + i18n(
"label: value",
"%1: \n").arg(a.noteLabel());
96 TQFontMetrics fm( font() );
100 bool doBreak =
false;
106 while ( i <
int(notes.length()) ) {
108 if ( notes[i] !=
'\n' )
109 linew += fm.width( notes[i] );
111 if ( lastSpace >= a && notes[i] !=
'\n' )
112 if (linew >= parentWidget()->width()) {
114 if ( lastSpace > a ) {
122 if ( notes[i] ==
'\n' || doBreak ) {
123 s += notes.mid( a, i - a + (doBreak?1:0) ) +
"\n";
130 if ( notes[i].isSpace() ) {
135 if ( lastSpace <= a ) {
149 ContactListViewItem::ContactListViewItem(
const TDEABC::Addressee &a,
150 ContactListView *parent,
151 TDEABC::AddressBook *doc,
152 const TDEABC::Field::List &fields,
154 : TDEListViewItem(parent), mAddressee(a), mFields( fields ),
155 parentListView( parent ), mDocument(doc), mIMProxy( proxy )
158 mHasIM = mIMProxy->isPresent( mAddressee.uid() );
164 TQString ContactListViewItem::key(
int column,
bool ascending)
const
167 if ( column >= parentListView->columns() )
170 #if TDE_VERSION >= 319
171 Q_UNUSED( ascending )
172 if ( parentListView->showIM() ) {
175 if ( column == parentListView->imColumn() ) {
179 TQString key = TQString::number( 5 - ( mIMProxy->presenceNumeric( mAddressee.uid() ) + 1 ) );
183 return mFields[ column ]->sortKey( mAddressee );
187 return mFields[ column ]->sortKey( mAddressee );
189 return TQListViewItem::key( column, ascending ).lower();
193 void ContactListViewItem::paintCell(TQPainter * p,
194 const TQColorGroup & cg,
199 TDEListViewItem::paintCell(p, cg, column, width, align);
204 if (parentListView->singleLine()) {
205 p->setPen( parentListView->alternateColor() );
206 p->drawLine( 0, height() - 1, width, height() - 1 );
211 ContactListView *ContactListViewItem::parent()
213 return parentListView;
217 void ContactListViewItem::refresh()
225 mAddressee = mDocument->findByUid(mAddressee.uid());
226 if (mAddressee.isEmpty())
232 if ( mIMProxy->presenceNumeric( mAddressee.uid() ) > 0 )
233 setPixmap( parentListView->imColumn(), mIMProxy->presenceIcon( mAddressee.uid() ) );
235 setPixmap( parentListView->imColumn(), TQPixmap() );
238 TDEABC::Field::List::ConstIterator it;
239 for ( it = mFields.begin(); it != mFields.end(); ++it ) {
240 if ( (*it)->label() == TDEABC::Addressee::birthdayLabel() ) {
241 TQDate date = mAddressee.birthday().date();
242 if ( date.isValid() )
243 setText( i++, TDEGlobal::locale()->formatDate( date,
true ) );
247 setText( i++, (*it)->value( mAddressee ) );
251 void ContactListViewItem::setHasIM(
bool hasIM )
260 TDEABC::AddressBook* ,
263 : TDEListView( parent, name ),
271 mAlternateColor = TDEGlobalSettings::alternateBackgroundColor();
273 setAlternateBackgroundEnabled(mABackground);
274 setAcceptDrops(
true );
275 viewport()->setAcceptDrops(
true );
276 setAllColumnsShowFocus(
true );
277 setShowSortIndicator(
true);
278 setSelectionModeExt( TDEListView::Extended );
279 setDropVisualizer(
false);
281 connect(
this, TQ_SIGNAL(dropped(TQDropEvent*)),
282 this, TQ_SLOT(itemDropped(TQDropEvent*)));
287 void ContactListView::paintEmptyArea( TQPainter * p,
const TQRect & rect )
289 TQBrush b = palette().brush(TQPalette::Active, TQColorGroup::Base);
294 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
296 rect.left() + contentsX(),
297 rect.top() + contentsY() );
303 TDEListView::paintEmptyArea(p, rect);
307 void ContactListView::contentsMousePressEvent(TQMouseEvent* e)
310 TDEListView::contentsMousePressEvent(e);
315 void ContactListView::contentsMouseMoveEvent( TQMouseEvent *e )
317 if ((e->state() & TQt::LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
318 emit startAddresseeDrag();
321 TDEListView::contentsMouseMoveEvent( e );
324 bool ContactListView::acceptDrag(TQDropEvent *e)
const
326 return TQTextDrag::canDecode(e);
329 void ContactListView::itemDropped(TQDropEvent *e)
331 contentsDropEvent(e);
334 void ContactListView::contentsDropEvent( TQDropEvent *e )
336 emit addresseeDropped(e);
339 void ContactListView::setAlternateBackgroundEnabled(
bool enabled)
341 mABackground = enabled;
345 setAlternateBackground(mAlternateColor);
349 setAlternateBackground(TQColor());
353 void ContactListView::setBackgroundPixmap(
const TQString &filename)
355 if (filename.isEmpty())
361 setPaletteBackgroundPixmap(TQPixmap(filename));
365 void ContactListView::setShowIM(
bool enabled )
370 bool ContactListView::showIM()
375 void ContactListView::setIMColumn(
int column )
377 mInstantMsgColumn = column;
380 int ContactListView::imColumn()
382 return mInstantMsgColumn;
385 #include "contactlistview.moc"
The whole tooltip design needs a lot of work.
This class is the table view for kaddressbook.