-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtlenpublicchatwidget.cpp
More file actions
87 lines (81 loc) · 2.45 KB
/
Copy pathqtlenpublicchatwidget.cpp
File metadata and controls
87 lines (81 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "qtlenpublicchatwidget.h"
QTlenPublicChatWidget::QTlenPublicChatWidget(QWidget * parent): QWidget(parent)
{
list = new QListWidget(this);
list->setSortingEnabled(true);
browser = new QTextBrowser(this);
input = new QTlenTextEdit(this);
QSplitter *vsplitter = new QSplitter(this);
vsplitter->setOrientation(Qt::Vertical);
QSplitter *hsplitter = new QSplitter(this);
hsplitter->setOrientation(Qt::Horizontal);
vsplitter->addWidget(browser);
vsplitter->addWidget(input);
hsplitter->addWidget(vsplitter);
hsplitter->addWidget(list);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(hsplitter);
this->setLayout(layout);
connect(input,
SIGNAL(returnPressed()),
this,
SLOT(sendMessage()));
connect(list,
SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this,
SLOT(itemDoubleClicked(QListWidgetItem*)));
}
void QTlenPublicChatWidget::appendMessage(QString nick, QString body)
{
browser->append("<" + nick + "> " + body);
}
void QTlenPublicChatWidget::presence(QString nick, int a, bool ok)
{
QList<QListWidgetItem*> l = list->findItems(nick, Qt::MatchExactly);
if (l.isEmpty() && ok)
{
QIcon icon;
switch (a)
{
case 0:
icon.addPixmap(QPixmap(":/icons/icons/16x16/user.png"));
break;
case 1:
icon.addPixmap(QPixmap(":/icons/icons/16x16/owner.png"));
break;
case 2:
icon.addPixmap(QPixmap(":/icons/icons/16x16/admin.png"));
break;
case 4:
icon.addPixmap(QPixmap(":/icons/icons/16x16/banned.png"));
break;
case 5:
icon.addPixmap(QPixmap(":/icons/icons/16x16/superuser.png"));
break;
}
QListWidgetItem* i = new QListWidgetItem;
i->setIcon(icon);
i->setText(nick);
list->addItem(i);
}
else
{
QListWidgetItem* i = list->takeItem(list->row(l.at(0)));
if (i != 0)
delete i;
}
}
void QTlenPublicChatWidget::sendMessage()
{
emit message(roomId, input->toPlainText());
input->clear();
}
void QTlenPublicChatWidget::setRoomId(QString id)
{
this->roomId = id;
}
void QTlenPublicChatWidget::itemDoubleClicked(QListWidgetItem *item)
{
emit startPriv(roomId + "/" + item->text());
qDebug("starting priv");
}