-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmwidget.cpp
55 lines (45 loc) · 1.7 KB
/
pmwidget.cpp
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
#include "pmwidget.h"
#include "ui_pmwidget.h"
#include <QTabWidget>
PMWidget::PMWidget(CyanChat::User user, CyanChat* tcc, QWidget *parent) : QWidget(parent), m_ui(new Ui::PMWidget), target(user), cc(tcc) {
this->setObjectName(user.fullName());
m_ui->setupUi(this);
pmBox = m_ui->pmBox;
// there used to be a label in this widget
//m_ui->pmTitle->setText("Private chat with [" + user.name + "]");
((QTabWidget*)parent)->addTab(this, user.name);
connect(m_ui->pmBox, SIGNAL(returnPressed()), this, SLOT(pmSendSlot()));
QShortcut* autoComplete = new QShortcut(QKeySequence("Ctrl+Space"), m_ui->pmBox);
connect(autoComplete, SIGNAL(activated()), tcc, SLOT(nameCompleteSlot()));
}
PMWidget::~PMWidget() {
delete m_ui;
}
void PMWidget::changeEvent(QEvent *e) {
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void PMWidget::pmSendSlot() {
QStringList lines = m_ui->pmBox->text().split("\n");
foreach(QString line, lines) {
QStringList args = line.split(" ");
if(args.count() > 1 && args[0] == "/me") {
args.pop_front();
line = "*" + args.join(" ") + "*";
}
cc->addChatLine(m_ui->pmText, CyanChat::User("0" + cc->currentName), CyanChat::Msg(line, CyanChat::kMsgTypePMTab));
cc->pm(target, line);
}
m_ui->pmBox->clear();
}
void PMWidget::closeSlot() {
cc->closeTabSlot(this);
}
void PMWidget::pmRecv(const CyanChat::User& user, const CyanChat::Msg& message) {
cc->addChatLine(m_ui->pmText, user, CyanChat::Msg(message.text, CyanChat::kMsgTypePMTab));
}