20 #include <QApplication> 
   22 #include <QSortFilterProxyModel> 
   24 #include <QVBoxLayout> 
   25 #include <QPushButton> 
   27 #include <QStyledItemDelegate> 
   30 #include <personsmodel.h> 
   34 const int SPACING = 8;
 
   35 const int PHOTO_SIZE = 32;
 
   37 class PersonsDelegate : 
public QStyledItemDelegate
 
   40     PersonsDelegate(QObject *parent = 0);
 
   43     void paint(QPainter *painter, 
const QStyleOptionViewItem &option, 
const QModelIndex &index) 
const;
 
   44     QSize sizeHint(
const QStyleOptionViewItem &option, 
const QModelIndex &index) 
const;
 
   47 PersonsDelegate::PersonsDelegate(QObject *parent)
 
   48     : QStyledItemDelegate(parent)
 
   52 PersonsDelegate::~PersonsDelegate()
 
   56 void PersonsDelegate::paint(QPainter *painter, 
const QStyleOptionViewItem &option, 
const QModelIndex &index)
 const 
   58     QStyleOptionViewItemV4 optV4 = option;
 
   59     initStyleOption(&optV4, index);
 
   63     painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
 
   64     painter->setClipRect(optV4.rect);
 
   66     QStyle *style = QApplication::style();
 
   67     style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
 
   69     QRect contactPhotoRect = optV4.rect;
 
   70     contactPhotoRect.adjust(SPACING, SPACING, SPACING, SPACING);
 
   71     contactPhotoRect.setWidth(PHOTO_SIZE);
 
   72     contactPhotoRect.setHeight(PHOTO_SIZE);
 
   74     QImage avatar = index.data(Qt::DecorationRole).value<QImage>();
 
   75     painter->drawImage(contactPhotoRect, avatar);
 
   77     painter->drawRect(contactPhotoRect);
 
   79     QRect nameRect = optV4.rect;
 
   80     nameRect.adjust(SPACING + PHOTO_SIZE + SPACING, SPACING, 0, 0);
 
   82     painter->drawText(nameRect, index.data(Qt::DisplayRole).toString());
 
   84     QRect idRect = optV4.rect;
 
   85     idRect.adjust(SPACING + PHOTO_SIZE + SPACING, SPACING + 15, 0, 0);
 
   86     painter->drawText(idRect, index.data(PersonsModel::PersonUriRole).toString());
 
   91 QSize PersonsDelegate::sizeHint(
const QStyleOptionViewItem &option, 
const QModelIndex &index)
 const 
   95     return QSize(128, 48);
 
   98 class ContactListApp : public QWidget
 
  104     void onMergeClicked();
 
  105     void onUnmergeClicked();
 
  111 ContactListApp::ContactListApp()
 
  113     m_view = 
new QTreeView(
this);
 
  116     QVBoxLayout *layout = 
new QVBoxLayout(
this);
 
  117     QSortFilterProxyModel *sortFilter = 
new QSortFilterProxyModel(m_view);
 
  118     sortFilter->setDynamicSortFilter(
true);
 
  119     sortFilter->setSourceModel(m_model);
 
  121     m_view->setRootIsDecorated(
false);
 
  122     m_view->setModel(sortFilter);
 
  123     m_view->setItemDelegate(
new PersonsDelegate(
this));
 
  124     m_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
  126     layout->addWidget(m_view);
 
  127     QPushButton *mergeButton = 
new QPushButton(QStringLiteral(
"Merge"), 
this);
 
  128     connect(mergeButton, SIGNAL(released()), SLOT(onMergeClicked()));
 
  129     layout->addWidget(mergeButton);
 
  131     QPushButton *unmergeButton = 
new QPushButton(QStringLiteral(
"Unmerge"), 
this);
 
  132     connect(unmergeButton, SIGNAL(released()), SLOT(onUnmergeClicked()));
 
  133     layout->addWidget(unmergeButton);
 
  136 void ContactListApp::onMergeClicked()
 
  138     QModelIndexList indexes = m_view->selectionModel()->selectedIndexes();
 
  140     Q_FOREACH (
const QModelIndex &index, indexes) {
 
  141         ids << index.data(PersonsModel::PersonUriRole).toString();
 
  144     if (!ids.isEmpty()) {
 
  149 void ContactListApp::onUnmergeClicked()
 
  151     QModelIndexList indexes = m_view->selectionModel()->selectedIndexes();
 
  152     if (indexes.size()) {
 
  153         QString 
id = indexes.first().data(PersonsModel::PersonUriRole).toString();
 
  158 int main(
int argc, 
char **argv)
 
  160     QApplication app(argc, argv);
 
  162     ContactListApp widget;
 
  167 #include "contactlistwidgets.moc" 
KPEOPLE_EXPORT QString mergeContacts(const QStringList &uris)
Merge all uris into a single person. 
 
The KPeople namespace contains all the classes for Libkpeople. 
 
This class creates a model of all known contacts from all sources Contacts are represented as a tree ...
 
KPEOPLE_EXPORT bool unmergeContact(const QString &uri)
Unmerge a contact.