diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..38eb6e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,172 @@ +# ---> Qt +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.so.* +*.dll +*.dylib + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +*_qmlcache.qrc + +# ---> C++ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# ---> C +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# ---> macOS +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/TcpClient.pro.user b/TcpClient.pro.user deleted file mode 100644 index 8416732..0000000 --- a/TcpClient.pro.user +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - EnvironmentId - {d3fed20c-1c94-44fc-8f6a-4dbf39b54775} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - -fno-delayed-template-parsing - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 4 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.2.3 MinGW 64-bit - Desktop Qt 6.2.3 MinGW 64-bit - qt.qt6.623.win64_mingw_kit - 2 - 0 - 0 - - 0 - C:\Users\25761\Desktop\Error-in-"-Util.asciify("build-C:\Users\25761\Desktop\tcpclient\TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-Profile")":-SyntaxError:-Expected-token-`)' - C:/Users/25761/Desktop/Error-in-"-Util.asciify("build-C:/Users/25761/Desktop/tcpclient/TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-Profile")":-SyntaxError:-Expected-token-`)' - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - - C:\Users\25761\Desktop\Error-in-"-Util.asciify("build-C:\Users\25761\Desktop\tcpclient\TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-111")":-SyntaxError:-Expected-token-`)' - C:/Users/25761/Desktop/Error-in-"-Util.asciify("build-C:/Users/25761/Desktop/tcpclient/TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-111")":-SyntaxError:-Expected-token-`)' - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - 111 - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - C:\Users\25761\Desktop\build-TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-111 - C:/Users/25761/Desktop/build-TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-111 - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - 1112 - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/25761/Desktop/tcpclient/TcpClient.pro - C:/Users/25761/Desktop/tcpclient/TcpClient.pro - false - true - true - false - true - C:/Users/25761/Desktop/build-TcpClient-Desktop_Qt_6_2_3_MinGW_64_bit-111 - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/imgs/exeicon.ico b/imgs/exeicon.ico new file mode 100644 index 0000000..5b3d3d6 Binary files /dev/null and b/imgs/exeicon.ico differ diff --git a/imgs/exeicon.rc b/imgs/exeicon.rc new file mode 100644 index 0000000..8aa6f8c --- /dev/null +++ b/imgs/exeicon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "exeicon.ico" \ No newline at end of file diff --git a/imgs/quit.png b/imgs/quit.png index f270eac..8483679 100644 Binary files a/imgs/quit.png and b/imgs/quit.png differ diff --git a/login.cpp b/login.cpp index cc431a1..cd7bd27 100644 --- a/login.cpp +++ b/login.cpp @@ -1,5 +1,6 @@ #include "login.h" #include "ui_login.h" +#include Login::Login(QWidget *parent) : QMainWindow(parent), @@ -74,7 +75,7 @@ void Login::paintEvent(QPaintEvent *event) // painter.drawPath(painterPath); //设置阴影 - QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + QPointer shadow(new QGraphicsDropShadowEffect(this)); shadow->setOffset(0, 0); //设置阴影距离 shadow->setColor(QColor("#87CEFA")); //设置阴影颜色 shadow->setBlurRadius(10); //设置阴影圆角 @@ -237,7 +238,7 @@ void Login::exit_client() /************************************private functions************************************/ void Login::zoom_down(QPushButton* btn) { - QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); + QScopedPointer animalton(new QPropertyAnimation(btn,"geometry")); //设置间隔时间 animalton->setDuration(200); //设置起始位置 @@ -252,7 +253,7 @@ void Login::zoom_down(QPushButton* btn) void Login::zoom_up(QPushButton* btn) { - QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); + QScopedPointeranimalton(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())); diff --git a/login.h b/login.h index 90504fd..f4d9b67 100644 --- a/login.h +++ b/login.h @@ -54,10 +54,10 @@ private: QPoint point; QString user,passwd; static Login login_instance; - Login *login; - Signup *signup; - MainWidget *mainwidget; - DataManager *datamanager; + QPointer login; + QPointer signup; + QPointer mainwidget; + QPointer datamanager; bool connect_flag = false; void new_closebutton(QPushButton* btn, QString position,QSize size); diff --git a/mainwidget.cpp b/mainwidget.cpp index de9282d..0c15374 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -1,5 +1,6 @@ #include "mainwidget.h" #include "ui_mainwidget.h" +#include MainWidget::MainWidget(QString username,QWidget *parent) : QWidget(parent), @@ -186,7 +187,7 @@ void MainWidget::on_send_btn_clicked() QString to_user = text.mid(1,n-1); QString insert = "tell you quietly:"; 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; if(username == to_user) { @@ -235,20 +236,7 @@ void MainWidget::on_exit_btn_clicked() { zoom_down(ui->exit_btn); zoom_up(ui->exit_btn); - QMessageBox::StandardButton response; - response = QMessageBox::question(this, "退出", tr("确定退出软件?否则将最小化窗口")); - - if(response == QMessageBox::Yes) - { - //emit exit_client(); - //emit update_namelist(username); - this->close(); - } - else - { - this->hide(); - CreatSystemTray(); - } + close(); } void MainWidget::on_stop_clicked() @@ -352,11 +340,10 @@ void MainWidget::update_users(int count,QListonline_users) void MainWidget::disconnect_form_server() { QMessageBox::critical(this,"连接超时","请检查您的网络连接!"); + qApp->quit(); } void MainWidget::sendFile(QString filePath,QString filename,QString name) { - //发送的数据存入block中 - QByteArray block; QFile file(filePath); //打开文件,定义错误提醒 if(!file.open(QIODevice::ReadOnly)){ @@ -364,10 +351,6 @@ void MainWidget::sendFile(QString filePath,QString filename,QString name) return; } - /*打开文件流,以写的方式打开 - QDataStream out(&block,QIODevice::WriteOnly); - out.setVersion(QDataStream::Qt_5_8);*/ - //将数据读取到QByteArray 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); } - QProgressDialog *progressDlg = new QProgressDialog(this); + QScopedPointer progressDlg(new QProgressDialog(this)); progressDlg->setWindowModality(Qt::WindowModal); progressDlg->setMinimumDuration(0); 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) { - /*QString homePath = QDir::homePath(); - QString filePath = QFileDialog::getExistingDirectory(this,tr("Open Directory"),homePath, - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);*/ QString filepath = "./Document"; QDir dir(filepath); if(dir.exists()) @@ -453,20 +433,20 @@ bool MainWidget::eventFilter(QObject *target, QEvent *event) void MainWidget::CreatSystemTray() { //创建菜单对象和托盘图标对象 - TrayMennu = new QMenu(this); - SystemTray = new QSystemTrayIcon(this); + QPointer TrayMennu(new QMenu(this)); + QPointer SystemTray(new QSystemTrayIcon(this)); //创建菜单项 - ActionShow = new QAction(tr("Show"), this); - ActionQuit = new QAction(tr("Exit"), this); - connect(ActionShow,&QAction::triggered,[=](){ + QPointer ActionShow(new QAction(tr("Show"), this)); + QPointer ActionQuit(new QAction(tr("Exit"), this)); + connect(ActionShow,&QAction::triggered,this,[=](){ this->show(); SystemTray->hide(); }); - connect(ActionQuit,&QAction::triggered,[=](){ + connect(ActionQuit,&QAction::triggered,this,[=](){ this->close(); }); - connect(SystemTray,&QSystemTrayIcon::activated,[=](){ + connect(SystemTray,&QSystemTrayIcon::activated,this,[=](){ this->show(); SystemTray->hide(); }); @@ -486,7 +466,7 @@ void MainWidget::CreatSystemTray() void MainWidget::zoom_down(QPushButton* btn) { - QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); + QScopedPointer animalton(new QPropertyAnimation(btn,"geometry")); animalton->setDuration(150); animalton->setStartValue(QRect(btn->x(),btn->y(),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) { - QPropertyAnimation *animalton = new QPropertyAnimation(btn,"geometry"); + QScopedPointer animalton(new QPropertyAnimation(btn,"geometry")); animalton->setDuration(150); 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 MainWidget::closeEvent(QCloseEvent *event) +{ + std::function 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(); +} diff --git a/mainwidget.h b/mainwidget.h index fa15c1b..82590cb 100644 --- a/mainwidget.h +++ b/mainwidget.h @@ -71,6 +71,7 @@ private: void zoom_up(QPushButton* btn); void zoom_down(QPushButton* btn); void CreatSystemTray(); + void closeEvent(QCloseEvent *event); }; #endif // MAINWIDGET_H diff --git a/signup.cpp b/signup.cpp index 5f48a5b..179814c 100644 --- a/signup.cpp +++ b/signup.cpp @@ -1,11 +1,12 @@ #include "signup.h" #include "ui_signup.h" +#include Signup::Signup(QWidget *parent) : QWidget(parent), ui(new Ui::Signup) { ui->setupUi(this); - QPixmap *pix = new QPixmap(":/blue.png"); + QScopedPointer pix (new QPixmap(":/blue.png")); QSize sz = ui->label_image->size(); ui->label_image->setPixmap(pix->scaled(sz)); @@ -13,7 +14,7 @@ Signup::Signup(QWidget *parent) : QWidget(parent), this->setWindowFlags(Qt::FramelessWindowHint); //无边框 //设置阴影 - QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + QPointer shadow (new QGraphicsDropShadowEffect(this)); shadow->setOffset(-3, 0); shadow->setColor(QColor("#888888")); shadow->setBlurRadius(30); @@ -22,7 +23,6 @@ Signup::Signup(QWidget *parent) : QWidget(parent), Signup::~Signup() { - emit delete ui; }