mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
chat code
This commit is contained in:
parent
120193fb0b
commit
e6a419aa3d
9 changed files with 51 additions and 9 deletions
|
|
@ -2,13 +2,15 @@
|
|||
#include "chatwidget.h"
|
||||
#include "client.h"
|
||||
|
||||
ChannelWidget::ChannelWidget(const QString &_name, QWidget *parent)
|
||||
: QWidget(parent), name(_name)
|
||||
ChannelWidget::ChannelWidget(Client *_client, const QString &_name, QWidget *parent)
|
||||
: QWidget(parent), client(_client), name(_name)
|
||||
{
|
||||
playerList = new QListWidget;
|
||||
|
||||
textEdit = new QTextEdit;
|
||||
textEdit->setReadOnly(true);
|
||||
sayEdit = new QLineEdit;
|
||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(textEdit);
|
||||
|
|
@ -21,6 +23,14 @@ ChannelWidget::ChannelWidget(const QString &_name, QWidget *parent)
|
|||
setLayout(hbox);
|
||||
}
|
||||
|
||||
void ChannelWidget::sendMessage()
|
||||
{
|
||||
if (sayEdit->text().isEmpty())
|
||||
return;
|
||||
client->chatSay(name, sayEdit->text());
|
||||
sayEdit->clear();
|
||||
}
|
||||
|
||||
void ChannelWidget::joinEvent(const QString &playerName)
|
||||
{
|
||||
textEdit->append(tr("%1 has joined the channel.").arg(playerName));
|
||||
|
|
@ -102,6 +112,14 @@ void ChatWidget::chatEvent(const ChatEventData &data)
|
|||
case eventChatListChannels: {
|
||||
if (msg.size() != 3)
|
||||
break;
|
||||
for (int i = 0; i < channelList->topLevelItemCount(); ++i) {
|
||||
QTreeWidgetItem *twi = channelList->topLevelItem(i);
|
||||
if (twi->text(0) == msg[0]) {
|
||||
twi->setText(1, msg[1]);
|
||||
twi->setText(2, msg[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
channelList->addTopLevelItem(new QTreeWidgetItem(QStringList() << msg[0] << msg[1] << msg[2]));
|
||||
break;
|
||||
}
|
||||
|
|
@ -167,7 +185,7 @@ void ChatWidget::joinFinished(ServerResponse resp)
|
|||
|
||||
PendingCommand *pc = qobject_cast<PendingCommand *>(sender());
|
||||
QString channelName = pc->getExtraData();
|
||||
ChannelWidget *cw = new ChannelWidget(channelName);
|
||||
ChannelWidget *cw = new ChannelWidget(client, channelName);
|
||||
tab->addTab(cw, channelName);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue