480
|
1 |
/*
|
1066
|
2 |
* Hedgewars, a free turn based strategy 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>
|
1391
|
21 |
#include <QAction>
|
461
|
22 |
|
|
23 |
#include "chatwidget.h"
|
|
24 |
|
|
25 |
HWChatWidget::HWChatWidget(QWidget* parent) :
|
|
26 |
QWidget(parent),
|
|
27 |
mainLayout(this)
|
|
28 |
{
|
|
29 |
mainLayout.setSpacing(1);
|
|
30 |
mainLayout.setMargin(1);
|
462
|
31 |
mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
|
464
|
32 |
mainLayout.setColumnStretch(0, 75);
|
|
33 |
mainLayout.setColumnStretch(1, 25);
|
461
|
34 |
|
|
35 |
chatEditLine = new QLineEdit(this);
|
|
36 |
connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
|
|
37 |
|
463
|
38 |
mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
|
462
|
39 |
|
461
|
40 |
chatText = new QListWidget(this);
|
|
41 |
chatText->setMinimumHeight(10);
|
462
|
42 |
chatText->setMinimumWidth(10);
|
463
|
43 |
chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
461
|
44 |
mainLayout.addWidget(chatText, 0, 0);
|
462
|
45 |
|
|
46 |
chatNicks = new QListWidget(this);
|
|
47 |
chatNicks->setMinimumHeight(10);
|
|
48 |
chatNicks->setMinimumWidth(10);
|
463
|
49 |
chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
1391
|
50 |
chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
|
462
|
51 |
mainLayout.addWidget(chatNicks, 0, 1);
|
1391
|
52 |
|
|
53 |
QAction * acBan = new QAction(QAction::tr("Kick"), chatNicks);
|
|
54 |
connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onKick()));
|
|
55 |
chatNicks->insertAction(0, acBan);
|
461
|
56 |
}
|
|
57 |
|
|
58 |
void HWChatWidget::returnPressed()
|
|
59 |
{
|
|
60 |
emit chatLine(chatEditLine->text());
|
|
61 |
chatEditLine->clear();
|
|
62 |
}
|
|
63 |
|
1360
|
64 |
void HWChatWidget::onChatString(const QString& str)
|
461
|
65 |
{
|
1316
|
66 |
QListWidget* w = chatText;
|
1357
|
67 |
w->addItem(str);
|
461
|
68 |
w->scrollToBottom();
|
|
69 |
w->setSelectionMode(QAbstractItemView::NoSelection);
|
|
70 |
}
|
465
|
71 |
|
|
72 |
void HWChatWidget::nickAdded(const QString& nick)
|
|
73 |
{
|
1391
|
74 |
QListWidgetItem * item = new QListWidgetItem(nick);
|
|
75 |
chatNicks->addItem(item);
|
465
|
76 |
}
|
|
77 |
|
|
78 |
void HWChatWidget::nickRemoved(const QString& nick)
|
|
79 |
{
|
1391
|
80 |
QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
|
465
|
81 |
for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) {
|
|
82 |
chatNicks->takeItem(chatNicks->row(*it));
|
|
83 |
++it;
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
void HWChatWidget::clear()
|
|
88 |
{
|
1311
|
89 |
chatText->clear();
|
|
90 |
chatNicks->clear();
|
465
|
91 |
}
|
1391
|
92 |
|
|
93 |
void HWChatWidget::onKick()
|
|
94 |
{
|
|
95 |
QListWidgetItem * curritem = chatNicks->currentItem();
|
|
96 |
if (curritem)
|
|
97 |
emit kick(curritem->text());
|
|
98 |
}
|
1405
|
99 |
|
|
100 |
void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
|
|
101 |
{
|
|
102 |
QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
|
|
103 |
if (items.size() != 1)
|
|
104 |
{
|
|
105 |
qWarning("Bug: cannot find user in chat");
|
|
106 |
return;
|
|
107 |
}
|
|
108 |
|
|
109 |
if(isReady)
|
|
110 |
items[0]->setIcon(QIcon(":/res/checked.png"));
|
|
111 |
else
|
|
112 |
items[0]->setIcon(QIcon(":/res/unchecked.png"));
|
|
113 |
}
|