1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
This file is part of the KDE games library
Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KCHAT_H__
#define __KCHAT_H__
#include <tqstring.h>
#include "kchatbase.h"
#include <kdemacros.h>
class KChatPrivate;
/**
* @short A chat widget for non-KGame games
*
* Docu is TODO
*
* @author Andreas Beckermann <b_mann@gmx.de>
**/
class KDE_EXPORT KChat : public KChatBase
{
Q_OBJECT
TQ_OBJECT
public:
/**
* @param parent The parent widget for this widget.
* @param twoPlayerGame If true the combo box where the player can
* choose to send to a single player or to all players will not be added
* as you will hardly need it in 2-player games.
**/
KChat(TQWidget* parent, bool twoPlayerGame = false);
virtual ~KChat();
/**
* Equivalent to player(fromId())
* @return The name that will be shown for messages from this widget.
* That is the string from @ref setFromNickname
**/
virtual const TQString& fromName() const;
/**
* This sets the name that will be shown on all chat widgets if this
* widget sends a message. See signalSendMessage
* @param name The name of the player owning this widget
**/
void setFromNickname(const TQString& name);
// TODO:
// void setPlayerList(TQIntDict<TQString>);// use this for non-KGame use
/**
* Adds a player nickname.
* @return The unique ID of the player
**/
int addPlayer(const TQString& nick);
/**
* Removes all players with this nickname. Better don't use this as it
* will remove *all* players with this nickname. Save the id instead and
* call removePlayer(id)
* @param nick The nickname of the removed players
**/
void removePlayer(const TQString& nick);
/**
* Removes the player with this id, as returned by @ref addPlayer
* @param id The id of the player to be removed
**/
void removePlayer(int id);
/**
* @return true if the messages which will be sent from here will be
* added automatically using @ref KChatBase::addMessage. See also @ref
* setAutoAddMessages
**/
bool autoAddMessages() const;
/**
* Usually the messages which will be sent from here (see @ref
* signalSendMessage) are added autmatically to this widget. But under
* some circumstances that would be very unhandy. So you can deactivate
* this behaviour here and call @ref KChatBase::addMessage yourself
* @param add If true (default) messages sent from here will be added
* automatically. Otherwise you will have to add them yourself
**/
void setAutoAddMessages(bool add);
/**
* @return The nickname of the player which belongs to this id
**/
const TQString& player(int id) const;
/**
* @return The ID that belongs to the local player.
* @see setFromNickname
**/
int fromId() const;
signals:
/**
* This signal is emitted when the player wants to send a message.
*
* The message is added automatically using @ref KChatBase::addMessage if @ref
* autoAddMessages is enabled.
* @param id The id of the player who sends the message - see
* setFromNickname and player
* @param msg The message itself
**/
void signalSendMessage(int id, const TQString& msg);
protected:
/**
* This emits @ref signalSendMessage and, if @ref autoAddMessages is
* true, calls @ref KChatBase::addMessage
**/
virtual void returnPressed(const TQString&);
/**
* The Id of the next player. Incremented after every call.
**/
int uniqueId();
private:
void init();
KChatPrivate* d;
};
#endif
|