This commit is contained in:
Max-Wilhelm Bruker 2009-08-23 16:53:51 +02:00
parent b51d4cd4f4
commit b113b78e7c
3 changed files with 20 additions and 4 deletions

View file

@ -2,8 +2,8 @@
#include "chatwidget.h" #include "chatwidget.h"
#include "client.h" #include "client.h"
ChannelWidget::ChannelWidget(Client *_client, const QString &_name, bool readOnly, QWidget *parent) ChannelWidget::ChannelWidget(Client *_client, const QString &_name, bool readOnly, bool _virtualChannel, QWidget *parent)
: QWidget(parent), client(_client), name(_name) : QWidget(parent), client(_client), name(_name), virtualChannel(_virtualChannel)
{ {
playerList = new QListWidget; playerList = new QListWidget;
@ -27,6 +27,12 @@ ChannelWidget::ChannelWidget(Client *_client, const QString &_name, bool readOnl
setLayout(hbox); setLayout(hbox);
} }
ChannelWidget::~ChannelWidget()
{
if (!virtualChannel)
client->chatLeaveChannel(name);
}
void ChannelWidget::sendMessage() void ChannelWidget::sendMessage()
{ {
if (sayEdit->text().isEmpty()) if (sayEdit->text().isEmpty())
@ -111,6 +117,12 @@ void ChatWidget::enableChat()
void ChatWidget::disableChat() void ChatWidget::disableChat()
{ {
disconnect(client, 0, this, 0); disconnect(client, 0, this, 0);
while (tab->count()) {
ChannelWidget *cw = qobject_cast<ChannelWidget *>(tab->widget(0));
tab->removeTab(0);
delete cw;
}
channelList->clear();
hide(); hide();
} }
@ -177,7 +189,7 @@ void ChatWidget::chatEvent(const ChatEventData &data)
if (msg[0].isEmpty()) { if (msg[0].isEmpty()) {
w = getChannel("Server"); w = getChannel("Server");
if (!w) { if (!w) {
w = new ChannelWidget(client, "Server", true); w = new ChannelWidget(client, "Server", true, true);
tab->addTab(w, "Server"); tab->addTab(w, "Server");
} }
} else } else

View file

@ -20,10 +20,12 @@ private:
QLineEdit *sayEdit; QLineEdit *sayEdit;
Client *client; Client *client;
QString name; QString name;
bool virtualChannel;
private slots: private slots:
void sendMessage(); void sendMessage();
public: public:
ChannelWidget(Client *_client, const QString &_name, bool readOnly = false, QWidget *parent = 0); ChannelWidget(Client *_client, const QString &_name, bool readOnly = false, bool _virtualChannel = false, QWidget *parent = 0);
~ChannelWidget();
const QString &getName() const { return name; } const QString &getName() const { return name; }
void joinEvent(const QString &playerName); void joinEvent(const QString &playerName);

View file

@ -350,6 +350,8 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
void MainWindow::closeEvent(QCloseEvent */*event*/) void MainWindow::closeEvent(QCloseEvent */*event*/)
{ {
delete game; delete game;
chatWidget->disableChat();
gameSelector->disableGameList();
} }
void MainWindow::changeEvent(QEvent *event) void MainWindow::changeEvent(QEvent *event)