├── .gitignore ├── README.md ├── Server ├── Server.pro ├── chat.cpp ├── chat.h ├── file.cpp ├── file.h ├── main.cpp ├── mysocket.cpp ├── mysocket.h ├── transfer.cpp └── transfer.h └── officeCooperation ├── addfriend.cpp ├── addfriend.h ├── addfriend.ui ├── chatclient.cpp ├── chatclient.h ├── chatclient.ui ├── configuration.cpp ├── configuration.h ├── controller.cpp ├── controller.h ├── controllerlogregister.cpp ├── controllerlogregister.h ├── dialog.cpp ├── dialog.h ├── dialog.ui ├── doc.cpp ├── doc.h ├── doc.ui ├── fileclient.cpp ├── fileclient.h ├── fileclient.ui ├── friendwidget.cpp ├── friendwidget.h ├── friendwidget.ui ├── getdatabase.cpp ├── getdatabase.h ├── image.qrc ├── image ├── 1.jpg ├── QtPic │ ├── about.png │ ├── alignboth.png │ ├── aligncenter.png │ ├── alignleft.png │ ├── alignright.png │ ├── close.png │ ├── copy.png │ ├── cut.png │ ├── exit.png │ ├── font.png │ ├── newfile.png │ ├── open.png │ ├── paste.png │ ├── save.png │ ├── saveas.png │ └── time.png ├── add.png ├── background │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ └── 8.jpg ├── doc.png ├── fileclient.jpg ├── head.png ├── icon │ ├── 1.jpg │ ├── 10.jpg │ ├── 11.jpg │ ├── 12.jpg │ ├── 13.jpg │ ├── 14.jpg │ ├── 15.jpg │ ├── 16.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ ├── 8.jpg │ └── 9.jpg ├── icons48.png ├── mainwindow.png ├── project.png ├── schedule.png └── todo.png ├── login.cpp ├── login.h ├── login.ui ├── loginerror.cpp ├── loginerror.h ├── loginerror.ui ├── loginverify.cpp ├── loginverify.h ├── main.cpp ├── mainsiderbar.cpp ├── mainsiderbar.h ├── mainsiderbar.ui ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── myapp.cpp ├── myapp.h ├── myclient.cpp ├── myclient.h ├── myclient.ui ├── mydatabase.cpp ├── mydatabase.h ├── mytcpservice.cpp ├── mytcpservice.h ├── mytcpservice.ui ├── newproject.cpp ├── newproject.h ├── newproject.ui ├── officeCooperation.pro ├── passwordreset.cpp ├── passwordreset.h ├── passwordreset.ui ├── personcard.cpp ├── personcard.h ├── personcard.ui ├── picture.cpp ├── picture.h ├── register.cpp ├── register.h ├── register.ui ├── todo.cpp ├── todo.h ├── todolist.cpp ├── todolist.h ├── todolist.ui ├── welcome.cpp ├── welcome.h └── welcome.ui /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.so.* 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | object_script.*.Release 15 | object_script.*.Debug 16 | *_plugin_import.cpp 17 | /.qmake.cache 18 | /.qmake.stash 19 | *.pro.user 20 | *.pro.user.* 21 | *.qbs.user 22 | *.qbs.user.* 23 | *.moc 24 | moc_*.cpp 25 | moc_*.h 26 | qrc_*.cpp 27 | ui_*.h 28 | *.qmlc 29 | *.jsc 30 | Makefile* 31 | *build-* 32 | *.qm 33 | *.prl 34 | 35 | # Qt unit tests 36 | target_wrapper.* 37 | 38 | # QtCreator 39 | *.autosave 40 | 41 | # QtCreator Qml 42 | *.qmlproject.user 43 | *.qmlproject.user.* 44 | 45 | # QtCreator CMake 46 | CMakeLists.txt.user* 47 | 48 | # QtCreator 4.8< compilation database 49 | compile_commands.json 50 | 51 | # QtCreator local machine specific files for imported projects 52 | *creator.user* 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Qt_officeCooperation 2 | Qt写的一个简单的办公协作软件,计划实现注册、登录、即时通讯、文件互传、文本编辑、日程表等功能 3 | 4 | 其中 5 | - officecooperation文件夹存放了用户电脑运行的代码(win11 Qt5.15.2 需要加载MySQL数据库驱动) 6 | - Server文件夹存放服务器上运行的代码,用来监听用户的连接,转发消息,文件(centos7.9 Qt5.12.0) 7 | 8 | **已经实现的功能** 9 | - 注册 10 | - 登录 11 | - 添加联系人 12 | - 删除联系人 13 | - 右键删除 14 | - 搜索已有联系人 15 | - 点击头像,个人页面设置 16 | - 头像 17 | - 背景 18 | - 密码 19 | - 设定计划 20 | - 待办事项(to do list) 21 | - 左键点击完成 22 | - 项目编辑 23 | - 文本编辑 24 | - 项目管理 25 | - 发送消息 26 | - 左键打开聊天窗口 27 | - 发送文件 28 | -------------------------------------------------------------------------------- /Server/Server.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | QT += network 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | main.cpp \ 19 | mysocket.cpp \ 20 | chat.cpp \ 21 | file.cpp \ 22 | transfer.cpp 23 | 24 | # Default rules for deployment. 25 | qnx: target.path = /tmp/$${TARGET}/bin 26 | else: unix:!android: target.path = /opt/$${TARGET}/bin 27 | !isEmpty(target.path): INSTALLS += target 28 | 29 | HEADERS += \ 30 | mysocket.h \ 31 | chat.h \ 32 | file.h \ 33 | transfer.h 34 | 35 | #QMAKE_LFLAGS += -no-pie 36 | 37 | TEMPLATE = app 38 | -------------------------------------------------------------------------------- /Server/chat.cpp: -------------------------------------------------------------------------------- 1 | #include "chat.h" 2 | #include 3 | #include"mysocket.h" 4 | 5 | Chat::Chat(int port, QObject *parent) 6 | { 7 | listen(QHostAddress::Any,port); 8 | } 9 | 10 | void Chat::incomingConnection(qintptr socketDescriptor) 11 | { 12 | MySocket* socket=new MySocket(); 13 | socket->setSocketDescriptor(socketDescriptor);//描述符 14 | connect(socket,&MySocket::reportMsg,this,&Chat::forwardMsg); 15 | } 16 | 17 | void Chat::forwardMsg(QStringList sp,MySocket* socket) 18 | { 19 | if(sp[0]=="connected"){//首次连接 20 | qDebug()<isWritable()){toSocket->write(qmsg.toUtf8());} 28 | } 29 | 30 | } 31 | else if(sp[0]=="msg"){ 32 | if(!sockets2.contains(sp[2])){return;}//no socket 33 | MySocket* toSocket=sockets2.value(sp[2]); 34 | QString qmsg=sp[0]+split+sp[1]+split+sp[3]; 35 | if(toSocket->isWritable()){toSocket->write(qmsg.toUtf8());} 36 | } 37 | else if(sp[0]=="disconnected"){ 38 | int size=sp.size(); 39 | for(int i=3;iisWritable()){toSocket->write(qmsg.toUtf8());} 44 | } 45 | MySocket* ms= sockets2.value(sp[1]); 46 | ms->disconnectFromHost(); 47 | delete ms; 48 | sockets2.remove(sp[1]); 49 | } 50 | else if(sp[0]=="refresh"){ 51 | if(!sockets2.contains(sp[2])){return;}//no socket 52 | MySocket* toSocket=sockets2.value(sp[2]); 53 | QString qmsg=sp[0]; 54 | if(toSocket->isWritable()){toSocket->write(qmsg.toUtf8());}; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Server/chat.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAT_H 2 | #define CHAT_H 3 | #include 4 | #include 5 | #include"mysocket.h" 6 | #include 7 | 8 | class Chat:public QTcpServer 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit Chat(int port,QObject *parent=nullptr); 13 | QMap sockets2;//username,socket 14 | protected://处理新的连接 15 | virtual void incomingConnection(qintptr socketDescriptor); 16 | 17 | public slots: 18 | void forwardMsg(QStringList,MySocket*); 19 | private: 20 | const QString split="↓⊙ā"; 21 | }; 22 | 23 | #endif // CHAT_H 24 | -------------------------------------------------------------------------------- /Server/file.cpp: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | #include 3 | #include"mysocket.h" 4 | #include"transfer.h" 5 | 6 | File::File(int port, QObject *parent) 7 | { 8 | listen(QHostAddress::Any,port); 9 | } 10 | 11 | void File::incomingConnection(qintptr socketDescriptor) 12 | { 13 | MySocket* socket=new MySocket(); 14 | socket->setSocketDescriptor(socketDescriptor);//描述符 15 | connect(socket,&MySocket::reportMsg,this,&File::forwardMsg); 16 | } 17 | 18 | void File::forwardMsg(QStringList sp,MySocket* socket) 19 | { 20 | if(sp[0]=="connected"){//首次连接 21 | sockets2.insert(sp[1],socket);//save socket 22 | } 23 | else if(sp[0]=="file"){ 24 | if(!sockets2.contains(sp[2])){return;}//no socket 25 | MySocket* toSocket=sockets2.value(sp[2]); 26 | int curPort=port++; 27 | if(port==20000){port=10000;} 28 | Transfer* mt = new Transfer(curPort); 29 | QString qmsg = QString::number(curPort)+split+sp[1]+split+sp[2]; 30 | if(socket->isWritable()){socket->write(qmsg.toUtf8());} 31 | if(toSocket->isWritable()){toSocket->write(qmsg.toUtf8());} 32 | } 33 | else if(sp[0]=="disconnected"){ 34 | MySocket* ms= sockets2.value(sp[1]); 35 | ms->disconnectFromHost(); 36 | delete ms; 37 | sockets2.remove(sp[1]); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Server/file.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H 2 | #define FILE_H 3 | #include 4 | #include 5 | #include"mysocket.h" 6 | #include 7 | 8 | class File:public QTcpServer 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit File(int port,QObject *parent=nullptr); 13 | QMap sockets2;//username,socket 14 | protected://处理新的连接 15 | virtual void incomingConnection(qintptr socketDescriptor); 16 | 17 | public slots: 18 | void forwardMsg(QStringList,MySocket*); 19 | private: 20 | const QString split="↓⊙ā"; 21 | int port=10000;//true transfer file port , auto_increment 22 | }; 23 | 24 | #endif // FILE_H 25 | -------------------------------------------------------------------------------- /Server/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"file.h" 3 | #include"chat.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QCoreApplication a(argc, argv); 8 | Chat* c = new Chat(25000); 9 | File* f= new File(26000); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Server/mysocket.cpp: -------------------------------------------------------------------------------- 1 | #include "mysocket.h" 2 | 3 | MySocket::MySocket() 4 | { 5 | connect(this,&MySocket::readyRead,this,&MySocket::myReceive); 6 | } 7 | 8 | void MySocket::myReceive() 9 | { 10 | QString qmsg=""; 11 | while(true){ 12 | char buffer[1024]={0}; 13 | int len=this->read(buffer,sizeof(buffer)); 14 | if(!len){break;} 15 | qmsg+=QString::fromUtf8(buffer); 16 | } 17 | QStringList sp=qmsg.split(split); 18 | if(username=="")username=sp[1]; 19 | emit reportMsg(sp,this); 20 | } 21 | -------------------------------------------------------------------------------- /Server/mysocket.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSOCKET_H 2 | #define MYSOCKET_H 3 | #include 4 | #include 5 | 6 | class MySocket:public QTcpSocket 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MySocket(); 11 | const QString split="↓⊙ā"; 12 | 13 | private: 14 | QString username="";//一个socket绑定 一个user 15 | 16 | signals: 17 | void reportMsg(QStringList,MySocket*);//消息给服务器转发 18 | 19 | public slots: 20 | void myReceive();//处理接收消息 21 | }; 22 | 23 | #endif // MYSOCKET_H 24 | -------------------------------------------------------------------------------- /Server/transfer.cpp: -------------------------------------------------------------------------------- 1 | #include "transfer.h" 2 | #include 3 | 4 | Transfer::Transfer(int port) 5 | { 6 | listen(QHostAddress::Any, port); 7 | } 8 | 9 | Transfer::~Transfer() 10 | { 11 | qDebug()<<"delete transfer "; 12 | 13 | delete timer; 14 | } 15 | 16 | void Transfer::incomingConnection(qintptr socketDescriptor) 17 | { 18 | if(socket1==nullptr){ 19 | socket1 = new QTcpSocket(this); 20 | socket1->setSocketDescriptor(socketDescriptor); 21 | connect(socket1,&QTcpSocket::readyRead,this, &Transfer::send1 ); 22 | } 23 | else{ 24 | socket2 = new QTcpSocket(this ); 25 | socket2->setSocketDescriptor(socketDescriptor); 26 | connect(socket2,&QTcpSocket::readyRead,this, &Transfer::send2 ); 27 | } 28 | } 29 | 30 | void Transfer::myDelete() 31 | { 32 | timer->stop(); 33 | delete this; 34 | } 35 | 36 | void Transfer::send1(){ 37 | if(fileSizeAll == 0){ 38 | QString head = socket1->readAll(); 39 | QStringList sp = head.split(split); 40 | fileSizeAll = sp[1].toInt(); 41 | fileSizeSend = 0; 42 | if(socket2->isWritable()){socket2->write(head.toUtf8());} 43 | } 44 | else{ 45 | int len= 0; 46 | do{ 47 | char buffer[1024]={0}; 48 | len = socket1->read(buffer ,sizeof(buffer)); 49 | if(socket2->isWritable()){socket2->write(buffer,len);} 50 | if(len>0){fileSizeSend += len;} 51 | if(fileSizeAll == fileSizeSend){ 52 | timer = new QTimer(this); 53 | timer->start(10000); 54 | connect(timer, &QTimer::timeout, this,&Transfer::myDelete ); 55 | } 56 | }while(len>0); 57 | } 58 | } 59 | 60 | void Transfer::send2() 61 | { 62 | if(fileSizeAll == 0){ 63 | QString head = socket2->readAll(); 64 | QStringList sp = head.split(split); 65 | fileSizeAll = sp[1].toInt(); 66 | fileSizeSend = 0; 67 | if(socket1->isWritable()){socket1->write(head.toUtf8());} 68 | } 69 | else{ 70 | int len= 0; 71 | do{ 72 | char buffer[1024]={0}; 73 | len = socket2->read(buffer ,sizeof(buffer)); 74 | if(socket1->isWritable()){socket1->write(buffer,len);} 75 | if(len>0){fileSizeSend += len;} 76 | if(fileSizeAll == fileSizeSend){ 77 | timer = new QTimer(this); 78 | timer->start(10000); 79 | connect(timer, &QTimer::timeout, this,&Transfer::myDelete ); 80 | } 81 | }while(len>0); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Server/transfer.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFER_H 2 | #define TRANSFER_H 3 | #include 4 | #include 5 | #include 6 | 7 | class Transfer:public QTcpServer 8 | { 9 | Q_OBJECT 10 | public: 11 | Transfer(int port); 12 | ~Transfer(); 13 | 14 | protected://处理新的连接 15 | virtual void incomingConnection(qintptr socketDescriptor); 16 | 17 | private: 18 | QTcpSocket* socket1=nullptr, *socket2=nullptr; 19 | int descrip[2]; 20 | int index=0; 21 | int fileSizeAll=0; 22 | int fileSizeSend=0; 23 | QString split = "↓⊙ā"; 24 | QTimer* timer=nullptr; 25 | 26 | public slots: 27 | void send1(); 28 | void send2(); 29 | void myDelete(); 30 | 31 | }; 32 | 33 | #endif // TRANSFER_H 34 | -------------------------------------------------------------------------------- /officeCooperation/addfriend.cpp: -------------------------------------------------------------------------------- 1 | #include "addfriend.h" 2 | #include 3 | #include "configuration.h" 4 | #include "ui_addfriend.h" 5 | #include"friendwidget.h" 6 | #include 7 | 8 | AddFriend::AddFriend(QString uname, int id_, QWidget *parent) : 9 | QWidget(parent),ui(new Ui::AddFriend), 10 | id(id_),username(uname) 11 | { 12 | ui->setupUi(this); 13 | ui->lineEdit->setFocus(); 14 | this->setWindowTitle("添加好友"); 15 | this->setWindowIcon(QIcon(":/image/icons48.png")); 16 | ui->pushButton->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); 17 | ui->pushButton->setShortcut(Qt::Key_Enter); 18 | ui->pushButton->setShortcut(Qt::Key_Return); 19 | md=new MyDatabase("add"+uname);//数据库初始化 20 | db=md->getDatabase(); 21 | query=QSqlQuery(db); 22 | connect(ui->pushButton,&QPushButton::clicked,this, &AddFriend::showFriends ); 23 | } 24 | 25 | AddFriend::~AddFriend() 26 | { 27 | emit forwardRefresh();//通知刷新好友列表 28 | delete ui; 29 | } 30 | 31 | void AddFriend::paintEvent(QPaintEvent *e) 32 | { 33 | QPixmap pixmap = QPixmap(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg").scaled(this->size()); 34 | QPainter painter(this); 35 | painter.drawPixmap(this->rect(),pixmap); 36 | } 37 | 38 | void AddFriend::closeEvent(QCloseEvent *e) 39 | { 40 | emit delete_addfriend_signals(); 41 | } 42 | 43 | void AddFriend::showFriends() 44 | { 45 | if(ui->lineEdit->text()==""){QMessageBox::information(this,"","请输入您想查询的联系人关键词");return;} 46 | QString peername = "%" + ui->lineEdit->text() + "%"; 47 | QString sql="SELECT id,username,state,icon FROM `user` WHERE username like '"+peername+"'"; 48 | 49 | query.exec(sql); 50 | 51 | ui->friendsListWidget->clear(); 52 | qDeleteAll(friends);//清空指针空间 53 | friends.clear(); 54 | 55 | while(query.next()){//显示好友列表 56 | int peerid = query.value(0).toInt(); 57 | QString peername=query.value(1).toString(); 58 | QString state= query.value(2).toInt() ? "在线" : "离线" ; 59 | int icon=query.value(3).toInt(); 60 | 61 | FriendWidget* f=new FriendWidget(peerid,peername,state,icon,ui->friendsListWidget); 62 | QListWidgetItem *item=new QListWidgetItem(ui->friendsListWidget); 63 | item->setSizeHint(QSize(320,60)); 64 | ui->friendsListWidget->addItem(item); 65 | ui->friendsListWidget->setItemWidget(item,f); 66 | f->show(); 67 | friends.push(f); 68 | connect(f,&FriendWidget::forwardPeer,this,&AddFriend::add ); 69 | } 70 | } 71 | 72 | void AddFriend::add(int peerid ,QString peername) 73 | { 74 | int res = QMessageBox::information(this,"","是否添加对方为好友?",QMessageBox::Yes,QMessageBox::No ); 75 | if(res == QMessageBox::Yes ){ 76 | if(peername==username){QMessageBox::information(this,"","您不能将自己添加为联系人");return;} 77 | QString sql = "SELECT uid1 FROM relationship WHERE uid1="+QString::number(id)+" AND uid2="+QString::number(peerid); 78 | query.exec(sql); 79 | if(query.next()){//是否已经是好友了 80 | QMessageBox::information(this,"","您已添加对方为好友,请勿重复添加"); 81 | return ; 82 | } 83 | else{ 84 | QString sql = "INSERT INTO `relationship` (uid1,uid2) VALUES('"+QString::number(id)+"','"+QString::number(peerid)+"')"; 85 | bool ok1 = query.exec(sql); 86 | sql = "INSERT INTO `relationship` (uid2,uid1) VALUES('"+QString::number(id)+"','"+QString::number(peerid)+"')"; 87 | bool ok2 = query.exec(sql); 88 | if(!ok1||!ok2){QMessageBox::information(this,"","添加好友失败,请重新尝试");} 89 | else{ 90 | emit forwardNotice(peername); 91 | QMessageBox::information(this,"","添加好友成功"); 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /officeCooperation/addfriend.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDFRIEND_H 2 | #define ADDFRIEND_H 3 | 4 | #include 5 | #include "friendwidget.h" 6 | #include"mydatabase.h" 7 | #include 8 | 9 | namespace Ui { 10 | class AddFriend; 11 | } 12 | 13 | class AddFriend : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit AddFriend(QString uname,int id,QWidget *parent = nullptr); 19 | ~AddFriend(); 20 | protected: 21 | virtual void paintEvent(QPaintEvent* e); 22 | virtual void closeEvent(QCloseEvent* e); 23 | private: 24 | Ui::AddFriend *ui; 25 | int id; 26 | MyDatabase* md=nullptr; 27 | QSqlDatabase db; 28 | QSqlQuery query; 29 | QString username; 30 | QStack friends; 31 | public slots: 32 | void showFriends(); 33 | void add(int peerid, QString peername); 34 | 35 | signals: 36 | void forwardRefresh(); 37 | void forwardNotice(QString peername); 38 | void delete_addfriend_signals(); 39 | }; 40 | 41 | #endif // ADDFRIEND_H 42 | -------------------------------------------------------------------------------- /officeCooperation/addfriend.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddFriend 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 440 11 | 12 | 13 | 14 | 15 | 400 16 | 440 17 | 18 | 19 | 20 | 21 | 400 22 | 440 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 30 32 | 20 33 | 342 34 | 380 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 250 45 | 20 46 | 47 | 48 | 49 | 50 | 250 51 | 20 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 80 61 | 20 62 | 63 | 64 | 65 | 66 | 80 67 | 20 68 | 69 | 70 | 71 | 72 | 黑体 73 | 74 | 75 | 76 | 搜索 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 340 87 | 350 88 | 89 | 90 | 91 | 92 | 340 93 | 350 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /officeCooperation/chatclient.cpp: -------------------------------------------------------------------------------- 1 | #include "chatclient.h" 2 | #include "configuration.h" 3 | #include "fileclient.h" 4 | #include "ui_chatclient.h" 5 | #include 6 | #include"mainwindow.h" 7 | #include 8 | #include 9 | #include 10 | 11 | chatClient::chatClient(QString _state, MainWindow* mw_, QTcpSocket* file,QTcpSocket* chat,QString username_,QString peername_,QWidget *parent) : 12 | QWidget(parent),ui(new Ui::chatClient), 13 | peername(peername_),username(username_),state(_state),chatsocket(chat),filesocket(file),mw(mw_) 14 | { 15 | ui->setupUi(this); 16 | init(); 17 | ui->sendmsgpushButton_3->setFocus();//焦点 18 | ui->sendmsgpushButton_3->setDefault(true); 19 | ui->msgtextEdit->installEventFilter(this);//事件过滤器 20 | connect(ui->filepushButton_2,&QPushButton::clicked,this, &chatClient::newFileClient ); 21 | connect(ui->sendmsgpushButton_3,&QPushButton::clicked,this, &chatClient::mySend ); 22 | } 23 | 24 | chatClient::~chatClient() 25 | { 26 | delete fc; 27 | delete ui; 28 | } 29 | 30 | void chatClient::closeEvent(QCloseEvent *e) 31 | {//不关闭,只是隐藏 32 | e->ignore(); 33 | if(fc)fc->hide(); 34 | this->hide(); 35 | } 36 | 37 | bool chatClient::eventFilter(QObject *target, QEvent *event) 38 | {//回车键发送 39 | if(target == ui->msgtextEdit) 40 | { 41 | if(event->type() == QEvent::KeyPress) 42 | { 43 | QKeyEvent *k = static_cast(event); 44 | if(k->key() == Qt::Key_Return || k->key()==Qt::Key_Enter) 45 | { 46 | mySend(); 47 | return true; 48 | } 49 | } 50 | } 51 | return QWidget::eventFilter(target,event); 52 | } 53 | 54 | void chatClient::paintEvent(QPaintEvent *e) 55 | { 56 | QPixmap pixmap = QPixmap(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg").scaled(this->size()); 57 | QPainter painter(this); 58 | painter.drawPixmap(this->rect(),pixmap); 59 | } 60 | 61 | void chatClient::init() 62 | { 63 | setWindowTitle("聊天窗口"); 64 | this->setWindowIcon(QIcon(":/image/icons48.png")); 65 | 66 | ui->peernamelabel->setText(peername); 67 | ui->statelabel->setText(state); 68 | 69 | ui->sendmsgpushButton_3->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 70 | ui->filepushButton_2->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 71 | } 72 | 73 | void chatClient::mySend() 74 | {//发送 75 | QString oriMsg=ui->msgtextEdit->toPlainText(); 76 | if(oriMsg==""){return;} 77 | QString qmsg="msg"+split+username+split+peername+split+oriMsg; 78 | std::string smsg=qmsg.toStdString(); 79 | const char* cmsg =smsg.c_str(); 80 | if(chatsocket->isWritable()) 81 | chatsocket->write(cmsg); 82 | else{ 83 | QMessageBox::information(this,"发送失败","与服务器连接失败,请退出后重新登录"); 84 | // chatsocket->connectToHost(SERVER_IP,CHAT_PORT); 85 | return; 86 | } 87 | QDateTime curDateTime=QDateTime::currentDateTime();//当前时间 88 | QString space=" "; 89 | ui->receivetextBrowser->setTextBackgroundColor(QColor(209,217,224));//发送颜色 90 | ui->receivetextBrowser->append(username+space+curDateTime.toString("yyyy-MM-dd hh:mm:ss"));//消息框显示 91 | ui->receivetextBrowser->append(oriMsg); 92 | ui->msgtextEdit->clear(); 93 | } 94 | 95 | void chatClient::transer_port_slots(int _port) 96 | { 97 | emit transfer_port_signals(_port); 98 | } 99 | 100 | void chatClient::newFileClient() 101 | { 102 | if(fc==nullptr){ 103 | fc = new fileClient(filesocket); 104 | // fc->setAttribute(Qt::WA_DeleteOnClose,true); 105 | QString qs="file"+split+username+split+peername;//指明传输文件双方 106 | 107 | if(filesocket && filesocket->isWritable()) 108 | filesocket->write(qs.toUtf8()); 109 | else{ 110 | QMessageBox::warning(this,"断开连接","与服务器断开连接,请退出后重新登录"); 111 | // filesocket->connectToHost(SERVER_IP,FILE_PORT); 112 | return; 113 | } 114 | 115 | connect(fc,&fileClient::delete_fileclient_signals, [&]{delete fc;fc=nullptr;} ); 116 | connect(mw,&MainWindow::forwardPort,fc, &fileClient::myPort); 117 | // connect(mw,&MainWindow::forwardPort,this, &chatClient::transer_port_slots); 118 | } 119 | fc->showMaximized();fc->raise(); 120 | } 121 | 122 | void chatClient::myShow(QString qmsg) 123 | { 124 | QDateTime curDateTime=QDateTime::currentDateTime();//当前时间 125 | QString space=" "; 126 | ui->receivetextBrowser->setTextBackgroundColor(QColor(255,251,240));//接收颜色 127 | ui->receivetextBrowser->append(peername+space+curDateTime.toString("yyyy-MM-dd hh:mm:ss")); 128 | ui->receivetextBrowser->append(qmsg); 129 | } 130 | 131 | -------------------------------------------------------------------------------- /officeCooperation/chatclient.h: -------------------------------------------------------------------------------- 1 | #ifndef CHATCLIENT_H 2 | #define CHATCLIENT_H 3 | 4 | #include "fileclient.h" 5 | #include 6 | #include 7 | #include 8 | 9 | class MainWindow; 10 | 11 | namespace Ui { 12 | class chatClient; 13 | } 14 | 15 | class chatClient : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit chatClient(QString _state, MainWindow* mw_, QTcpSocket* file, QTcpSocket* chat, QString username_, QString peername_, QWidget *parent = nullptr); 21 | ~chatClient(); 22 | void myShow(QString);//显示转发过来的消息 23 | 24 | protected: 25 | virtual void closeEvent(QCloseEvent* e); 26 | bool eventFilter(QObject *target, QEvent *e);//事件过滤器,回车键发送消息 27 | virtual void paintEvent(QPaintEvent* e); 28 | 29 | private: 30 | Ui::chatClient *ui; 31 | 32 | QString peername; 33 | QString username; 34 | QString state; 35 | 36 | const QString split="↓⊙ā"; 37 | QTcpSocket* chatsocket=nullptr; 38 | QTcpSocket* filesocket=nullptr; 39 | 40 | fileClient *fc=nullptr; 41 | 42 | MainWindow* mw=nullptr; 43 | 44 | void init(); 45 | 46 | public slots: 47 | void mySend(); 48 | void transer_port_slots(int _port); 49 | void newFileClient(); 50 | 51 | signals: 52 | void transfer_port_signals(int _port); 53 | }; 54 | 55 | #endif // CHATCLIENT_H 56 | -------------------------------------------------------------------------------- /officeCooperation/chatclient.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | chatClient 4 | 5 | 6 | 7 | 0 8 | 0 9 | 500 10 | 480 11 | 12 | 13 | 14 | 15 | 500 16 | 480 17 | 18 | 19 | 20 | 21 | 500 22 | 494 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 0 32 | 380 33 | 70 34 | 20 35 | 36 | 37 | 38 | 39 | 70 40 | 20 41 | 42 | 43 | 44 | 45 | 70 46 | 20 47 | 48 | 49 | 50 | 发送文件 51 | 52 | 53 | 54 | 55 | 56 | 430 57 | 380 58 | 70 59 | 20 60 | 61 | 62 | 63 | 64 | 70 65 | 20 66 | 67 | 68 | 69 | 70 | 70 71 | 20 72 | 73 | 74 | 75 | 发送消息 76 | 77 | 78 | 79 | 80 | 81 | 460 82 | 10 83 | 31 84 | 20 85 | 86 | 87 | 88 | 89 | 11 90 | 91 | 92 | 93 | state 94 | 95 | 96 | 97 | 98 | 99 | 7 100 | 10 101 | 200 102 | 20 103 | 104 | 105 | 106 | 107 | 0 108 | 20 109 | 110 | 111 | 112 | 113 | 16777215 114 | 20 115 | 116 | 117 | 118 | 119 | 11 120 | 121 | 122 | 123 | peername 124 | 125 | 126 | 127 | 128 | 129 | 0 130 | 400 131 | 500 132 | 80 133 | 134 | 135 | 136 | 137 | 500 138 | 80 139 | 140 | 141 | 142 | 143 | 500 144 | 80 145 | 146 | 147 | 148 | 149 | 150 | 151 | 0 152 | 40 153 | 500 154 | 340 155 | 156 | 157 | 158 | 159 | 500 160 | 340 161 | 162 | 163 | 164 | 165 | 500 166 | 340 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /officeCooperation/configuration.cpp: -------------------------------------------------------------------------------- 1 | #include"configuration.h" 2 | extern const QHostAddress SERVER_IP=QHostAddress("***");//服务器IP地址,就是运行Server的服务器地址 3 | extern const int CHAT_PORT = 25000;//聊天端口 4 | extern const int FILE_PORT = 26000;//调度文件传输端口 5 | extern int NUMBER_OF_BACKGROUNDS = 8;//壁纸数量 6 | extern int NUMBER_OF_ICONS = 16;//头像数量 7 | extern int ID_OF_BACKGROUND=3;//壁纸id 8 | extern int ID_OF_ICON=1;//头像id 9 | -------------------------------------------------------------------------------- /officeCooperation/configuration.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGURATION_H 2 | #define CONFIGURATION_H 3 | #include 4 | 5 | extern const QHostAddress SERVER_IP; 6 | extern const int CHAT_PORT; 7 | extern const int FILE_PORT; 8 | extern int NUMBER_OF_BACKGROUNDS; 9 | extern int NUMBER_OF_ICONS; 10 | extern int ID_OF_BACKGROUND; 11 | extern int ID_OF_ICON; 12 | 13 | 14 | #endif // CONFIGURATION_H 15 | -------------------------------------------------------------------------------- /officeCooperation/controller.cpp: -------------------------------------------------------------------------------- 1 | #include "controller.h" 2 | 3 | Controller::Controller() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /officeCooperation/controller.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROLLER_H 2 | #define CONTROLLER_H 3 | 4 | 5 | class Controller 6 | { 7 | public: 8 | Controller(); 9 | }; 10 | 11 | #endif // CONTROLLER_H -------------------------------------------------------------------------------- /officeCooperation/controllerlogregister.cpp: -------------------------------------------------------------------------------- 1 | #include "controllerlogregister.h" 2 | 3 | ControllerLogRegister::ControllerLogRegister() 4 | { 5 | // log=new login(); 6 | // Ui::login* logui=log->getUi(); 7 | // QObject::connect(logui->username,&QLineEdit::textChange,this,&getUsername); 8 | } 9 | -------------------------------------------------------------------------------- /officeCooperation/controllerlogregister.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROLLERLOGREGISTER_H 2 | #define CONTROLLERLOGREGISTER_H 3 | #include"login.h" 4 | #include"register.h" 5 | 6 | class ControllerLogRegister 7 | { 8 | Q_OBJECT 9 | public: 10 | ControllerLogRegister(); 11 | login* log=nullptr; 12 | Register* reg = nullptr; 13 | private slots: 14 | void verify(); 15 | void getUsername(QString text); 16 | void getPwd(QString text); 17 | void showRegister(); 18 | }; 19 | 20 | #endif // CONTROLLERLOGREGISTER_H 21 | -------------------------------------------------------------------------------- /officeCooperation/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "mydatabase.h" 13 | 14 | 15 | namespace Ui { 16 | class Dialog; 17 | } 18 | 19 | class Dialog : public QDialog 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit Dialog(int id,QWidget *parent = 0); 25 | ~Dialog(); 26 | 27 | private slots: 28 | void on_pBton_shezhi_clicked(); 29 | void on_pBton_cancel_clicked(); 30 | 31 | private: 32 | Ui::Dialog *ui; 33 | public: 34 | 35 | MyDatabase* md=nullptr; 36 | QSqlDatabase db; 37 | 38 | int uid;//用户id 39 | QTime setTime[7][8]; //星期一到星期天的时间设置 40 | QString setEvent[7][4]; 41 | 42 | QStringList IPlist; //事件列表 43 | 44 | }; 45 | 46 | #endif // DIALOG_H 47 | -------------------------------------------------------------------------------- /officeCooperation/doc.cpp: -------------------------------------------------------------------------------- 1 | #include "doc.h" 2 | #include "ui_doc.h" 3 | #include"QDateTime" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "newproject.h" 23 | doc::doc(QWidget *parent) : 24 | QMainWindow(parent), 25 | ui(new Ui::doc) 26 | { 27 | ui->setupUi(this); 28 | isSaved=false; 29 | close=false; 30 | QString curFile = tr("项目编辑.txt"); 31 | ui->treeWidget->setHeaderLabel(tr("项目-参与者")); 32 | setWindowTitle(curFile); 33 | this->setWindowIcon(QIcon(":/image/icons48.png")); 34 | 35 | //设置水平和垂直分割器,界面布局 36 | hsplitter=new QSplitter;//水平 37 | vsplitter=new QSplitter;//垂直 38 | vsplitter->setOrientation(Qt::Vertical); 39 | setCentralWidget(hsplitter); 40 | //注意部件顺序 41 | hsplitter->addWidget(ui->treeWidget); 42 | hsplitter->addWidget(ui->textEdit); 43 | 44 | //新建项目信号槽 45 | connect(ui->newProject,SIGNAL(triggered()),this,SLOT(new_project())); 46 | //打开项目信号槽 47 | connect(ui->openProject,SIGNAL(triggered()),this,SLOT(open_project())); 48 | } 49 | 50 | doc::~doc() 51 | { 52 | delete ui; 53 | } 54 | void doc::do_file_SaveAS(){ 55 | QString fileName=QFileDialog::getSaveFileName(this,tr("另存为"),curFile); 56 | 57 | if(!fileName.isEmpty()){ 58 | saveFile(fileName); 59 | } 60 | 61 | } 62 | 63 | void doc::do_file_Save(){ 64 | if(isSaved){ 65 | saveFile(curFile); 66 | } 67 | else{ 68 | 69 | do_file_SaveAS(); 70 | } 71 | } 72 | void doc::do_file_SaveOrNot(){ 73 | if(ui->textEdit->document()->isModified()){ 74 | QMessageBox box; 75 | box.setWindowTitle(tr("Warning")); 76 | box.setIcon(QMessageBox::Warning); 77 | box.setText(curFile+tr("是否保存?")); 78 | box.setStandardButtons(QMessageBox::Yes); 79 | do_file_Save(); 80 | } 81 | 82 | } 83 | bool doc::saveFile(const QString&fileName){ 84 | QFile file(fileName); 85 | if(!file.open(QFile::WriteOnly|QFile::Text)){ 86 | 87 | return false; 88 | } 89 | QTextStream out(&file); 90 | out<textEdit->toPlainText(); 91 | isSaved=true; 92 | curFile = QFileInfo(fileName).canonicalFilePath(); 93 | setWindowTitle(curFile); 94 | return true; 95 | } 96 | 97 | 98 | //新建文件 99 | void doc::on_action_triggered() 100 | { 101 | do_file_SaveOrNot(); 102 | isSaved=false; 103 | curFile=tr("记事本.txt"); 104 | setWindowTitle(curFile); 105 | ui->textEdit->clear(); 106 | ui->textEdit->setVisible(true); 107 | } 108 | //打开文件 action 2 109 | void doc::on_action_Open_triggered() 110 | { 111 | QString filename = QFileDialog::getOpenFileName(this); 112 | loadFile(filename); 113 | } 114 | //本地连接 115 | void doc::loadFile(QString filename){ 116 | printf("file name:%s\n",filename.data()); 117 | 118 | QFile file(filename); 119 | if(file.open(QIODevice::ReadOnly|QIODevice::Text)) 120 | { 121 | QTextStream textStream(&file); 122 | while(!textStream.atEnd()) 123 | { 124 | ui->textEdit->append(textStream.readLine()); 125 | printf("read line\n"); 126 | } 127 | printf("end\n"); 128 | } 129 | } 130 | //保存文件 action 3 131 | void doc::on_action_Save_triggered() 132 | { 133 | if(isSaved){ 134 | saveFile(curFile); 135 | } 136 | else{ 137 | 138 | do_file_SaveAS(); 139 | } 140 | } 141 | //另存为文件 action 4 142 | void doc::on_action_SaveAs_triggered() 143 | { 144 | QString fileName=QFileDialog::getSaveFileName(this,tr("另存为"),curFile); 145 | 146 | if(!fileName.isEmpty()){ 147 | saveFile(fileName); 148 | } 149 | 150 | } 151 | //字体颜色 action 16 152 | void doc::on_action_Color_triggered() 153 | { 154 | QColor color=QColorDialog::getColor(Qt::red,this); 155 | 156 | if(color.isValid()) 157 | { 158 | QTextCharFormat fmt; 159 | fmt.setForeground(color); 160 | ui->textEdit->mergeCurrentCharFormat(fmt); 161 | } 162 | } 163 | //关闭文件 action 5 164 | 165 | void doc::on_action_Close_triggered() 166 | { 167 | if(close){ 168 | QMessageBox::information(this,"提示","文件尚未保存,关闭"); 169 | }else{ 170 | ui->textEdit->close(); 171 | } 172 | } 173 | //撤销 action 6 174 | void doc::on_action_Cancel_triggered() 175 | { 176 | ui->textEdit->undo(); 177 | } 178 | //剪切 action 7 179 | void doc::on_action_Cut_triggered() 180 | { 181 | ui->textEdit->cut(); 182 | } 183 | //复制 action 8 184 | void doc::on_action_Copy_triggered() 185 | { 186 | ui->textEdit->copy(); 187 | } 188 | //粘贴 action 9 189 | void doc::on_action_Paste_triggered() 190 | { 191 | ui->textEdit->paste(); 192 | } 193 | //删除 action 10 194 | void doc::on_action_Delete_triggered() 195 | { 196 | ui->textEdit->redo(); 197 | } 198 | 199 | //全选 action 13 200 | void doc::on_action_SelectAll_triggered() 201 | { 202 | ui->textEdit->selectAll(); 203 | } 204 | //显示时间 action 14 205 | void doc::on_action_ShowTime_triggered() 206 | { 207 | QDateTime time =QDateTime::currentDateTime(); 208 | QString str= time.toString("yyyy-MM-dd hh:mm:ss dddd"); 209 | ui->textEdit->setText(str); 210 | } 211 | 212 | 213 | //查找 action 11 214 | void doc::close_findhangshu() 215 | { 216 | ui->gridLayoutWidget->close(); 217 | } 218 | void doc::on_action_Find_triggered() 219 | { 220 | QDialog *closefind=new QDialog(this); 221 | QDialog *findDlg=new QDialog(this); 222 | find_textLineEdit=new QLineEdit(findDlg); 223 | QPushButton *find_Bth=new QPushButton(tr("查找下一个"),findDlg); 224 | QPushButton *close_find=new QPushButton(tr("关闭"),closefind); 225 | ui->gridLayout->addWidget(find_textLineEdit); 226 | ui->gridLayout->addWidget(find_Bth); 227 | ui->gridLayout->addWidget(close_find); 228 | connect(find_Bth,SIGNAL(clicked()),this,SLOT(show_findText())); 229 | connect(close_find,SIGNAL(clicked()),this,SLOT(close_findhangshu())); 230 | } 231 | void doc::show_findText() 232 | { 233 | QString findText=find_textLineEdit->text(); 234 | if(!ui->textEdit->find(findText,QTextDocument::FindBackward)) 235 | { 236 | QMessageBox::warning(this,tr("查找"),tr("找不到 %1").arg(findText)); 237 | 238 | } 239 | } 240 | //退出 action 12 241 | void doc::on_action_Exit_triggered() 242 | { 243 | delete ui->textEdit; 244 | } 245 | 246 | //关于 action 17 247 | void doc::on_action_About_triggered() 248 | { 249 | //ui->textEdit->setText(tr("About Message Box")); 250 | QMessageBox::about(this,tr("About"),tr("这是一个记事本,作者:咕咕咕")); 251 | return; 252 | 253 | } 254 | //字体 action 15 255 | void doc::on_action_Font_triggered() 256 | { 257 | bool ok; 258 | QFont currentFont=QFontDialog::getFont(&ok); 259 | if(ok){ 260 | ui->textEdit->setFont(currentFont); 261 | } 262 | 263 | 264 | } 265 | //字体倾斜 action 18 266 | void doc::on_action_Italic_triggered() 267 | { 268 | QTextCharFormat fmt; 269 | fmt.setFontItalic(ui->action_Italic->isChecked()); 270 | ui->textEdit->mergeCurrentCharFormat(fmt); 271 | 272 | } 273 | //下划线 action 19 274 | void doc::on_action_Underline_triggered() 275 | { 276 | QTextCharFormat fmt; 277 | fmt.setFontUnderline(ui->action_Underline->isChecked()); 278 | ui->textEdit->mergeCurrentCharFormat(fmt); 279 | } 280 | 281 | //左对齐 action 20 282 | void doc::on_action_LAlign_triggered() 283 | { 284 | ui->textEdit->setAlignment(Qt::AlignLeft); 285 | 286 | } 287 | //右对齐 action 21 288 | void doc::on_action_RAlign_triggered() 289 | { 290 | ui->textEdit->setAlignment(Qt::AlignRight); 291 | } 292 | 293 | //居中 action 22 294 | void doc::on_action_CAlign_triggered() 295 | { 296 | ui->textEdit->setAlignment(Qt::AlignCenter); 297 | 298 | 299 | } 300 | //两端对齐 action 23 301 | void doc::on_action_JAlign_triggered() 302 | { 303 | ui->textEdit->setAlignment(Qt::AlignJustify); 304 | 305 | } 306 | 307 | void doc::new_project() 308 | { 309 | NewProject project; 310 | //所有栏都填完,且按下确定按钮 311 | if(project.exec()==QDialog::Accepted) 312 | { 313 | //获取新建项目名 314 | QString project_name__=project.get_new_project_name(); 315 | //获取项目路径名 316 | QString project_dir__=project.get_new_project_dir(); 317 | //获取可执行文件所在文件夹路径名 318 | //QString excute_dir__=project.get_excute_file_dir(); 319 | //获取参与人员信息 320 | QString proj_members__=project.get_members(); 321 | 322 | //新建项目失败 323 | if(project_name__.isEmpty() || project_dir__.isEmpty()) 324 | return; 325 | //新建项目成功 326 | else 327 | { 328 | project_name_.append(project_name__);//添加项目名称 329 | //新建项目文件夹 330 | QDir dir(project_dir__);//项目文件夹所在目录 331 | dir.mkdir(project_name__);//创建以项目名为名字的目录 332 | QString _project_dir_=dir.absoluteFilePath(project_name__);//获取项目文件夹的绝对路径 333 | project_dir_.append(_project_dir_);//添加项目文件夹路径 334 | QDir project_dir(_project_dir_); 335 | 336 | //新建项目文件pro 337 | QFile pro_file( project_dir.filePath(project_name__+".pro") ); 338 | loadFile(project_name__+".pro"); 339 | pro_file.open(QFile::WriteOnly|QIODevice::Text); 340 | pro_path_.append(pro_file.fileName());//添加txt文件 341 | QTextStream pro_stream(&pro_file); 342 | pro_stream<<"Project was created successfully!\n"; 343 | pro_stream<<"PROJECT NAME = "<treeWidget,QStringList(project_name__));//添加节点 351 | 352 | //添加子节点 353 | QStringList members=proj_members__.split(','); 354 | QTreeWidgetItem **items; 355 | int num_members=members.count(); 356 | items=new QTreeWidgetItem*[num_members]; 357 | for(int i=0;iaddChild(items[i]); 360 | } 361 | } 362 | } 363 | 364 | } 365 | 366 | //打开项目槽函数 367 | void doc::open_project() 368 | { 369 | QString file_path_=QFileDialog::getOpenFileName(this,".打开项目"); 370 | if(file_path_=="") return; 371 | QFile file(file_path_); 372 | file.open(QIODevice::ReadOnly|QIODevice::Text); 373 | QByteArray str_line_; 374 | QString temp; 375 | QString proname; 376 | file.readLine(); 377 | loadFile(file_path_); 378 | //项目名 379 | str_line_=file.readLine(); 380 | proname=str_line_.mid(QString("PROJECT NAME = ").length(),str_line_.length()-QString("PROJECT NAME = ").length()-1); 381 | project_name_.append(proname); 382 | //创建树形条 383 | QTreeWidgetItem *item=new QTreeWidgetItem(ui->treeWidget,QStringList(proname));//添加节点 384 | //项目文件夹 385 | str_line_=file.readLine(); 386 | temp=str_line_.mid(QString("PROJECT DIR = ").length(),str_line_.length()-QString("PROJECT DIR = ").length()-1); 387 | project_dir_.append(temp); 388 | //项目文件路径(pro) 389 | str_line_=file.readLine(); 390 | temp=str_line_.mid(QString("PROJECT FILE NAME = ").length(),str_line_.length()-QString("PROJECT FILE NAME = ").length()-1); 391 | pro_path_.append(temp); 392 | //参与项目人员 393 | str_line_=file.readLine(); 394 | temp=str_line_.mid(QString("PROJECT MEMBER = ").length(),str_line_.length()-QString("PROJECT MEMBER = ").length()); 395 | //excute_dir_.append(temp); 396 | 397 | //添加子节点 398 | QStringList members=temp.split(','); 399 | QTreeWidgetItem **items; 400 | int num_members=members.count(); 401 | items=new QTreeWidgetItem*[num_members]; 402 | for(int i=0;iaddChild(items[i]); 405 | } 406 | 407 | ui->treeWidget->expandAll();//展开所有节点 408 | } 409 | -------------------------------------------------------------------------------- /officeCooperation/doc.h: -------------------------------------------------------------------------------- 1 | #ifndef DOC_H 2 | #define DOC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | namespace Ui { 12 | class doc; 13 | } 14 | 15 | class doc : public QMainWindow 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit doc(QWidget *parent = 0); 21 | ~doc(); 22 | QString fileName; 23 | QString curFile; 24 | bool isSaved; 25 | bool close; 26 | void loadFile(QString fileNames); 27 | private slots: 28 | void new_project();//新建项目菜单 29 | void open_project();//打开项目菜单 30 | void on_action_triggered(); 31 | void do_file_SaveAS(); 32 | void do_file_Save(); 33 | void do_file_SaveOrNot(); 34 | bool saveFile(const QString&fileName); 35 | void show_findText(); 36 | void close_findhangshu(); 37 | void on_action_Open_triggered(); 38 | void on_action_Save_triggered(); 39 | void on_action_SaveAs_triggered(); 40 | 41 | void on_action_Color_triggered(); 42 | 43 | void on_action_Close_triggered(); 44 | 45 | void on_action_Cancel_triggered(); 46 | 47 | void on_action_Cut_triggered(); 48 | 49 | void on_action_Copy_triggered(); 50 | 51 | void on_action_Paste_triggered(); 52 | 53 | void on_action_Delete_triggered(); 54 | 55 | void on_action_About_triggered(); 56 | 57 | void on_action_Font_triggered(); 58 | 59 | void on_action_Italic_triggered(); 60 | 61 | void on_action_SelectAll_triggered(); 62 | 63 | void on_action_ShowTime_triggered(); 64 | 65 | 66 | void on_action_Find_triggered(); 67 | 68 | void on_action_Exit_triggered(); 69 | 70 | void on_action_Underline_triggered(); 71 | 72 | void on_action_LAlign_triggered(); 73 | 74 | void on_action_RAlign_triggered(); 75 | 76 | void on_action_CAlign_triggered(); 77 | 78 | void on_action_JAlign_triggered(); 79 | 80 | private: 81 | Ui::doc *ui; 82 | QLineEdit *find_textLineEdit=nullptr; 83 | QAction *centerAction=nullptr; 84 | QVector project_name_;//项目名称 85 | QVector pro_path_;//项目文件路径(pro文件) 86 | QVector project_dir_;//项目目录 87 | QVector excute_dir_;//可执行文件目录(在项目中的目录) 88 | QSplitter *hsplitter=nullptr;//水平分割器 89 | QSplitter *vsplitter=nullptr;//垂直分割器 90 | 91 | 92 | }; 93 | 94 | #endif // DOC_H 95 | -------------------------------------------------------------------------------- /officeCooperation/doc.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | doc 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1430 10 | 905 11 | 12 | 13 | 14 | 15 | 16777215 16 | 16777215 17 | 18 | 19 | 20 | MainWindow 21 | 22 | 23 | 24 | :/new/prefix1/33.png 25 | 26 | 27 | 28 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(190, 255, 191, 255), stop:1 rgba(255, 255, 255, 255)); 29 | 30 | 31 | Qt::ToolButtonTextUnderIcon 32 | 33 | 34 | 35 | 36 | 37 | 260 38 | 10 39 | 1161 40 | 801 41 | 42 | 43 | 44 | 45 | 16777215 46 | 16777215 47 | 48 | 49 | 50 | false 51 | 52 | 53 | background-color: rgb(255, 255, 255); 54 | 55 | 56 | false 57 | 58 | 59 | 60 | 61 | 62 | 520 63 | 130 64 | 341 65 | 171 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 10 74 | 10 75 | 241 76 | 461 77 | 78 | 79 | 80 | 81 | 1 82 | 83 | 84 | 85 | gridLayoutWidget 86 | textEdit 87 | treeWidget 88 | 89 | 90 | 91 | 92 | 0 93 | 0 94 | 1430 95 | 17 96 | 97 | 98 | 99 | background-color: rgb(188,255,190); 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 | background-color:rgb(188, 255, 190) 156 | 157 | 158 | TopToolBarArea 159 | 160 | 161 | false 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | :/image/QtPic/newfile.png:/image/QtPic/newfile.png 186 | 187 | 188 | 新建文件 189 | 190 | 191 | 192 | 193 | 194 | :/image/QtPic/open.png:/image/QtPic/open.png 195 | 196 | 197 | 打开文件 198 | 199 | 200 | 201 | 202 | 203 | :/image/QtPic/save.png:/image/QtPic/save.png 204 | 205 | 206 | 保存 207 | 208 | 209 | 210 | 211 | 212 | :/image/QtPic/saveas.png:/image/QtPic/saveas.png 213 | 214 | 215 | 另存为 216 | 217 | 218 | 219 | 220 | 221 | ../QtPic/关闭.png../QtPic/关闭.png 222 | 223 | 224 | 关闭 225 | 226 | 227 | 228 | 229 | 撤销Ctrl+Z 230 | 231 | 232 | 233 | 234 | 235 | :/image/QtPic/cut.png:/image/QtPic/cut.png 236 | 237 | 238 | 剪切Ctrl+X 239 | 240 | 241 | 剪切Ctrl+X 242 | 243 | 244 | 245 | 246 | 247 | :/image/QtPic/copy.png:/image/QtPic/copy.png 248 | 249 | 250 | 复制Ctrl+C 251 | 252 | 253 | 254 | 255 | 256 | :/image/QtPic/paste.png:/image/QtPic/paste.png 257 | 258 | 259 | 粘贴Ctrl+V 260 | 261 | 262 | 263 | 264 | 265 | :/new/prefix1/图片24.png:/new/prefix1/图片24.png 266 | 267 | 268 | 删除 269 | 270 | 271 | 272 | 273 | 274 | :/new/prefix1/图片23.png:/new/prefix1/图片23.png 275 | 276 | 277 | 查找 278 | 279 | 280 | 281 | 282 | 283 | :/image/QtPic/exit.png:/image/QtPic/exit.png 284 | 285 | 286 | 退出 287 | 288 | 289 | 290 | 291 | 全选Ctrl+A 292 | 293 | 294 | 295 | 296 | 297 | :/image/QtPic/time.png:/image/QtPic/time.png 298 | 299 | 300 | 时间 301 | 302 | 303 | 304 | 305 | 306 | :/image/QtPic/font.png:/image/QtPic/font.png 307 | 308 | 309 | 字体 310 | 311 | 312 | 313 | 314 | 字体颜色 315 | 316 | 317 | 318 | 319 | 320 | :/image/QtPic/about.png:/image/QtPic/about.png 321 | 322 | 323 | 关于记事本 324 | 325 | 326 | 327 | 328 | true 329 | 330 | 331 | 字体倾斜 332 | 333 | 334 | 335 | 336 | true 337 | 338 | 339 | false 340 | 341 | 342 | 下划线 343 | 344 | 345 | 346 | 347 | 348 | :/image/QtPic/alignleft.png:/image/QtPic/alignleft.png 349 | 350 | 351 | 左对齐 352 | 353 | 354 | 355 | 356 | 357 | :/image/QtPic/alignright.png:/image/QtPic/alignright.png 358 | 359 | 360 | 右对齐 361 | 362 | 363 | 364 | 365 | 366 | :/image/QtPic/aligncenter.png:/image/QtPic/aligncenter.png 367 | 368 | 369 | 居中 370 | 371 | 372 | 373 | 374 | 375 | :/image/QtPic/alignboth.png:/image/QtPic/alignboth.png 376 | 377 | 378 | 两端对齐 379 | 380 | 381 | 382 | 383 | 新建项目 384 | 385 | 386 | 新建项目 387 | 388 | 389 | 390 | 391 | 打开项目 392 | 393 | 394 | 打开项目 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | -------------------------------------------------------------------------------- /officeCooperation/fileclient.cpp: -------------------------------------------------------------------------------- 1 | #include "fileclient.h" 2 | #include "ui_fileclient.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include"configuration.h" 8 | 9 | fileClient::fileClient(QTcpSocket* socket_,QWidget *parent) : 10 | QWidget(parent),ui(new Ui::fileClient), 11 | socket(socket_) 12 | { 13 | ui->setupUi(this); 14 | init(); 15 | 16 | timer=new QTimer(this); 17 | 18 | connect(ui->selectpushButton,&QPushButton::clicked,this,&fileClient::mySelect ); 19 | connect(timer,&QTimer::timeout,this, &fileClient::mySendFile );//定时到,发送文件本体 20 | connect(ui->sendpushButton,&QPushButton::clicked,this, &fileClient::mySendHead);//发送,先发送头信息 21 | } 22 | 23 | fileClient::~fileClient() 24 | { 25 | qDebug()<<"走了fileclient 析构"; 26 | delete ui; 27 | } 28 | 29 | void fileClient::paintEvent(QPaintEvent *e) 30 | { 31 | QPixmap pixmap = QPixmap(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg").scaled(this->size()); 32 | QPainter painter(this); 33 | painter.drawPixmap(this->rect(),pixmap); 34 | } 35 | 36 | void fileClient::init() 37 | { 38 | setWindowTitle("文件传输"); 39 | this->setWindowIcon(QIcon(":/image/icons48.png")); 40 | ui->progressBar->setVisible(false);//先不显示进度条 41 | ui->filelineEdit->setText(""); 42 | ui->sendpushButton->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 43 | ui->selectpushButton->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 44 | } 45 | 46 | void fileClient::myPort(int port) 47 | {//确定好传输对象以后,新建transfer专门传文件 48 | qDebug()<<"发送创建 trannsefer "<connectToHost(SERVER_IP,port); 52 | connect(transfer,&QTcpSocket::connected,this,[=]{qDebug()<<"发送方连接成功";}); 53 | } 54 | 55 | void fileClient::mySelect() 56 | { 57 | QString path=QFileDialog::getOpenFileName(this); 58 | ui->filelineEdit->setText(path); 59 | } 60 | 61 | void fileClient::mySendHead() 62 | {//文件名,文件大小,已发送大小 63 | QString path=ui->filelineEdit->text(); 64 | if(path==""){ 65 | QMessageBox::information(this,"发送失败","请先选择需要发送的文件"); 66 | return; 67 | } 68 | if(transfer==nullptr){ 69 | QMessageBox::information(this,"发送失败","发送失败,请重新发送"); 70 | emit delete_fileclient_signals(); 71 | return; 72 | } 73 | file.setFileName(path);//文件 74 | QFileInfo info(path); 75 | fileName=info.fileName(); 76 | fileSizeAll=info.size(); 77 | fileSizeSend=0; 78 | QString head=fileName+split+QString::number(fileSizeAll) ; 79 | 80 | qDebug()<<"head filename and size"<isWritable()) 83 | len=transfer->write(head.toUtf8()); 84 | else{ 85 | QMessageBox::information(this,"发送失败","发送失败,请重新发送"); 86 | emit delete_fileclient_signals(); 87 | return; 88 | } 89 | if(len){ 90 | ui->filelineEdit->setEnabled(false); 91 | ui->selectpushButton->setEnabled(false); 92 | ui->sendpushButton->setDisabled(true); 93 | timer->start(50); 94 | }//延时发送本体 95 | else{QMessageBox::information(this,"发送失败","文件信息发送失败,请重新发送");emit delete_fileclient_signals();} 96 | } 97 | 98 | void fileClient::mySendFile() 99 | { 100 | timer->stop();//停止定时器 101 | if(file.open(QIODevice::ReadOnly )==false){ 102 | QMessageBox::information(this,"发送失败","打开文件失败,请重新发送"); 103 | return; 104 | } 105 | ui->progressBar->setVisible(true); 106 | timer2 = new QTimer(this); 107 | connect(timer2,&QTimer::timeout, this, &fileClient::timeSend ); 108 | timer2->start(1); 109 | } 110 | 111 | void fileClient::timeSend() 112 | { 113 | char buffer[4096]={0}; 114 | int len=file.read(buffer,sizeof(buffer)); 115 | if(transfer && transfer->isWritable()){ 116 | int len2 = transfer->write(buffer,len); 117 | fileSizeSend+=len2; 118 | ui->progressBar->setValue(1.0*fileSizeSend/fileSizeAll*100); 119 | if(fileSizeSend==fileSizeAll){ 120 | timer2->stop(); 121 | file.close(); 122 | QMessageBox::information(this,"发送成功","文件发送成功"); 123 | emit delete_fileclient_signals(); 124 | } 125 | } 126 | else{ 127 | QMessageBox::information(this,"发送失败","发送失败,请重新连接服务器"); 128 | emit delete_fileclient_signals(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /officeCooperation/fileclient.h: -------------------------------------------------------------------------------- 1 | #ifndef FILECLIENT_H 2 | #define FILECLIENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class fileClient; 10 | } 11 | 12 | class fileClient : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit fileClient(QTcpSocket* socket_, QWidget *parent = nullptr); 18 | ~fileClient(); 19 | 20 | protected: 21 | virtual void paintEvent(QPaintEvent* e); 22 | 23 | private: 24 | Ui::fileClient *ui; 25 | 26 | QTcpSocket* socket=nullptr; 27 | QTcpSocket* transfer=nullptr; 28 | int transferPort; 29 | 30 | QFile file; 31 | QString fileName; 32 | int fileSizeAll; 33 | int fileSizeSend; 34 | const QString split="↓⊙ā";//分隔 35 | 36 | QTimer* timer=nullptr;//先发送头信息,定时一段时间再发送本体 37 | QTimer* timer2=nullptr;//文件本体不要读的太快 38 | 39 | void init(); 40 | 41 | public slots: 42 | void myPort(int port); 43 | void mySelect(); 44 | void mySendHead(); 45 | void mySendFile(); 46 | void timeSend(); 47 | signals: 48 | void delete_fileclient_signals(); 49 | }; 50 | 51 | #endif // FILECLIENT_H 52 | -------------------------------------------------------------------------------- /officeCooperation/fileclient.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | fileClient 4 | 5 | 6 | 7 | 0 8 | 0 9 | 550 10 | 250 11 | 12 | 13 | 14 | 15 | 550 16 | 250 17 | 18 | 19 | 20 | 21 | 550 22 | 250 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 10 32 | 69 33 | 531 34 | 25 35 | 36 | 37 | 38 | 39 | 0 40 | 25 41 | 42 | 43 | 44 | 0 45 | 46 | 47 | 48 | 49 | 50 | 10 51 | 39 52 | 100 53 | 25 54 | 55 | 56 | 57 | 58 | 0 59 | 25 60 | 61 | 62 | 63 | 发送 64 | 65 | 66 | 67 | 68 | 69 | 10 70 | 10 71 | 100 72 | 25 73 | 74 | 75 | 76 | 77 | 100 78 | 25 79 | 80 | 81 | 82 | 选择文件 83 | 84 | 85 | 86 | 87 | 88 | 120 89 | 10 90 | 421 91 | 25 92 | 93 | 94 | 95 | 96 | 200 97 | 0 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /officeCooperation/friendwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "friendwidget.h" 2 | #include "ui_friendwidget.h" 3 | #include 4 | #include"chatclient.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | FriendWidget::FriendWidget(int peerid_, MainWindow* mw, QTcpSocket* file, QTcpSocket* chat, QString username_, QString peername_, QString state_, int icon_, QWidget *parent) : 12 | QWidget(parent),ui(new Ui::FriendWidget),peerid(peerid_),username(username_),peername(peername_), 13 | state(state_),icon(icon_),chatSocket(chat),fileSocket(file) 14 | { 15 | ui->setupUi(this); 16 | //初始化界面 17 | init(); 18 | act_delete = new QAction("删除联系人",this); 19 | connect(act_delete,&QAction::triggered, this, &FriendWidget::delete_slots ); 20 | cc=new chatClient(state, mw, fileSocket,chatSocket,username,peername);//聊天框 21 | cc->setAutoFillBackground(true); 22 | } 23 | 24 | FriendWidget::FriendWidget(int peerid_, QString peername_, QString state_, int icon_, QWidget *parent): 25 | QWidget(parent),ui(new Ui::FriendWidget),peerid(peerid_),peername(peername_),state(state_), 26 | icon(icon_) 27 | { 28 | ui->setupUi(this); 29 | isOverload = true; 30 | init(); 31 | } 32 | 33 | 34 | FriendWidget::~FriendWidget() 35 | { 36 | if(!isOverload) 37 | delete cc; 38 | delete ui; 39 | } 40 | 41 | void FriendWidget::changeState() 42 | { 43 | if(state=="在线"){ 44 | state="离线"; 45 | } 46 | else if(state=="离线"){ 47 | state="在线"; 48 | } 49 | ui->statelabel_3->setText(state); 50 | } 51 | 52 | void FriendWidget::mousePressEvent(QMouseEvent *e) 53 | { 54 | if(e->button()==Qt::RightButton){ 55 | QCursor cur = this->cursor(); 56 | QMenu* menu = new QMenu(this); 57 | menu->addAction(act_delete); 58 | menu->exec(cur.pos()); 59 | } 60 | else{ 61 | if(!isOverload){cc->showMaximized();cc->raise();} 62 | else 63 | emit forwardPeer(peerid,peername); 64 | } 65 | } 66 | 67 | void FriendWidget::contextMenuEvent(QContextMenuEvent *event) 68 | { 69 | // QCursor cur = this->cursor(); 70 | // QMenu* menu = new QMenu(this); 71 | // menu->addAction(act_delete); 72 | // menu->exec(cur.pos()); 73 | } 74 | 75 | void FriendWidget::init() 76 | { 77 | QPixmap *pixmap = new QPixmap(":/image/icon/"+QString::number(icon)+".jpg"); 78 | pixmap->scaled(ui->iconlabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 79 | ui->iconlabel->setScaledContents(true); 80 | ui->iconlabel->setPixmap(*pixmap); 81 | 82 | ui->peernamelabel_2->setText(peername); 83 | ui->statelabel_3->setText(state); 84 | } 85 | 86 | void FriendWidget::delete_slots() 87 | { 88 | emit delete_signals(peerid,peername); 89 | } 90 | 91 | -------------------------------------------------------------------------------- /officeCooperation/friendwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef FRIENDWIDGET_H 2 | #define FRIENDWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include"chatclient.h" 9 | #include 10 | 11 | class MainWindow; 12 | 13 | namespace Ui { 14 | class FriendWidget; 15 | } 16 | 17 | class FriendWidget : public QWidget 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | explicit FriendWidget(int peerid,MainWindow* mw, QTcpSocket* file,QTcpSocket* chat,QString username,QString peername,QString state,int icon_,QWidget *parent = nullptr); 23 | explicit FriendWidget(int peerid,QString peername,QString state,int icon_,QWidget *parent = nullptr); 24 | ~FriendWidget(); 25 | 26 | void setPeername(const QString &newPeername); 27 | 28 | void changeState(); 29 | 30 | chatClient* cc=nullptr; 31 | 32 | protected: 33 | virtual void mousePressEvent(QMouseEvent *event);//鼠标点击 34 | virtual void contextMenuEvent(QContextMenuEvent *event);//右键菜单 35 | private: 36 | Ui::FriendWidget *ui; 37 | int peerid; 38 | QString username; 39 | QString peername; 40 | QString state;//在线状态 41 | int icon;//头像 42 | QTcpSocket* chatSocket=nullptr; 43 | QTcpSocket* fileSocket=nullptr; 44 | bool isOverload=false;//是否重载,已有的联系人和搜索出来的不一样 45 | 46 | QAction* act_delete = nullptr; 47 | 48 | void init(); 49 | public slots: 50 | void delete_slots(); 51 | signals: 52 | void forwardPeer(int peerid, QString peername); 53 | void delete_signals(int peerid,QString peername); 54 | }; 55 | 56 | #endif // FRIENDWIDGET_H 57 | -------------------------------------------------------------------------------- /officeCooperation/friendwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | FriendWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 320 10 | 50 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 16777215 22 | 16777215 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 5 32 | 5 33 | 40 34 | 40 35 | 36 | 37 | 38 | icon 39 | 40 | 41 | 42 | 43 | 44 | 55 45 | 5 46 | 100 47 | 15 48 | 49 | 50 | 51 | peername 52 | 53 | 54 | 55 | 56 | 57 | 55 58 | 30 59 | 100 60 | 15 61 | 62 | 63 | 64 | state 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /officeCooperation/getdatabase.cpp: -------------------------------------------------------------------------------- 1 | #include "getdatabase.h" 2 | 3 | GetDatabase::GetDatabase() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /officeCooperation/getdatabase.h: -------------------------------------------------------------------------------- 1 | #ifndef GETDATABASE_H 2 | #define GETDATABASE_H 3 | 4 | 5 | class GetDatabase 6 | { 7 | public: 8 | GetDatabase(); 9 | }; 10 | 11 | #endif // GETDATABASE_H 12 | -------------------------------------------------------------------------------- /officeCooperation/image.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | image/1.jpg 4 | image/icons48.png 5 | image/todo.png 6 | image/schedule.png 7 | image/doc.png 8 | image/project.png 9 | image/head.png 10 | image/QtPic/alignboth.png 11 | image/QtPic/save.png 12 | image/QtPic/about.png 13 | image/QtPic/close.png 14 | image/QtPic/cut.png 15 | image/QtPic/saveas.png 16 | image/QtPic/alignright.png 17 | image/QtPic/copy.png 18 | image/QtPic/font.png 19 | image/QtPic/aligncenter.png 20 | image/QtPic/alignleft.png 21 | image/QtPic/open.png 22 | image/QtPic/newfile.png 23 | image/QtPic/time.png 24 | image/QtPic/paste.png 25 | image/QtPic/exit.png 26 | image/add.png 27 | image/mainwindow.png 28 | image/fileclient.jpg 29 | image/background/1.jpg 30 | image/background/2.jpg 31 | image/background/3.jpg 32 | image/background/4.jpg 33 | image/background/5.jpg 34 | image/background/6.jpg 35 | image/background/7.jpg 36 | image/icon/1.jpg 37 | image/icon/2.jpg 38 | image/icon/3.jpg 39 | image/icon/4.jpg 40 | image/icon/5.jpg 41 | image/icon/6.jpg 42 | image/icon/7.jpg 43 | image/icon/8.jpg 44 | image/background/8.jpg 45 | image/icon/9.jpg 46 | image/icon/10.jpg 47 | image/icon/11.jpg 48 | image/icon/12.jpg 49 | image/icon/13.jpg 50 | image/icon/14.jpg 51 | image/icon/15.jpg 52 | image/icon/16.jpg 53 | 54 | 55 | -------------------------------------------------------------------------------- /officeCooperation/image/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/1.jpg -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/about.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/alignboth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/alignboth.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/aligncenter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/aligncenter.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/alignleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/alignleft.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/alignright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/alignright.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/close.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/copy.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/cut.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/exit.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/font.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/newfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/newfile.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/open.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/paste.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/save.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/saveas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/saveas.png -------------------------------------------------------------------------------- /officeCooperation/image/QtPic/time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/QtPic/time.png -------------------------------------------------------------------------------- /officeCooperation/image/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/add.png -------------------------------------------------------------------------------- /officeCooperation/image/background/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/1.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/2.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/3.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/4.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/5.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/6.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/7.jpg -------------------------------------------------------------------------------- /officeCooperation/image/background/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/background/8.jpg -------------------------------------------------------------------------------- /officeCooperation/image/doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/doc.png -------------------------------------------------------------------------------- /officeCooperation/image/fileclient.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/fileclient.jpg -------------------------------------------------------------------------------- /officeCooperation/image/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/head.png -------------------------------------------------------------------------------- /officeCooperation/image/icon/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/1.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/10.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/11.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/12.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/13.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/14.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/15.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/16.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/2.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/3.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/4.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/5.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/6.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/7.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/8.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icon/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icon/9.jpg -------------------------------------------------------------------------------- /officeCooperation/image/icons48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/icons48.png -------------------------------------------------------------------------------- /officeCooperation/image/mainwindow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/mainwindow.png -------------------------------------------------------------------------------- /officeCooperation/image/project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/project.png -------------------------------------------------------------------------------- /officeCooperation/image/schedule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/schedule.png -------------------------------------------------------------------------------- /officeCooperation/image/todo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learnCodeHasAborted/Qt_officeCooperation/05fbbcc36e44b103ccd8bb71dfc8ded559a7d1a8/officeCooperation/image/todo.png -------------------------------------------------------------------------------- /officeCooperation/login.cpp: -------------------------------------------------------------------------------- 1 | #include "login.h" 2 | #include "ui_login.h" 3 | #include 4 | #include 5 | #include"mydatabase.h" 6 | #include"mainwindow.h" 7 | #include 8 | #include 9 | #include 10 | #include"configuration.h" 11 | 12 | login::login(QWidget *parent) : 13 | QWidget(parent), 14 | ui(new Ui::login) 15 | { 16 | ui->setupUi(this); 17 | init(); 18 | ui->username->setFocus();//默认焦点 19 | //默认回车确认登录 20 | ui->loginBtn->setShortcut(Qt::Key_Enter); 21 | ui->loginBtn->setShortcut(Qt::Key_Return); 22 | } 23 | 24 | 25 | login::~login() 26 | { 27 | delete ui; 28 | } 29 | 30 | void login::init() 31 | { 32 | this->setWindowTitle("登录"); 33 | this->setWindowIcon(QIcon(":/image/icons48.png")); 34 | //背景、字体 颜色 35 | ui->loginBtn->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); 36 | ui->registerBtn->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); 37 | } 38 | 39 | void login::paintEvent(QPaintEvent *event) 40 | { 41 | QPixmap pixmap = QPixmap(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg").scaled(this->size()); 42 | QPainter painter(this); 43 | painter.drawPixmap(this->rect(), pixmap); 44 | } 45 | 46 | void login::verify(){ 47 | username=ui->username->text();pwd=ui->pwd->text(); 48 | //判断有效输入 49 | if(username==""||pwd==""){ 50 | QMessageBox::StandardButton dialog=QMessageBox::critical(this,"登录失败","用户名或密码不能为空"); 51 | return; 52 | } 53 | MyDatabase md("log"+username); 54 | QSqlDatabase db=md.getDatabase(); 55 | 56 | QSqlQuery query(db); 57 | QString sql = "select `id`,`username`,`icon`,`background` from `user` " 58 | "where binary `username`='"+username+"' and binary `pwd`='"+pwd+"' and state =0"; 59 | query.exec(sql); 60 | 61 | //登录成功 62 | if(query.next()){ 63 | query.first(); 64 | int id=query.value(0).toInt(); 65 | QString username=query.value(1).toString(); 66 | ID_OF_ICON = query.value(2).toInt(); 67 | ID_OF_BACKGROUND = query.value(3).toInt(); 68 | //修改登录状态为上线 69 | query.exec("UPDATE `user` SET state=1 WHERE id="+QString::number(id)); 70 | emit login_success_signals(id,username); 71 | }//失败 72 | else{ 73 | QMessageBox::StandardButton dialog=QMessageBox::critical(this,"登录失败","可能的原因有:\n1、用户名不存在\n2、密码错误\n3、账号已在线,无法重复登录"); 74 | } 75 | 76 | } 77 | 78 | void login::showRegister(){ 79 | emit new_register_signals(); 80 | } 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /officeCooperation/login.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGIN_H 2 | #define LOGIN_H 3 | #include"register.h" 4 | #include 5 | 6 | namespace Ui { 7 | class login; 8 | } 9 | 10 | class login : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit login(QWidget *parent = 0); 16 | ~login(); 17 | Ui::login* getUi(); 18 | 19 | protected: 20 | virtual void paintEvent(QPaintEvent *event); 21 | 22 | private slots: 23 | void verify(); 24 | void showRegister(); 25 | 26 | private: 27 | Ui::login *ui; 28 | void init(); 29 | QString username=""; 30 | QString pwd=""; 31 | 32 | signals: 33 | void login_success_signals(int _id,QString _username); 34 | void new_register_signals(); 35 | }; 36 | 37 | #endif // LOGIN_H 38 | -------------------------------------------------------------------------------- /officeCooperation/login.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | login 4 | 5 | 6 | 7 | 0 8 | 0 9 | 350 10 | 180 11 | 12 | 13 | 14 | 15 | 350 16 | 180 17 | 18 | 19 | 20 | 21 | 350 22 | 180 23 | 24 | 25 | 26 | login 27 | 28 | 29 | 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | 36 | 40 37 | 20 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 30 53 | 20 54 | 55 | 56 | 57 | 58 | 30 59 | 20 60 | 61 | 62 | 63 | 64 | 黑体 65 | 9 66 | false 67 | 68 | 69 | 70 | <html><head/><body><p><span style=" color:#000000;">账号</span></p></body></html> 71 | 72 | 73 | username 74 | 75 | 76 | 77 | 78 | 79 | 80 | Qt::Horizontal 81 | 82 | 83 | 84 | 40 85 | 20 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 230 95 | 20 96 | 97 | 98 | 99 | 100 | 230 101 | 20 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | Qt::Vertical 112 | 113 | 114 | 115 | 20 116 | 40 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 30 128 | 20 129 | 130 | 131 | 132 | 133 | 30 134 | 20 135 | 136 | 137 | 138 | 139 | 黑体 140 | 9 141 | false 142 | 143 | 144 | 145 | <html><head/><body><p><span style=" color:#000000;">密码</span></p></body></html> 146 | 147 | 148 | pwd 149 | 150 | 151 | 152 | 153 | 154 | 155 | Qt::Horizontal 156 | 157 | 158 | 159 | 40 160 | 20 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 230 170 | 20 171 | 172 | 173 | 174 | 175 | 230 176 | 20 177 | 178 | 179 | 180 | QLineEdit::Password 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | false 193 | 194 | 195 | 196 | Qt::Vertical 197 | 198 | 199 | 200 | 20 201 | 40 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 80 213 | 20 214 | 215 | 216 | 217 | 218 | 80 219 | 20 220 | 221 | 222 | 223 | 224 | 黑体 225 | 9 226 | false 227 | 228 | 229 | 230 | 登录 231 | 232 | 233 | 234 | 235 | 236 | 237 | Qt::Horizontal 238 | 239 | 240 | 241 | 40 242 | 20 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 80 252 | 20 253 | 254 | 255 | 256 | 257 | 80 258 | 20 259 | 260 | 261 | 262 | 263 | 黑体 264 | 9 265 | false 266 | 267 | 268 | 269 | 注册 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | Qt::Vertical 281 | 282 | 283 | 284 | 20 285 | 40 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | Qt::Horizontal 294 | 295 | 296 | 297 | 40 298 | 20 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | Qt::Vertical 307 | 308 | 309 | 310 | 20 311 | 40 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | loginBtn 323 | clicked() 324 | login 325 | verify() 326 | 327 | 328 | 192 329 | 224 330 | 331 | 332 | 246 333 | 290 334 | 335 | 336 | 337 | 338 | pwd 339 | returnPressed() 340 | login 341 | verify() 342 | 343 | 344 | 522 345 | 150 346 | 347 | 348 | 710 349 | 138 350 | 351 | 352 | 353 | 354 | registerBtn 355 | clicked() 356 | login 357 | showRegister() 358 | 359 | 360 | 498 361 | 231 362 | 363 | 364 | 500 365 | 264 366 | 367 | 368 | 369 | 370 | 371 | verify() 372 | getUsername(QString) 373 | getPwd(QString) 374 | showRegister() 375 | 376 | 377 | -------------------------------------------------------------------------------- /officeCooperation/loginerror.cpp: -------------------------------------------------------------------------------- 1 | #include "loginerror.h" 2 | #include "ui_loginerror.h" 3 | 4 | loginError::loginError(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::loginError) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | loginError::~loginError() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /officeCooperation/loginerror.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINERROR_H 2 | #define LOGINERROR_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class loginError; 8 | } 9 | 10 | class loginError : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit loginError(QWidget *parent = 0); 16 | ~loginError(); 17 | 18 | private: 19 | Ui::loginError *ui; 20 | }; 21 | 22 | #endif // LOGINERROR_H 23 | -------------------------------------------------------------------------------- /officeCooperation/loginerror.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | loginError 4 | 5 | 6 | 7 | 0 8 | 0 9 | 600 10 | 400 11 | 12 | 13 | 14 | Qt::DefaultContextMenu 15 | 16 | 17 | Dialog 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 26 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 27 | p, li { white-space: pre-wrap; } 28 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 29 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">账户不存在或密码错误</span></p> 30 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">如果已创建账户,请您重新检查密码或账号</span></p> 31 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">如果还未创建账户,请您在登录界面点击“注册”按钮进行注册</span></p></body></html> 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 50 40 | 30 41 | 42 | 43 | 44 | Qt::Horizontal 45 | 46 | 47 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | buttonBox 59 | accepted() 60 | loginError 61 | accept() 62 | 63 | 64 | 248 65 | 254 66 | 67 | 68 | 157 69 | 274 70 | 71 | 72 | 73 | 74 | buttonBox 75 | rejected() 76 | loginError 77 | reject() 78 | 79 | 80 | 316 81 | 260 82 | 83 | 84 | 286 85 | 274 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /officeCooperation/loginverify.cpp: -------------------------------------------------------------------------------- 1 | #include "loginverify.h" 2 | 3 | loginVerify::loginVerify() 4 | { 5 | } 6 | void loginVerify::verify(){ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /officeCooperation/loginverify.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINVERIFY_H 2 | #define LOGINVERIFY_H 3 | 4 | 5 | class loginVerify 6 | { 7 | Q_OBJECT 8 | public slots: 9 | //verify login message 10 | void verify(); 11 | public: 12 | loginVerify(); 13 | }; 14 | 15 | #endif // LOGINVERIFY_H 16 | -------------------------------------------------------------------------------- /officeCooperation/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"login.h" 3 | #include"mytcpservice.h" 4 | #include"myclient.h" 5 | #include"doc.h" 6 | #include"dialog.h" 7 | #include"mainsiderbar.h" 8 | #include "qboxlayout.h" 9 | #include "qpushbutton.h" 10 | #include"mainwindow.h" 11 | #include 12 | #include"friendwidget.h" 13 | #include"addfriend.h" 14 | #include"personcard.h" 15 | #include"configuration.h" 16 | #include"myapp.h" 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);//适应高分辨率屏幕 21 | QApplication a(argc, argv); 22 | 23 | MyApp* ma = new MyApp(); 24 | 25 | // MyApp* ma2 = new MyApp(); 26 | 27 | return a.exec(); 28 | } 29 | -------------------------------------------------------------------------------- /officeCooperation/mainsiderbar.cpp: -------------------------------------------------------------------------------- 1 | #include "mainsiderbar.h" 2 | #include "todolist.h" 3 | #include "ui_mainsiderbar.h" 4 | #include 5 | #include"configuration.h" 6 | 7 | MainSiderBar::MainSiderBar(int id_, QWidget *parent) : 8 | QWidget(parent), 9 | ui(new Ui::MainSiderBar),id(id_) 10 | { 11 | ui->setupUi(this); 12 | 13 | init(); 14 | 15 | connect(ui->icontoolButton,&QToolButton::clicked, this, &MainSiderBar::icon_slot);//头像修改个人资料); 16 | connect(ui->doctoolButton_6,&QToolButton::clicked, [&]{//文本编辑界面 17 | if(d == nullptr)d = new doc(); 18 | d->showMaximized();d->raise(); 19 | } ); 20 | connect(ui->scheduletoolButton_3,&QToolButton::clicked,[&]{//设定计划 21 | if(dia==nullptr)dia = new Dialog(id); 22 | dia->showMaximized();dia->raise(); 23 | } ); 24 | connect(ui->todolisttoolButton_4,&QToolButton::clicked,[&]{//待办事项 25 | if(to==nullptr)to = new ToDoList(id); 26 | to->showMaximized();to->raise(); 27 | } ); 28 | } 29 | 30 | MainSiderBar::~MainSiderBar() 31 | { 32 | delete p;delete d;delete dia;delete to; 33 | delete ui; 34 | } 35 | 36 | void MainSiderBar::init() 37 | { 38 | this->setFixedSize(QSize(55,550));//匹配主界面边栏 39 | this->setStyleSheet("background-color:rgb(65,138,180);"); 40 | 41 | QWidget* blank1 = new QWidget(this); 42 | blank1->setFixedSize(QSize(55,25)); 43 | blank1->move(0,55); 44 | QWidget* blank2 = new QWidget(this); 45 | blank2->setFixedSize(QSize(55,305)); 46 | blank2->move(0,245); 47 | 48 | ui->icontoolButton->setIconSize(ui->icontoolButton->size()); 49 | ui->icontoolButton->setIcon(QIcon(":/image/icon/"+QString::number(ID_OF_ICON)+".jpg")); 50 | 51 | ui->scheduletoolButton_3->setIconSize(QSize(25,25)); 52 | ui->scheduletoolButton_3->setIcon(QIcon(":/image/schedule.png")); 53 | ui->scheduletoolButton_3->setText("设定计划"); 54 | ui->scheduletoolButton_3->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 55 | ui->scheduletoolButton_3->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 56 | 57 | ui->todolisttoolButton_4->setIconSize(QSize(25,25)); 58 | ui->todolisttoolButton_4->setIcon(QIcon(":/image/todo.png")); 59 | ui->todolisttoolButton_4->setText("待办事项"); 60 | ui->todolisttoolButton_4->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 61 | ui->todolisttoolButton_4->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 62 | 63 | ui->doctoolButton_6->setIconSize(QSize(25,25)); 64 | ui->doctoolButton_6->setIcon(QIcon(":/image/project.png")); 65 | ui->doctoolButton_6->setText("项目编辑"); 66 | ui->doctoolButton_6->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 67 | ui->doctoolButton_6->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 68 | 69 | } 70 | 71 | void MainSiderBar::icon_slot() 72 | { 73 | if(p == nullptr){ 74 | p = new PersonCard(id); 75 | connect(p,&PersonCard::forwardInit, this, &MainSiderBar::forward ); 76 | connect(p,&PersonCard::forwardLogout, [&]{emit back_login_signals();}); 77 | connect(p,&PersonCard::close_personcard_signals, this, [&]{delete p;p=nullptr;} ); 78 | } 79 | p->showMaximized();p->raise(); 80 | } 81 | 82 | void MainSiderBar::forward() 83 | { 84 | init(); 85 | emit forwardInit(); 86 | } 87 | -------------------------------------------------------------------------------- /officeCooperation/mainsiderbar.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINSIDERBAR_H 2 | #define MAINSIDERBAR_H 3 | 4 | #include"todolist.h" 5 | #include "dialog.h" 6 | #include "doc.h" 7 | #include "personcard.h" 8 | #include 9 | 10 | namespace Ui { 11 | class MainSiderBar; 12 | } 13 | 14 | class MainSiderBar : public QWidget 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit MainSiderBar(int id, QWidget *parent = nullptr); 20 | ~MainSiderBar(); 21 | 22 | private: 23 | Ui::MainSiderBar *ui; 24 | int id; 25 | PersonCard* p=nullptr; 26 | doc* d=nullptr; 27 | Dialog* dia=nullptr; 28 | ToDoList* to = nullptr; 29 | 30 | void init(); 31 | public slots: 32 | void icon_slot(); 33 | void forward(); 34 | 35 | signals: 36 | void forwardInit(); 37 | void back_login_signals(); 38 | }; 39 | 40 | #endif // MAINSIDERBAR_H 41 | -------------------------------------------------------------------------------- /officeCooperation/mainsiderbar.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainSiderBar 4 | 5 | 6 | 7 | 0 8 | 0 9 | 84 10 | 550 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 55 22 | 550 23 | 24 | 25 | 26 | 27 | 84 28 | 550 29 | 30 | 31 | 32 | Form 33 | 34 | 35 | 36 | 37 | 0 38 | 80 39 | 55 40 | 55 41 | 42 | 43 | 44 | 45 | 55 46 | 55 47 | 48 | 49 | 50 | 51 | 55 52 | 55 53 | 54 | 55 | 56 | 57 | 黑体 58 | 9 59 | 50 60 | false 61 | 62 | 63 | 64 | 设定计划 65 | 66 | 67 | 68 | 69 | 70 | 0 71 | 135 72 | 55 73 | 55 74 | 75 | 76 | 77 | 78 | 55 79 | 55 80 | 81 | 82 | 83 | 84 | 55 85 | 55 86 | 87 | 88 | 89 | 90 | 黑体 91 | 9 92 | 50 93 | false 94 | 95 | 96 | 97 | 待办事项 98 | 99 | 100 | 101 | 102 | 103 | 0 104 | 190 105 | 55 106 | 55 107 | 108 | 109 | 110 | 111 | 55 112 | 55 113 | 114 | 115 | 116 | 117 | 55 118 | 55 119 | 120 | 121 | 122 | 123 | 黑体 124 | 9 125 | 50 126 | false 127 | 128 | 129 | 130 | 项目编辑 131 | 132 | 133 | 134 | 135 | 136 | 0 137 | 0 138 | 55 139 | 55 140 | 141 | 142 | 143 | 144 | 0 145 | 0 146 | 147 | 148 | 149 | 150 | 55 151 | 55 152 | 153 | 154 | 155 | 156 | 55 157 | 55 158 | 159 | 160 | 161 | Qt::LeftToRight 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /officeCooperation/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include"QListWidget" 4 | #include"QListWidgetItem" 5 | #include"friendwidget.h" 6 | #include 7 | #include 8 | #include 9 | #include"chatclient.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include"addfriend.h" 16 | #include"login.h" 17 | #include"mainsiderbar.h" 18 | #include"configuration.h" 19 | #include 20 | 21 | //#include 22 | 23 | MainWindow::MainWindow(int id_,QString username_, QWidget *parent) : 24 | QMainWindow(parent), 25 | ui(new Ui::MainWindow),id(id_),username(username_) 26 | { 27 | ui->setupUi(this); 28 | init(); 29 | md=new MyDatabase("main"+username);//数据库初始化 30 | db=md->getDatabase(); 31 | query=QSqlQuery(db); 32 | myConnect();//连接服务器,chatServer和fileServer 33 | timer=new QTimer(this); 34 | timer->start(2000);//两秒后判断是否连接成功 35 | connect(timer,&QTimer::timeout, this,&MainWindow::isConnected); 36 | showFriends();//显示联系人 37 | //界面功能 38 | connect(ui->searchlineEdit,&QLineEdit::textEdited, this, &MainWindow::search );//搜索已有联系人 39 | connect(ui->addtoolButton, &QPushButton::clicked, this,&MainWindow::add_friend_slots); //添加联系人 40 | } 41 | 42 | MainWindow::~MainWindow() 43 | { 44 | delete chatSocket;delete fileSocket;delete md;delete msb; 45 | delete ui; 46 | } 47 | 48 | void MainWindow::closeEvent(QCloseEvent* e){ 49 | if(query.exec("UPDATE `user` SET state=0 WHERE id="+QString::number(id))){ 50 | qDebug()<<"UPDATE `user` SET state=0 WHERE id="+QString::number(id); 51 | } 52 | noticify("disconnected"); 53 | QString filedis = "disconnected"+split+username; 54 | if(fileSocket->isWritable()) 55 | fileSocket->write(filedis.toUtf8()); 56 | chatSocket->disconnectFromHost(); 57 | fileSocket->disconnectFromHost(); 58 | qDebug()<<"走了 noticify dis"; 59 | 60 | QMessageBox::Button button2 = QMessageBox::question(this,"退出","是否退回登录界面?"); 61 | if(button2==QMessageBox::Yes){ 62 | emit back_login_signals(); 63 | } 64 | else{ 65 | emit exit_signals(); 66 | } 67 | } 68 | 69 | void MainWindow::paintEvent(QPaintEvent *e) 70 | { 71 | // QPixmap pixmap = QPixmap(":/image/blue.jpg").scaled(this->size()); 72 | // QPainter painter(this); 73 | // painter.drawPixmap(this->rect(),pixmap); 74 | } 75 | 76 | void MainWindow::init() 77 | { 78 | this->setWindowTitle("主界面"); 79 | this->setWindowIcon(QIcon(":/image/icons48.png")); 80 | this->setStyleSheet("#MainWindow{border-image:url(:/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg)}"); 81 | 82 | if(msb==nullptr){//左侧工具栏 83 | msb = new MainSiderBar(id,this); 84 | msb->move(0,0); 85 | msb->setAutoFillBackground(true); 86 | connect(msb,&MainSiderBar::forwardInit, this, &MainWindow::init );//刷新界面 87 | connect(msb,&MainSiderBar::back_login_signals, this, &MainWindow::back_login_slots );//退出登录 88 | } 89 | 90 | ui->searchlineEdit->setPlaceholderText("搜索"); 91 | 92 | ui->addtoolButton->setIconSize(ui->addtoolButton->size()); 93 | ui->addtoolButton->setIcon(QIcon(":/image/add.png")); 94 | ui->addtoolButton->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 95 | } 96 | 97 | void MainWindow::myConnect() 98 | { 99 | chatSocket=new QTcpSocket(); 100 | fileSocket=new QTcpSocket(); 101 | chatSocket->connectToHost(SERVER_IP, CHAT_PORT); 102 | fileSocket->connectToHost(SERVER_IP, FILE_PORT); 103 | connect(chatSocket,&QTcpSocket::connected,this,&MainWindow::chatConnected ); 104 | connect(fileSocket,&QTcpSocket::connected,this,&MainWindow::fileConnected ); 105 | } 106 | 107 | void MainWindow::showFriends() 108 | { 109 | QString sql="SELECT username,state,icon,user.id FROM `user`,relationship WHERE uid1="+QString::number(id)+" AND uid2=user.id"; 110 | refresh(sql); 111 | } 112 | 113 | void MainWindow::showFriends(QString sql) 114 | { 115 | refresh(sql); 116 | } 117 | 118 | void MainWindow::refresh(QString sql) 119 | { 120 | query.exec(sql); 121 | ui->friendsListWidget->clear(); 122 | qDeleteAll(friends);//清空指针空间 123 | friends.clear(); 124 | while(query.next()){//显示好友列表 125 | QString peername=query.value(0).toString(); 126 | QString state= query.value(1).toInt() ? "在线" : "离线" ; 127 | int icon=query.value(2).toInt(); 128 | int pid = query.value(3).toInt(); 129 | 130 | FriendWidget* f=new FriendWidget(pid,this,fileSocket,chatSocket,username,peername,state,icon,ui->friendsListWidget); 131 | connect(f,&FriendWidget::delete_signals,this,&MainWindow::delete_slots ); 132 | 133 | QListWidgetItem *item=new QListWidgetItem(ui->friendsListWidget); 134 | item->setSizeHint(QSize(320,60)); 135 | item->setBackground(QColor(245,245,245)); 136 | 137 | ui->friendsListWidget->addItem(item); 138 | ui->friendsListWidget->setItemWidget(item,f); 139 | f->show(); 140 | friends.insert(peername,f); 141 | } 142 | } 143 | 144 | void MainWindow::noticify(QString notice) 145 | { 146 | QString qmsg=notice+split+username; 147 | QSqlQuery query(db); 148 | QString sql="SELECT username FROM `user`,relationship WHERE uid1="+QString::number(id)+" AND uid2=user.id AND state=1"; 149 | query.exec(sql); 150 | qmsg+=split+"notice"; 151 | while(query.next()){ 152 | qmsg+=split+query.value(0).toString(); 153 | } 154 | if(chatSocket->isWritable()) 155 | chatSocket->write(qmsg.toUtf8()); 156 | } 157 | 158 | void MainWindow::chatConnected(){//通知好友自己上线 159 | connect(chatSocket,&QTcpSocket::readyRead,this, &MainWindow::myReceive); 160 | ok_chat=true; 161 | noticify("connected"); 162 | } 163 | 164 | void MainWindow::fileConnected(){ 165 | connect(fileSocket,&QTcpSocket::readyRead,this, &MainWindow::myTransfer); 166 | ok_file=true; 167 | QString qmsg="connected"+split+username; 168 | if(fileSocket->isWritable()) 169 | fileSocket->write(qmsg.toUtf8()); 170 | } 171 | 172 | void MainWindow::isConnected() 173 | {//是否连接成功 174 | timer->stop(); 175 | qDebug()<<"ok_chat="<read(buffer,sizeof(buffer)); 186 | if(!len){break;} 187 | qmsg+=QString::fromUtf8(buffer); 188 | } 189 | QStringList qsl=qmsg.split(split); 190 | qDebug()<changeState(); 194 | showFriends();//其实只要刷新表就好了 195 | } 196 | else if(qsl[0]=="msg"){ 197 | FriendWidget* f=friends.value(qsl[1]); 198 | f->cc->myShow(qsl[2]); 199 | } 200 | else if(qsl[0]=="refresh"){ 201 | showFriends(); 202 | } 203 | 204 | } 205 | 206 | void MainWindow::myTransfer() 207 | {//新建transfer专门接收文件 208 | QString qmsg=""; 209 | while(true){ 210 | char buffer[1024]={0}; 211 | int len=fileSocket->read(buffer,sizeof(buffer)); 212 | if(!len){break;} 213 | qmsg+=QString::fromUtf8(buffer); 214 | } 215 | QStringList sp = qmsg.split(split); 216 | int filePort=sp[0].toInt(); 217 | qDebug()<<"emit port = "<connectToHost(SERVER_IP,filePort); 225 | connect(transfer,&QTcpSocket::connected,this,[=]{qDebug()<<"接收方连接成功transfer";} ); 226 | connect(transfer,&QTcpSocket::readyRead,this,&MainWindow::receiveFile ); 227 | } 228 | } 229 | 230 | void MainWindow::receiveFile() 231 | { 232 | if(fileSizeAll==0){ 233 | QString head=transfer->readAll(); 234 | 235 | qDebug()<<"receive head "<read(buffer,sizeof(buffer)); 252 | int len2 = file.write(buffer,len);//读一点,写一点 253 | if(len2 >0){ 254 | fileSizeReceive+=len2; 255 | } 256 | // int percent=(1.0*fileSizeReceive/fileSizeAll)*100; 257 | // qDebug()<<"fileSizeReceive = "<0); 266 | 267 | } 268 | } 269 | 270 | void MainWindow::search(QString text) 271 | { 272 | if(text==""){//全部显示 273 | showFriends(); 274 | return ; 275 | } 276 | qDebug()<<"text = "<setAttribute(Qt::WA_DeleteOnClose,true);//重载槽函数,刷新好友列表 290 | connect(af,&AddFriend::forwardRefresh, this, QOverload<>::of(&MainWindow::showFriends) ); 291 | connect(af,&AddFriend::forwardNotice, this, &MainWindow::noticeRfresh);//通知添加好友 292 | connect(af,&AddFriend::delete_addfriend_signals, [&]{delete af;af=nullptr;});//通知添加好友 293 | } 294 | af->showMaximized();af->raise();//this->lower(); 295 | } 296 | 297 | void MainWindow::noticeRfresh(QString pname) 298 | { 299 | showFriends(); 300 | QString qmsg="refresh"+split+username+split+pname;//通知对方刷新好友列表 301 | if(chatSocket->isWritable()) 302 | chatSocket->write(qmsg.toUtf8()); 303 | } 304 | 305 | void MainWindow::delete_slots(int pid,QString pname) 306 | { 307 | int bt = QMessageBox::question(this,"删除操作确认","您是否确认删除该联系人"); 308 | if(bt != QMessageBox::Yes) return; 309 | QString sql = "DELETE FROM `relationship` WHERE `uid1`="+QString::number(id)+" AND `uid2`="+QString::number(pid)+";"; 310 | sql += "DELETE FROM `relationship` WHERE `uid1`="+QString::number(pid)+" AND `uid2`="+QString::number(id)+";"; 311 | if(query.exec(sql)){ 312 | qDebug()< 5 | #include "addfriend.h" 6 | #include "friendwidget.h" 7 | #include "mainsiderbar.h" 8 | #include"mydatabase.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace Ui { 17 | class MainWindow; 18 | } 19 | 20 | class MainWindow : public QMainWindow 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | explicit MainWindow(int id_,QString uername_, QWidget *parent = nullptr); 26 | ~MainWindow(); 27 | 28 | protected: 29 | virtual void closeEvent(QCloseEvent* e); 30 | virtual void paintEvent(QPaintEvent* e); 31 | 32 | private: 33 | Ui::MainWindow *ui; 34 | void init(); 35 | MyDatabase* md=nullptr; 36 | QSqlDatabase db; 37 | QSqlQuery query; 38 | int id; 39 | QString username; 40 | QMap friends; 41 | void myConnect(); 42 | QTcpSocket* chatSocket=nullptr; 43 | QTcpSocket* fileSocket=nullptr; 44 | bool ok_chat=false,ok_file=false;//连接是否成功 45 | QTimer* timer=nullptr;//延时判断 46 | const QString split="↓⊙ā"; 47 | void showFriends(); 48 | void showFriends(QString sql); 49 | void refresh(QString sql); 50 | QTcpSocket* transfer=nullptr; 51 | void noticify(QString); 52 | MainSiderBar* msb=nullptr; 53 | AddFriend* af=nullptr; 54 | 55 | public slots: 56 | void chatConnected(); 57 | void fileConnected(); 58 | void isConnected(); 59 | void myReceive(); 60 | void myTransfer(); 61 | void receiveFile(); 62 | void search(QString text); 63 | void add_friend_slots(); 64 | void noticeRfresh(QString pname); 65 | void delete_slots(int pid,QString pname); 66 | void back_login_slots(); 67 | 68 | 69 | 70 | //传文件 71 | private: 72 | QFile file; 73 | QString fileName=""; 74 | int fileSizeAll=0; 75 | int fileSizeReceive=0; 76 | QString dir="C:/officeCooperation/download"; //接收文件所在目录C:\officeCooperation\download 77 | 78 | signals: 79 | void forwardMsg(QString); 80 | void forwardPort(int); 81 | void back_login_signals(); 82 | void exit_signals(); 83 | }; 84 | 85 | #endif // MAINWINDOW_H 86 | -------------------------------------------------------------------------------- /officeCooperation/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 395 10 | 550 11 | 12 | 13 | 14 | 15 | 395 16 | 550 17 | 18 | 19 | 20 | 21 | 395 22 | 550 23 | 24 | 25 | 26 | MainWindow 27 | 28 | 29 | 30 | 31 | 32 | 70 33 | 25 34 | 280 35 | 20 36 | 37 | 38 | 39 | 40 | 0 41 | 0 42 | 43 | 44 | 45 | 46 | 280 47 | 20 48 | 49 | 50 | 51 | 52 | 280 53 | 20 54 | 55 | 56 | 57 | 58 | 11 59 | 60 | 61 | 62 | 63 | 64 | 65 | 365 66 | 25 67 | 20 68 | 20 69 | 70 | 71 | 72 | 73 | 0 74 | 0 75 | 76 | 77 | 78 | 79 | 20 80 | 20 81 | 82 | 83 | 84 | 85 | 20 86 | 20 87 | 88 | 89 | 90 | 91 | Adobe 黑体 Std R 92 | 14 93 | 94 | 95 | 96 | Qt::RightToLeft 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 55 106 | 80 107 | 340 108 | 470 109 | 110 | 111 | 112 | 113 | 340 114 | 470 115 | 116 | 117 | 118 | 119 | 340 120 | 470 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /officeCooperation/myapp.cpp: -------------------------------------------------------------------------------- 1 | #include "myapp.h" 2 | 3 | MyApp::MyApp() 4 | { 5 | newLogin(); 6 | } 7 | 8 | MyApp::~MyApp() 9 | { 10 | delete lg;delete rg;delete mw; 11 | } 12 | 13 | void MyApp::newLogin() 14 | { 15 | lg = new login(); 16 | connect(lg,&login::login_success_signals, this, &MyApp::login_success_slots ); 17 | connect(lg,&login::new_register_signals, this, &MyApp::new_register_slots ); 18 | lg->show(); 19 | } 20 | 21 | void MyApp::newRegister() 22 | { 23 | rg = new Register(); 24 | connect(rg,&Register::back_login_signals, this, &MyApp::back_login_slots ); 25 | rg->show(); 26 | } 27 | 28 | void MyApp::newMainWindow(int _id, QString _username) 29 | { 30 | mw = new MainWindow(_id, _username); 31 | connect(mw,&MainWindow::back_login_signals, this, &MyApp::back_login_slots ); 32 | connect(mw,&MainWindow::exit_signals, this, &MyApp::exit_slots); 33 | mw->show(); 34 | } 35 | 36 | void MyApp::login_success_slots(int _id, QString _username) 37 | { 38 | delete lg;lg=nullptr; 39 | newMainWindow(_id,_username); 40 | } 41 | 42 | void MyApp::new_register_slots() 43 | { 44 | delete lg;lg=nullptr; 45 | newRegister(); 46 | } 47 | 48 | void MyApp::back_login_slots() 49 | { 50 | delete rg;delete mw; 51 | rg=nullptr;mw=nullptr; 52 | newLogin(); 53 | } 54 | 55 | void MyApp::exit_slots() 56 | { 57 | delete this; 58 | } 59 | -------------------------------------------------------------------------------- /officeCooperation/myapp.h: -------------------------------------------------------------------------------- 1 | #ifndef MYAPP_H 2 | #define MYAPP_H 3 | #include 4 | #include"login.h" 5 | #include"register.h" 6 | #include"mainwindow.h" 7 | 8 | class MyApp:public QObject 9 | { 10 | Q_OBJECT 11 | public: 12 | MyApp(); 13 | ~MyApp(); 14 | private: 15 | login* lg=nullptr; 16 | Register* rg=nullptr; 17 | MainWindow* mw=nullptr; 18 | 19 | void newLogin(); 20 | void newRegister(); 21 | void newMainWindow(int _id, QString _username); 22 | void login_success_slots(int _id, QString _username); 23 | void new_register_slots(); 24 | void back_login_slots(); 25 | void exit_slots(); 26 | }; 27 | 28 | #endif // MYAPP_H 29 | -------------------------------------------------------------------------------- /officeCooperation/myclient.cpp: -------------------------------------------------------------------------------- 1 | #include "myclient.h" 2 | #include "ui_myclient.h" 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | MyClient::MyClient(QString username_,QWidget *parent) : 9 | QWidget(parent), 10 | ui(new Ui::MyClient),username(username_) 11 | { 12 | ui->setupUi(this); 13 | 14 | serverIP=new QHostAddress(); 15 | port = 23333; 16 | //未连接不能发送消息 17 | ui-> sendpushButton->setEnabled(false); 18 | 19 | ui->iplineEdit->setText("127.0.0.1"); 20 | ui->portlineEdit->setText("23333"); 21 | ui->connectpushButton->setShortcut(Qt::Key_Enter); 22 | ui->connectpushButton->setShortcut(Qt::Key_Return); 23 | connect(ui->connectpushButton,SIGNAL(clicked()),this,SLOT(myConnect()));//绑定连接 24 | connect(ui->sendpushButton,SIGNAL(clicked()),this,SLOT(mySend())); 25 | } 26 | 27 | MyClient::~MyClient() 28 | { 29 | delete ui; 30 | } 31 | 32 | bool MyClient::myWrite(QString qmsg) 33 | { 34 | string smsg=qmsg.toStdString(); 35 | const char* chmsg=smsg.c_str(); 36 | int res=mySocket->write(chmsg,strlen(chmsg)); 37 | return res==-1 ? false : true; 38 | } 39 | 40 | void MyClient::myConnect() 41 | {//已经连接,此时点击按钮断开连接 42 | if(status){ 43 | //发送下线消息 44 | QString qmsg="disconnected|"+username; 45 | myWrite(qmsg); 46 | mySocket->disconnectFromHost(); 47 | status=false; 48 | } 49 | else{ 50 | QString ip = ui->iplineEdit->text();//ip isvalid 51 | if(!serverIP->setAddress(ip)){ 52 | QMessageBox::critical(this,"连接失败","ip地址不合法"); 53 | return ; 54 | } 55 | if(!mySocket){ 56 | mySocket=new QTcpSocket(this);//绑定parent应该可以自动析构 57 | } 58 | int port=ui->portlineEdit->text().toInt(); 59 | mySocket->connectToHost(*serverIP,port); 60 | if(!mySocket->waitForConnected(5000)){//5秒超时失败 61 | QMessageBox::information(this,"连接失败","响应超时,连接失败,请检查您的网络连接"); 62 | return ; 63 | } 64 | else{ 65 | status=true; 66 | 67 | //发送键激活,并绑定快捷键ctrl+enter 68 | ui->sendpushButton->setEnabled(true); 69 | QKeySequence key1(Qt::CTRL+Qt::Key_Enter); 70 | QKeySequence key2(Qt::CTRL+Qt::Key_Return); 71 | ui->sendpushButton->setShortcut(key1); 72 | ui->sendpushButton->setShortcut(key2); 73 | //连接按钮显示为断开按钮 74 | ui->connectpushButton->setText("断开"); 75 | connect(mySocket,&QTcpSocket::connected, this, &MyClient::mySuccessConnected); 76 | 77 | connect(mySocket,SIGNAL(readyRead()),this,SLOT(myReceive())); 78 | connect(mySocket,SIGNAL(disconnected()),this,SLOT(myDisconnect())); 79 | QMessageBox::information(this,"连接成功","连接成功,可以开始接收、发送消息"); 80 | } 81 | } 82 | 83 | } 84 | 85 | void MyClient::mySend() 86 | { 87 | qDebug()<<"client mysend"; 88 | if(!mySocket->isValid()){ 89 | QMessageBox::information(this,"发送失败","socket不合法"); 90 | qDebug()<<"发送失败socket不合法\n"; 91 | return ; 92 | } 93 | 94 | QString qmsg=ui->sendtextEdit->toPlainText(); 95 | 96 | if(qmsg==""){ 97 | QMessageBox::information(this,"发送失败","发送信息为空,请输入信息后再发送"); 98 | qDebug()<<"发送信息为空,请输入信息后再发送\n"; 99 | return ; 100 | } 101 | 102 | ui->sendtextEdit->clear(); 103 | ui->receivetextBrowser->append(username+":\n"+qmsg); 104 | bool res=false; 105 | if(isFirst){ 106 | isFirst=false; 107 | //向服务器注册连接信息 108 | qmsg="connected|"+username+"|"+qmsg; 109 | res=myWrite(qmsg); 110 | } 111 | else{ 112 | res=myWrite("msg|"+username+"|"+qmsg); 113 | } 114 | if(!res){ 115 | qDebug()<<"socket发送失败\n"; 116 | QMessageBox::information(this,"发送失败","socket发送失败"); 117 | } 118 | } 119 | 120 | void MyClient::myReceive() 121 | { 122 | char buffer[1024]={0}; 123 | int numRead=mySocket->read(buffer,1024); 124 | while(numRead){ 125 | ui->receivetextBrowser->append(QString::fromUtf8(buffer,strlen(buffer))); 126 | numRead=mySocket->read(buffer,1024); 127 | } 128 | } 129 | 130 | void MyClient::myDisconnect() 131 | { 132 | ui->connectpushButton->setText("连接"); 133 | ui->sendpushButton->setEnabled(false); 134 | QMessageBox::information(this,"连接断开","与对方连接断开"); 135 | } 136 | 137 | void MyClient::mySuccessConnected() 138 | { 139 | myWrite(QString("连接成功|"+username)); 140 | } 141 | -------------------------------------------------------------------------------- /officeCooperation/myclient.h: -------------------------------------------------------------------------------- 1 | #ifndef MYCLIENT_H 2 | #define MYCLIENT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class MyClient; 9 | } 10 | 11 | class MyClient : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit MyClient(QString username_, QWidget *parent = nullptr); 17 | ~MyClient(); 18 | 19 | private: 20 | Ui::MyClient *ui; 21 | QTcpSocket* mySocket=nullptr; 22 | bool status=false;//是否连上服务器 23 | int port; 24 | QHostAddress* serverIP; 25 | QString username; 26 | bool myWrite(QString qmsg);//封装发送QString类型,返回发送结果 27 | bool isFirst=true;//是否第一次发送 28 | 29 | 30 | private slots: 31 | void myConnect(); 32 | void mySend(); 33 | void myReceive(); 34 | void myDisconnect(); 35 | void mySuccessConnected(); 36 | }; 37 | 38 | #endif // MYCLIENT_H 39 | -------------------------------------------------------------------------------- /officeCooperation/myclient.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MyClient 4 | 5 | 6 | 7 | 0 8 | 0 9 | 426 10 | 426 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 40 25 | 20 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 服务器ip 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 | 50 71 | 20 72 | 73 | 74 | 75 | 76 | 70 77 | 40 78 | 79 | 80 | 81 | Qt::RightToLeft 82 | 83 | 84 | 连接 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 350 95 | 200 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | Qt::Horizontal 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 350 112 | 70 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 50 122 | 30 123 | 124 | 125 | 126 | 127 | 70 128 | 40 129 | 130 | 131 | 132 | Qt::RightToLeft 133 | 134 | 135 | 发送 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | Qt::Vertical 145 | 146 | 147 | 148 | 20 149 | 40 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | Qt::Vertical 158 | 159 | 160 | 161 | 20 162 | 40 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | Qt::Horizontal 171 | 172 | 173 | 174 | 40 175 | 20 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | portlineEdit 184 | connectpushButton 185 | sendpushButton 186 | sendtextEdit 187 | receivetextBrowser 188 | iplineEdit 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /officeCooperation/mydatabase.cpp: -------------------------------------------------------------------------------- 1 | #include "mydatabase.h" 2 | 3 | MyDatabase::MyDatabase(QString name) 4 | { 5 | db = QSqlDatabase::addDatabase("QMYSQL",name); 6 | // 数据库连接需要设置的信息 7 | db.setHostName("***"); // 数据库服务器IP,把 *** 改成自己的数据库 IP 地址,下面也要改 8 | db.setDatabaseName("***");// 数据库名 9 | db.setUserName("***");// 用户名 10 | db.setPassword("***");// 密码 11 | db.setPort(3306);// 端口号 12 | db.open(); 13 | } 14 | 15 | QSqlDatabase MyDatabase::getDatabase(){ 16 | return db; 17 | } 18 | -------------------------------------------------------------------------------- /officeCooperation/mydatabase.h: -------------------------------------------------------------------------------- 1 | #ifndef MYDATABASE_H 2 | #define MYDATABASE_H 3 | 4 | #include 5 | #include 6 | 7 | class MyDatabase 8 | { 9 | public: 10 | MyDatabase(QString name); 11 | QSqlDatabase getDatabase(); 12 | private: 13 | QSqlDatabase db; 14 | }; 15 | 16 | #endif // MYDATABASE_H 17 | -------------------------------------------------------------------------------- /officeCooperation/mytcpservice.cpp: -------------------------------------------------------------------------------- 1 | #include "mytcpservice.h" 2 | #include "ui_mytcpservice.h" 3 | #include 4 | #include 5 | 6 | #include 7 | using namespace std; 8 | 9 | 10 | MyTCPService::MyTCPService(QWidget *parent) : 11 | QWidget(parent), 12 | ui(new Ui::MyTCPService) 13 | { 14 | ui->setupUi(this); 15 | ui->portLine->setText("23333"); 16 | ui->listenBtn->setShortcut(Qt::Key_Enter); 17 | ui->listenBtn->setShortcut(Qt::Key_Return); 18 | } 19 | 20 | MyTCPService::~MyTCPService() 21 | { 22 | delete ui; 23 | } 24 | 25 | QString MyTCPService::toOutput(QString all) 26 | { 27 | QStringList sl=all.split("|"); 28 | if(sl[0]=="connected"){ 29 | QString curUsername=sl[1]; 30 | QString msg=sl[2]; 31 | 32 | } 33 | else if(sl[0]=="msg"){ 34 | QString curUsername=sl[1]; 35 | QString msg=sl[2]; 36 | } 37 | else if(sl[0]=="disconnected"){ 38 | QString curUsername=sl[1]; 39 | QString msg=sl[2]; 40 | } 41 | return sl[2]; 42 | } 43 | 44 | void MyTCPService::myListen() 45 | { 46 | if(myServer==nullptr){ 47 | myServer=new QTcpServer(); 48 | } 49 | int port=ui->portLine->text().toInt(); 50 | // 51 | if(!myServer->listen(QHostAddress::Any,port)){ 52 | QMessageBox::critical(this,"监听失败","服务器监听失败,请您检查端口设置或网络连接情况"); 53 | return; 54 | } 55 | else{ 56 | ok=true; 57 | ui->listenBtn->setEnabled(false); 58 | connect(myServer,SIGNAL(newConnection()),this,SLOT(myGetNewSocket()));//新连接 59 | QKeySequence key1(Qt::CTRL+Qt::Key_Enter); 60 | QKeySequence key2(Qt::CTRL+Qt::Key_Return); 61 | ui->sendBtn->setShortcut(key1); 62 | ui->sendBtn->setShortcut(key2); 63 | QMessageBox::information(this,"监听成功","服务器监听成功,可以开始接收、发送消息"); 64 | } 65 | } 66 | 67 | void MyTCPService::mySend() 68 | { 69 | qDebug()<<"mysend"; 70 | if(!mySocket->isValid()){ 71 | QMessageBox::information(this,"发送失败","socket不合法"); 72 | qDebug()<<"发送失败socket不合法\n"; 73 | return ; 74 | } 75 | QString qmsg=ui->sendTextEdit->toPlainText(); 76 | ui->receiveTextBrowser->append(qmsg); 77 | 78 | if(qmsg==""){ 79 | QMessageBox::information(this,"发送失败","发送信息为空,请输入信息后再发送"); 80 | qDebug()<<"发送信息为空,请输入信息后再发送\n"; 81 | return ; 82 | } 83 | 84 | ui->sendTextEdit->clear(); 85 | 86 | string smsg=qmsg.toStdString(); 87 | const char* chmsg=smsg.c_str(); 88 | qDebug()<<"chmsg"<write(chmsg,strlen(chmsg)); 90 | if(res==-1){ 91 | qDebug()<<"socket发送失败\n"; 92 | QMessageBox::information(this,"发送失败","socket发送失败"); 93 | } 94 | } 95 | 96 | void MyTCPService::myReceive() 97 | { 98 | char buffer[1024]={0}; 99 | mySocket=mySockets.first(); 100 | int numRead=mySocket->read(buffer,1024); 101 | // if(numRead==0){ 102 | // QMessageBox::critical(this,"接收失败","未接收到对方发送的消息"); 103 | // return ; 104 | // } 105 | QString all=QString::fromUtf8(buffer,strlen(buffer)); 106 | while(numRead){ 107 | numRead=mySocket->read(buffer,1024); 108 | all+=QString::fromUtf8(buffer,strlen(buffer)); 109 | } 110 | //字符串处理 111 | QString output=toOutput(all); 112 | ui->receiveTextBrowser->append(all); 113 | } 114 | 115 | void MyTCPService::myGetNewSocket() 116 | { 117 | QTcpSocket* newSocket = new QTcpSocket(this); 118 | newSocket= myServer->nextPendingConnection(); 119 | mySockets.insert("a",newSocket); 120 | connect(newSocket,SIGNAL(readyRead()),this,SLOT(myReceive())); 121 | // mySocket=myServer->nextPendingConnection(); 122 | // if(!mySocket){ 123 | // QMessageBox::critical(this,"连接失败","获取客户端连接失败"); 124 | // return ; 125 | // } 126 | // else{ 127 | // QMessageBox::information(this,"连接成功","获取客户端连接成功"); 128 | // connect(mySocket,SIGNAL(readyRead()),this,SLOT(myReceive())); 129 | // connect(mySocket,SIGNAL(disconnected()),this,SLOT(myDisconnect())); 130 | // } 131 | } 132 | 133 | void MyTCPService::myDisconnect() 134 | { 135 | QMessageBox::information(this,"连接断开","与对方连接断开"); 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /officeCooperation/mytcpservice.h: -------------------------------------------------------------------------------- 1 | #ifndef MYTCPSERVICE_H 2 | #define MYTCPSERVICE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class MyTCPService; 11 | } 12 | 13 | class MyTCPService : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit MyTCPService(QWidget *parent = nullptr); 19 | ~MyTCPService(); 20 | 21 | private: 22 | Ui::MyTCPService *ui; 23 | QTcpServer* myServer=nullptr; 24 | QTcpSocket* mySocket=nullptr; 25 | bool ok=false; 26 | QMap mySockets; 27 | QString toOutput(QString); 28 | 29 | private slots: 30 | void myListen(); 31 | void mySend(); 32 | void myReceive(); 33 | void myGetNewSocket(); 34 | void myDisconnect(); 35 | 36 | }; 37 | 38 | #endif // MYTCPSERVICE_H 39 | -------------------------------------------------------------------------------- /officeCooperation/mytcpservice.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MyTCPService 4 | 5 | 6 | 7 | 0 8 | 0 9 | 426 10 | 437 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | Qt::RightToLeft 18 | 19 | 20 | 21 | 22 | 23 | Qt::Vertical 24 | 25 | 26 | 27 | 20 28 | 40 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Qt::Horizontal 39 | 40 | 41 | 42 | 40 43 | 20 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 0 55 | 30 56 | 57 | 58 | 59 | 60 | 11 61 | 62 | 63 | 64 | 开始监听 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 0 73 | 30 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 70 83 | 30 84 | 85 | 86 | 87 | <html><head/><body><p><span style=" font-size:12pt;">端口号</span></p></body></html> 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 0 100 | 200 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | Qt::Horizontal 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 350 126 | 70 127 | 128 | 129 | 130 | 131 | 16777215 132 | 16777215 133 | 134 | 135 | 136 | Qt::LeftToRight 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 50 145 | 30 146 | 147 | 148 | 149 | 150 | 70 151 | 40 152 | 153 | 154 | 155 | 156 | 11 157 | 158 | 159 | 160 | Qt::RightToLeft 161 | 162 | 163 | 发送 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | Qt::Horizontal 175 | 176 | 177 | 178 | 40 179 | 20 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | Qt::Vertical 190 | 191 | 192 | 193 | 20 194 | 40 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | listenBtn 205 | clicked() 206 | MyTCPService 207 | myListen() 208 | 209 | 210 | 383 211 | 61 212 | 213 | 214 | 204 215 | 28 216 | 217 | 218 | 219 | 220 | sendBtn 221 | clicked() 222 | MyTCPService 223 | mySend() 224 | 225 | 226 | 390 227 | 402 228 | 229 | 230 | 401 231 | 404 232 | 233 | 234 | 235 | 236 | 237 | myListen() 238 | mySend() 239 | 240 | 241 | -------------------------------------------------------------------------------- /officeCooperation/newproject.cpp: -------------------------------------------------------------------------------- 1 | #include "newproject.h" 2 | #include "ui_newproject.h" 3 | 4 | #include 5 | #include 6 | 7 | NewProject::NewProject(QWidget *parent) : 8 | QDialog(parent), 9 | ui(new Ui::NewProject) 10 | { 11 | ui->setupUi(this); 12 | setWindowTitle("项目"); 13 | this->setWindowIcon(QIcon(":/image/icons48.png")); 14 | //选择新建项目目录按钮信号槽 15 | connect(ui->chooseProjectDir,SIGNAL(clicked()),this,SLOT(choose_project_dir())); 16 | //确定按钮信号槽 17 | connect(ui->okNewProject,SIGNAL(clicked()),this,SLOT(ok_new_project())); 18 | //取消按钮信号槽 19 | connect(ui->cancelNewProject,SIGNAL(clicked()),this,SLOT(cancel_new_project_())); 20 | //连接接受槽 21 | connect(ui->okNewProject,SIGNAL(clicked()),this,SLOT(accept())); 22 | //连接拒绝槽 23 | connect(ui->cancelNewProject,SIGNAL(clicked()),this,SLOT(reject())); 24 | 25 | } 26 | 27 | NewProject::~NewProject() 28 | { 29 | delete ui; 30 | } 31 | 32 | void NewProject::choose_project_dir() 33 | { 34 | QFileDialog *file_dialog=new QFileDialog(this); 35 | file_dialog->setOption(QFileDialog::ShowDirsOnly);//设置显示选项 36 | file_dialog->setFileMode(QFileDialog::Directory);//设置文件模式 37 | file_dialog->setViewMode(QFileDialog::List);//设置显示模式 38 | //点击确定按钮 39 | if(file_dialog->exec()==QFileDialog::Accepted) 40 | { 41 | //获取新建项目路径 42 | new_project_dir_=file_dialog->selectedFiles().at(0); 43 | ui->projectDir->setText(new_project_dir_);//设置路径栏 44 | } 45 | //点取消则返回 46 | else 47 | { 48 | return; 49 | } 50 | delete file_dialog; 51 | file_dialog=NULL; 52 | } 53 | 54 | void NewProject::ok_new_project() 55 | { 56 | //获取项目名和成员名 57 | new_project_name_=ui->projectName->text().trimmed(); 58 | new_project_members_=ui->projectMembers->text().trimmed(); 59 | 60 | //判断名字是否为空 61 | if( new_project_name_.isEmpty() || new_project_dir_.isEmpty()||new_project_members_.isEmpty() ) 62 | { 63 | QMessageBox::information(this,"提示","表格未填完整,新建项目失败",QMessageBox::Yes); 64 | } 65 | } 66 | 67 | 68 | void NewProject::cancel_new_project_() 69 | { 70 | QMessageBox::information(this,"提示","已取消新建项目",QMessageBox::Yes); 71 | } 72 | -------------------------------------------------------------------------------- /officeCooperation/newproject.h: -------------------------------------------------------------------------------- 1 | #ifndef NEWPROJECT_H 2 | #define NEWPROJECT_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class NewProject; 8 | } 9 | 10 | class NewProject : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit NewProject(QWidget *parent = nullptr); 16 | ~NewProject(); 17 | 18 | 19 | //获得新建项目名 20 | QString get_new_project_name(){return new_project_name_;} 21 | //获得新建项目的目录 22 | QString get_new_project_dir(){return new_project_dir_;} 23 | //获取参与人员信息 24 | QString get_members(){return new_project_members_;} 25 | 26 | private: 27 | Ui::NewProject *ui; 28 | 29 | 30 | QString new_project_name_;//新建项目名 31 | QString new_project_dir_;//新建项目文件夹路径 32 | QString new_project_members_;//项目成员 33 | 34 | 35 | private slots: 36 | void choose_project_dir();//选择项目目录按钮 37 | void ok_new_project();//确定按钮 38 | void cancel_new_project_();//取消按钮 39 | 40 | }; 41 | 42 | #endif // NEWPROJECT_H 43 | -------------------------------------------------------------------------------- /officeCooperation/newproject.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NewProject 4 | 5 | 6 | 7 | 0 8 | 0 9 | 631 10 | 447 11 | 12 | 13 | 14 | 新建项目 15 | 16 | 17 | 18 | 19 | 200 20 | 70 21 | 361 22 | 41 23 | 24 | 25 | 26 | 27 | 28 | 29 | 200 30 | 130 31 | 191 32 | 41 33 | 34 | 35 | 36 | 37 | 38 | 39 | 430 40 | 130 41 | 131 42 | 41 43 | 44 | 45 | 46 | 选择文件夹 47 | 48 | 49 | 50 | 51 | 52 | 110 53 | 350 54 | 141 55 | 41 56 | 57 | 58 | 59 | 确定 60 | 61 | 62 | 63 | 64 | 65 | 390 66 | 350 67 | 131 68 | 41 69 | 70 | 71 | 72 | 取消 73 | 74 | 75 | 76 | 77 | 78 | 60 79 | 70 80 | 121 81 | 41 82 | 83 | 84 | 85 | 项目名称 86 | 87 | 88 | 89 | 90 | 91 | 60 92 | 130 93 | 121 94 | 41 95 | 96 | 97 | 98 | 项目位置 99 | 100 | 101 | 102 | 103 | 104 | 60 105 | 190 106 | 121 107 | 41 108 | 109 | 110 | 111 | 参与人员 112 | 113 | 114 | 115 | 116 | 117 | 200 118 | 190 119 | 361 120 | 41 121 | 122 | 123 | 124 | 125 | 126 | 127 | 60 128 | 270 129 | 441 130 | 41 131 | 132 | 133 | 134 | 多个参与人员请用英文逗号分隔。 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /officeCooperation/officeCooperation.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2022-05-18T13:02:24 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui sql network 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = officeCooperation 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | 26 | SOURCES += \ 27 | addfriend.cpp \ 28 | chatclient.cpp \ 29 | configuration.cpp \ 30 | dialog.cpp \ 31 | fileclient.cpp \ 32 | friendwidget.cpp \ 33 | main.cpp \ 34 | login.cpp \ 35 | mainsiderbar.cpp \ 36 | mainwindow.cpp \ 37 | myapp.cpp \ 38 | mydatabase.cpp \ 39 | newproject.cpp \ 40 | passwordreset.cpp \ 41 | personcard.cpp \ 42 | picture.cpp \ 43 | register.cpp \ 44 | doc.cpp \ 45 | todo.cpp \ 46 | todolist.cpp 47 | 48 | HEADERS += \ 49 | addfriend.h \ 50 | chatclient.h \ 51 | configuration.h \ 52 | dialog.h \ 53 | doc.h \ 54 | fileclient.h \ 55 | friendwidget.h \ 56 | login.h \ 57 | mainsiderbar.h \ 58 | mainwindow.h \ 59 | myapp.h \ 60 | mydatabase.h \ 61 | newproject.h \ 62 | passwordreset.h \ 63 | personcard.h \ 64 | picture.h \ 65 | register.h \ 66 | todo.h \ 67 | todolist.h 68 | 69 | FORMS += \ 70 | addfriend.ui \ 71 | chatclient.ui \ 72 | dialog.ui \ 73 | fileclient.ui \ 74 | friendwidget.ui \ 75 | login.ui \ 76 | mainsiderbar.ui \ 77 | mainwindow.ui \ 78 | newproject.ui \ 79 | passwordreset.ui \ 80 | personcard.ui \ 81 | register.ui \ 82 | doc.ui \ 83 | todolist.ui 84 | 85 | RESOURCES += \ 86 | image.qrc 87 | 88 | # Default rules for deployment. 89 | qnx: target.path = /tmp/$${TARGET}/bin 90 | else: unix:!android: target.path = /opt/$${TARGET}/bin 91 | !isEmpty(target.path): INSTALLS += target 92 | -------------------------------------------------------------------------------- /officeCooperation/passwordreset.cpp: -------------------------------------------------------------------------------- 1 | #include "passwordreset.h" 2 | #include 3 | #include 4 | #include 5 | #include "configuration.h" 6 | #include "qdebug.h" 7 | #include "ui_passwordreset.h" 8 | #include 9 | 10 | PasswordReset::PasswordReset(int id_,QWidget *parent) : 11 | QWidget(parent), 12 | ui(new Ui::PasswordReset),id(id_) 13 | { 14 | ui->setupUi(this); 15 | init(); 16 | md=new MyDatabase("PasswordReset"+QString::number(id));//数据库初始化 17 | db=md->getDatabase(); 18 | query=QSqlQuery(db); 19 | 20 | timer = new QTimer(this); 21 | connect(timer,&QTimer::timeout,this,&PasswordReset::blink ); 22 | 23 | connect(ui->confirmlineEdit_4, &QLineEdit::textEdited,this, &PasswordReset::confirm ); 24 | connect(ui->confirmtoolButton, &QToolButton::clicked, this, &PasswordReset::changePassword); 25 | connect(ui->canceltoolButton_2, &QToolButton::clicked, [&]{this->close();}); 26 | } 27 | 28 | PasswordReset::~PasswordReset() 29 | { 30 | qDebug()<<" passwor 析构 "; 31 | delete md; 32 | delete ui; 33 | } 34 | 35 | void PasswordReset::paintEvent(QPaintEvent *e) 36 | { 37 | QPixmap pixmap = QPixmap(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg").scaled(this->size()); 38 | QPainter painter(this); 39 | painter.drawPixmap(this->rect(),pixmap); 40 | } 41 | 42 | void PasswordReset::closeEvent(QCloseEvent* e) 43 | { 44 | ui->curlineEdit->clear(); 45 | ui->newlineEdit_3->clear(); 46 | ui->confirmlineEdit_4->clear(); 47 | ui->warninglabel_2->hide(); 48 | e->accept(); 49 | } 50 | 51 | void PasswordReset::init() 52 | { 53 | this->setWindowTitle("修改密码"); 54 | this->setWindowIcon(QIcon(":/image/icons48.png")); 55 | //密码模式 56 | ui->curlineEdit->setEchoMode(QLineEdit::Password);ui->newlineEdit_3->setEchoMode(QLineEdit::Password);ui->confirmlineEdit_4->setEchoMode(QLineEdit::Password); 57 | //按钮样式 58 | ui->confirmtoolButton->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); ui->canceltoolButton_2->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); 59 | ui->warninglabel_2->hide();//警告信息 60 | } 61 | 62 | void PasswordReset::confirm(QString confirmPassword) 63 | { 64 | if(confirmPassword!=ui->newlineEdit_3->text()){ 65 | ui->warninglabel_2->show(); 66 | }else{ 67 | ui->warninglabel_2->hide(); 68 | } 69 | } 70 | 71 | void PasswordReset::changePassword() 72 | {//前后设置密码不一致,闪烁 73 | if(ui->confirmlineEdit_4->text()!=ui->newlineEdit_3->text()){ 74 | timer->start(250); 75 | return; 76 | } 77 | QMessageBox::Button button = QMessageBox::question(this,"确认修改","是否确认修改密码"); 78 | if(button==QMessageBox::Yes){ 79 | QString sql = "SELECT username FROM `user` WHERE `id`="+ QString::number(id)+ " AND pwd='"+ui->curlineEdit->text()+ "'"; 80 | query.exec(sql); 81 | if(query.next()){ 82 | sql = "UPDATE `user` SET pwd='"+ui->confirmlineEdit_4->text() + "' WHERE `id`= "+ QString::number(id); 83 | if(query.exec(sql)){QMessageBox::information(this,"修改密码成功","修改密码成功");return;} 84 | } 85 | else{ 86 | QMessageBox::information(this,"修改密码失败","当前的账号密码输入错误"); 87 | return; 88 | } 89 | } 90 | } 91 | 92 | void PasswordReset::blink() 93 | { 94 | if(blinkCnt++ == 10){timer->stop();blinkCnt=0;confirm(ui->confirmlineEdit_4->text());return;} 95 | if(ui->warninglabel_2->isHidden()) ui->warninglabel_2->show(); 96 | else ui->warninglabel_2->hide(); 97 | } 98 | -------------------------------------------------------------------------------- /officeCooperation/passwordreset.h: -------------------------------------------------------------------------------- 1 | #ifndef PASSWORDRESET_H 2 | #define PASSWORDRESET_H 3 | 4 | #include 5 | #include"mydatabase.h" 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class PasswordReset; 11 | } 12 | 13 | class PasswordReset : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit PasswordReset(int id,QWidget *parent = nullptr); 19 | ~PasswordReset(); 20 | protected: 21 | virtual void paintEvent(QPaintEvent* e); 22 | virtual void closeEvent(QCloseEvent* e); 23 | private: 24 | Ui::PasswordReset *ui; 25 | 26 | MyDatabase* md=nullptr; 27 | QSqlDatabase db; 28 | QSqlQuery query; 29 | 30 | int id; 31 | int blinkCnt=0; 32 | QTimer* timer=nullptr; 33 | 34 | void init(); 35 | 36 | public slots: 37 | void confirm(QString); 38 | void changePassword(); 39 | void blink(); 40 | }; 41 | 42 | #endif // PASSWORDRESET_H 43 | -------------------------------------------------------------------------------- /officeCooperation/passwordreset.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | PasswordReset 4 | 5 | 6 | 7 | 0 8 | 0 9 | 300 10 | 180 11 | 12 | 13 | 14 | 15 | 300 16 | 180 17 | 18 | 19 | 20 | 21 | 300 22 | 180 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 10 32 | 20 33 | 50 34 | 20 35 | 36 | 37 | 38 | 39 | 9 40 | 41 | 42 | 43 | 当前密码 44 | 45 | 46 | 47 | 48 | 49 | 80 50 | 20 51 | 200 52 | 20 53 | 54 | 55 | 56 | 57 | 58 | 59 | 10 60 | 60 61 | 50 62 | 20 63 | 64 | 65 | 66 | 67 | 9 68 | 69 | 70 | 71 | 新密码 72 | 73 | 74 | 75 | 76 | 77 | 80 78 | 60 79 | 200 80 | 20 81 | 82 | 83 | 84 | 85 | 86 | 87 | 10 88 | 100 89 | 50 90 | 20 91 | 92 | 93 | 94 | 95 | 9 96 | 97 | 98 | 99 | 确认密码 100 | 101 | 102 | 103 | 104 | 105 | 80 106 | 100 107 | 200 108 | 20 109 | 110 | 111 | 112 | 113 | 114 | 115 | 10 116 | 140 117 | 60 118 | 20 119 | 120 | 121 | 122 | 确认 123 | 124 | 125 | 126 | 127 | 128 | 220 129 | 140 130 | 60 131 | 20 132 | 133 | 134 | 135 | 取消 136 | 137 | 138 | 139 | 140 | 141 | 85 142 | 140 143 | 120 144 | 20 145 | 146 | 147 | 148 | <html><head/><body><p align="center"><span style=" font-size:10pt; color:#aa0000;">前后两次密码不一致</span></p></body></html> 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /officeCooperation/personcard.cpp: -------------------------------------------------------------------------------- 1 | #include "personcard.h" 2 | #include "ui_personcard.h" 3 | #include 4 | #include 5 | #include"configuration.h" 6 | #include 7 | #include 8 | #include"picture.h" 9 | #include 10 | #include 11 | #include"passwordreset.h" 12 | 13 | PersonCard::PersonCard(int i,QWidget *parent) : 14 | QWidget(parent),ui(new Ui::PersonCard), 15 | id(i) 16 | { 17 | ui->setupUi(this); 18 | init(); 19 | md=new MyDatabase("personcard"+QString::number(id));//数据库初始化 20 | db=md->getDatabase(); 21 | query=QSqlQuery(db); 22 | connect(ui->icontoolButton, &QToolButton::clicked,this, &PersonCard::showIcon ); 23 | connect(ui->backgroundtoolButton_2, &QToolButton::clicked,this, &PersonCard::showBackground ); 24 | connect(ui->passwordtoolButton_5, &QToolButton::clicked,this, &PersonCard::setPassword ); 25 | connect(ui->exittoolButton_3, &QToolButton::clicked,this, &PersonCard::logout ); 26 | } 27 | 28 | PersonCard::~PersonCard() 29 | { 30 | qDebug()<<"Personcard 析构"; 31 | delete md;delete iw;delete bw;delete pw;delete pixmap;delete pixmap2; 32 | delete ui; 33 | } 34 | 35 | void PersonCard::closeEvent(QCloseEvent *e) 36 | { 37 | emit close_personcard_signals();//通知工具窗口析构personcard 38 | } 39 | 40 | void PersonCard::init() 41 | { 42 | this->setWindowTitle("个人名片"); 43 | this->setWindowIcon(QIcon(":/image/icons48.png")); 44 | 45 | if(pixmap==nullptr) pixmap = new QPixmap(); 46 | pixmap->load(":/image/icon/"+QString::number(ID_OF_ICON)+".jpg"); 47 | pixmap->scaled(ui->iconlabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 48 | ui->iconlabel->setScaledContents(true); 49 | ui->iconlabel->setPixmap(*pixmap); 50 | 51 | if(pixmap2==nullptr) pixmap2 = new QPixmap(); 52 | pixmap2->load(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg"); 53 | pixmap2->scaled(ui->iconlabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 54 | ui->backgroundlabel->setScaledContents(true); 55 | ui->backgroundlabel->setPixmap(*pixmap2); 56 | 57 | ui->icontoolButton->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 58 | ui->backgroundtoolButton_2->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 59 | ui->passwordtoolButton_5->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 60 | ui->exittoolButton_3->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);"); 61 | } 62 | 63 | void PersonCard::showIcon() 64 | { 65 | if(iw==nullptr) { 66 | iw = new QWidget(); 67 | iw->setWindowTitle("选择头像"); 68 | iw->setWindowIcon(QIcon(":/image/icons48.png")); 69 | iw->setFixedSize(QSize(400,400)); 70 | 71 | for(int i=0;imove(x,y); 75 | connect(pic,&Picture::forwardPicture,this, &PersonCard::setIcon ); 76 | } 77 | } 78 | iw->showMaximized();iw->raise(); 79 | if(bw)bw->close();if(pw)pw->close(); 80 | } 81 | 82 | void PersonCard::setIcon(int i) 83 | { 84 | QMessageBox::Button button = QMessageBox::question(iw,"选择头像","是否设置选中图片为头像?"); 85 | if(button == QMessageBox::Yes){ 86 | ID_OF_ICON = i; 87 | init(); 88 | QString sql = "UPDATE `user` SET icon="+QString::number(ID_OF_ICON)+" WHERE `id`="+QString::number(id); 89 | query.exec(sql); 90 | emit forwardInit(); 91 | } 92 | } 93 | 94 | void PersonCard::showBackground() 95 | { 96 | if(bw==nullptr) { 97 | bw = new QWidget(); 98 | bw->setWindowTitle("选择背景"); 99 | bw->setWindowIcon(QIcon(":/image/icons48.png")); 100 | bw->setFixedSize(QSize(400,400)); 101 | 102 | for(int i=0;imove(x,y); 106 | connect(pic,&Picture::forwardPicture,this, &PersonCard::setBackground ); 107 | } 108 | } 109 | bw->showMaximized();bw->raise(); 110 | if(iw)iw->close();if(pw)pw->close(); 111 | } 112 | 113 | void PersonCard::setBackground(int i) 114 | { 115 | QMessageBox::Button button = QMessageBox::question(bw,"选择背景","是否设置选中图片为背景?"); 116 | if(button == QMessageBox::Yes){ 117 | ID_OF_BACKGROUND = i; 118 | init(); 119 | QString sql = "UPDATE `user` SET background="+QString::number(ID_OF_BACKGROUND)+" WHERE `id`="+QString::number(id); 120 | query.exec(sql); 121 | emit forwardInit(); 122 | } 123 | } 124 | 125 | void PersonCard::setPassword() 126 | { 127 | if(pw==nullptr) pw = new PasswordReset(id); 128 | pw->showMaximized();pw->raise(); 129 | if(iw)iw->close();if(bw)bw->close(); 130 | } 131 | 132 | void PersonCard::logout() 133 | { 134 | emit forwardLogout(); 135 | } 136 | -------------------------------------------------------------------------------- /officeCooperation/personcard.h: -------------------------------------------------------------------------------- 1 | #ifndef PERSONCARD_H 2 | #define PERSONCARD_H 3 | 4 | #include 5 | #include"mydatabase.h" 6 | #include"passwordreset.h" 7 | 8 | namespace Ui { 9 | class PersonCard; 10 | } 11 | 12 | class PersonCard : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit PersonCard(int id, QWidget *parent = nullptr); 18 | ~PersonCard(); 19 | protected: 20 | virtual void closeEvent(QCloseEvent* e); 21 | private: 22 | Ui::PersonCard *ui; 23 | 24 | MyDatabase* md=nullptr; 25 | QSqlDatabase db; 26 | QSqlQuery query; 27 | 28 | int id; 29 | 30 | QWidget* iw=nullptr; 31 | QWidget* bw=nullptr; 32 | PasswordReset* pw=nullptr; 33 | QPixmap *pixmap=nullptr; 34 | QPixmap *pixmap2=nullptr; 35 | 36 | void init(); 37 | public slots: 38 | void showIcon(); 39 | void setIcon(int); 40 | void showBackground(); 41 | void setBackground(int i); 42 | void setPassword(); 43 | void logout(); 44 | 45 | signals: 46 | void forwardInit(); 47 | void forwardLogout(); 48 | void close_personcard_signals(); 49 | }; 50 | 51 | #endif // PERSONCARD_H 52 | -------------------------------------------------------------------------------- /officeCooperation/personcard.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | PersonCard 4 | 5 | 6 | 7 | 0 8 | 0 9 | 500 10 | 300 11 | 12 | 13 | 14 | 15 | 500 16 | 300 17 | 18 | 19 | 20 | 21 | 500 22 | 300 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 400 32 | 0 33 | 100 34 | 100 35 | 36 | 37 | 38 | icon 39 | 40 | 41 | 42 | 43 | 44 | 400 45 | 100 46 | 100 47 | 50 48 | 49 | 50 | 51 | 52 | 12 53 | 54 | 55 | 56 | 更换头像 57 | 58 | 59 | 60 | 61 | 62 | 0 63 | 0 64 | 400 65 | 300 66 | 67 | 68 | 69 | background 70 | 71 | 72 | 73 | 74 | 75 | 400 76 | 150 77 | 100 78 | 50 79 | 80 | 81 | 82 | 83 | 12 84 | 85 | 86 | 87 | 更换背景 88 | 89 | 90 | Qt::NoArrow 91 | 92 | 93 | 94 | 95 | 96 | 400 97 | 250 98 | 100 99 | 50 100 | 101 | 102 | 103 | 104 | 12 105 | 106 | 107 | 108 | 退出登录 109 | 110 | 111 | 112 | 113 | 114 | 400 115 | 200 116 | 100 117 | 50 118 | 119 | 120 | 121 | 122 | 12 123 | 124 | 125 | 126 | 修改密码 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /officeCooperation/picture.cpp: -------------------------------------------------------------------------------- 1 | #include "picture.h" 2 | #include "qdebug.h" 3 | #include 4 | 5 | Picture::Picture(QString pre, int pic, QWidget *parent):QWidget(parent),picture(pic) 6 | { 7 | if(pre=="icon") this->setFixedSize(QSize(100,100)); 8 | else if(pre == "background") this->setFixedSize(QSize(200,100)); 9 | 10 | QLabel* label = new QLabel(this); 11 | label->setFixedSize(this->size()); 12 | pixmap = new QPixmap(":/image/"+pre+"/"+QString::number(picture)+".jpg"); 13 | 14 | pixmap->scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 15 | label->setScaledContents(true); 16 | label->setPixmap(*pixmap); 17 | } 18 | 19 | void Picture::mousePressEvent(QMouseEvent *event) 20 | { 21 | emit forwardPicture(picture); 22 | } 23 | -------------------------------------------------------------------------------- /officeCooperation/picture.h: -------------------------------------------------------------------------------- 1 | #ifndef PICTURE_H 2 | #define PICTURE_H 3 | 4 | #include 5 | 6 | class Picture:public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | Picture(QString pre, int pic,QWidget* parent=nullptr); 11 | 12 | protected: 13 | virtual void mousePressEvent(QMouseEvent *event);//鼠标点击 14 | 15 | private: 16 | int picture; 17 | QPixmap *pixmap; 18 | 19 | signals: 20 | void forwardPicture(int picture); 21 | }; 22 | 23 | #endif // PICTURE_H 24 | -------------------------------------------------------------------------------- /officeCooperation/register.cpp: -------------------------------------------------------------------------------- 1 | #include "register.h" 2 | #include "ui_register.h" 3 | #include 4 | #include "login.h" 5 | #include"mydatabase.h" 6 | #include 7 | #include 8 | #include"configuration.h" 9 | 10 | Register::Register(QWidget *parent) : 11 | QWidget(parent), 12 | ui(new Ui::Register) 13 | { 14 | ui->setupUi(this); 15 | init(); 16 | ui->usernameLine->setFocus(); 17 | ui->confirmBtn->setShortcut(Qt::Key_Enter); 18 | ui->confirmBtn->setShortcut(Qt::Key_Return); 19 | 20 | } 21 | 22 | Register::~Register() 23 | { 24 | qDebug()<<"delete register "; 25 | delete ui; 26 | } 27 | 28 | void Register::paintEvent(QPaintEvent *event) 29 | { 30 | QPixmap pixmap = QPixmap(":/image/background/"+QString::number(ID_OF_BACKGROUND)+".jpg").scaled(this->size()); 31 | QPainter painter(this); 32 | painter.drawPixmap(this->rect(), pixmap); 33 | } 34 | 35 | void Register::init() 36 | { 37 | this->setWindowTitle("注册"); 38 | this->setWindowIcon(QIcon(":/image/icons48.png") ); 39 | 40 | ui->confirmBtn->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); 41 | ui->pushButton_2->setStyleSheet("background-color:rgb(65,138,180);color:rgb(255,255,255);border-radius:5px;"); 42 | } 43 | 44 | void Register::verify(){ 45 | //判断有效输入 46 | if(username==""||pwd==""){ 47 | qDebug()<<"ZHUCE SHIBAI"<username=text; 77 | } 78 | 79 | void Register::getPwd(QString text){ 80 | this->pwd=text; 81 | } 82 | 83 | void Register::showLogin(){ 84 | emit back_login_signals(); 85 | } 86 | -------------------------------------------------------------------------------- /officeCooperation/register.h: -------------------------------------------------------------------------------- 1 | #ifndef REGISTER_H 2 | #define REGISTER_H 3 | 4 | #include 5 | namespace Ui { 6 | class Register; 7 | } 8 | 9 | class Register : public QWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit Register(QWidget *parent = 0); 15 | ~Register(); 16 | 17 | protected: 18 | virtual void paintEvent(QPaintEvent *event); 19 | 20 | private: 21 | Ui::Register *ui; 22 | void init(); 23 | 24 | private slots: 25 | void verify(); 26 | void getUsername(QString text); 27 | void getPwd(QString text); 28 | void showLogin(); 29 | private: 30 | QString username=""; 31 | QString pwd=""; 32 | signals: 33 | void back_login_signals(); 34 | }; 35 | 36 | #endif // REGISTER_H 37 | -------------------------------------------------------------------------------- /officeCooperation/register.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Register 4 | 5 | 6 | 7 | 0 8 | 0 9 | 370 10 | 220 11 | 12 | 13 | 14 | 15 | 370 16 | 220 17 | 18 | 19 | 20 | 21 | 370 22 | 220 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | 36 | 40 37 | 20 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Qt::Vertical 46 | 47 | 48 | 49 | 20 50 | 40 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 300 66 | 20 67 | 68 | 69 | 70 | 71 | 300 72 | 20 73 | 74 | 75 | 76 | 77 | 黑体 78 | 79 | 80 | 81 | <html><head/><body><p>请输入您想注册的用户名</p></body></html> 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 0 90 | 20 91 | 92 | 93 | 94 | 95 | 800 96 | 20 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 300 110 | 20 111 | 112 | 113 | 114 | 115 | 300 116 | 20 117 | 118 | 119 | 120 | 121 | 黑体 122 | 123 | 124 | 125 | <html><head/><body><p>请设置密码</p></body></html> 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 0 134 | 20 135 | 136 | 137 | 138 | 139 | 800 140 | 20 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 80 156 | 20 157 | 158 | 159 | 160 | 161 | 80 162 | 20 163 | 164 | 165 | 166 | 167 | 黑体 168 | 9 169 | 50 170 | false 171 | 172 | 173 | 174 | 确认注册 175 | 176 | 177 | 178 | 179 | 180 | 181 | Qt::Horizontal 182 | 183 | 184 | 185 | 40 186 | 20 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 80 196 | 20 197 | 198 | 199 | 200 | 201 | 80 202 | 20 203 | 204 | 205 | 206 | 207 | 黑体 208 | 9 209 | 50 210 | false 211 | 212 | 213 | 214 | 返回登录 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | Qt::Horizontal 226 | 227 | 228 | 229 | 40 230 | 20 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | Qt::Vertical 239 | 240 | 241 | 242 | 20 243 | 40 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | usernameLine 254 | textChanged(QString) 255 | Register 256 | getUsername(QString) 257 | 258 | 259 | 152 260 | 207 261 | 262 | 263 | 81 264 | 197 265 | 266 | 267 | 268 | 269 | pwdLine 270 | textChanged(QString) 271 | Register 272 | getPwd(QString) 273 | 274 | 275 | 578 276 | 315 277 | 278 | 279 | 606 280 | 259 281 | 282 | 283 | 284 | 285 | confirmBtn 286 | clicked() 287 | Register 288 | verify() 289 | 290 | 291 | 156 292 | 420 293 | 294 | 295 | 80 296 | 357 297 | 298 | 299 | 300 | 301 | pushButton_2 302 | clicked() 303 | Register 304 | showLogin() 305 | 306 | 307 | 538 308 | 425 309 | 310 | 311 | 653 312 | 389 313 | 314 | 315 | 316 | 317 | pwdLine 318 | returnPressed() 319 | Register 320 | verify() 321 | 322 | 323 | 555 324 | 311 325 | 326 | 327 | 624 328 | 286 329 | 330 | 331 | 332 | 333 | 334 | getUsername(QString) 335 | getPwd(QString) 336 | verify() 337 | showLogin() 338 | 339 | 340 | -------------------------------------------------------------------------------- /officeCooperation/todo.cpp: -------------------------------------------------------------------------------- 1 | #include "todo.h" 2 | 3 | ToDo::ToDo(int id, int ip, QString start, QString end, QString event, int colorId):uid(id),IP(ip) 4 | { 5 | this->setFont(QFont("Microsoft YaHei")); 6 | this->setFontPointSize(12); 7 | if(colorId++%2){this->setStyleSheet("background-color:rgb( 218,227,230);");} 8 | else{this->setStyleSheet("background-color:rgb( 255 ,250 ,240);");} 9 | this->append("开始时间:"+start); 10 | this->append("截止时间:"+end); 11 | this->append("待办事项:"+event); 12 | } 13 | 14 | void ToDo::mousePressEvent(QMouseEvent *event) 15 | { 16 | emit forwardComplete(uid,IP); 17 | } 18 | -------------------------------------------------------------------------------- /officeCooperation/todo.h: -------------------------------------------------------------------------------- 1 | #ifndef TODO_H 2 | #define TODO_H 3 | #include 4 | 5 | class ToDo:public QTextBrowser 6 | { 7 | Q_OBJECT 8 | public: 9 | ToDo(int id, int IP, QString start, QString end, QString event, int colorId); 10 | int uid; 11 | int IP; 12 | protected: 13 | virtual void mousePressEvent(QMouseEvent *event);//鼠标点击 14 | signals: 15 | void forwardComplete(int uid,int IP); 16 | }; 17 | 18 | #endif // TODO_H 19 | -------------------------------------------------------------------------------- /officeCooperation/todolist.cpp: -------------------------------------------------------------------------------- 1 | #include "todolist.h" 2 | #include "ui_todolist.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | ToDoList::ToDoList(int id, QWidget *parent) : 9 | QWidget(parent), 10 | uid(id),ui(new Ui::ToDoList) 11 | { 12 | ui->setupUi(this); 13 | this->setWindowTitle("待办事项"); 14 | this->setWindowIcon(QIcon(":/image/icons48.png")); 15 | md=new MyDatabase("todolist"+QString::number(id));//数据库初始化 16 | db=md->getDatabase(); 17 | query=QSqlQuery(db); 18 | showTodo(uid,""); 19 | } 20 | 21 | ToDoList::~ToDoList() 22 | { 23 | delete ui; 24 | } 25 | 26 | void ToDoList::showTodo(int id, QString pre) 27 | { 28 | ui->listWidget->clear(); 29 | if(pre!=""){query.exec(pre);}//删除 30 | QString sql = "SELECT `start`,`end`,`event`,`IP` FROM `timetable` WHERE uid="+QString::number(id); 31 | qDebug()<listWidget); 44 | item->setSizeHint(QSize(ui->listWidget->width()-5,80)); 45 | ui->listWidget->addItem(item); 46 | ui->listWidget->setItemWidget(item,tb); 47 | tb->show(); 48 | } 49 | } 50 | 51 | void ToDoList::complete(int uid, int IP) 52 | { 53 | QMessageBox::Button button = QMessageBox::question(this,"","是否完成该任务"); 54 | if(button==QMessageBox::Yes){ 55 | QString sql = "delete FROM `timetable` WHERE uid="+QString::number(uid)+" and IP="+QString::number(IP); 56 | showTodo(uid,sql); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /officeCooperation/todolist.h: -------------------------------------------------------------------------------- 1 | #ifndef TODOLIST_H 2 | #define TODOLIST_H 3 | 4 | #include 5 | #include"mydatabase.h" 6 | #include 7 | #include"todo.h" 8 | 9 | namespace Ui { 10 | class ToDoList; 11 | } 12 | 13 | class ToDoList : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit ToDoList(int id,QWidget *parent = nullptr); 19 | ~ToDoList(); 20 | 21 | int uid; 22 | MyDatabase* md=nullptr; 23 | QSqlDatabase db; 24 | QSqlQuery query; 25 | QMap things; 26 | 27 | QTimer* timer=nullptr; 28 | 29 | private: 30 | Ui::ToDoList *ui; 31 | void showTodo(int id,QString pre); 32 | public slots: 33 | void complete(int uid, int IP); 34 | }; 35 | 36 | #endif // TODOLIST_H 37 | -------------------------------------------------------------------------------- /officeCooperation/todolist.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ToDoList 4 | 5 | 6 | 7 | 0 8 | 0 9 | 500 10 | 500 11 | 12 | 13 | 14 | 15 | 500 16 | 500 17 | 18 | 19 | 20 | 21 | 500 22 | 500 23 | 24 | 25 | 26 | Form 27 | 28 | 29 | 30 | 31 | 0 32 | 0 33 | 500 34 | 500 35 | 36 | 37 | 38 | 39 | 500 40 | 500 41 | 42 | 43 | 44 | 45 | 500 46 | 500 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /officeCooperation/welcome.cpp: -------------------------------------------------------------------------------- 1 | #include "welcome.h" 2 | #include "ui_welcome.h" 3 | 4 | Welcome::Welcome(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::Welcome) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | Welcome::~Welcome() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /officeCooperation/welcome.h: -------------------------------------------------------------------------------- 1 | #ifndef WELCOME_H 2 | #define WELCOME_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Welcome; 8 | } 9 | 10 | class Welcome : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Welcome(QWidget *parent = 0); 16 | ~Welcome(); 17 | 18 | private: 19 | Ui::Welcome *ui; 20 | }; 21 | 22 | #endif // WELCOME_H 23 | -------------------------------------------------------------------------------- /officeCooperation/welcome.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Welcome 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 60 20 | 50 21 | 256 22 | 192 23 | 24 | 25 | 26 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 27 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 28 | p, li { white-space: pre-wrap; } 29 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 30 | <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">登录成功!</span></p></body></html> 31 | 32 | 33 | 34 | 35 | 36 | 37 | --------------------------------------------------------------------------------