File indexing completed on 2024-05-12 04:06:10
0001 /* 0002 This file is part of the KDE games library 0003 SPDX-FileCopyrightText: 2007 Gael de Chalendar (aka Kleag) <kleag@free.fr> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef __KCHATBASEITEMDELEGATE_H__ 0009 #define __KCHATBASEITEMDELEGATE_H__ 0010 0011 // own 0012 #include "kdegamesprivate_export.h" 0013 // Qt 0014 #include <QAbstractItemDelegate> 0015 0016 /** 0017 * \class KChatBaseItemDelegate kchatbaseitemdelegate.h <KChatBaseItemDelegate> 0018 * 0019 * A delegate (see the Qt Model/View module for details) to paint the lines of 0020 * the KChatBase list model (@ref KChatBaseModel). 0021 * 0022 * A KChatBaseItemDelegate paints two text items: first the player part then the 0023 * text part. This honors KChatBase::addMessage which also uses both. 0024 * 0025 * Colors and fonts for both parts are set in the corresponding model. 0026 */ 0027 class KDEGAMESPRIVATE_EXPORT KChatBaseItemDelegate : public QAbstractItemDelegate 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * Constructs a KChatBaseItemDelegate object 0034 */ 0035 explicit KChatBaseItemDelegate(QObject *parent = nullptr); 0036 0037 /** 0038 * Destruct a KChatBaseItemDelegate object. 0039 */ 0040 ~KChatBaseItemDelegate() override; 0041 0042 /** 0043 * Reimplementation of the default paint method. Draws the item at the 0044 * given index in the model with good fonts for player name and message. 0045 * 0046 * Should be reimplemented in inherited delegates 0047 */ 0048 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0049 0050 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QString &sender, const QString &message) const; 0051 /** 0052 * Reimplementation of the default sizeHint. Computes the given item size 0053 * depending on the name and message sizes and on the fonts they use. 0054 * 0055 * Should be reimplemented in inherited delegates 0056 */ 0057 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0058 0059 virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index, const QString &sender, const QString &message) const; 0060 }; 0061 0062 #endif