#include "LiveOpeWidget.h"
#include "ui_LiveOpeWidget.h"
#include <QMessageBox>
#include "Protocol.h"
#include "Login.h"
#include <QTime>
#include <QCameraInfo>
#include <QBuffer>
#include <QImageReader>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QGuiApplication>
#include <QScreen>
#include <QMovie>
#include "ReceMsgHandle.h"
LiveOpeWidget::LiveOpeWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::LiveOpeWidget),
cvIsopen(false)
{
ui->setupUi(this);
startPoint = QPoint(0,0);
this->sender = new QUdpSocket(this);
this->giftComboInit();
QAudioFormat format;
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setSampleType(QAudioFormat::SignedInt);
format.setByteOrder(QAudioFormat::LittleEndian);
//音频采集对象初始化
this->voiceInput = new QAudioInput(format);
//音频输出对象初始化
this->voiceOutput = new QAudioOutput(format);
this->voiceOutDevice = this->voiceOutput->start();
this->receiver = new QUdpSocket(this);
connect(this->receiver,SIGNAL(readyRead()),this,SLOT(readyReadSlot()));
this->voiceReceiver = new QUdpSocket(this);
connect(this->voiceReceiver,SIGNAL(readyRead()),this,SLOT(voiceReadSlot()));
this->voiceSender = new QUdpSocket(this);
//视频采集对象初始化
QCameraInfo info = QCameraInfo::defaultCamera();
this->cv = new QCamera(info, this);
this->vs = new VideoSurface(this);
this->cv->setViewfinder(vs);
connect(vs,SIGNAL(frameChanged(QVideoFrame)),
this,SLOT(videoFrameChangedSlot(QVideoFrame)));
//定时刷新成员列表
this->cycFlushMemberList = new QTimer(this);
connect(this->cycFlushMemberList,SIGNAL(timeout()),
this,SLOT(on_pbFlushMemberlist_clicked()));
//定时发送屏幕画面
this->cycSendMyScreen = new QTimer(this);
connect(this->cycSendMyScreen,SIGNAL(timeout()),
this,SLOT(displayDesktop()));
//事件过滤器安装
ui->lb_ShowVideo->installEventFilter(this);
ui->lineMsgLE->installEventFilter(this);
}
void LiveOpeWidget::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
on_pbExitRoom_clicked();
}
//事件过滤器:视频显示标签全屏切换显示功能
bool LiveOpeWidget::eventFilter(QObject *ob, QEvent *ev)
{
if(ob == ui->lb_ShowVideo){
if(ev->type() == QEvent::MouseButtonDblClick){
QMouseEvent* mouse = static_cast<QMouseEvent*>(ev);
if(mouse->button() == Qt::LeftButton){
//鼠标左键双击进入全屏
ui->lb_ShowVideo->setWindowFlags(Qt::Dialog);
ui->lb_ShowVideo->showFullScreen();
return true;
}else if(mouse->button() == Qt::RightButton){
//右键双击退出全屏
ui->lb_ShowVideo->setWindowFlags(Qt::SubWindow);
ui->lb_ShowVideo->showNormal();
return true;
}else{
// return QWidget::eventFilter(ob,ev);
}
}
}else if(ob == ui->lineMsgLE){
if(ev->type() == QEvent::KeyPress){
QKeyEvent* key = static_cast<QKeyEvent*>(ev);
if(key->key() == Qt::Key_Return){
this->on_pbSendMsg_clicked();
return true;
}
}else{
// return QWidget::eventFilter(ob,ev);
}
}
return QWidget::eventFilter(ob,ev);
}
LiveOpeWidget *LiveOpeWidget::instance = nullptr;
LiveOpeWidget *LiveOpeWidget::getInstance()
{
if(nullptr == instance){
instance = new LiveOpeWidget;
}
return instance;
}
LiveOpeWidget::~LiveOpeWidget()
{
delete this->voiceInput;
delete this->voiceOutput;
delete this->voiceInDevice;
delete this->voiceOutDevice;
delete ui;
}
void LiveOpeWidget::setSenderGroupAddr(const QHostAddress &rhsAddr, quint16 videoPort, quint16 voicePort)
{
this->senderGroupAddr = rhsAddr;
this->senderGroupPort = videoPort;
this->senderGroupvoicePort = voicePort;
}
void LiveOpeWidget::setReceiverGroupAddr(const QHostAddress &rhsAddr, quint16 videoPort,quint16 voicePort)
{
this->receiverGroupAddr = rhsAddr;
this->receiverGroupPort = videoPort;
this->receiverGroupvoicePort = voicePort;
//视频组播地址端口绑定
if(this->receiver->state() == QAbstractSocket::BoundState){
this->receiver->leaveMulticastGroup(receiverGroupAddr);
this->receiver->close();
}
this->receiver->bind(QHostAddress::AnyIPv4,this->receiverGroupPort,
QUdpSocket::ShareAddress|QUdpSocket::ReuseAddressHint);
this->receiver->joinMulticastGroup(this->receiverGroupAddr);
//音频组播地址端口绑定
if(this->voiceReceiver->state() == QAbstractSocket::BoundState){
this->voiceReceiver->leaveMulticastGroup(receiverGroupAddr);
this->voiceReceiver->close();
}
this->voiceReceiver->bind(QHostAddress::AnyIPv4,this->receiverGroupvoicePort,
QUdpSocket::ShareAddress|QUdpSocket::ReuseAddressHint);
this->voiceReceiver->joinMulticastGroup(this->receiverGroupAddr);
}
void LiveOpeWidget::FlushMemberLisg(const PDU &package)
{
ui->RoomMemberListLW->clear();
QString roomName = "房主:" + m_strRoomName;
ui->RoomMemberListLW->addItem(roomName);
int i = 0;
for(; i < package.getObjectSize(); i++){
QString key = JSON_KEY_MEMBERNAME + QString::number(i);
ui->RoomMemberListLW->addItem(package[key].toString());
}
}
void LiveOpeWidget::FlushMsgTE(const PDU &package)
{
if(this->m_strRoomName != package[JSON_KEY_ROOMNAME].toString()){
return ;
}
QString sender = package[JSON_KEY_NAME].toString();
QString role;
if(sender == package[JSON_KEY_ROOMNAME].toString()){
//判断是否是房主
role = "-房主-";
}else{
role = "-观众-";
}
QString time = QTime::currentTime().toString();
sender += role + " " + time + ":";
QTextCharFormat formatsender;
formatsender.setForeground(QBrush(QColor(Qt::blue)));
formatsender.setFont(QFont("Consolas",6));
ui->showMsgTE->setCurrentCharFormat(formatsender);
ui->showMsgTE->append(sender);
QTextCharFormat formatMsg;
formatMsg.setFont(QFont("Consolas",12));
formatMsg.setForeground(QBrush(QColor(Qt::black)));
ui->showMsgTE->setCurrentCharFormat(formatMsg);
ui->showMsgTE->append(package[JSON_KEY_CHATMSG].toString());
this->displayDanmu(package[JSON_KEY_CHATMSG].toString());
}
void LiveOpeWidget::displayDanmu(const QString &text)
{
QFont familystyle = ui->fontComboBox->currentFont();
int size = ui->sizeCB->currentText().toInt();
familystyle.setPointSize(size);
QString color = "color:" + ui->colorCB->currentText() + ";";
QLabel* danmu = new QLabel(text,this);
danmu->setFont(familystyle);
danmu->setStyleSheet(color);
danmu->adjustSize();
danmu->show();
int y = startPoint.y();
y+=20;
if(y >= this->rect().height()-20){
y = 0;
}
startPoint.setY(y);
startPoint.setX(this->rect().width());
startPoint.setX(ui->lb_ShowVideo->rect().width());
LabelMoveThread* mt = new LabelMoveThread(danmu,startPoint,this);
this->danmuThreadVector.push_back(mt);
connect(mt,SIGNAL(moveLabel(const QPoint&,QLabel*)),
this,SLOT(moveLabel(const QPoint&,QLabel*)));
connect(mt,SIGNAL(moveComplete(QLabel*)),
this,SLOT(moveComplete(QLabel*)));
mt->start();
}
void LiveOpeWidget::displayGift(const QString& filename)
{
QLabel* gift = new QLabel(this);
QImage image(filename);
QPixmap pix = QPixmap
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1.项目代码均经过功能验证ok,确保稳定可靠运行。欢迎下载食用体验! 2.主要针对各个计算机相关专业,包括计算机科学、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师、企业员工。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可直接作为毕设、课程设计、大作业、初期项目立项演示等用途。 4.当然也鼓励大家基于此进行二次开发。在使用过程中,如有问题或建议,请及时沟通。 5.期待你能在项目中找到乐趣和灵感,也欢迎你的分享和反馈! 【项目介绍】 课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip 课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip 课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip 课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip
资源推荐
资源详情
资源评论
收起资源包目录
课程设计基于QT和C++开发的直播管理系统源码(含客户端+服务端).zip (95个子文件)
Pro_live
TcpClient
VideoSurface.h 523B
Login.ui 3KB
splashScreen.jpg 222KB
Protocol.cpp 1KB
RoomOpeWidget.h 946B
LiveOpeWidget.h 4KB
TcpClient.pro 2KB
LiveOpeWidget.cpp 19KB
RegistWidget.h 496B
image
gif
waiting.gif 1019KB
冰阔落.png 65KB
递茶.png 230KB
rocket.png 173KB
666.png 103KB
Login.h 1KB
MsgHandle_module
RoomAccessHandle.cpp 1KB
RoomCreateHandle.cpp 1KB
RoomCreateHandle.h 246B
InterfaceMsgHandle.cpp 138B
InterfaceMsgHandle.h 412B
RoomAccessHandle.h 244B
RoomOpeWidget.cpp 3KB
IPconfig.h 421B
MyThread
LabelMoveThread.h 762B
LabelMoveThread.cpp 503B
image.qrc 363B
foot.ico 13KB
config.qrc 50B
VideoSurface.cpp 469B
LiveOpeWidget.ui 10KB
RoomOpeWidget.ui 3KB
main.cpp 489B
FBK.png 422KB
IP.config 17B
rocket.ico 7KB
IPconfig.ui 3KB
Protocol.h 5KB
Login.cpp 3KB
Log_module
myLog.ui 1KB
myLog.cpp 2KB
myLog.h 839B
RegistWidget.ui 4KB
ReceMsgHandle.cpp 3KB
RegistWidget.cpp 1KB
ReceMsgHandle.h 245B
IPconfig.cpp 1KB
TcpServer
RoomHelper.h 1KB
Protocol.cpp 1KB
SocketHandle.h 686B
MsgHandle_module
LoginHandle.cpp 908B
RoomAccessHandle.cpp 935B
RoomlistFlushHandle.cpp 576B
RegistHandle.h 256B
RoomChatHandle.cpp 1KB
RoomGiftHandle.cpp 2KB
RoomCreateHandle.cpp 1KB
RoomMemberFlushHandle.cpp 664B
RoomChatHandle.h 269B
RoomCreateHandle.h 277B
RoomMemberFlushHandle.h 308B
InterfaceMsgHandle.cpp 154B
InterfaceMsgHandle.h 455B
RoomAccessHandle.h 279B
RoomlistFlushHandle.h 296B
RoomExitHandle.h 273B
LoginHandle.h 252B
RoomGiftHandle.h 266B
RegistHandle.cpp 790B
RoomExitHandle.cpp 749B
UdpPortHelper.h 671B
image.qrc 91B
foot.ico 13KB
Room.h 3KB
NetworkHandle.cpp 1KB
Room.cpp 3KB
OpeDB.cpp 4KB
main.cpp 372B
FBK.png 422KB
OpeDB.h 843B
DBHelper.h 442B
DBHelper.cpp 1KB
RoomHelper.cpp 4KB
UdpPortHelper.cpp 1021B
Protocol.h 5KB
SocketHandle.cpp 1KB
Log_module
myLog.ui 1KB
myLog.cpp 2KB
myLog.h 839B
ReceMsgHandle.cpp 2KB
MainWindow.cpp 4KB
ReceMsgHandle.h 291B
MainWindow.ui 3KB
TcpServer.pro 2KB
NetworkHandle.h 1006B
MainWindow.h 674B
共 95 条
- 1
资源评论
北航程序员小C
- 粉丝: 2222
- 资源: 1823
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功