2 This file is part of the KDE games library
3 Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
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.
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.
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.
22 #include <QtCore/QMap>
27 #include "kchatbasemodel.h"
28 #include "kchatbaseitemdelegate.h"
37 bool mAutoAddMessages
;
39 QMap
<int, QString
> mPlayerMap
;
44 KChat::KChat(QWidget
* parent
, bool twoPlayerGame
)
46 new KChatBaseModel(parent
),
47 new KChatBaseItemDelegate(parent
),twoPlayerGame
),
53 KChat::KChat(QWidget
* parent
, KChatBaseModel
* model
, KChatBaseItemDelegate
* delegate
, bool noComboBox
)
54 : KChatBase(parent
, model
, delegate
, noComboBox
),
62 kDebug(11000) << "DESTRUCT KChat" << this;
68 kDebug(11001) << "INIT KChat" << this;
69 d
->mAutoAddMessages
= true;
74 void KChat::setFromNickname(const QString
& n
)
75 { d
->mFromId
= addPlayer(n
); }
76 QString
KChat::fromName() const
77 { return player(fromId()); }
78 void KChat::setAutoAddMessages(bool add
)
79 { d
->mAutoAddMessages
= add
; }
80 bool KChat::autoAddMessages() const
81 { return d
->mAutoAddMessages
; }
83 { return d
->mPlayerId
++; }
84 int KChat::fromId() const
85 { return d
->mFromId
; }
86 QString
KChat::player(int id
) const
87 { return d
->mPlayerMap
[id
]; }
89 void KChat::returnPressed(const QString
& text
)
93 // don't return - just display "unknown" as name
94 kWarning(11000) << "KChat: no fromNickname has been set!";
96 emit
signalSendMessage(id
, text
);
97 if (autoAddMessages()) {
98 QString p
= player(id
);
100 p
= i18nc("Unknown player", "Unknown");
102 kDebug(11000) << "auto adding message from player" << p
<< " ;id=" << id
;
107 int KChat::addPlayer(const QString
& nickname
)
110 d
->mPlayerMap
.insert(id
, nickname
);
114 void KChat::removePlayer(int id
)
116 d
->mPlayerMap
.remove(id
);
119 void KChat::removePlayer(const QString
& nickname
)
121 QMap
<int, QString
>::Iterator it
;
122 for (it
= d
->mPlayerMap
.begin(); it
!= d
->mPlayerMap
.end(); ++it
) {
123 if (it
.value() == nickname
) {
124 d
->mPlayerMap
.erase(it
);