KDEGames

kchatbaseitemdelegate.cpp
1/*
2 This file is part of the KDE games library
3 SPDX-FileCopyrightText: 2007 Gael de Chalendar (aka Kleag) <kleag@free.fr>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "kchatbaseitemdelegate.h"
9
10// own
11#include "kchatbasemodel.h"
12// KF
13#include <KLocalizedString>
14// Qt
15#include <QPainter>
16
21
25
26void KChatBaseItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
27{
28 // qDebug() << "KChatBaseItemDelegate::paint";
30 paint(painter, option, index, m.first, m.second);
31}
32
34 const QStyleOptionViewItem &option,
35 const QModelIndex &index,
36 const QString &sender,
37 const QString &message) const
38{
39 // qDebug() << "KChatBaseItemDelegate::paint";
40 painter->setFont(((KChatBaseModel *)index.model())->nameFont());
41 painter->drawText(option.rect.x(), QFontMetrics(option.font).height() + option.rect.y(), i18n("%1: ", sender));
42 painter->setFont(((KChatBaseModel *)index.model())->messageFont());
43 painter->drawText(option.rect.x() + 3 + QFontMetrics(((KChatBaseModel *)index.model())->nameFont()).boundingRect(i18n("%1: ", sender)).width(),
44 QFontMetrics(option.font).height() + option.rect.y(),
45 message);
46}
47
49{
50 // qDebug() << "KChatBaseItemDelegate::sizeHint";
52 return sizeHint(option, index, m.first, m.second);
53}
54
55QSize KChatBaseItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index, const QString &sender, const QString &message) const
56{
57 // qDebug() << "KChatBaseItemDelegate::sizeHint";
58 int w = 0;
59 w += 6;
60 w += QFontMetrics(option.font).boundingRect(sender + i18n("%1: ", sender)).width();
61 w += QFontMetrics(option.font).boundingRect(message).width();
62 int h = 0;
63 h += 2;
64 if (QFontMetrics(((KChatBaseModel *)index.model())->nameFont()).lineSpacing()
65 > QFontMetrics(((KChatBaseModel *)index.model())->messageFont()).lineSpacing()) {
66 h += QFontMetrics(((KChatBaseModel *)index.model())->nameFont()).lineSpacing();
67 } else {
68 h += QFontMetrics(((KChatBaseModel *)index.model())->messageFont()).lineSpacing();
69 }
70 return QSize(w, h);
71}
72
73#include "moc_kchatbaseitemdelegate.cpp"
~KChatBaseItemDelegate() override
Destruct a KChatBaseItemDelegate object.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Reimplementation of the default sizeHint.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Reimplementation of the default paint method.
KChatBaseItemDelegate(QObject *parent=nullptr)
Constructs a KChatBaseItemDelegate object.
The class of the elements stored in the chat list model.
The model used to store messages displayed in the chat dialog messages list.
QString i18n(const char *text, const TYPE &arg...)
virtual QVariant data(const QModelIndex &index, int role) const const=0
QRect boundingRect(QChar ch) const const
int height() const const
int lineSpacing() const const
const QAbstractItemModel * model() const const
QObject * sender() const const
void drawText(const QPoint &position, const QString &text)
void setFont(const QFont &font)
int width() const const
DisplayRole
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.