2 This file is part of the KDE games library
3 Copyright (C) 2007 Gael de Chalendar (aka Kleag) <kleag@free.fr>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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 Library General Public License for more details.
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
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "kchatbaseitemdelegate.h"
21 #include "kchatbasemodel.h"
27 KChatBaseItemDelegate::KChatBaseItemDelegate(QObject
*parent
) :
28 QAbstractItemDelegate(parent
)
32 KChatBaseItemDelegate::~KChatBaseItemDelegate()
36 void KChatBaseItemDelegate::paint(QPainter
*painter
, const QStyleOptionViewItem
&option
,
37 const QModelIndex
&index
) const
39 // kDebug() << "KChatBaseItemDelegate::paint";
40 KChatBaseMessage m
= index
.model()->data(index
, Qt::DisplayRole
).value
<KChatBaseMessage
>();
41 paint(painter
, option
, index
,m
.first
, m
.second
);
44 void KChatBaseItemDelegate::paint(QPainter
*painter
,
45 const QStyleOptionViewItem
&option
,
46 const QModelIndex
&index
,
47 const QString
& sender
,
48 const QString
& message
) const
50 // kDebug() << "KChatBaseItemDelegate::paint";
51 QFontMetrics fm
= painter
->fontMetrics();
52 painter
->setFont(((KChatBaseModel
*)index
.model())->nameFont());
53 painter
->drawText(option
.rect
.x(),
54 QFontMetrics(option
.font
).height()+option
.rect
.y(), i18n("%1: ",sender
));
55 painter
->setFont(((KChatBaseModel
*)index
.model())->messageFont());
56 painter
->drawText(option
.rect
.x() + 3 + QFontMetrics(((KChatBaseModel
*)index
.model())->nameFont()).width(i18n("%1: ",sender
)),
57 QFontMetrics(option
.font
).height()+option
.rect
.y(), message
);
60 QSize
KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem
& option
,
61 const QModelIndex
& index
) const
63 // kDebug() << "KChatBaseItemDelegate::sizeHint";
64 KChatBaseMessage m
= index
.model()->data(index
, Qt::DisplayRole
).value
<KChatBaseMessage
>();
65 return sizeHint(option
, index
, m
.first
, m
.second
);
68 QSize
KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem
& option
,
69 const QModelIndex
& index
,
70 const QString
& sender
,
71 const QString
& message
) const
73 // kDebug() << "KChatBaseItemDelegate::sizeHint";
76 w
+= QFontMetrics(option
.font
).width(sender
+i18n("%1: ",sender
));
77 w
+= QFontMetrics(option
.font
).width(message
);
80 if (QFontMetrics(((KChatBaseModel
*)index
.model())->nameFont()).lineSpacing() >
81 QFontMetrics(((KChatBaseModel
*)index
.model())->messageFont()).lineSpacing())
83 h
+= QFontMetrics(((KChatBaseModel
*)index
.model())->nameFont()).lineSpacing();
87 h
+= QFontMetrics(((KChatBaseModel
*)index
.model())->messageFont()).lineSpacing();
92 #include "kchatbaseitemdelegate.moc"