home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kgame / kgamechat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.6 KB  |  224 lines

  1. /*
  2.     This file is part of the KDE games library
  3.     Copyright (C) 2001-2002 Andreas Beckermann (b_mann@gmx.de)
  4.     Copyright (C) 2001 Martin Heni (martin@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.h>
  25.  
  26. #include "kchatbase.h"
  27. #include <kdemacros.h>
  28. class KPlayer;
  29. class KGame;
  30. class KGamePropertyBase;
  31.  
  32. class KGameChatPrivate;
  33.  
  34. /**
  35.  * @short A Chat widget for KGame-based games
  36.  *
  37.  * Call @ref setFromPlayer() first - this will be used as the "from" part of
  38.  * every message you will send. Otherwise it won't work! You can also use the
  39.  * fromPlayer parameter in the constructor though...
  40.  *
  41.  * @author Andreas Beckermann <b_mann@gmx.de>
  42.  **/
  43. class KDE_EXPORT KGameChat : public KChatBase
  44. {
  45.     Q_OBJECT
  46. public:
  47.     /**
  48.      * Construct a @ref KGame chat widget on @p game that used @p msgid for
  49.      * the chat message. The @p fromPlayer is the local player (see @ref
  50.      * setFromPlayer).
  51.      **/
  52.     KGameChat(KGame* game, int msgid, KPlayer* fromPlayer, QWidget * parent);
  53.  
  54.     /**
  55.      * @overload
  56.      * To make use of this widget you need to call @ref setFromPlayer
  57.      * manually.
  58.      **/
  59.     KGameChat(KGame* game, int msgId, QWidget* parent);
  60.  
  61.     /**
  62.      * @overload
  63.      * This constructs a widget that is not usable. You must call at least
  64.      * setGame, setFromPlayer and setMessageId manually.
  65.      * @since 3.2
  66.      **/
  67.     KGameChat(QWidget* parent);
  68.  
  69.     virtual ~KGameChat();
  70.  
  71.     enum SendingIds {
  72.         SendToGroup = 1
  73.     };
  74.  
  75.     /**
  76.      * This sets the fromPlayer to @p player. The fromPlayer is the
  77.      * player that will appear as "from" when you send messages through this
  78.      * widget.
  79.      * @param player The player of this widget
  80.      **/
  81.     void setFromPlayer(KPlayer* player);
  82.  
  83.     KPlayer* fromPlayer() const;
  84.  
  85.     /**
  86.      * Set the @ref KGame object for this chat widget. All messages will be
  87.      * sent through this object. You don't have to implement any send
  88.      * functions, just call this function, call @ref setFromPlayer and be
  89.      * done :-)
  90.      * @param g The @ref KGame object the messages will be sent through
  91.      **/
  92.     void setKGame(KGame* g);
  93.  
  94.     KGame* game() const;
  95.  
  96.     /**
  97.      * @return The id of the messages produced by KGameChat. The id will be
  98.      * used in @ref KGame as parameter msgid in the method @ref KGame::sendMessage
  99.      **/
  100.     int messageId() const;
  101.  
  102.     /**
  103.      * Change the message id of the chat widget. It is recommended that you
  104.      * don't use this but prefer the constructor instead, but in certain
  105.      * situations (such as using this widget in Qt designer) it may be
  106.      * useful to change the message id.
  107.      *
  108.      * See also @ref messageId
  109.      * @since 3.2
  110.      **/
  111.     void setMessageId(int msgid);
  112.  
  113.     /**
  114.      * reimplemented from @ref KChatBase
  115.      * @return @ref KPlayer::name() for the player set by @ref setFromPlayer
  116.      **/
  117.     virtual const QString& fromName() const;
  118.  
  119.  
  120. public slots:
  121.     virtual void addMessage(const QString& fromName, const QString& text) { KChatBase::addMessage(fromName, text);}
  122.     virtual void addMessage(int fromId, const QString& text);
  123.  
  124.     void slotReceiveMessage(int, const QByteArray&, Q_UINT32 receiver, Q_UINT32 sender);
  125.  
  126. protected:
  127.     /**
  128.      * @param id The ID of the sending entry, as returned by @ref
  129.      * KChatBase::sendingEntry
  130.      * @return True if the entry "send to all" was selected, otherwise false
  131.      **/
  132.     bool isSendToAllMessage(int id) const;
  133.  
  134.     /**
  135.      * Used to indicate whether a message shall be sent to a group of
  136.      * players. Note that this was not yet implemented when this doc was
  137.      * written so this description might be wrong. (FIXME)
  138.      * @param id The ID of the sending entry, as returned by @ref
  139.      * KChatBase::sendingEntry
  140.      * @return True if the message is meant to be sent to a group (see @ref
  141.      * KPlayer::group), e.g. if "send to my group" was selected.
  142.      **/
  143.     bool isToGroupMessage(int id) const;
  144.     
  145.  
  146.     /**
  147.      * Used to indicate whether the message shall be sent to a single player
  148.      * only. Note that you can also call @ref isSendToAllMessage and @ref
  149.      * isToGroupMessage - if both return false it must be a player message.
  150.      * This behaviour might be changed later - so don't depend on it.
  151.      *
  152.      * See also toPlayerId
  153.      * @param id The ID of the sending entry, as returned by 
  154.      * KChatBase::sendingEntry
  155.      * @return True if the message shall be sent to a special player,
  156.      * otherwise false.
  157.      **/
  158.     bool isToPlayerMessage(int id) const;
  159.  
  160.     /**
  161.      * @param id The ID of the sending entry, as returned by
  162.      * KChatBase::sendingEntry
  163.      * @return The ID of the player (see KPlayer::id) the sending entry
  164.      * belongs to. Note that the parameter id is an id as returned by ref
  165.      * KChatBase::sendingEntry and the id this method returns is a 
  166.      * KPlayer ID. If isToPlayerMessage returns false this method
  167.      * returns -1
  168.      **/
  169.     int playerId(int id) const;
  170.  
  171.     /**
  172.      * @param playerId The ID of the KPlayer object
  173.      * @return The ID of the sending entry (see KChatBase) or -1 if
  174.      * the player id was not found.
  175.      **/
  176.     int sendingId(int playerId) const;
  177.  
  178.     /**
  179.      * @return True if the player with this ID was added before (see 
  180.      * slotAddPlayer)
  181.      **/
  182.     bool hasPlayer(int id) const;
  183.  
  184.     /**
  185.      * @param name The name of the added player
  186.      * @return A string that will be added as sending entry in @ref
  187.      * KChatBase. By default this is "send to name" where name is the name
  188.      * that you specify. See also KChatBase::addSendingEntry
  189.      **/
  190.     virtual QString sendToPlayerEntry(const QString& name) const;
  191.  
  192.  
  193. protected slots:
  194.     /**
  195.      * Unsets a KGame object that has been set using setKGame
  196.      * before. You don't have to call this - this is usually done
  197.      * automatically.
  198.      **/
  199.     void slotUnsetKGame();
  200.  
  201.  
  202.     void slotPropertyChanged(KGamePropertyBase*, KPlayer*);
  203.     void slotAddPlayer(KPlayer*);
  204.     void slotRemovePlayer(KPlayer*);
  205.  
  206.     /**
  207.      * Called when KPlayer::signalNetworkData is emitted. The message
  208.      * gets forwarded to slotReceiveMessage if @p me equals
  209.      * fromPlayer.
  210.      **/
  211.     void slotReceivePrivateMessage(int msgid, const QByteArray& buffer, Q_UINT32 sender, KPlayer* me);
  212.  
  213. protected:
  214.     virtual void returnPressed(const QString& text);
  215.  
  216. private:
  217.     void init(KGame* g, int msgid);
  218.  
  219. private:
  220.     KGameChatPrivate* d;
  221. };
  222.  
  223. #endif
  224.