forked from Blackmamba-xuan/QtQQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.cpp
220 lines (199 loc) · 6.63 KB
/
form.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "form.h"
#include "ui_form.h"
#include<QNetworkRequest>
#include<QByteArray>
#include<QJsonObject>
#include<QJsonDocument>
#include<QNetworkReply>
#include<QJsonArray>
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
i=0;
setWindowFlags(Qt::FramelessWindowHint|Qt::Tool);
QMovie *movie = new QMovie(":/red69-2.gif");
ui->label->setMovie(movie);
ui->label_2->installEventFilter(this);
ui->label_3->installEventFilter(this);
movie->start();
//QImage image;
//image.load(":/10.jpeg");
//QImage result = image.scaled(85, 85, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
//ui->label_4->setPixmap(QPixmap::fromImage(result));
ui->label_4->setStyleSheet("border-radius:15px;background-color:green;border-image:url(':/11.jpg')");
ui->label_5->setOpenExternalLinks(true);
ui->label_5->installEventFilter(this);
animation=new QPropertyAnimation(ui->label_4, "geometry");
animation->setDuration(400);
animation->setStartValue(QRect(30, 170, 85, 85));
animation->setEndValue(QRect(150, 170, 85, 85));
QString qss;
QFile qssFile(":/myqss/login.qss");
qssFile.open(QFile::ReadOnly);
qDebug()<<"sdfasd";
if(qssFile.isOpen())
{
qss = QLatin1String(qssFile.readAll());
this->setStyleSheet(qss);
qssFile.close();
qDebug()<<"成功引入qss";
}
}
Form::~Form()
{
delete ui;
}
void Form::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 Form::mouseReleaseEvent(QMouseEvent *event)
{
//设置鼠标为未被按下
mouse_press = false;
}
void Form::mouseMoveEvent(QMouseEvent *event)
{
//若鼠标左键被按下
// qDebug()<<"mouse_press="<<event->globalPos();
if(mouse_press)
{
i++;
//鼠标相对于屏幕的位置
QPoint move_pos = event->globalPos();
qDebug()<<"移动"<<i;
//移动主窗体位置
this->move(move_pos - move_point);
}
}
bool Form::eventFilter(QObject *object, QEvent *e)
{
if(e->type()==QEvent::MouseButtonPress&&object==ui->label_3)
{
close();
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_2){
showMinimized();
qDebug()<<"最小化";
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_5){
QDesktopServices::openUrl(QUrl("http://www.baidu.com"));
mouse_press=false;
}
return false;
}
void Form::on_pushButton_clicked()
{
qDebug()<<ui->lineEdit->text();
if(ui->lineEdit->text()==""||ui->lineEdit_2->text()==""){
qDebug()<<"内容为空";
ui->label_6->setText("账号密码不能为空");
}
else{
ui->label_6->hide();
ui->pushButton->hide();
ui->lineEdit->hide();
ui->lineEdit_2->hide();
ui->label_5->hide();
animation->start();
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("type",1);
json.insert("ID",ui->lineEdit->text());
json.insert("password",ui->lineEdit_2->text());
QJsonDocument document;
document.setObject(json);
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/Login"));
network_manager->post(network_request, post_data);
connect(network_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(parseresult(QNetworkReply*)));
qDebug()<<post_data;
}
/*ui->pushButton->hide();
ui->lineEdit->hide();
ui->lineEdit_2->hide();
ui->label_5->hide();
animation->start();*/
}
void Form::on_lineEdit_2_returnPressed()
{
qDebug()<<"输入结束66";
}
void Form::showEvent(QShowEvent *event)
{
mouse_press=false;
}
void Form::on_lineEdit_textEdited(const QString &arg1)
{
qDebug()<<"正在编辑"+arg1;
if(ui->label_6->text()!=""){
qDebug()<<"进入了这个函数";
ui->label_6->setText("");
}
}
void Form::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);
//QString ss=QVariant(qba).toString();
//qDebug("%s", qba);
//qDebug()<<ss;
if (error.error == QJsonParseError::NoError) {
if (jsonDocument.isObject()) {
/*QVariantMap result = jsonDocument.toVariant().toMap();
qDebug()<<result;
qDebug()<<result["userinfo"].toJsonArray();
foreach (QVariant plugin, result["userinfo"].toList()) {
qDebug()<<plugin.toString();
}*/
QJsonObject obj=jsonDocument.object();
//QJsonArray array=obj["userinfo"].toArray();
//QJsonObject obj1=array[0].toObject();
qDebug()<<obj["Flag"].toString();
qDebug()<<obj;
qDebug()<<obj["Flag"];
if(obj["Flag"]==1){
qDebug()<<"44444";
//Talk t;
//t.show();
Talk* t=new Talk();
setVisible(false);
t->init(byte_array);
t->show();
//close();
//hide();
//setWindowFlags(Qt::Tool);
//this->setAttribute(Qt::WA_DeleteOnClose);
}
}
} else {
qDebug()<<"解析失败";
}
}
delete reply;
}