author | unc0rr |
Fri, 07 Mar 2008 20:25:19 +0000 | |
changeset 806 | d397c502a5dd |
parent 575 | 9a18a9b9d7d4 |
child 1066 | 1f1b3686a2b0 |
permissions | -rw-r--r-- |
480 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com> |
480 | 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 |
{ |
|
575
9a18a9b9d7d4
One more security fix (check size of QList before using QList::operator[])
unc0rr
parents:
486
diff
changeset
|
60 |
if (str.size() < 2) return; |
461 | 61 |
QListWidget* w=chatText; |
62 |
w->addItem(str[0]+": "+str[1]); |
|
63 |
w->scrollToBottom(); |
|
64 |
w->setSelectionMode(QAbstractItemView::NoSelection); |
|
65 |
} |
|
465 | 66 |
|
67 |
void HWChatWidget::nickAdded(const QString& nick) |
|
68 |
{ |
|
69 |
chatNicks->addItem(nick); |
|
70 |
} |
|
71 |
||
72 |
void HWChatWidget::nickRemoved(const QString& nick) |
|
73 |
{ |
|
74 |
QList<QListWidgetItem *> items=chatNicks->findItems(nick, Qt::MatchExactly); |
|
75 |
for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) { |
|
76 |
chatNicks->takeItem(chatNicks->row(*it)); |
|
77 |
++it; |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
void HWChatWidget::clear() |
|
82 |
{ |
|
83 |
chatNicks->clear(); |
|
84 |
} |