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 / kchat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.1 KB  |  148 lines

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