修改了linux下的bug,并一定程度优化了逻辑
This commit is contained in:
parent
b05254e259
commit
546b53a5e8
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 6.0.2, 2023-01-08T22:52:47. -->
|
||||
<!-- Written by QtCreator 6.0.2, 2023-01-09T15:53:28. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
|
@ -8,6 +8,7 @@ DataManager::DataManager(QObject *parent)
|
|||
connect(tcpclient, &TCPClient::TCPClientConnected, this, &DataManager::TCPClientConnected);
|
||||
connect(tcpclient, &TCPClient::TCPClientDisconnected, this, &DataManager::TCPClientDisconnected);
|
||||
connect(tcpclient, &TCPClient::recv_data, this, &DataManager::recv_from_server);
|
||||
tcpclient->setServer("192.168.126.129",7890);
|
||||
tcpclient->configAndrun();
|
||||
// tcpclient->setCallBack(recv_from_server);
|
||||
protocol = Protocol::getInstance();
|
||||
|
@ -126,7 +127,7 @@ void DataManager::Register(QString username, QString password)
|
|||
data = protocol->data_maker(Protocol::REQUEST, QString("register"), QList<QString>{"user", username, "password", password});
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "发送注册信息" << username << password;
|
||||
qDebug() << "发送注册信息" << data;
|
||||
}
|
||||
|
||||
void DataManager::signin_request(QString username, QString password)
|
||||
|
@ -135,7 +136,7 @@ void DataManager::signin_request(QString username, QString password)
|
|||
data = protocol->data_maker(Protocol::REQUEST, QString("signin"), QList<QString>{"user", username, "password", password});
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "发送登录信息" << username << password;
|
||||
qDebug() << "发送登录信息" << data;
|
||||
}
|
||||
|
||||
void DataManager::send_text(QString sendname, QString text)
|
||||
|
@ -144,7 +145,7 @@ void DataManager::send_text(QString sendname, QString text)
|
|||
data = protocol->data_maker(Protocol::MESSAGE, sendname, text);
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "群发文本信息" << sendname;
|
||||
qDebug() << "群发文本信息" << data;
|
||||
}
|
||||
|
||||
void DataManager::send_to_user(QString sendname, QString to_user, QString text)
|
||||
|
@ -153,7 +154,7 @@ void DataManager::send_to_user(QString sendname, QString to_user, QString text)
|
|||
data = protocol->data_maker(Protocol::MESSAGE, sendname, to_user, text);
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "私发文本信息" << sendname << to_user;
|
||||
qDebug() << "私发文本信息" << data;
|
||||
}
|
||||
|
||||
void DataManager::send_file_to_all(QString sendname, QString filename, QByteArray file)
|
||||
|
@ -162,7 +163,7 @@ void DataManager::send_file_to_all(QString sendname, QString filename, QByteArra
|
|||
data = protocol->data_maker(Protocol::FILE, sendname, filename, QString(file));
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "群发文件" << sendname;
|
||||
qDebug() << "群发文件" << data;
|
||||
}
|
||||
|
||||
void DataManager::send_file_private(QString sendname, QString filename, QByteArray file, QString name)
|
||||
|
@ -171,7 +172,7 @@ void DataManager::send_file_private(QString sendname, QString filename, QByteArr
|
|||
data = protocol->data_maker(Protocol::FILE, name, sendname, filename, QString(file));
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "私发文件" << sendname << name;
|
||||
qDebug() << "私发文件" << data;
|
||||
}
|
||||
|
||||
void DataManager::account_cancellation(QString username)
|
||||
|
@ -189,5 +190,5 @@ void DataManager::update_namelist(QString username)
|
|||
data = protocol->data_maker(Protocol::REQUEST, QString("update_namelist"),QList<QString>{"name",username});
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "发送更新在线用户列表信息";
|
||||
qDebug() << "发送更新在线用户列表信息" << data;
|
||||
}
|
||||
|
|
55
login.cpp
55
login.cpp
|
@ -28,6 +28,7 @@ Login::~Login()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
/**************************************QEvent*************************************/
|
||||
void Login::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
//创建画家,指定绘图设备
|
||||
|
@ -78,17 +79,6 @@ void Login::paintEvent(QPaintEvent *event)
|
|||
ui->btn_signup->setGraphicsEffect(shadow);
|
||||
}
|
||||
|
||||
void Login::new_closebutton(QPushButton* btn, QString position,QSize size)
|
||||
{
|
||||
QPixmap pixmap;
|
||||
pixmap.load(position);
|
||||
btn->setIconSize(size);
|
||||
btn->setStyleSheet("QPushButton{border-width: 1px;border-style: solid;border-radius:15px;background-color: rgb(64, 145, 252);}"
|
||||
"QPushButton:hover{background-color:#999999;}");
|
||||
//设置图标
|
||||
btn->setIcon(pixmap);
|
||||
}
|
||||
|
||||
void Login::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() == Qt::LeftButton)
|
||||
|
@ -122,8 +112,12 @@ void Login::mouseMoveEvent(QMouseEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
|
||||
/***************************************SLOTS************************************/
|
||||
void Login::on_btn_signin_clicked()
|
||||
{
|
||||
this->zoom_down(ui->btn_signin);
|
||||
this->zoom_up(ui->btn_signin);
|
||||
if(connect_flag == true)
|
||||
{
|
||||
user = ui->lineEdit_username->text();
|
||||
|
@ -143,6 +137,8 @@ void Login::on_btn_signin_clicked()
|
|||
|
||||
void Login::on_btn_signup_clicked()
|
||||
{
|
||||
this->zoom_down(ui->btn_signup);
|
||||
this->zoom_up(ui->btn_signup);
|
||||
signup = new Signup();
|
||||
connect(signup,&Signup::show_login_ui,this,&Login::show_login_ui);
|
||||
connect(signup,&Signup::Register,this,&Login::slot_Register);
|
||||
|
@ -232,3 +228,40 @@ void Login::exit_client()
|
|||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
/************************************private functions************************************/
|
||||
void Login::zoom_down(QPushButton* btn)
|
||||
{
|
||||
QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry");
|
||||
//设置间隔时间
|
||||
animalton->setDuration(200);
|
||||
//设置起始位置
|
||||
animalton->setStartValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));
|
||||
//设置结束位置
|
||||
animalton->setEndValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
|
||||
//设置动画曲线
|
||||
animalton->setEasingCurve(QEasingCurve::OutBounce);
|
||||
animalton->start();
|
||||
|
||||
}
|
||||
|
||||
void Login::zoom_up(QPushButton* btn)
|
||||
{
|
||||
QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry");
|
||||
animalton->setDuration(200);
|
||||
animalton->setStartValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
|
||||
animalton->setEndValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));
|
||||
animalton->setEasingCurve(QEasingCurve::OutBounce);
|
||||
animalton->start();
|
||||
}
|
||||
|
||||
void Login::new_closebutton(QPushButton* btn, QString position,QSize size)
|
||||
{
|
||||
QPixmap pixmap;
|
||||
pixmap.load(position);
|
||||
btn->setIconSize(size);
|
||||
btn->setStyleSheet("QPushButton{border-width: 1px;border-style: solid;border-radius:15px;background-color: rgb(64, 145, 252);}"
|
||||
"QPushButton:hover{background-color:#999999;}");
|
||||
//设置图标
|
||||
btn->setIcon(pixmap);
|
||||
}
|
||||
|
|
6
login.h
6
login.h
|
@ -6,6 +6,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
@ -30,7 +31,6 @@ public:
|
|||
void paintEvent(QPaintEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void new_closebutton(QPushButton* btn, QString position,QSize size);
|
||||
|
||||
signals:
|
||||
void signin_request(QString username,QString password);
|
||||
|
@ -60,6 +60,10 @@ private:
|
|||
DataManager *datamanager;
|
||||
bool connect_flag = false;
|
||||
|
||||
void new_closebutton(QPushButton* btn, QString position,QSize size);
|
||||
void zoom_up(QPushButton* btn);
|
||||
void zoom_down(QPushButton* btn);
|
||||
|
||||
};
|
||||
|
||||
#endif // LOGIN_H
|
||||
|
|
4
login.ui
4
login.ui
|
@ -40,7 +40,7 @@ border-radius:7px;
|
|||
padding:2px 4px;
|
||||
font: 14pt "Candara";}
|
||||
|
||||
QPushButton:hover
|
||||
QPushButton:pressed
|
||||
{background-color:#999999;}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -98,7 +98,7 @@ border-radius:7px;
|
|||
padding:2px 4px;
|
||||
font: 14pt "Candara";}
|
||||
|
||||
QPushButton:hover
|
||||
QPushButton:pressed
|
||||
{background-color:#999999;}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
|
|
@ -6,6 +6,7 @@ MainWidget::MainWidget(QString username,QWidget *parent) :
|
|||
ui(new Ui::MainWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setFixedSize(this->width(), this->height());
|
||||
this->setWindowIcon(QIcon(":/icon.png"));
|
||||
this->setWindowTitle(QString("TCP聊天室:%1").arg(username));
|
||||
ui->name_list->setEditTriggers(QAbstractItemView::NoEditTriggers); //不允许编辑
|
||||
|
@ -166,8 +167,8 @@ void MainWidget::on_exit_btn_clicked()
|
|||
|
||||
if(response == QMessageBox::Yes)
|
||||
{
|
||||
emit exit_client();
|
||||
emit update_namelist(username);
|
||||
//emit exit_client();
|
||||
//emit update_namelist(username);
|
||||
this->close();
|
||||
}
|
||||
else
|
||||
|
@ -184,7 +185,7 @@ void MainWidget::on_stop_clicked()
|
|||
if(response == QMessageBox::Yes)
|
||||
{
|
||||
qDebug() << "点击注销账户按钮";
|
||||
emit exit_client();
|
||||
//emit exit_client();
|
||||
emit account_cancellation(username);
|
||||
this->close();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QFile>
|
||||
#include <QProgressDialog>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QScrollBar>
|
||||
#include <QKeyEvent>
|
||||
|
|
|
@ -6,19 +6,25 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>798</width>
|
||||
<width>722</width>
|
||||
<height>587</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>722</width>
|
||||
<height>587</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>510</y>
|
||||
<width>401</width>
|
||||
<x>60</x>
|
||||
<y>500</y>
|
||||
<width>361</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -42,8 +48,8 @@
|
|||
<widget class="QWidget" name="layoutWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>520</x>
|
||||
<y>510</y>
|
||||
<x>470</x>
|
||||
<y>500</y>
|
||||
<width>211</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
|
@ -68,27 +74,30 @@
|
|||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>30</y>
|
||||
<width>401</width>
|
||||
<height>421</height>
|
||||
<x>60</x>
|
||||
<y>50</y>
|
||||
<width>361</width>
|
||||
<height>401</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-radius:20px;</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>520</x>
|
||||
<y>30</y>
|
||||
<width>211</width>
|
||||
<height>441</height>
|
||||
<x>490</x>
|
||||
<y>50</y>
|
||||
<width>171</width>
|
||||
<height>401</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 12pt "Arial Black";</string>
|
||||
<string notr="true">font: 10pt "Arial Black";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>在线用户列表</string>
|
||||
|
@ -98,11 +107,11 @@
|
|||
<item>
|
||||
<widget class="QListWidget" name="name_list">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"> QListWidget { outline: none; border:1px solid white; color: #696969;}
|
||||
QListWidget::Item { width: 60px; height: 40px; }
|
||||
QListWidget::Item:hover { background: #FFA500; color: white; }
|
||||
QListWidget::item:selected { background: #FFC0CB; color: #DC143C; }
|
||||
QListWidget::item:selected:!active { background: blue; }
|
||||
<string notr="true"> QListWidget { outline: none; border:1px solid white; color: #696969;border-radius:\n7px;}
|
||||
QListWidget::Item { width: 60px; height: 35px; }
|
||||
QListWidget::Item:hover { background: #FFA500; color: white; }
|
||||
QListWidget::item:selected { background: #FFC0CB; color: #DC143C; }
|
||||
/*QListWidget::item:selected:!active { background: blue; }*/
|
||||
|
||||
QScrollBar:vertical
|
||||
{
|
||||
|
@ -206,18 +215,26 @@ QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical
|
|||
<widget class="QWidget" name="layoutWidget_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<x>60</x>
|
||||
<y>460</y>
|
||||
<width>401</width>
|
||||
<width>361</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="msg_edit"/>
|
||||
<widget class="QLineEdit" name="msg_edit">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-radius:
|
||||
7px;padding:2px 4px;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="send_btn">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>发送</string>
|
||||
</property>
|
||||
|
|
|
@ -117,15 +117,15 @@ QPair<Protocol::data_types,QJsonObject> Protocol::data_parser(QByteArray data)
|
|||
return qMakePair(RESPONSE,json_data.object());
|
||||
}
|
||||
|
||||
QByteArray Protocol::XOR_En_Decrypt(QString src)
|
||||
QByteArray Protocol::XOR_En_Decrypt(QByteArray src)
|
||||
{
|
||||
QByteArray result;
|
||||
for(auto &i:src)
|
||||
result.append(i.toLatin1() ^ cipher_word);
|
||||
result.append(i ^ cipher_word);
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray Protocol::Upper_Lower_En_Decrypt(QString src)
|
||||
QByteArray Protocol::Upper_Lower_En_Decrypt(QString src)
|
||||
{
|
||||
QByteArray result;
|
||||
for(auto &i:src)
|
||||
|
@ -155,8 +155,11 @@ QByteArray Protocol::data_encrypt(QByteArray src)
|
|||
|
||||
QByteArray Protocol::data_decrypt(QByteArray src)
|
||||
{
|
||||
qDebug() << QString(src);
|
||||
QByteArray result = XOR_En_Decrypt(src);
|
||||
//qDebug() << result;
|
||||
result = Upper_Lower_En_Decrypt(result);
|
||||
//qDebug() << result;
|
||||
return QByteArray::fromBase64(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
explicit Protocol(QObject *parent = nullptr);
|
||||
~Protocol();
|
||||
QByteArray data_builder(QList<any_types> &args);
|
||||
QByteArray XOR_En_Decrypt(QString src);
|
||||
QByteArray XOR_En_Decrypt(QByteArray src);
|
||||
QByteArray Upper_Lower_En_Decrypt(QString src);
|
||||
signals:
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ Signup::Signup(QWidget *parent) : QWidget(parent),
|
|||
|
||||
Signup::~Signup()
|
||||
{
|
||||
emit
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ void TCPClient::configAndrun()
|
|||
|
||||
void TCPClient::sendToserver(QByteArray &data)
|
||||
{
|
||||
qDebug() << data;
|
||||
if (socket.isOpen())
|
||||
{
|
||||
socket.write(data);
|
||||
|
|
Loading…
Reference in New Issue