KDEGames

kgamechat.h
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001-2002 Andreas Beckermann ([email protected])
4  Copyright (C) 2001 Martin Heni (kde at heni-online.de)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KGAMECHAT_H__
22 #define __KGAMECHAT_H__
23 
24 #include <QString>
25 
26 #include "../kchatbase.h"
27 #include "libkdegamesprivate_export.h"
28 class KPlayer;
29 class KGame;
30 class KGamePropertyBase;
31 
32 class KGameChatPrivate;
33 
45 class KDEGAMESPRIVATE_EXPORT KGameChat : public KChatBase
46 {
47  Q_OBJECT
48 public:
54  KGameChat(KGame* game, int msgid, KPlayer* fromPlayer, QWidget * parent, KChatBaseModel* model=nullptr, KChatBaseItemDelegate* delegate=nullptr);
55 
61  KGameChat(KGame* game, int msgId, QWidget* parent, KChatBaseModel* model=nullptr, KChatBaseItemDelegate* delegate=nullptr);
62 
68  explicit KGameChat(QWidget* parent);
69 
70  virtual ~KGameChat();
71 
72  enum SendingIds {
73  SendToGroup = 1
74  };
75 
82  void setFromPlayer(KPlayer* player);
83 
84  KPlayer* fromPlayer() const;
85 
93  void setKGame(KGame* g);
94 
95  KGame* game() const;
96 
101  int messageId() const;
102 
111  void setMessageId(int msgid);
112 
117  QString fromName() const override;
118 
119 
120 public Q_SLOTS:
121  void addMessage(const QString& fromName, const QString& text) override { KChatBase::addMessage(fromName, text);}
122  virtual void addMessage(int fromId, const QString& text);
123 
124  void slotReceiveMessage(int, const QByteArray&, quint32 receiver, quint32 sender);
125 
126 protected:
131  bool isSendToAllMessage(int id) const;
132 
141  bool isToGroupMessage(int id) const;
142 
143 
156  bool isToPlayerMessage(int id) const;
157 
167  int playerId(int id) const;
168 
174  int sendingId(int playerId) const;
175 
180  bool hasPlayer(int id) const;
181 
188  virtual QString sendToPlayerEntry(const QString& name) const;
189 
190 
191 protected Q_SLOTS:
197  void slotUnsetKGame();
198 
199 
200  void slotPropertyChanged(KGamePropertyBase*, KPlayer*);
201  void slotAddPlayer(KPlayer*);
202  void slotRemovePlayer(KPlayer*);
203 
209  void slotReceivePrivateMessage(int msgid, const QByteArray& buffer, quint32 sender, KPlayer* me);
210 
211 protected:
212  void returnPressed(const QString& text) override;
213 
214 private:
215  void init(KGame* g, int msgid);
216 
217 private:
218  KGameChatPrivate* const d;
219 };
220 
221 #endif
virtual QString fromName() const =0
virtual void returnPressed(const QString &text)=0
This is called whenever the user pushed return ie wants to send a message.
The base class for chat widgets.
Definition: kchatbase.h:75
A delegate (see the Qt Model/View module for details) to paint the lines of the KChatBase list model ...
virtual void addMessage(const QString &fromName, const QString &text)
Add a text in the listbox.
Definition: kchatbase.cpp:357
Base class for a game player.
Definition: kplayer.h:69
Base class of KGameProperty.
Definition: kgameproperty.h:45
QCA_EXPORT void init()
The main KDE game object.
Definition: kgame.h:64
A Chat widget for KGame-based games.
Definition: kgamechat.h:45
The model used to store messages displayed in the chat dialog messages list.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:36:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.