KGameChat Class Reference

A Chat widget for KGame-based games. More...

#include <kgamechat.h>

Inheritance diagram for KGameChat:

Inheritance graph
[legend]
Collaboration diagram for KGameChat:

Collaboration graph
[legend]
List of all members.

Public Types

enum  SendingIds { SendToGroup = 1 }

Public Slots

virtual void addMessage (const QString &fromName, const QString &text)
 Add a text in the listbox.
virtual void addMessage (int fromId, const QString &text)
void slotReceiveMessage (int, const QByteArray &, Q_UINT32 receiver, Q_UINT32 sender)

Public Member Functions

 KGameChat (KGame *game, int msgid, KPlayer *fromPlayer, QWidget *parent)
 Construct a KGame chat widget on game that used msgid for the chat message.
 KGameChat (KGame *game, int msgId, QWidget *parent)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. To make use of this widget you need to call setFromPlayer manually.
 KGameChat (QWidget *parent)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This constructs a widget that is not usable.
virtual ~KGameChat ()
void setFromPlayer (KPlayer *player)
 This sets the fromPlayer to player.
KPlayerfromPlayer () const
void setKGame (KGame *g)
 Set the KGame object for this chat widget.
KGamegame () const
int messageId () const
void setMessageId (int msgid)
 Change the message id of the chat widget.
virtual const QString & fromName () const
 reimplemented from KChatBase

Protected Slots

void slotUnsetKGame ()
 Unsets a KGame object that has been set using setKGame before.
void slotPropertyChanged (KGamePropertyBase *, KPlayer *)
void slotAddPlayer (KPlayer *)
void slotRemovePlayer (KPlayer *)
void slotReceivePrivateMessage (int msgid, const QByteArray &buffer, Q_UINT32 sender, KPlayer *me)
 Called when KPlayer::signalNetworkData is emitted.

Protected Member Functions

bool isSendToAllMessage (int id) const
bool isToGroupMessage (int id) const
 Used to indicate whether a message shall be sent to a group of players.
bool isToPlayerMessage (int id) const
 Used to indicate whether the message shall be sent to a single player only.
int playerId (int id) const
int sendingId (int playerId) const
bool hasPlayer (int id) const
virtual QString sendToPlayerEntry (const QString &name) const
virtual void returnPressed (const QString &text)
 This is called whenever the user pushed return ie wants to send a message.

Detailed Description

A Chat widget for KGame-based games.

Call setFromPlayer() first - this will be used as the "from" part of every message you will send. Otherwise it won't work! You can also use the fromPlayer parameter in the constructor though...

Author:
Andreas Beckermann <b_mann@gmx.de>

Definition at line 43 of file kgamechat.h.


Member Enumeration Documentation

enum KGameChat::SendingIds
 

Enumerator:
SendToGroup 

Reimplemented from KChatBase.

Definition at line 71 of file kgamechat.h.


Constructor & Destructor Documentation

KGameChat::KGameChat KGame game,
int  msgid,
KPlayer fromPlayer,
QWidget *  parent
 

Construct a KGame chat widget on game that used msgid for the chat message.

The fromPlayer is the local player (see setFromPlayer).

Definition at line 65 of file kgamechat.cpp.

References fromPlayer(), and setFromPlayer().

Here is the call graph for this function:

KGameChat::KGameChat KGame game,
int  msgId,
QWidget *  parent
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. To make use of this widget you need to call setFromPlayer manually.

Definition at line 60 of file kgamechat.cpp.

KGameChat::KGameChat QWidget *  parent  ) 
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This constructs a widget that is not usable.

You must call at least setGame, setFromPlayer and setMessageId manually.

Since:
3.2

Definition at line 71 of file kgamechat.cpp.

KGameChat::~KGameChat  )  [virtual]
 

Definition at line 76 of file kgamechat.cpp.


Member Function Documentation

void KGameChat::addMessage int  fromId,
const QString &  text
[virtual, slot]
 

Definition at line 91 of file kgamechat.cpp.

References addMessage(), KGame::findPlayer(), KGameChatPrivate::mGame, and KPlayer::name().

virtual void KGameChat::addMessage const QString &  fromName,
const QString &  text
[inline, virtual, slot]
 

Add a text in the listbox.

See also signalSendMessage()

Maybe you want to replace this with a function that creates a nicer text than "fromName: text"

Update: the function layoutMessage is called by this now. This means that you will get user defined outlook on the messages :-)

Parameters:
fromName The player who sent this message
text The text to be added

Reimplemented from KChatBase.

Definition at line 121 of file kgamechat.h.

References KChatBase::addMessage().

Referenced by addMessage(), and slotReceiveMessage().

const QString & KGameChat::fromName  )  const [virtual]
 

reimplemented from KChatBase

Returns:
KPlayer::name() for the player set by setFromPlayer

Implements KChatBase.

Definition at line 190 of file kgamechat.cpp.

References KGameChatPrivate::mFromPlayer, and KPlayer::name().

Here is the call graph for this function:

KPlayer * KGameChat::fromPlayer  )  const
 

Definition at line 250 of file kgamechat.cpp.

References KGameChatPrivate::mFromPlayer.

Referenced by KGameChat().

KGame * KGameChat::game  )  const
 

Definition at line 245 of file kgamechat.cpp.

References KGameChatPrivate::mGame.

bool KGameChat::hasPlayer int  id  )  const [protected]
 

Returns:
True if the player with this ID was added before (see slotAddPlayer)

Definition at line 193 of file kgamechat.cpp.

References sendingId().

Referenced by slotAddPlayer(), and slotRemovePlayer().

Here is the call graph for this function:

bool KGameChat::isSendToAllMessage int  id  )  const [protected]
 

Parameters:
id The ID of the sending entry, as returned by KChatBase::sendingEntry
Returns:
True if the entry "send to all" was selected, otherwise false

Definition at line 157 of file kgamechat.cpp.

References KChatBase::SendToAll.

Referenced by returnPressed().

bool KGameChat::isToGroupMessage int  id  )  const [protected]
 

Used to indicate whether a message shall be sent to a group of players.

Note that this was not yet implemented when this doc was written so this description might be wrong. (FIXME)

Parameters:
id The ID of the sending entry, as returned by KChatBase::sendingEntry
Returns:
True if the message is meant to be sent to a group (see KPlayer::group), e.g. if "send to my group" was selected.

Definition at line 160 of file kgamechat.cpp.

References KGameChatPrivate::mToMyGroup.

Referenced by returnPressed().

bool KGameChat::isToPlayerMessage int  id  )  const [protected]
 

Used to indicate whether the message shall be sent to a single player only.

Note that you can also call isSendToAllMessage and isToGroupMessage - if both return false it must be a player message. This behaviour might be changed later - so don't depend on it.

See also toPlayerId

Parameters:
id The ID of the sending entry, as returned by KChatBase::sendingEntry
Returns:
True if the message shall be sent to a special player, otherwise false.

Definition at line 163 of file kgamechat.cpp.

References KGameChatPrivate::mSendId2PlayerId.

Referenced by playerId(), and returnPressed().

int KGameChat::messageId  )  const
 

Returns:
The id of the messages produced by KGameChat. The id will be used in KGame as parameter msgid in the method KGame::sendMessage

Definition at line 154 of file kgamechat.cpp.

References KGameChatPrivate::mMessageId.

Referenced by returnPressed(), and slotReceiveMessage().

int KGameChat::playerId int  id  )  const [protected]
 

Parameters:
id The ID of the sending entry, as returned by KChatBase::sendingEntry
Returns:
The ID of the player (see KPlayer::id) the sending entry belongs to. Note that the parameter id is an id as returned by ref KChatBase::sendingEntry and the id this method returns is a KPlayer ID. If isToPlayerMessage returns false this method returns -1

Definition at line 170 of file kgamechat.cpp.

References isToPlayerMessage(), and KGameChatPrivate::mSendId2PlayerId.

Referenced by returnPressed().

Here is the call graph for this function:

void KGameChat::returnPressed const QString &  text  )  [protected, virtual]
 

This is called whenever the user pushed return ie wants to send a message.

Note that you MUST add the message to the widget when this function is called as it has already been added to the KCompletion object of the KLineEdit widget!

Must be implemented in derived classes

Parameters:
text The message to be sent

Implements KChatBase.

Definition at line 108 of file kgamechat.cpp.

References KPlayer::group(), KPlayer::id(), isSendToAllMessage(), isToGroupMessage(), isToPlayerMessage(), messageId(), KGameChatPrivate::mFromPlayer, KGameChatPrivate::mGame, KPlayer::name(), playerId(), KGame::sendGroupMessage(), KChatBase::sendingEntry(), and KGameNetwork::sendMessage().

Here is the call graph for this function:

int KGameChat::sendingId int  playerId  )  const [protected]
 

Parameters:
playerId The ID of the KPlayer object
Returns:
The ID of the sending entry (see KChatBase) or -1 if the player id was not found.

Definition at line 179 of file kgamechat.cpp.

References KGameChatPrivate::mSendId2PlayerId.

Referenced by hasPlayer(), slotAddPlayer(), slotPropertyChanged(), and slotRemovePlayer().

QString KGameChat::sendToPlayerEntry const QString &  name  )  const [protected, virtual]
 

Parameters:
name The name of the added player
Returns:
A string that will be added as sending entry in KChatBase. By default this is "send to name" where name is the name that you specify. See also KChatBase::addSendingEntry

Definition at line 167 of file kgamechat.cpp.

void KGameChat::setFromPlayer KPlayer player  ) 
 

This sets the fromPlayer to player.

The fromPlayer is the player that will appear as "from" when you send messages through this widget.

Parameters:
player The player of this widget

Definition at line 198 of file kgamechat.cpp.

References KChatBase::addSendingEntry(), KChatBase::changeSendingEntry(), KPlayer::group(), KGameChatPrivate::mFromPlayer, KGameChatPrivate::mToMyGroup, KChatBase::nextId(), and KChatBase::removeSendingEntry().

Referenced by KGameChat(), and KGameDialogChatConfig::setOwner().

Here is the call graph for this function:

void KGameChat::setKGame KGame g  ) 
 

Set the KGame object for this chat widget.

All messages will be sent through this object. You don't have to implement any send functions, just call this function, call setFromPlayer and be done :-)

Parameters:
g The KGame object the messages will be sent through

Definition at line 221 of file kgamechat.cpp.

References KGameChatPrivate::mGame, KGame::playerList(), slotAddPlayer(), slotReceiveMessage(), slotRemovePlayer(), and slotUnsetKGame().

Referenced by KGameDialogChatConfig::setKGame().

Here is the call graph for this function:

void KGameChat::setMessageId int  msgid  ) 
 

Change the message id of the chat widget.

It is recommended that you don't use this but prefer the constructor instead, but in certain situations (such as using this widget in Qt designer) it may be useful to change the message id.

See also messageId

Since:
3.2

Definition at line 151 of file kgamechat.cpp.

References KGameChatPrivate::mMessageId.

void KGameChat::slotAddPlayer KPlayer  )  [protected, slot]
 

Definition at line 270 of file kgamechat.cpp.

References KChatBase::addSendingEntry(), KChatBase::comboBoxItem(), hasPlayer(), KPlayer::id(), KGameChatPrivate::mSendId2PlayerId, KPlayer::name(), KChatBase::nextId(), sendingId(), slotPropertyChanged(), and slotReceivePrivateMessage().

Referenced by setKGame().

void KGameChat::slotPropertyChanged KGamePropertyBase ,
KPlayer
[protected, slot]
 

Definition at line 307 of file kgamechat.cpp.

References KChatBase::changeSendingEntry(), KPlayer::id(), KGamePropertyBase::id(), KGamePropertyBase::IdName, KPlayer::name(), and sendingId().

Referenced by slotAddPlayer().

void KGameChat::slotReceiveMessage int  ,
const QByteArray &  ,
Q_UINT32  receiver,
Q_UINT32  sender
[slot]
 

Definition at line 329 of file kgamechat.cpp.

References addMessage(), and messageId().

Referenced by setKGame().

void KGameChat::slotReceivePrivateMessage int  msgid,
const QByteArray &  buffer,
Q_UINT32  sender,
KPlayer me
[protected, slot]
 

Called when KPlayer::signalNetworkData is emitted.

The message gets forwarded to slotReceiveMessage if me equals fromPlayer.

Definition at line 320 of file kgamechat.cpp.

References KPlayer::id().

Referenced by slotAddPlayer().

void KGameChat::slotRemovePlayer KPlayer  )  [protected, slot]
 

Definition at line 290 of file kgamechat.cpp.

References hasPlayer(), KPlayer::id(), KGameChatPrivate::mSendId2PlayerId, KChatBase::removeSendingEntry(), and sendingId().

Referenced by setKGame().

void KGameChat::slotUnsetKGame  )  [protected, slot]
 

Unsets a KGame object that has been set using setKGame before.

You don't have to call this - this is usually done automatically.

Definition at line 255 of file kgamechat.cpp.

References KGameChatPrivate::mGame, KGameChatPrivate::mSendId2PlayerId, KGameChatPrivate::mToMyGroup, and KChatBase::removeSendingEntry().

Referenced by setKGame().


The documentation for this class was generated from the following files:
Generated on Wed Aug 23 18:05:03 2006 for libkdegames by  doxygen 1.4.6