19 #include "emaillistviewdelegate.h"
22 #include <KLocalizedString>
23 #include <QApplication>
25 QSize EmailListViewDelegate::sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
29 s = QSize(option.decorationSize.width(), option.decorationSize.height());
30 s.setHeight(option.decorationSize.height() * 2);
34 void EmailListViewDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
36 QStyledItemDelegate::paint(painter, option, index);
40 QString subject = index.data(EmailListModel::SubjectRole).toString();
41 QString body = index.data(EmailListModel::BodyRole).toString();
42 QString time = index.data(EmailListModel::TimeRole).toString();
44 QFont subjectFont = QApplication::font();
45 QFont timeFont = QApplication::font();
46 QFont bodyFont = QApplication::font();
47 QFontMetrics fm = QFontMetrics(subjectFont);
48 timeFont.setItalic(
true);
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());
56 painter->setFont(subjectFont);
57 painter->drawText(subjectRect, i18n(
"Subject: ") + subject);
59 painter->setFont(bodyFont);
60 painter->setPen(Qt::darkGray);
61 painter->drawText(bodyRect, fm.elidedText(body, Qt::ElideRight, bodyRect.width()));
63 painter->setFont(timeFont);
64 painter->drawText(timeRect, Qt::AlignRight, time);
69 #include "emaillistviewdelegate.moc"