KDEGames

kchatbasemodel.h
1 /*
2  This file is part of the KDE games library
3  SPDX-FileCopyrightText: 2001 Andreas Beckermann <[email protected]>
4  SPDX-FileCopyrightText: 2007 Gael de Chalendar (aka Kleag) <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 
9 #ifndef __KCHATBASEMODEL_H__
10 #define __KCHATBASEMODEL_H__
11 
12 // own
13 #include "libkdegamesprivate_export.h"
14 // Qt
15 #include <QAbstractListModel>
16 #include <QPair>
17 #include <QSharedDataPointer>
18 #include <QLoggingCategory>
19 // Std
20 #include <memory>
21 
22 Q_DECLARE_LOGGING_CATEGORY(GAMES_LIB)
23 
24 class KChatBaseModelPrivate;
25 class KChatBaseMessagePrivate;
26 class KConfig;
27 
28 /**
29  * \class KChatBaseMessage kchatbasemodel.h <KChatBaseModel>
30  *
31  * @short The class of the elements stored in the chat list model
32  *
33  * It's a pair of strings where the first element is the sender name and the
34  * second one is the actual message. It furthermore indicates the type of the
35  * message: normal or system
36  */
37 class KDEGAMESPRIVATE_EXPORT KChatBaseMessage : public QPair< QString, QString >
38 {
39  public:
40  /** The different types of messages */
42  {
43  Normal,
44  System
45  };
46 
47  /** Default constructor. Necessary for Qt metatypes */
49 
50  /** Initializing constructor */
51  KChatBaseMessage(const QString& sender, const QString& message,
52  MessageType type=Normal);
53 
54  /** Copy constructor. Necessary for Qt metatypes */
56 
57  KChatBaseMessage & operator=(const KChatBaseMessage& m);
58 
59  /** Default destructor */
60  virtual ~KChatBaseMessage();
61 
62  private:
64 };
65 Q_DECLARE_METATYPE(KChatBaseMessage)
66 
67 /**
68  * \class KChatBaseModel kchatbasemodel.h <KChatBaseModel>
69  *
70  * The model used to store messages displayed in the chat dialog messages
71  * list. This is a list model and thus derived from @ref QAbstractListModel
72  * and implementing its abstract API.
73  */
74 class KDEGAMESPRIVATE_EXPORT KChatBaseModel : public QAbstractListModel
75 {
76  Q_OBJECT
77 
78 public:
79  /** Default constructor */
80  explicit KChatBaseModel(QObject *parent = nullptr);
81 
82  /** Default destructor */
83  ~KChatBaseModel() override;
84 
85  /**
86  * Reimplementation of the inherited method.
87  * @return The current number of messages in the list
88  */
89  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
90 
91 
92  /**
93  * Reimplementation of the inherited method.
94  * @return The KChatBaseMessage at the given index as a QVariant
95  */
96  QVariant data(const QModelIndex &index, int role) const override;
97 
98  /**
99  * Set the font that is used for the name part of a message. See also
100  * nameFont and setBothFont
101  **/
102  void setNameFont(const QFont& font);
103 
104  /**
105  * Set the font that is used for the message part of a message.
106  * @see messageFont, setBothFont
107  **/
108  void setMessageFont(const QFont& font);
109 
110  /**
111  * This sets both - nameFont and messageFont to font. You
112  * probably want to use this if you don't wish to distinguish between
113  * these parts of a message.
114  * @param font A font used for both nameFont and messageFont
115  **/
116  void setBothFont(const QFont& font);
117 
118  /**
119  * Same as setNameFont but applies only to system messages.
120  **/
121  void setSystemNameFont(const QFont& font);
122 
123  /**
124  * Same as setMessageFont but applies only to system messages.
125  **/
126  void setSystemMessageFont(const QFont& font);
127 
128  /**
129  * Same as setBothFont but applies only to system messages.
130  **/
131  void setSystemBothFont(const QFont& font);
132 
133  /**
134  * This font should be used for the name (the "from: " part) of a
135  * message. layoutMessage uses this to set the font using
136  * KChatBaseItemDelegate::setNameFont but if you want to overwrite
137  * layoutMessage you should do this yourself.
138  * @return The font that is used for the name part of the message.
139  **/
140  const QFont& nameFont() const;
141 
142  /**
143  * This font should be used for a message. layoutMessage sets the
144  * font of a message using KChatBaseItemDelegate::setMessageFont but if you
145  * replace layoutMessage with your own function you should use
146  * messageFont() yourself.
147  * @return The font that is used for a message
148  **/
149  const QFont& messageFont() const;
150 
151  /**
152  * Same as systemNameFont but applies only to system messages.
153  **/
154  const QFont& systemNameFont() const;
155 
156  /**
157  * Same as systemMessageFont but applies only to system messages.
158  **/
159  const QFont& systemMessageFont() const;
160 
161  /**
162  * Save the configuration of the dialog to a KConfig object. If
163  * the supplied KConfig pointer is NULL then KGlobal::config() is used
164  * instead (and the group is changed to "KChatBase") butr the current
165  * group is restored at the end.
166  * @param conf A pointer to the KConfig object to save the config
167  * to. If you use 0 then KGlobal::config() is used and the group is changed
168  * to "KChatBase" (the current group is restored at the end).
169  **/
170  virtual void saveConfig(KConfig* conf = nullptr);
171 
172  /**
173  * Read the configuration from a KConfig object. If the pointer is
174  * NULL KGlobal::config() is used and the group is changed to "KChatBase".
175  * The current KConfig::group is restored after this call.
176  **/
177  virtual void readConfig(KConfig* conf = nullptr);
178 
179  /**
180  * Set the maximum number of items in the list. If the number of item
181  * exceeds the maximum as many items are deleted (oldest first) as
182  * necessary. The number of items will never exceed this value.
183  * @param maxItems the maximum number of items. -1 (default) for
184  * unlimited.
185  **/
186  void setMaxItems(int maxItems);
187 
188  /**
189  * Clear all messages in the list.
190  **/
191  void clear();
192 
193  /**
194  * @return The maximum number of messages in the list. -1 is unlimited. See also
195  * setMaxItems
196  **/
197  int maxItems() const;
198 
199 public Q_SLOTS:
200  /**
201  * Add a text in the listbox. See also signalSendMessage()
202  *
203  * Maybe you want to replace this with a function that creates a nicer text
204  * than "fromName: text"
205  *
206  * Update: the function layoutMessage is called by this now. This
207  * means that you will get user defined outlook on the messages :-)
208  * @param fromName The player who sent this message
209  * @param text The text to be added
210  **/
211  virtual void addMessage(const QString& fromName, const QString& text);
212 
213  /**
214  * This works just like addMessage but adds a system message. System
215  * messages will have a different look than player messages.
216  *
217  * You may wish to use this to display status information from your game.
218  **/
219  virtual void addSystemMessage(const QString& fromName, const QString& text);
220 
221  /**
222  * This clears all messages in the view. Note that only the messages are
223  * cleared, not the sender names in the combo box!
224  **/
225  void slotClear();
226 
227  private:
228  std::unique_ptr<KChatBaseModelPrivate> const d;
229 };
230 
231 #endif
The class of the elements stored in the chat list model.
MessageType
The different types of messages.
PartitionTable::TableType type
The model used to store messages displayed in the chat dialog messages list.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:34:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.