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

akonadi_next

  • sources
  • kde-4.12
  • kdepim
  • akonadi_next
amazingdelegate.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "amazingdelegate.h"
21 
22 #include <QPainter>
23 
24 #include <kdebug.h>
25 #include <akonadi/entitytreemodel.h>
26 #include <kabc/addressee.h>
27 #include <klocalizedstring.h>
28 #include <akonadi/entitydisplayattribute.h>
29 
30 using namespace Akonadi;
31 
32 AmazingContactItemDelegate::AmazingContactItemDelegate(QObject* parent): QStyledItemDelegate(parent)
33 {
34 
35 }
36 
37 void AmazingContactItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
38 {
39 
40  Item item = index.data(EntityTreeModel::ItemRole).value<Item>();
41 
42  if (!item.isValid())
43  QStyledItemDelegate::paint(painter, option, index);
44 
45  if (!item.hasPayload<KABC::Addressee>())
46  {
47  kWarning() << "Not a KABC::Addressee" << item.id() << item.remoteId();
48  return;
49  }
50 
51  KABC::Addressee addressee = item.payload<KABC::Addressee>();
52 
53  painter->save();
54 
55  if (option.state & QStyle::State_Selected)
56  painter->fillRect(option.rect, option.palette.highlight());
57 
58  int PaintingScaleFactor = 2;
59  int yOffset = (option.rect.height() - PaintingScaleFactor) / 2;
60  painter->translate(option.rect.x(), option.rect.y() + yOffset);
61 
62  Collection parentCollection = index.data(EntityTreeModel::ParentCollectionRole).value<Collection>();
63 
64  QString name = addressee.givenName() + QLatin1Char( ' ' ) + addressee.familyName();
65 
66  KABC::Picture pic =addressee.photo();
67 
68  if (!pic.isEmpty())
69  {
70  QImage image = pic.data();
71  painter->drawImage(QRect(0, 0, 40, 40), image);
72  }
73 
74  const QString parentName = parentCollection.displayName();
75 
76  QString email = addressee.preferredEmail();
77  if (email.isEmpty())
78  email =
79  i18nc( "An email address is not known for a contact. This is the default text provided",
80  "<placeholder>no email</placeholder>" );
81 
82  painter->drawText(50, 0, name);
83  painter->drawText(50, 15, email);
84  painter->drawText(50, 30, parentName);
85 
86 
87  painter->restore();
88 
89 }
90 
91 
92 QSize AmazingContactItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
93 {
94  Item item = index.data(EntityTreeModel::ItemRole).value<Item>();
95 
96  if (!item.isValid())
97  return QStyledItemDelegate::sizeHint(option, index);
98 
99  QSize s = QStyledItemDelegate::sizeHint(option, index);
100  s.setHeight( s.height() * 4.5);
101  return s;
102 
103 }
104 
QObject
QStyledItemDelegate
amazingdelegate.h
AmazingContactItemDelegate::AmazingContactItemDelegate
AmazingContactItemDelegate(QObject *parent=0)
Definition: amazingdelegate.cpp:32
AmazingContactItemDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: amazingdelegate.cpp:92
AmazingContactItemDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: amazingdelegate.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi_next

Skip menu "akonadi_next"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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