/******************************************************************
Copyright (C) 2017 - All Rights Reserved by
文 件 名 : mainwindow.cpp --- MainWindow
作 者 :
编写日期 : 2017
说 明 :
历史纪录 :
<作者> <日期> <版本> <内容>
*******************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "unit.h"
#include "qqcell.h"
#include "qqlistviewgroup.h"
#include "global.h"
#include "chatbubble.h"
#include "chatwindow.h"
#include "databasemagr.h"
#include "systemsetting.h"
#include "systemmessagedialog.h"
#include <QTimer>
#include <QMenu>
#include <QInputDialog>
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonParseError>
#include <QJsonDocument>
#include <QCloseEvent>
MainWindow::MainWindow(QWidget *parent) :
CustomMoveWidget(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
m_bQuit = false;
m_btnGroup = new QButtonGroup(this);
m_btnGroup->addButton(ui->btnFrind, 0);
m_btnGroup->addButton(ui->btnGroup, 1);
m_btnGroup->addButton(ui->btnConversation, 2);
m_btnGroup->addButton(ui->btnApplay, 3);
connect(m_btnGroup, SIGNAL(buttonClicked(int)), this, SLOT(SltMainPageChanged(int)));
// 系统菜单初始化
InitSysMenu();
InitQQListMenu();
InitSysTrayIcon();
// 默认显示主的界面
ui->GCStackedWidget->setCurrentIndex(0);
// 关联头像编辑信号槽
connect(ui->widgetHead, SIGNAL(signalCutHeadOk()), this, SLOT(SltHeadPicCutOk()));
connect(ui->widgetHead, SIGNAL(signalUpdateUserHead(int,QString)), this, SLOT(SltUpdateUserHead(int,QString)));
}
MainWindow::~MainWindow()
{
delete ui;
qDebug() << "delete";
delete m_tcpSocket;
m_tcpSocket = NULL;
// 关闭所有的聊天窗口
foreach (ChatWindow *window, m_chatFriendWindows) {
window->close();
}
foreach (ChatWindow *window, m_chatGroupWindows) {
window->close();
}
}
/**
* @brief MainWindow::SetSocket
* @param tcpSocket
* @param name
*/
void MainWindow::SetSocket(ClientSocket *tcpSocket, const QString &name)
{
if (NULL != tcpSocket) {
m_tcpSocket = tcpSocket;
connect(m_tcpSocket, SIGNAL(signalMessage(quint8,QJsonValue)), this, SLOT(SltTcpReply(quint8,QJsonValue)));
connect(m_tcpSocket, SIGNAL(signalStatus(quint8)), this, SLOT(SltTcpStatus(quint8)));
// 加载头像
ui->widgetHead->SetHeadPixmap(MyApp::m_strHeadFile);
// 上线的时候获取当前好友的状态
QJsonArray friendArr = DataBaseMagr::Instance()->GetMyFriend(MyApp::m_nId);
// 组织Jsonarror
m_tcpSocket->SltSendMessage(GetMyFriends, friendArr);
// 添加我的群组
AddMyGroups(DataBaseMagr::Instance()->GetMyGroup(MyApp::m_nId));
}
if (name.isEmpty()) return;
ui->labelUser->setText(name);
}
void MainWindow::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
/**
* @brief MainWindow::closeEvent
* 拦截关闭事件
* @param event
*/
void MainWindow::closeEvent(QCloseEvent *event) {
#if 0
this->hide();
event->ignore();
#else
event->accept();
QWidget::closeEvent(event);
#endif
}
void MainWindow::showEvent(QShowEvent *event)
{
MyApp::m_nWinX = this->pos().x();
MyApp::m_nWinY = this->pos().y();
QWidget::showEvent(event);
}
/**
* @brief MainWindow::InitMenu
*/
void MainWindow::InitSysMenu()
{
// 设置子菜单
QMenu *sysmenu = new QMenu(this);
sysmenu->addAction(tr("系统设置"));
sysmenu->addAction("消息管理器");
sysmenu->addAction("文件助手");
sysmenu->addSeparator();
sysmenu->addAction("修改密码");
sysmenu->addAction("帮助");
sysmenu->addAction("连接服务器");
sysmenu->addSeparator();
sysmenu->addAction("升级");
// 添加菜单
ui->btnSysMenu->setMenu(sysmenu);
connect(sysmenu, SIGNAL(triggered(QAction*)), this, SLOT(SltSysmenuCliecked(QAction*)));
}
/**
* @brief MainWindow::InitQQListMenu
* 添加好友列表菜单
*/
void MainWindow::InitQQListMenu()
{
//设置菜单
//设置组菜单
QMenu *addFriend = new QMenu(this);
addFriend->addAction(tr("添加好友"));
addFriend->addAction(tr("刷新"));
addFriend->addSeparator();
addFriend->addAction(tr("删除该组"));
connect(addFriend, SIGNAL(triggered(QAction*)), this, SLOT(onAddFriendMenuDidSelected(QAction*)));
ui->frindListWidget->setGroupPopMenu(addFriend);
// 设置子菜单
QMenu *childMenu = new QMenu(this);
childMenu->addAction(tr("发送即时消息"));
childMenu->addSeparator();
childMenu->addAction("移动至黑名单");
childMenu->addAction("删除联系人");
QMenu *groupListMenu = new QMenu(tr("移动联系人至"));
childMenu->addMenu(groupListMenu);
// childMenu->addAction(tr("创建讨论组"));
connect(childMenu, SIGNAL(triggered(QAction*)), this, SLOT(onChildPopMenuDidSelected(QAction*)));
ui->frindListWidget->setChildPopMenu(childMenu);
//添加默认项
//好友列表
QQCell *myFriend = new QQCell;
myFriend->groupName = QString(tr("我的好友"));
myFriend->isOpen = false;
myFriend->type = QQCellType_Group;
myFriend->name = QString(tr("我的好友"));
myFriend->subTitle = QString("(0/0)");
ui->frindListWidget->insertQQCell(myFriend);
QQCell *blacklist = new QQCell;
blacklist->groupName = QString(tr("黑名单"));
blacklist->isOpen = false;
blacklist->type = QQCellType_Group;
blacklist->name = QString(tr("黑名单"));
blacklist->subTitle = QString("(0/0)");
ui->frindListWidget->insertQQCell(blacklist);
connect(ui->frindListWidget, SIGNAL(onChildDidDoubleClicked(QQCell*)), this, SLOT(SltFriendsClicked(QQCell*)));
//组列表
QMenu *myGroupMenu = new QMenu(this);
myGroupMenu->addAction(tr("创建讨论组"));
myGroupMenu->addAction(tr("加入讨论组"));
myGroupMenu->addAction(tr("删除该组"));
myGroupMenu->addSeparator();
connect(myGroupMenu, SIGNAL(triggered(QAction*)), this, SLOT(onGroupPopMenuDidSelected(QAction*)));
ui->groupListWidget->setGroupPopMenu(myGroupMenu);
//设置子菜单
QMenu *groupChildMen = new QMenu(this);
groupChildMen->addAction(tr("发送即时消息"));
ui->groupListWidget->setChildPopMenu(groupChildMen);
//添加默认项
QQCell *groupCell = new QQCell;
groupCell->groupName = QString(tr("我的群组"));
groupCell->isOpen = false;
groupCell->type = QQCellType_GroupEx;
groupCell->name = QString(tr("讨论组"));
groupCell->subTitle = QString("(0/0)");
ui->groupListWidget->insertQQCell(groupCell);
connect(ui->groupListWidget, SIGNAL(onChildDidDoubleClicked(QQCell*)), this, SLOT(SltGroupsClicked(QQCell*)));
}
/**
* @brief MainWindow::InitSysTrayIcon
* 托盘菜单
*/
void MainWindow::InitSysTrayIcon()
{
systemTrayIcon = new QSystemTrayIcon(this);
systemTrayIcon->setIcon(QIcon(":/resource/background/app.png"));
QMenu *m_trayMenu = new QMenu(this);
m_trayMenu->addAction("我在线上");
m_trayMenu->addAction("离线");
m_trayMenu->addSeparator();
m_trayMenu->addAction("显示主面板");
m_trayMenu->addSeparator();
m_trayMenu->addAction("退出");
systemTrayIcon->setContextMenu(m_trayMenu);
systemTrayIcon->show();
connect(systemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),t
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Qt5 局域网通信软件升级版(仿QQ界面) (200个子文件)
6.bmp 5KB
7.bmp 5KB
0.bmp 5KB
4.bmp 5KB
5.bmp 5KB
8.bmp 5KB
9.bmp 5KB
2.bmp 5KB
3.bmp 5KB
1.bmp 5KB
3.bmp 5KB
0.bmp 5KB
4.bmp 5KB
8.bmp 5KB
6.bmp 5KB
1.bmp 5KB
5.bmp 5KB
2.bmp 5KB
7.bmp 5KB
9.bmp 5KB
mainwindow.cpp 37KB
clientsocket.cpp 23KB
chatbubble.cpp 21KB
databasemagr.cpp 18KB
clientsocket.cpp 17KB
chatwindow.cpp 16KB
customwidget.cpp 13KB
clineedit.cpp 12KB
databasemagr.cpp 9KB
myapp.cpp 7KB
tcpserver.cpp 6KB
loginwidget.cpp 6KB
qqlistwidget.cpp 5KB
systemmessagedialog.cpp 5KB
widgethead.cpp 5KB
animationstackedwidget.cpp 5KB
myapp.cpp 4KB
mainwindow.cpp 4KB
rotatingstackedwidget.cpp 4KB
systemsetting.cpp 4KB
weatherwidget.cpp 3KB
iteminfo.cpp 2KB
qqlistviewchild.cpp 2KB
customwidget.cpp 1KB
main.cpp 1KB
qqlistviewgroup.cpp 1KB
main.cpp 1KB
qqpopmenuwidget.cpp 458B
qqcell.cpp 335B
default.css 8KB
default.css 4KB
info.db 28KB
user.db 16KB
msg.db 12KB
back.gif 1.16MB
global.h 11KB
unit.h 5KB
unit.h 5KB
customwidget.h 4KB
clientsocket.h 4KB
mainwindow.h 4KB
clientsocket.h 4KB
chatbubble.h 3KB
chatwindow.h 2KB
databasemagr.h 2KB
iteminfo.h 2KB
tcpserver.h 2KB
rotatingstackedwidget.h 2KB
databasemagr.h 2KB
myapp.h 2KB
animationstackedwidget.h 2KB
clineedit.h 2KB
myapp.h 2KB
systemmessagedialog.h 1KB
widgethead.h 1KB
loginwidget.h 1KB
mainwindow.h 1KB
qqlistwidget.h 1KB
customwidget.h 981B
systemsetting.h 956B
weatherwidget.h 901B
qqcell.h 802B
qqlistviewchild.h 769B
qqlistviewgroup.h 655B
qqpopmenuwidget.h 518B
app.ico 17KB
app.ico 9KB
config.ini 116B
config.ini 38B
Makefile 35KB
background.png 97KB
logo.png 34KB
HeadImage.png 9KB
head-64.png 8KB
head-48.png 5KB
ic_question.png 5KB
ic_question.png 4KB
app.png 4KB
closeback.png 3KB
arrowback.png 3KB
共 200 条
- 1
- 2
资源评论
- 秋月的私语2020-11-11非常不错 linux下直接编译运行 Windows下一直出错,app_res资源文件出错,去掉资源文件相关的内容可以正常运行!
lynnhua_
- 粉丝: 128
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功