kgamechat.h

00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001-2002 Andreas Beckermann (b_mann@gmx.de)
00004     Copyright (C) 2001 Martin Heni (martin@heni-online.de)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef __KGAMECHAT_H__
00022 #define __KGAMECHAT_H__
00023 
00024 #include <qstring.h>
00025 
00026 #include "kchatbase.h"
00027 #include <kdemacros.h>
00028 class KPlayer;
00029 class KGame;
00030 class KGamePropertyBase;
00031 
00032 class KGameChatPrivate;
00033 
00043 class KDE_EXPORT KGameChat : public KChatBase
00044 {
00045     Q_OBJECT
00046 public:
00052     KGameChat(KGame* game, int msgid, KPlayer* fromPlayer, QWidget * parent);
00053 
00059     KGameChat(KGame* game, int msgId, QWidget* parent);
00060 
00067     KGameChat(QWidget* parent);
00068 
00069     virtual ~KGameChat();
00070 
00071     enum SendingIds {
00072         SendToGroup = 1
00073     };
00074 
00081     void setFromPlayer(KPlayer* player);
00082 
00083     KPlayer* fromPlayer() const;
00084 
00092     void setKGame(KGame* g);
00093 
00094     KGame* game() const;
00095 
00100     int messageId() const;
00101 
00111     void setMessageId(int msgid);
00112 
00117     virtual const QString& fromName() const;
00118 
00119 
00120 public slots:
00121     virtual void addMessage(const QString& fromName, const QString& text) { KChatBase::addMessage(fromName, text);}
00122     virtual void addMessage(int fromId, const QString& text);
00123 
00124     void slotReceiveMessage(int, const QByteArray&, Q_UINT32 receiver, Q_UINT32 sender);
00125 
00126 protected:
00132     bool isSendToAllMessage(int id) const;
00133 
00143     bool isToGroupMessage(int id) const;
00144     
00145 
00158     bool isToPlayerMessage(int id) const;
00159 
00169     int playerId(int id) const;
00170 
00176     int sendingId(int playerId) const;
00177 
00182     bool hasPlayer(int id) const;
00183 
00190     virtual QString sendToPlayerEntry(const QString& name) const;
00191 
00192 
00193 protected slots:
00199     void slotUnsetKGame();
00200 
00201 
00202     void slotPropertyChanged(KGamePropertyBase*, KPlayer*);
00203     void slotAddPlayer(KPlayer*);
00204     void slotRemovePlayer(KPlayer*);
00205 
00211     void slotReceivePrivateMessage(int msgid, const QByteArray& buffer, Q_UINT32 sender, KPlayer* me);
00212 
00213 protected:
00214     virtual void returnPressed(const QString& text);
00215 
00216 private:
00217     void init(KGame* g, int msgid);
00218 
00219 private:
00220     KGameChatPrivate* d;
00221 };
00222 
00223 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys