/
addwindow.cpp
163 lines (147 loc) · 4.18 KB
/
addwindow.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "addwindow.h"
#include "ui_addwindow.h"
#include "QtScript/QScriptValue"
#include "QtScript/QScriptEngine"
#include "QtScript/QScriptValueIterator"
AddWindow::AddWindow(QString myAccount, QWidget *parent) :
QFrame(parent), myAccount(myAccount),
ui(new Ui::AddWindow)
{
ui->setupUi(this);
//connect(this, SIGNAL(clicked()), this, SLOT(headPressEventSlot()));
ui->label->setText("<font color=white>请输入ichat号:</font>");
ui->label_2->hide();
ui->faceButton->hide();
ui->label_4->hide();
ui->pushButton_2->hide();
setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
setFixedSize(this->width(), this->height());
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this,SLOT(replyFinished(QNetworkReply*)));
this->setWindowFlags(Qt::FramelessWindowHint);
dragPosition = QPoint(-1,-1);
}
AddWindow::~AddWindow()
{
delete ui;
}
//获取要查找的帐号。。。及查找
void AddWindow::on_pushButton_clicked()
{
//获取输入的帐号
QString s;
s=ui->lineEdit->text();
s="account="+s;
//到服务器数据库去查。。。
QUrl url("http://182.92.69.19/ichat-server/public/user/find-contact");
QByteArray append=s.toLatin1();
manager->post(QNetworkRequest(url),append);
/* bool IsFind=0; //用来判断是否有该用户
if(IsFind)
{
AddItems *myitem = new AddItems(ui->listWidget);
myitem->move(0,0);
}
else
{
QLabel * text=new QLabel(ui->listWidget);
text->setText(QObject::tr("不存在该用户,请重新输入!"));
text->show();
}*/
}
void AddWindow::replyFinished(QNetworkReply *reply)
{
QVariant statusCodev = reply->readAll();
str = statusCodev.toString();
QScriptValue sc;
QScriptEngine engine;
sc=engine.evaluate("value="+str);
QScriptValueIterator it(sc);
it.next();
QString Id=it.value().toString();
if(Id=="Parse error")
{
ui->textBrowser->clear();
ui->label_2->hide();
ui->faceButton->hide();
ui->label_4->hide();
ui->pushButton_2->hide();
QString c="不存在该用户,请重新输入";
ui->textBrowser->setText(c);
}
else{
ui->textBrowser->clear();
it.next();
it.next();
QString nickname=it.value().toString();
ui->label_2->setText(nickname);
it.next();
//头像处理
QByteArray head,face;
QString str(it.value().toString());
int j = str.indexOf('-');
while(j!=-1){
str[j] = '+';
j = str.indexOf('-');
}
head = QByteArray::fromBase64(str.toLatin1());
face = qUncompress(head);
QImage img;
img.loadFromData(face);
ui->faceButton->setIcon(QPixmap::fromImage(img));
it.next();
QString signature=it.value().toString();
ui->label_4->setText(signature);
ui->label_2->show();
ui->faceButton->show();
ui->label_4->show();
ui->pushButton_2->show();
}
/*while (it.hasNext()){
it.next();
qDebug()<<it.name()<<":"<<it.value().toString();
}*/
}
//显示资料卡
void AddWindow::on_faceButton_clicked()
{
}
//添加好友
void AddWindow::on_pushButton_2_clicked()
{
cw=new confirmWindow(str, myAccount);
connect(cw,SIGNAL(addFinished()),this,SLOT(on_addContactFinished()));
cw->show();
}
void AddWindow::on_closeBtn_clicked()
{
this->hide();
}
void AddWindow::on_addContactFinished()
{
emit addFinished();
}
void AddWindow::mousePressEvent(QMouseEvent *e)
{
if(e->button() == Qt::LeftButton){
dragPosition = e->globalPos()-frameGeometry().topLeft();
QPoint p = e->pos();
e->accept();
}
else dragPosition = QPoint(-1,-1);
}
void AddWindow::mouseMoveEvent(QMouseEvent *e)
{
if(dragPosition != QPoint(-1,-1)){
move(e->globalPos()-dragPosition);
}
e->accept();
}
void AddWindow::mouseReleaseEvent(QMouseEvent *e)
{
if(e->button() == Qt::LeftButton){
dragPosition = QPoint(-1,-1);
e->accept();
}
}