• Skip to content
  • Skip to link menu
KDE API Documentation - emaillistviewdelegate.cpp Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • src
  • widgets
  • plugins
emaillistviewdelegate.cpp
1 /*
2  Copyright 2014 Nilesh Suthar <nileshsuthar@live.in>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "emaillistviewdelegate.h"
20 
21 #include <QPainter>
22 #include <KLocalizedString>
23 #include <QApplication>
24 
25 QSize EmailListViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
26 {
27  Q_UNUSED(index);
28  QSize s;
29  s = QSize(option.decorationSize.width(), option.decorationSize.height());
30  s.setHeight(option.decorationSize.height() * 2);
31  return s;
32 }
33 
34 void EmailListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
35 {
36  QStyledItemDelegate::paint(painter, option, index);
37 
38  painter->save();
39 
40  QString subject = index.data(EmailListModel::SubjectRole).toString();
41  QString body = index.data(EmailListModel::BodyRole).toString();
42  QString time = index.data(EmailListModel::TimeRole).toString();
43 
44  QFont subjectFont = QApplication::font();
45  QFont timeFont = QApplication::font();
46  QFont bodyFont = QApplication::font();
47  QFontMetrics fm = QFontMetrics(subjectFont);
48  timeFont.setItalic(true);
49 
50  QRect bodyRect = option.rect;
51  QRect timeRect = option.rect;
52  QRect subjectRect = option.rect;
53  subjectRect.setTop(subjectRect.top() + 5);
54  bodyRect.setTop(subjectRect.top() + fm.height());
55 
56  painter->setFont(subjectFont);
57  painter->drawText(subjectRect, i18n("Subject: ") + subject);
58 
59  painter->setFont(bodyFont);
60  painter->setPen(Qt::darkGray);
61  painter->drawText(bodyRect, fm.elidedText(body, Qt::ElideRight, bodyRect.width()));
62 
63  painter->setFont(timeFont);
64  painter->drawText(timeRect, Qt::AlignRight, time);
65 
66  painter->restore();
67 }
68 
69 #include "emaillistviewdelegate.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

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

Class Picker

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