480
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2006 Igor Ulyanov <iulyanov@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program 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
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
461
|
19 |
#include <QListWidget>
|
|
20 |
#include <QLineEdit>
|
|
21 |
|
|
22 |
#include "chatwidget.h"
|
|
23 |
|
|
24 |
HWChatWidget::HWChatWidget(QWidget* parent) :
|
|
25 |
QWidget(parent),
|
|
26 |
mainLayout(this)
|
|
27 |
{
|
|
28 |
mainLayout.setSpacing(1);
|
|
29 |
mainLayout.setMargin(1);
|
462
|
30 |
mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
|
464
|
31 |
mainLayout.setColumnStretch(0, 75);
|
|
32 |
mainLayout.setColumnStretch(1, 25);
|
461
|
33 |
|
|
34 |
chatEditLine = new QLineEdit(this);
|
|
35 |
connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
|
|
36 |
|
463
|
37 |
mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
|
462
|
38 |
|
461
|
39 |
chatText = new QListWidget(this);
|
|
40 |
chatText->setMinimumHeight(10);
|
462
|
41 |
chatText->setMinimumWidth(10);
|
463
|
42 |
chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
461
|
43 |
mainLayout.addWidget(chatText, 0, 0);
|
462
|
44 |
|
|
45 |
chatNicks = new QListWidget(this);
|
|
46 |
chatNicks->setMinimumHeight(10);
|
|
47 |
chatNicks->setMinimumWidth(10);
|
463
|
48 |
chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
462
|
49 |
mainLayout.addWidget(chatNicks, 0, 1);
|
461
|
50 |
}
|
|
51 |
|
|
52 |
void HWChatWidget::returnPressed()
|
|
53 |
{
|
|
54 |
emit chatLine(chatEditLine->text());
|
|
55 |
chatEditLine->clear();
|
|
56 |
}
|
|
57 |
|
|
58 |
void HWChatWidget::onChatStringFromNet(const QStringList& str)
|
|
59 |
{
|
|
60 |
QListWidget* w=chatText;
|
|
61 |
w->addItem(str[0]+": "+str[1]);
|
|
62 |
w->scrollToBottom();
|
|
63 |
w->setSelectionMode(QAbstractItemView::NoSelection);
|
|
64 |
}
|
465
|
65 |
|
|
66 |
void HWChatWidget::nickAdded(const QString& nick)
|
|
67 |
{
|
|
68 |
chatNicks->addItem(nick);
|
|
69 |
}
|
|
70 |
|
|
71 |
void HWChatWidget::nickRemoved(const QString& nick)
|
|
72 |
{
|
|
73 |
QList<QListWidgetItem *> items=chatNicks->findItems(nick, Qt::MatchExactly);
|
|
74 |
for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) {
|
|
75 |
chatNicks->takeItem(chatNicks->row(*it));
|
|
76 |
++it;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
void HWChatWidget::clear()
|
|
81 |
{
|
|
82 |
chatNicks->clear();
|
|
83 |
}
|