• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • libkopete
  • ui
metacontactselectorwidget.cpp
Go to the documentation of this file.
1 /*
2  MetaContactSelectorWidget
3 
4  Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org>
5 
6  Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include <qcheckbox.h>
19 #include <qlabel.h>
20 
21 #include <qimage.h>
22 #include <qpixmap.h>
23 #include <qpainter.h>
24 #include <qlayout.h>
25 #include <QVBoxLayout>
26 #include <QBoxLayout>
27 
28 #include <kconfig.h>
29 #include <klocale.h>
30 #include <kiconloader.h>
31 
32 #include <kdeversion.h>
33 #include <kinputdialog.h>
34 #include <kpushbutton.h>
35 #include <k3activelabel.h>
36 #include <kdebug.h>
37 #include <k3listview.h>
38 #include <k3listviewsearchline.h>
39 
40 #include "kopetelistview.h"
41 #include "kopetelistviewsearchline.h"
42 #include "kopetecontactlist.h"
43 #include "kopetemetacontact.h"
44 #include "kopetepicture.h"
45 #include "ui_addressbookselectorwidget_base.h"
46 #include "metacontactselectorwidget.h"
47 #include "ui_metacontactselectorwidget_base.h"
48 
49 using namespace Kopete::UI::ListView;
50 
51 namespace Kopete
52 {
53 namespace UI
54 {
55 
56 class MetaContactSelectorWidgetLVI::Private
57 {
58 public:
59  Kopete::MetaContact *metaContact;
60  ImageComponent *metaContactPhoto;
61  ImageComponent *metaContactIcon;
62  DisplayNameComponent *nameText;
63  TextComponent *extraText;
64  BoxComponent *contactIconBox;
65  BoxComponent *spacerBox;
66  int photoSize;
67  int contactIconSize;
68 };
69 
70 
71 MetaContactSelectorWidgetLVI::MetaContactSelectorWidgetLVI(Kopete::MetaContact *mc, Q3ListView *parent, QObject *owner) : Kopete::UI::ListView::Item(parent, owner) , d( new Private() )
72 {
73  d->metaContact = mc;
74  d->photoSize = 60;
75 
76  connect( d->metaContact, SIGNAL(photoChanged()),
77  SLOT(slotPhotoChanged()) );
78  connect( d->metaContact, SIGNAL(displayNameChanged(QString,QString)),
79  SLOT(slotDisplayNameChanged()) );
80  buildVisualComponents();
81 }
82 
83 MetaContactSelectorWidgetLVI::~MetaContactSelectorWidgetLVI()
84 {
85  delete d;
86 }
87 
88 Kopete::MetaContact* MetaContactSelectorWidgetLVI::metaContact()
89 {
90  return d->metaContact;
91 }
92 
93 void MetaContactSelectorWidgetLVI::slotDisplayNameChanged()
94 {
95  if ( d->nameText )
96  {
97  d->nameText->setText( d->metaContact->displayName() );
98 
99  // delay the sort if we can
100  if ( ListView::ListView *lv = dynamic_cast<ListView::ListView *>( listView() ) )
101  lv->delayedSort();
102  else
103  listView()->sort();
104  }
105 }
106 
107 QString MetaContactSelectorWidgetLVI::text ( int /* column */ ) const
108 {
109  return d->metaContact->displayName();
110 }
111 
112 void MetaContactSelectorWidgetLVI::slotPhotoChanged()
113 {
114  QPixmap photoPixmap;
115  QImage photoImg = d->metaContact->picture().image();
116  if ( !photoImg.isNull() && (photoImg.width() > 0) && (photoImg.height() > 0) )
117  {
118  int photoSize = d->photoSize;
119 
120  photoImg = photoImg.scaled( photoSize, photoSize, Qt::KeepAspectRatio ) ;
121 
122  // draw a 1 pixel black border
123  photoPixmap = QPixmap::fromImage( photoImg );
124  QPainter p(&photoPixmap);
125  p.setPen(Qt::black);
126  p.drawLine(0, 0, photoPixmap.width()-1, 0);
127  p.drawLine(0, photoPixmap.height()-1, photoPixmap.width()-1, photoPixmap.height()-1);
128  p.drawLine(0, 0, 0, photoPixmap.height()-1);
129  p.drawLine(photoPixmap.width()-1, 0, photoPixmap.width()-1, photoPixmap.height()-1);
130  }
131  else
132  {
133  // if no photo use the smilie icon
134  photoPixmap=SmallIcon(d->metaContact->statusIcon(), d->photoSize);
135  }
136  d->metaContactPhoto->setPixmap( photoPixmap, false);
137 }
138 
139 void MetaContactSelectorWidgetLVI::buildVisualComponents()
140 {
141  // empty...
142  while ( component( 0 ) )
143  delete component( 0 );
144 
145  d->nameText = 0L;
146  d->metaContactPhoto = 0L;
147  d->extraText = 0L;
148  d->contactIconSize = 16;
149  d->photoSize = 48;
150 
151  Component *hbox = new BoxComponent( this, BoxComponent::Horizontal );
152  d->spacerBox = new BoxComponent( hbox, BoxComponent::Horizontal );
153 
154  d->contactIconSize = IconSize( KIconLoader::Small );
155  Component *imageBox = new BoxComponent( hbox, BoxComponent::Vertical );
156  new VSpacerComponent( imageBox );
157  // include borders in size
158  d->metaContactPhoto = new ImageComponent( imageBox, d->photoSize + 2 , d->photoSize + 2 );
159  new VSpacerComponent( imageBox );
160  Component *vbox = new BoxComponent( hbox, BoxComponent::Vertical );
161  d->nameText = new DisplayNameComponent( vbox );
162  d->extraText = new TextComponent( vbox );
163 
164  Component *box = new BoxComponent( vbox, BoxComponent::Horizontal );
165  d->contactIconBox = new BoxComponent( box, BoxComponent::Horizontal );
166 
167  slotUpdateContactBox();
168  slotDisplayNameChanged();
169  slotPhotoChanged();
170 }
171 
172 void MetaContactSelectorWidgetLVI::slotUpdateContactBox()
173 {
174  QList<Kopete::Contact *> contacts = d->metaContact->contacts();
175  QListIterator<Contact *> it(contacts);
176  while (it.hasNext())
177  {
178  Kopete::Contact *c = it.next();
179  new ContactComponent(d->contactIconBox, c, IconSize( KIconLoader::Small ));
180  }
181 }
182 
183 class MetaContactSelectorWidget::Private
184 {
185 public:
186  Ui::MetaContactSelectorWidget_Base *widget;
187  QList<Kopete::MetaContact *> excludedMetaContacts;
188 };
189 
190 
191 MetaContactSelectorWidget::MetaContactSelectorWidget( QWidget *parent, const char *name )
192  : QWidget( parent ), d( new Private() )
193 {
194  setObjectName( name );
195 
196  d->widget = new Ui::MetaContactSelectorWidget_Base;
197 
198  QBoxLayout *l = new QVBoxLayout(this);
199  QWidget *w = new QWidget(this);
200  d->widget->setupUi(w);
201  l->addWidget(w);
202 
203  connect( d->widget->metaContactListView, SIGNAL(clicked(Q3ListViewItem*)),
204  SIGNAL(metaContactListClicked(Q3ListViewItem*)) );
205  connect( d->widget->metaContactListView, SIGNAL(selectionChanged(Q3ListViewItem*)),
206  SIGNAL(metaContactListClicked(Q3ListViewItem*)) );
207  connect( d->widget->metaContactListView, SIGNAL(spacePressed(Q3ListViewItem*)),
208  SIGNAL(metaContactListClicked(Q3ListViewItem*)) );
209 
210  connect( Kopete::ContactList::self(), SIGNAL(metaContactAdded(Kopete::MetaContact*)), this, SLOT(slotLoadMetaContacts()) );
211 
212  d->widget->kListViewSearchLine->setListView(d->widget->metaContactListView);
213  d->widget->kListViewSearchLine->setFocus();
214  d->widget->metaContactListView->setFullWidth( true );
215  d->widget->metaContactListView->addColumn( i18n( "Contacts" ), 0 );
216  d->widget->metaContactListView->header()->hide();
217  d->widget->metaContactListView->setColumnWidthMode(0, Q3ListView::Maximum);
218  slotLoadMetaContacts();
219 }
220 
221 
222 MetaContactSelectorWidget::~MetaContactSelectorWidget()
223 {
224  disconnect( Kopete::ContactList::self(), SIGNAL(metaContactAdded(Kopete::MetaContact*)), this, SLOT(slotLoadMetaContacts()) );
225  delete d->widget;
226  delete d;
227 }
228 
229 
230 Kopete::MetaContact* MetaContactSelectorWidget::metaContact()
231 {
232  MetaContactSelectorWidgetLVI *item = 0L;
233  item = static_cast<MetaContactSelectorWidgetLVI *>( d->widget->metaContactListView->selectedItem() );
234 
235  if ( item )
236  return item->metaContact();
237 
238  return 0L;
239 }
240 
241 void MetaContactSelectorWidget::selectMetaContact( Kopete::MetaContact *mc )
242 {
243  // iterate trough list view
244  Q3ListViewItemIterator it( d->widget->metaContactListView );
245  while( it.current() )
246  {
247  MetaContactSelectorWidgetLVI *item = (MetaContactSelectorWidgetLVI *) it.current();
248  if (!item)
249  continue;
250 
251  if ( mc == item->metaContact() )
252  {
253  // select the contact item
254  d->widget->metaContactListView->setSelected( item, true );
255  d->widget->metaContactListView->ensureItemVisible( item );
256  }
257  ++it;
258  }
259 }
260 
261 void MetaContactSelectorWidget::excludeMetaContact( Kopete::MetaContact *mc )
262 {
263  if( d->excludedMetaContacts.indexOf(mc) == -1 )
264  {
265  d->excludedMetaContacts.append(mc);
266  }
267  slotLoadMetaContacts();
268 }
269 
270 bool MetaContactSelectorWidget::metaContactSelected()
271 {
272  return d->widget->metaContactListView->selectedItem() ? true : false;
273 }
274 
276 void MetaContactSelectorWidget::slotLoadMetaContacts()
277 {
278  d->widget->metaContactListView->clear();
279 
280  QList<Kopete::MetaContact *> metaContacts = Kopete::ContactList::self()->metaContacts();
281  QListIterator<Kopete::MetaContact *> it(metaContacts);
282  while ( it.hasNext() )
283  {
284  Kopete::MetaContact *mc = it.next();
285  if( !mc->isTemporary() && mc != metaContact() )
286  if( !mc->isTemporary() && (d->excludedMetaContacts.indexOf(mc) == -1) )
287  {
288  new MetaContactSelectorWidgetLVI(mc, d->widget->metaContactListView);
289  }
290  }
291 
292  d->widget->metaContactListView->sort();
293 }
294 
295 void MetaContactSelectorWidget::setLabelMessage( const QString &msg )
296 {
297  d->widget->lblHeader->setPlainText(msg);
298 }
299 
300 } // namespace UI
301 } // namespace Kopete
302 
303 #include "metacontactselectorwidget.moc"
304 
305 // vim: set noet ts=4 sts=4 sw=4:
306 
Kopete::UI::MetaContactSelectorWidget::selectMetaContact
void selectMetaContact(Kopete::MetaContact *mc)
pre-selects a contact
Definition: metacontactselectorwidget.cpp:241
kopetemetacontact.h
Kopete::ContactList::self
static ContactList * self()
The contact list is a singleton object.
Definition: kopetecontactlist.cpp:71
Kopete::UI::MetaContactSelectorWidget::~MetaContactSelectorWidget
~MetaContactSelectorWidget()
Definition: metacontactselectorwidget.cpp:222
Kopete::UI::MetaContactSelectorWidgetLVI::buildVisualComponents
void buildVisualComponents()
Definition: metacontactselectorwidget.cpp:139
Kopete::UI::ListView::BoxComponent
Definition: kopetelistviewitem.h:233
kopetelistview.h
Kopete::UI::MetaContactSelectorWidget::excludeMetaContact
void excludeMetaContact(Kopete::MetaContact *mc)
excludes a metacontact from being shown in the list if the metacontact is already excluded...
Definition: metacontactselectorwidget.cpp:261
metacontactselectorwidget.h
Kopete::UI::MetaContactSelectorWidgetLVI::slotUpdateContactBox
void slotUpdateContactBox()
Definition: metacontactselectorwidget.cpp:172
QWidget
Kopete::UI::ListView::Component
This class represents a rectangular subsection of a ListItem.
Definition: kopetelistviewitem.h:103
Kopete::UI::ListView::ListView
Definition: kopetelistview.h:37
Kopete::ContactList::metaContacts
QList< MetaContact * > metaContacts() const
return a list of all metacontact of the contact list Retrieve the list of all available meta contacts...
Definition: kopetecontactlist.cpp:112
QObject
Kopete::UI::ListView::TextComponent
Definition: kopetelistviewitem.h:260
Kopete::UI::ListView::DisplayNameComponent
DisplayNameComponent.
Definition: kopetelistviewitem.h:339
Kopete::UI::MetaContactSelectorWidget::setLabelMessage
void setLabelMessage(const QString &msg)
sets the widget label message example: Please select a contact or, Choose a contact to delete ...
Definition: metacontactselectorwidget.cpp:295
Kopete::UI::MetaContactSelectorWidget::MetaContactSelectorWidget
MetaContactSelectorWidget(QWidget *parent=0, const char *name=0)
Definition: metacontactselectorwidget.cpp:191
kopetepicture.h
Kopete::UI::ListView::ImageComponent
Definition: kopetelistviewitem.h:290
Kopete::UI::MetaContactSelectorWidget::slotLoadMetaContacts
void slotLoadMetaContacts()
Utility function, populates the metacontact list.
Definition: metacontactselectorwidget.cpp:276
kopetelistviewsearchline.h
Kopete::UI::MetaContactSelectorWidgetLVI::slotPhotoChanged
void slotPhotoChanged()
Definition: metacontactselectorwidget.cpp:112
kopetecontactlist.h
Kopete::UI::MetaContactSelectorWidgetLVI::metaContact
Kopete::MetaContact * metaContact()
Definition: metacontactselectorwidget.cpp:88
Kopete::UI::ListView::ComponentBase::component
Component * component(uint n)
Definition: kopetelistviewitem.cpp:66
Kopete::Contact
Definition: kopetecontact.h:58
Kopete::UI::MetaContactSelectorWidgetLVI::~MetaContactSelectorWidgetLVI
virtual ~MetaContactSelectorWidgetLVI()
Definition: metacontactselectorwidget.cpp:83
Kopete::MetaContact::isTemporary
bool isTemporary
Definition: kopetemetacontact.h:63
Kopete::UI::ListView::ContactComponent
ContactComponent.
Definition: kopetelistviewitem.h:313
Kopete::UI::MetaContactSelectorWidgetLVI::MetaContactSelectorWidgetLVI
MetaContactSelectorWidgetLVI(Kopete::MetaContact *mc, Q3ListView *parent, QObject *owner=0)
Definition: metacontactselectorwidget.cpp:71
Kopete::UI::MetaContactSelectorWidgetLVI
Definition: metacontactselectorwidget.h:80
Kopete::UI::MetaContactSelectorWidget::metaContactListClicked
void metaContactListClicked(Q3ListViewItem *mc)
Kopete::UI::MetaContactSelectorWidget::metaContactSelected
bool metaContactSelected()
Definition: metacontactselectorwidget.cpp:270
Kopete::UI::ListView::Item
List-view item composed of Component items.
Definition: kopetelistviewitem.h:396
Kopete::MetaContact
Definition: kopetemetacontact.h:54
Kopete::UI::ListView::VSpacerComponent
Definition: kopetelistviewitem.h:380
Kopete::UI::MetaContactSelectorWidgetLVI::text
virtual QString text(int column) const
Definition: metacontactselectorwidget.cpp:107
Kopete::UI::MetaContactSelectorWidgetLVI::slotDisplayNameChanged
void slotDisplayNameChanged()
Definition: metacontactselectorwidget.cpp:93
Kopete::UI::MetaContactSelectorWidget::metaContact
Kopete::MetaContact * metaContact()
Definition: metacontactselectorwidget.cpp:230
name
const char * name
Definition: kopeteonlinestatus.cpp:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal