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