20 #include "mergedelegate.h" 
   21 #include "personsmodel.h" 
   22 #include "mergedialog.h" 
   27 #include <QStyleOptionViewItem> 
   28 #include <QAbstractItemView> 
   29 #include <QModelIndex> 
   30 #include <QApplication> 
   33 #include <QItemSelection> 
   36 #include <KLocalizedString> 
   38 #define MAX_MATCHING_CONTACTS_ICON 5 
   39 #define SIZE_STANDARD_PIXMAP 35 
   44 QSize MergeDelegate::s_decorationSize(SIZE_STANDARD_PIXMAP, SIZE_STANDARD_PIXMAP);
 
   45 QSize MergeDelegate::s_arrowSize(15, 15);
 
   47 QSize MergeDelegate::pictureSize()
 
   49     return s_decorationSize;
 
   52 MergeDelegate::MergeDelegate(QAbstractItemView *parent)
 
   53     : KExtendableItemDelegate(parent)
 
   55     static QIcon arrowD = QIcon::fromTheme(QStringLiteral(
"arrow-down"));
 
   56     setContractPixmap(arrowD.pixmap(s_arrowSize));
 
   58     static QIcon arrowR = QIcon::fromTheme(QStringLiteral(
"arrow-right"));
 
   59     setExtendPixmap(arrowR.pixmap(s_arrowSize));
 
   62 MergeDelegate::~MergeDelegate()
 
   65 void MergeDelegate::onClickContactParent(
const QModelIndex &parent)
 
   67     if (isExtended(parent)) {
 
   70         QItemSelection item = QItemSelection(parent, parent);
 
   71         onSelectedContactsChanged(item, QItemSelection());
 
   75 void MergeDelegate::onSelectedContactsChanged(
const QItemSelection &now , 
const QItemSelection &old)
 
   77     if (old.indexes().size()) {
 
   78         QModelIndex oldIdx = old.indexes().first();
 
   80         if (isExtended(oldIdx)) {
 
   84     if (now.indexes().size()) {
 
   85         QModelIndex idx = now.indexes().first();
 
   86         extendItem(buildMultipleLineLabel(idx), idx);
 
   90 QWidget *MergeDelegate::buildMultipleLineLabel(
const QModelIndex &idx)
 
   93     int rows = idx.model()->rowCount(idx);
 
   94     for (
int i = 0 ; i < rows; ++i) {
 
   95         QModelIndex child = idx.child(i, 0);
 
   96         Match m = child.data(MergeDialog::MergeReasonRole).value<Match>();
 
   98         QString name = m.indexB.data(Qt::DisplayRole).toString();
 
   99         QString display = i18nc(
"name: merge reasons", 
"%1: %2", name, m.matchReasons().join(i18nc(
"reasons join", 
", ")));
 
  100         contents += display + QLatin1String(
"<p/>");
 
  102     QLabel *childDisplay = 
new QLabel(contents, dynamic_cast<QWidget *>(parent()));
 
  103     childDisplay->setAlignment(Qt::AlignRight);
 
  104     childDisplay->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
 
  108 void MergeDelegate::paint(QPainter *painter, 
const QStyleOptionViewItem &optionOld, 
const QModelIndex &index)
 const 
  110     QStyleOptionViewItem option(optionOld);
 
  111     QStyleOptionViewItemV4 opt(option);
 
  112     KExtendableItemDelegate::paint(painter, option, index);
 
  114     const int separation = 5;
 
  116     int facesRows = qMin(index.model()->rowCount(index), MAX_MATCHING_CONTACTS_ICON);
 
  117     for (
int i = 0; i < facesRows; i++) { 
 
  118         const QModelIndex child = index.child(i, 0);
 
  120         QVariant decoration = child.data(Qt::DecorationRole);
 
  121         Q_ASSERT(decoration.type() == (QVariant::Icon));
 
  123         QIcon pix = decoration.value<QIcon>();
 
  124         QPoint pixmapPoint = {option.rect.width() / 2 + i *(s_decorationSize.width() + separation), option.rect.top()};
 
  125         painter->drawPixmap(pixmapPoint, pix.pixmap(s_decorationSize));
 
  128     int midWidth = option.rect.width() / 2;
 
  129     painter->setPen(opt.palette.color(QPalette::Background));
 
  130     painter->drawLine(option.rect.left() + midWidth - SIZE_STANDARD_PIXMAP, option.rect.bottom() - 5,
 
  131                       option.rect.left() + midWidth - SIZE_STANDARD_PIXMAP, option.rect.top() + 5);
 
The KPeople namespace contains all the classes for Libkpeople.