forked from Blackmamba-xuan/QtQQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.cpp
158 lines (132 loc) · 4.37 KB
/
search.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
#include "search.h"
#include "ui_search.h"
Search::Search(QWidget *parent) :
QWidget(parent),
ui(new Ui::Search)
{
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
ui->label_2->installEventFilter(this);
ui->label_3->installEventFilter(this);
ui->label_4->installEventFilter(this);
ui->label_5->installEventFilter(this);
ui->label_7->setVisible(false);
ui->label_8->setVisible(false);
ui->pushButton_2->setVisible(false);
}
Search::~Search()
{
delete ui;
}
void Search::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
this->setMouseTracking(true);
mouse_press = true;
//鼠标相对于窗体的位置(或者使用event->globalPos() - this->pos())
move_point = event->pos();
qDebug()<<"移动1";
qDebug()<<event->source();
}
}
void Search::mouseReleaseEvent(QMouseEvent *event)
{
//设置鼠标为未被按下
mouse_press = false;
}
void Search::mouseMoveEvent(QMouseEvent *event)
{
//若鼠标左键被按下
// qDebug()<<"mouse_press="<<event->globalPos();
if(mouse_press)
{
//鼠标相对于屏幕的位置
QPoint move_pos = event->globalPos();
//移动主窗体位置
this->move(move_pos - move_point);
}
}
bool Search::eventFilter(QObject *object, QEvent *e)
{
if(e->type()==QEvent::MouseButtonPress&&object==ui->label_3)
{
//this->close();
//e->ignore();
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_2){
showMinimized();
qDebug()<<"最小化";
qDebug()<<mouse_press;
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_4){
ui->label_4->setStyleSheet("color:white;font-size:16px;font-weight:bold;");
ui->label_5->setStyleSheet("color:white");
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_5){
ui->label_5->setStyleSheet("color:white;font-size:16px;font-weight:bold;");
ui->label_4->setStyleSheet("color:white");
}
return false;
}
void Search::showEvent(QShowEvent *event)
{
qDebug()<<"出现了";
mouse_press=false;
qDebug()<<mouse_press;
}
void Search::on_pushButton_2_clicked()
{
}
void Search::doSearch(QString message)
{
ui->lineEdit->setText(message);
}
void Search::on_pushButton_clicked()
{
QNetworkAccessManager* network_manager = new QNetworkAccessManager();
QNetworkRequest network_request;
QByteArray post_data;
QJsonObject json;
//QByteArray bb;
// QString pwd=ui->lineEdit_2->text();
// bb = QCryptographicHash::hash ( pwd.toUtf8(), QCryptographicHash::Md5 );
// pwd=bb.toHex();
//QByteArray mid="你好";
//QString ID=QString::fromUtf8(mid);
json.insert("findID",ui->lineEdit->text());
QJsonDocument document;
document.setObject(json);
QByteArray byte_array = document.toJson(QJsonDocument::Compact);
post_data.append("data="+byte_array);
network_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
network_request.setHeader(QNetworkRequest::ContentLengthHeader, post_data.length());
network_request.setUrl(QUrl("http://172.29.107.7:8080/ChatProject/chat/findUser"));
network_manager->post(network_request, post_data);
connect(network_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(parseresult(QNetworkReply*)));
qDebug()<<post_data;
}
void Search::parseresult(QNetworkReply* reply)
{
if (reply->error() == QNetworkReply::NoError) {
QString qba= reply->readAll(); //读取
qba.toStdString().c_str();
qDebug()<<qba;
QJsonParseError error;
QJsonDocument jsonDocument = QJsonDocument::fromJson(qba.toUtf8(), &error);
if (error.error == QJsonParseError::NoError) {
if (jsonDocument.isObject()) {
QJsonObject obj=jsonDocument.object();
QJsonObject obj1=obj["infoFindVo"].toObject();
ui->label_8->setText(obj1["name"].toString());
ui->label_7->setVisible(true);
ui->label_8->setVisible(true);
ui->pushButton_2->setVisible(true);
}
} else {
qDebug()<<"解析失败";
}
}
delete reply;
}