Bug fixed.

This commit is contained in:
Mentalflow 2023-01-15 23:29:09 +08:00
parent 99d23522b2
commit 367173d1fc
Signed by untrusted user: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
6 changed files with 54 additions and 44 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,5 +1,6 @@
#include "login.h" #include "login.h"
#include "ui_login.h" #include "ui_login.h"
#include <QPointer>
Login::Login(QWidget *parent) : Login::Login(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
@ -74,7 +75,7 @@ void Login::paintEvent(QPaintEvent *event)
// painter.drawPath(painterPath); // painter.drawPath(painterPath);
//设置阴影 //设置阴影
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); QPointer<QGraphicsDropShadowEffect> shadow(new QGraphicsDropShadowEffect(this));
shadow->setOffset(0, 0); //设置阴影距离 shadow->setOffset(0, 0); //设置阴影距离
shadow->setColor(QColor("#87CEFA")); //设置阴影颜色 shadow->setColor(QColor("#87CEFA")); //设置阴影颜色
shadow->setBlurRadius(10); //设置阴影圆角 shadow->setBlurRadius(10); //设置阴影圆角
@ -237,7 +238,7 @@ void Login::exit_client()
/************************************private functions************************************/ /************************************private functions************************************/
void Login::zoom_down(QPushButton* btn) void Login::zoom_down(QPushButton* btn)
{ {
QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); QScopedPointer<QPropertyAnimation> animalton(new QPropertyAnimation(btn,"geometry"));
//设置间隔时间 //设置间隔时间
animalton->setDuration(200); animalton->setDuration(200);
//设置起始位置 //设置起始位置
@ -252,7 +253,7 @@ void Login::zoom_down(QPushButton* btn)
void Login::zoom_up(QPushButton* btn) void Login::zoom_up(QPushButton* btn)
{ {
QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); QScopedPointer<QPropertyAnimation>animalton(new QPropertyAnimation(btn,"geometry"));
animalton->setDuration(200); animalton->setDuration(200);
animalton->setStartValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height())); animalton->setStartValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
animalton->setEndValue(QRect(btn->x(),btn->y(),btn->width(),btn->height())); animalton->setEndValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));

View File

@ -54,10 +54,10 @@ private:
QPoint point; QPoint point;
QString user,passwd; QString user,passwd;
static Login login_instance; static Login login_instance;
Login *login; QPointer<Login> login;
Signup *signup; QPointer<Signup> signup;
MainWidget *mainwidget; QPointer<MainWidget> mainwidget;
DataManager *datamanager; QPointer<DataManager> datamanager;
bool connect_flag = false; bool connect_flag = false;
void new_closebutton(QPushButton* btn, QString position,QSize size); void new_closebutton(QPushButton* btn, QString position,QSize size);

View File

@ -1,5 +1,6 @@
#include "mainwidget.h" #include "mainwidget.h"
#include "ui_mainwidget.h" #include "ui_mainwidget.h"
#include <QPointer>
MainWidget::MainWidget(QString username,QWidget *parent) : MainWidget::MainWidget(QString username,QWidget *parent) :
QWidget(parent), QWidget(parent),
@ -186,7 +187,7 @@ void MainWidget::on_send_btn_clicked()
QString to_user = text.mid(1,n-1); QString to_user = text.mid(1,n-1);
QString insert = "tell you quietly:"; QString insert = "tell you quietly:";
QString data_text = insert + text.mid(n,-1); QString data_text = insert + text.mid(n,-1);
QString text_self = QString("私发给%1:%2").arg(to_user).arg(text.mid(n)); QString text_self = QString("私发给%1:%2").arg(to_user, text.mid(n));
qDebug() << text_self; qDebug() << text_self;
if(username == to_user) if(username == to_user)
{ {
@ -235,20 +236,7 @@ void MainWidget::on_exit_btn_clicked()
{ {
zoom_down(ui->exit_btn); zoom_down(ui->exit_btn);
zoom_up(ui->exit_btn); zoom_up(ui->exit_btn);
QMessageBox::StandardButton response; close();
response = QMessageBox::question(this, "退出", tr("确定退出软件?否则将最小化窗口"));
if(response == QMessageBox::Yes)
{
//emit exit_client();
//emit update_namelist(username);
this->close();
}
else
{
this->hide();
CreatSystemTray();
}
} }
void MainWidget::on_stop_clicked() void MainWidget::on_stop_clicked()
@ -352,11 +340,10 @@ void MainWidget::update_users(int count,QList<QString>online_users)
void MainWidget::disconnect_form_server() void MainWidget::disconnect_form_server()
{ {
QMessageBox::critical(this,"连接超时","请检查您的网络连接!"); QMessageBox::critical(this,"连接超时","请检查您的网络连接!");
qApp->quit();
} }
void MainWidget::sendFile(QString filePath,QString filename,QString name) void MainWidget::sendFile(QString filePath,QString filename,QString name)
{ {
//发送的数据存入block中
QByteArray block;
QFile file(filePath); QFile file(filePath);
//打开文件,定义错误提醒 //打开文件,定义错误提醒
if(!file.open(QIODevice::ReadOnly)){ if(!file.open(QIODevice::ReadOnly)){
@ -364,10 +351,6 @@ void MainWidget::sendFile(QString filePath,QString filename,QString name)
return; return;
} }
/*打开文件流,以写的方式打开
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_8);*/
//将数据读取到QByteArray //将数据读取到QByteArray
QByteArray dataOfFile = file.readAll(); QByteArray dataOfFile = file.readAll();
//关闭文件 //关闭文件
@ -382,7 +365,7 @@ void MainWidget::sendFile(QString filePath,QString filename,QString name)
{ {
emit send_file_private(username,filename,dataOfFile,name); emit send_file_private(username,filename,dataOfFile,name);
} }
QProgressDialog *progressDlg = new QProgressDialog(this); QScopedPointer<QProgressDialog> progressDlg(new QProgressDialog(this));
progressDlg->setWindowModality(Qt::WindowModal); progressDlg->setWindowModality(Qt::WindowModal);
progressDlg->setMinimumDuration(0); progressDlg->setMinimumDuration(0);
progressDlg->setAttribute(Qt::WA_DeleteOnClose, true); progressDlg->setAttribute(Qt::WA_DeleteOnClose, true);
@ -404,9 +387,6 @@ void MainWidget::sendFile(QString filePath,QString filename,QString name)
void MainWidget::readFile(QString filename,QByteArray data) void MainWidget::readFile(QString filename,QByteArray data)
{ {
/*QString homePath = QDir::homePath();
QString filePath = QFileDialog::getExistingDirectory(thistr("Open Directory"),homePath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);*/
QString filepath = "./Document"; QString filepath = "./Document";
QDir dir(filepath); QDir dir(filepath);
if(dir.exists()) if(dir.exists())
@ -453,20 +433,20 @@ bool MainWidget::eventFilter(QObject *target, QEvent *event)
void MainWidget::CreatSystemTray() void MainWidget::CreatSystemTray()
{ {
//创建菜单对象和托盘图标对象 //创建菜单对象和托盘图标对象
TrayMennu = new QMenu(this); QPointer<QMenu> TrayMennu(new QMenu(this));
SystemTray = new QSystemTrayIcon(this); QPointer<QSystemTrayIcon> SystemTray(new QSystemTrayIcon(this));
//创建菜单项 //创建菜单项
ActionShow = new QAction(tr("Show"), this); QPointer<QAction> ActionShow(new QAction(tr("Show"), this));
ActionQuit = new QAction(tr("Exit"), this); QPointer<QAction> ActionQuit(new QAction(tr("Exit"), this));
connect(ActionShow,&QAction::triggered,[=](){ connect(ActionShow,&QAction::triggered,this,[=](){
this->show(); this->show();
SystemTray->hide(); SystemTray->hide();
}); });
connect(ActionQuit,&QAction::triggered,[=](){ connect(ActionQuit,&QAction::triggered,this,[=](){
this->close(); this->close();
}); });
connect(SystemTray,&QSystemTrayIcon::activated,[=](){ connect(SystemTray,&QSystemTrayIcon::activated,this,[=](){
this->show(); this->show();
SystemTray->hide(); SystemTray->hide();
}); });
@ -486,7 +466,7 @@ void MainWidget::CreatSystemTray()
void MainWidget::zoom_down(QPushButton* btn) void MainWidget::zoom_down(QPushButton* btn)
{ {
QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); QScopedPointer<QPropertyAnimation> animalton(new QPropertyAnimation(btn,"geometry"));
animalton->setDuration(150); animalton->setDuration(150);
animalton->setStartValue(QRect(btn->x(),btn->y(),btn->width(),btn->height())); animalton->setStartValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));
animalton->setEndValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height())); animalton->setEndValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
@ -497,10 +477,38 @@ void MainWidget::zoom_down(QPushButton* btn)
void MainWidget::zoom_up(QPushButton* btn) void MainWidget::zoom_up(QPushButton* btn)
{ {
QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); QScopedPointer<QPropertyAnimation> animalton(new QPropertyAnimation(btn,"geometry"));
animalton->setDuration(150); animalton->setDuration(150);
animalton->setStartValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height())); animalton->setStartValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
animalton->setEndValue(QRect(btn->x(),btn->y(),btn->width(),btn->height())); animalton->setEndValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));
animalton->setEasingCurve(QEasingCurve::OutBounce); animalton->setEasingCurve(QEasingCurve::OutBounce);
animalton->start(); animalton->start();
} }
void MainWidget::closeEvent(QCloseEvent *event)
{
std::function<void(int)> callback;
callback = [=](int r)->void{
switch (r)
{
case QMessageBox::Ok:
{
event->accept();
qApp->quit();
break;
}
default:
{
event->ignore();
this->hide();
CreatSystemTray();
break;
}
}
};
QMessageBox box(QMessageBox::Question,QString("退出"), QString("确定退出软件?否则将最小化窗口"),QMessageBox::Ok|QMessageBox::Cancel);
box.button(QMessageBox::Ok)->setText("");
box.button(QMessageBox::Cancel)->setText("");
callback(box.exec());
event->ignore();
}

View File

@ -71,6 +71,7 @@ private:
void zoom_up(QPushButton* btn); void zoom_up(QPushButton* btn);
void zoom_down(QPushButton* btn); void zoom_down(QPushButton* btn);
void CreatSystemTray(); void CreatSystemTray();
void closeEvent(QCloseEvent *event);
}; };
#endif // MAINWIDGET_H #endif // MAINWIDGET_H

View File

@ -1,11 +1,12 @@
#include "signup.h" #include "signup.h"
#include "ui_signup.h" #include "ui_signup.h"
#include <QPointer>
Signup::Signup(QWidget *parent) : QWidget(parent), Signup::Signup(QWidget *parent) : QWidget(parent),
ui(new Ui::Signup) ui(new Ui::Signup)
{ {
ui->setupUi(this); ui->setupUi(this);
QPixmap *pix = new QPixmap(":/blue.png"); QScopedPointer<QPixmap> pix (new QPixmap(":/blue.png"));
QSize sz = ui->label_image->size(); QSize sz = ui->label_image->size();
ui->label_image->setPixmap(pix->scaled(sz)); ui->label_image->setPixmap(pix->scaled(sz));
@ -13,7 +14,7 @@ Signup::Signup(QWidget *parent) : QWidget(parent),
this->setWindowFlags(Qt::FramelessWindowHint); //无边框 this->setWindowFlags(Qt::FramelessWindowHint); //无边框
//设置阴影 //设置阴影
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); QPointer<QGraphicsDropShadowEffect> shadow (new QGraphicsDropShadowEffect(this));
shadow->setOffset(-3, 0); shadow->setOffset(-3, 0);
shadow->setColor(QColor("#888888")); shadow->setColor(QColor("#888888"));
shadow->setBlurRadius(30); shadow->setBlurRadius(30);
@ -22,7 +23,6 @@ Signup::Signup(QWidget *parent) : QWidget(parent),
Signup::~Signup() Signup::~Signup()
{ {
emit
delete ui; delete ui;
} }