• Qt项目-安防监控系统(各个界面功能实现)


    目录

    各个界面+功能实现

    点击回放模式可以查看回放视频+图片

    选择日期后点击查询可查看该日期回放视频​编辑 

     对于回放的视频可以---暂停播放 倍速 导出mp4 截图

     点击图片列表可以查看回放视频中的截图图片

    点击图片后可以查看详细的图片信息

    18.SetWidget.h .cpp

    19.Main_Widget.h .cpp

    20.Main_MonitorWidget.h .cpp

    21.Main_ReplayWidget.h .cpp

    22.Play_Widget.h .cpp

    23.Image_Widget.h .cpp

    main.cpp


    各个界面+功能实现

    点击回放模式可以查看回放视频+图片

    选择日期后点击查询可查看该日期回放视频

     对于回放的视频可以---暂停播放 倍速 导出mp4 截图

     点击图片列表可以查看回放视频中的截图图片

    点击图片后可以查看详细的图片信息

    本次的Qt项目-安防监控系统,由于工程量较大,分成四篇文章呈现源码。

    如果想学习这个安防监控系统项目,另外三篇文章源码可自行查看

    Qt项目-安防监控系统(欢迎登录注册)

    Qt项目-安防监控系统(MVC设计模式)

    Qt项目-安防监控系统(解码编码转码)

    Sqlite数据库和FFMPEG开源库,上传至资源,可自行领取学习,对于环境的搭建,可以参考以下文章

    windows中Qt+sqlite3的环境搭建

    Qt中FFMPEG环境的搭建

    对摄像头类不知如何获取的,可以参照以下这篇文章解决疑惑

    Qt学习-Qt中QCameraInfo类的使用

    18.SetWidget.h .cpp

    1. #ifndef SETWIDGET_H
    2. #define SETWIDGET_H
    3. #include<QDebug>//测试
    4. #include <QWidget>//窗口
    5. #include <QLabel>//文本
    6. #include <QPushButton>//按钮
    7. #include <QLineEdit>//编辑框
    8. #include <QButtonGroup>//按钮
    9. #include <QComboBox>//下拉框
    10. #include <QCheckBox>//检测
    11. #include <QIcon>//嵌入图
    12. #include <QMessageBox>//消息框
    13. #include <QKeyEvent>//按键事件
    14. #include <QCameraInfo>//获取摄像头信息
    15. #include <QFileDialog>//文件框
    16. #include "decode.h"//解码
    17. #include "setcontrol.h"//设置控制层
    18. class SetWidget : public QWidget
    19. {
    20. Q_OBJECT
    21. public:
    22. // explicit SetWidget(QWidget *parent = 0);
    23. SetWidget();//构造函数
    24. void init_UI();//UI窗口
    25. void init_control();//控件布局
    26. void init_connect();//按钮-信号槽机制
    27. int mark;//标志位--有无数据
    28. private:
    29. QLabel *Set_label,*VideoPath_label,*ImagePath_label,*Interval_label,*Camera_label;//标签文本
    30. QPushButton *VideoPath_btn,*ImagePath_btn,*OK_btn,*Esc_btn;//按钮控件
    31. QLineEdit *VideoPath_edit,*ImagePath_edit;//编辑框
    32. QComboBox *Interval_box,*Camera_box;//下拉框
    33. QLabel *setwidget_label,*setwidget_label1;//设置界面文本
    34. signals:
    35. void tomain();
    36. public slots:
    37. void Select_VideoPath();//视频路径选择窗口函数
    38. void Select_ImagePath();//图片路径选择窗口函数
    39. void init_data();//设置信息存储函数
    40. void getmain();//跳转到主界面函数
    41. };
    42. #endif // SETWIDGET_H
    1. #include "setwidget.h"
    2. #include"main_widget.h"
    3. //SetWidget::SetWidget(QWidget *parent) : QWidget(parent)
    4. //{
    5. //}
    6. //构造函数
    7. SetWidget::SetWidget()
    8. {
    9. this->mark=0;//标志位
    10. init_UI();//UI窗口
    11. init_control();//控件布局设计
    12. init_connect();//按钮-信号槽机制
    13. }
    14. //UI窗口
    15. void SetWidget::init_UI()
    16. {
    17. //设置窗口标题
    18. this->setWindowTitle("安防监控系统");
    19. //设置窗口大小
    20. this->setFixedSize(800,600);
    21. setWindowFlags(Qt::FramelessWindowHint);//无边框
    22. //自己设置背景图片
    23. QPixmap pixmap(":/image/060902.jpg");
    24. QPalette palette;
    25. palette.setBrush(backgroundRole(), QBrush(pixmap));
    26. setPalette(palette);
    27. }
    28. //设置窗口控件布局函数
    29. void SetWidget::init_control()
    30. {
    31. //字体大小--ft1 标题字体大小 ft2 标签字体大小
    32. QFont ft1,ft2;
    33. ft1.setPointSize(30);
    34. ft2.setPointSize(12);
    35. //文本
    36. this->Set_label = new QLabel("设置界面",this);
    37. this->Set_label->setGeometry(300,280,260,40);
    38. this->Set_label->setFont(ft1);
    39. this->VideoPath_label = new QLabel("视频存储位置",this);
    40. this->VideoPath_label->setGeometry(190,350,120,30);
    41. this->VideoPath_label->setFont(ft2);
    42. this->ImagePath_label = new QLabel("图片存储位置",this);
    43. this->ImagePath_label->setGeometry(190,400,120,30);
    44. this->ImagePath_label->setFont(ft2);
    45. this->Interval_label = new QLabel("采集时间间隔",this);
    46. this->Interval_label->setGeometry(190,450,120,30);
    47. this->Interval_label->setFont(ft2);
    48. this->Camera_label = new QLabel("摄像头配置",this);
    49. this->Camera_label->setGeometry(190,500,120,30);
    50. this->Camera_label->setFont(ft2);
    51. this->setwidget_label = new QLabel(this);
    52. this->setwidget_label->setGeometry(0,0,400,270);
    53. this->setwidget_label->setPixmap(QPixmap(":/image/061002.jpg").scaled(setwidget_label->size()));
    54. this->setwidget_label1 = new QLabel(this);
    55. this->setwidget_label1->setGeometry(400,0,400,270);
    56. this->setwidget_label1->setPixmap(QPixmap(":/image/061001.jpg").scaled(setwidget_label1->size()));
    57. //编辑框
    58. this->VideoPath_edit = new QLineEdit(this);
    59. this->VideoPath_edit->setReadOnly(true);
    60. this->VideoPath_edit->setGeometry(320,350,200,30);
    61. this->ImagePath_edit = new QLineEdit(this);
    62. this->ImagePath_edit->setReadOnly(true);
    63. this->ImagePath_edit->setGeometry(320,400,200,30);
    64. //按钮
    65. this->VideoPath_btn = new QPushButton("...",this);
    66. this->VideoPath_btn->setGeometry(530,350,30,30);
    67. this->ImagePath_btn = new QPushButton("...",this);
    68. this->ImagePath_btn->setGeometry(530,400,30,30);
    69. this->OK_btn = new QPushButton("确定",this);
    70. this->OK_btn->setGeometry(320,550,60,30);
    71. OK_btn->setFont(ft2);
    72. this->Esc_btn = new QPushButton("取消",this);
    73. this->Esc_btn->setGeometry(440,550,60,30);
    74. Esc_btn->setFont(ft2);
    75. //录制时长下拉框控件初始化
    76. this->Interval_box = new QComboBox(this);
    77. this->Interval_box->setGeometry(320,450,200,30);
    78. this->Interval_box->addItem("1分钟");
    79. this->Interval_box->addItem("2分钟");
    80. this->Interval_box->addItem("3分钟");
    81. this->Interval_box->setFont(ft2);
    82. //摄像头下拉框控件初始化
    83. this->Camera_box = new QComboBox(this);
    84. this->Camera_box->setGeometry(320,500,200,30);
    85. this->Camera_box->setFont(ft2);
    86. //获取摄像头
    87. QList<QString> cnames= Decode::getcamera();
    88. this->Camera_box->addItems(cnames);
    89. }
    90. //按钮-信号槽机制
    91. void SetWidget::init_connect()
    92. {
    93. //选择视频路径
    94. connect(this->VideoPath_btn,SIGNAL(clicked()),this,SLOT(Select_VideoPath()));
    95. //选择图片路径
    96. connect(this->ImagePath_btn,SIGNAL(clicked()),this,SLOT(Select_ImagePath()));
    97. //确定--设置信息存储
    98. connect(this->OK_btn,SIGNAL(clicked()),this,SLOT(init_data()));
    99. //确定--跳转到主界面
    100. connect(this->OK_btn,SIGNAL(clicked()),this,SLOT(getmain()));
    101. //关闭按钮关闭窗口
    102. connect(this->Esc_btn,SIGNAL(clicked(bool)),this,SLOT(close()));
    103. }
    104. //设置信息存储函数
    105. void SetWidget::init_data()
    106. {
    107. //framecount时长换算,60分钟=1000毫秒
    108. int framecount = 0;
    109. if(Interval_box->currentIndex() == 0)
    110. {
    111. framecount =1500;
    112. }
    113. if(Interval_box->currentIndex() == 1)
    114. {
    115. framecount =3000;
    116. }
    117. if(Interval_box->currentIndex() == 2)
    118. {
    119. framecount =4500;
    120. }
    121. //如果路径不为空
    122. if(VideoPath_edit->text().trimmed() != tr("") && ImagePath_edit->text().trimmed() != tr(""))
    123. {
    124. //先判断数据库里面是否有设置信息 mark 0为没有数据,1为有数据
    125. this->mark=SetControl::getInstance()->getSetting();
    126. int res;
    127. //如果没有设置信息,就存入数据库设置信息
    128. if(mark==0)
    129. {
    130. res=SetControl::getInstance()->doSet(this->VideoPath_edit->text().trimmed(),this->ImagePath_edit->text().trimmed(),
    131. framecount,Camera_box->currentText());
    132. }
    133. //如果有设置信息,就更新数据库设置信息
    134. else
    135. {
    136. res=SetControl::getInstance()->updateSetting(this->VideoPath_edit->text().trimmed(),this->ImagePath_edit->text().trimmed(),
    137. framecount,Camera_box->currentText());
    138. }
    139. //存入数据库信息 0表示成功,1表示失败
    140. if(res==0)
    141. {
    142. QMessageBox:: information(this,"提示","设置成功","确定");
    143. emit tomain();
    144. }
    145. else
    146. {
    147. QMessageBox:: information(this,"提示","设置失败","确定");
    148. }
    149. }
    150. //路径为空就提示
    151. else
    152. {
    153. QMessageBox:: information(this,"提示","路径不能为空","确定");
    154. }
    155. }
    156. //跳转到主界面函数
    157. void SetWidget::getmain()
    158. {
    159. //如果mark标志位为0为有数据,就不用设置就可以跳转到主界面
    160. if(mark==0)
    161. {
    162. this->close();
    163. Main_Widget *mainwidget = new Main_Widget();
    164. mainwidget->show();
    165. }
    166. else
    167. {
    168. this->close();
    169. Main_Widget *mainwidget = new Main_Widget();
    170. mainwidget->show();
    171. }
    172. }
    173. //视频路径选择窗口函数
    174. void SetWidget::Select_VideoPath()
    175. {
    176. QString Video_path=QFileDialog::getExistingDirectory(this,"选择视频存储路径","../");
    177. if(Video_path != nullptr)
    178. {
    179. //显示到编辑框上
    180. this->VideoPath_edit->setText(Video_path);
    181. }
    182. }
    183. //图片路径选择窗口函数
    184. void SetWidget::Select_ImagePath()
    185. {
    186. QString Image_path=QFileDialog::getExistingDirectory(this,"选择视频存储路径","../");
    187. if(Image_path != nullptr)
    188. {
    189. //显示到编辑框上
    190. this->ImagePath_edit->setText(Image_path);
    191. }
    192. }

    19.Main_Widget.h .cpp

    1. #ifndef MAIN_WIDGET_H
    2. #define MAIN_WIDGET_H
    3. #include <QWidget>
    4. #include <QLabel>//文本
    5. #include <QPushButton>//按钮
    6. #include <QLineEdit>//编辑框
    7. #include <QListWidget>//列表
    8. #include <QListWidgetItem>//列表项
    9. #include <QHBoxLayout>//水平
    10. #include <QVBoxLayout>//垂直
    11. #include <QIcon>//嵌入图
    12. #include <QPaintEvent>//绘制
    13. #include<QDebug>//调试
    14. #include<QList>//链表
    15. #include<QComboBox>//下拉框
    16. #include<QImage>//图像
    17. #include<QPixmap>//嵌入图
    18. #include<QStackedWidget>//栈窗口
    19. #include<QTimer>//定时器
    20. #include <QDateTime>//日期
    21. #include "main_monitorwidget.h"//监控窗口
    22. #include "main_replaywidget.h"//回放窗口
    23. #include "loginwidget.h"//登录窗口
    24. #include "setwidget.h"//设置窗口
    25. class Main_Widget : public QWidget
    26. {
    27. Q_OBJECT
    28. public:
    29. explicit Main_Widget(QWidget *parent = nullptr);//构造函数
    30. void init_UI();//UI窗口
    31. void init_control();//控件布局
    32. void init_connect();//按钮-信号槽机制
    33. static int status;//状态
    34. private:
    35. QWidget *topWidget;//窗口布局
    36. QStackedWidget *bottomWidget;//栈窗口
    37. QLabel *time_label,*logo_label;//文本
    38. QVBoxLayout *totalLayout;//垂直布局
    39. QHBoxLayout *topLayout;//水平布局
    40. QPushButton *play_btn,*replay_btn,*log_btn,*setting_btn;//按钮
    41. QTimer *timer;//定时器
    42. Main_MonitorWidget *monitor;//监控窗口
    43. Main_ReplayWidget *replay;//回放窗口
    44. SetWidget *setting;
    45. loginWidget *loginwidget;
    46. signals:
    47. public slots:
    48. void qtimeSlot();//获取当前时间函数
    49. void Tosetting();//跳转到设置窗口函数
    50. void Toreplay();//跳转到回放模式函数
    51. void Tomonitor();//跳转到监控模式函数
    52. void Tomain();//关闭设置窗口函数
    53. };
    54. #endif // MAIN_WIDGET_H
    1. #include "main_widget.h"
    2. int Main_Widget::status=0;//主窗口初始状态
    3. //主界面构造函数
    4. Main_Widget::Main_Widget(QWidget *parent) : QWidget(parent)
    5. {
    6. init_UI();
    7. init_control();
    8. init_connect();
    9. }
    10. //主界面窗口设置
    11. void Main_Widget::init_UI()
    12. {
    13. this->setWindowTitle("陈茹涵--保安大队");
    14. this->setFixedSize(1400,900);
    15. this->totalLayout = new QVBoxLayout();
    16. // setWindowFlags(Qt::FramelessWindowHint);//无边框
    17. // setAttribute(Qt::WA_TranslucentBackground);//背景透明
    18. }
    19. //主界面控件布局设计
    20. void Main_Widget::init_control()
    21. {
    22. //上布局
    23. this->topLayout = new QHBoxLayout();
    24. this->topWidget = new QWidget(this);
    25. this->topWidget->setStyleSheet("background-color: rgb(252,157,154)");
    26. //下布局
    27. this->bottomWidget = new QStackedWidget(this);
    28. this->bottomWidget->setStyleSheet("background:white");
    29. //按钮
    30. this->play_btn = new QPushButton("监控模式",this);
    31. this->play_btn->setFixedSize(100,60);
    32. this->replay_btn = new QPushButton("回放模式",this);
    33. this->replay_btn->setFixedSize(100,60);
    34. this->log_btn = new QPushButton("日志查询",this);
    35. this->log_btn->setFixedSize(100,60);
    36. this->setting_btn = new QPushButton("系统设置",this);
    37. this->setting_btn->setFixedSize(100,60);
    38. //定时器--刷新时间
    39. this->time_label =new QLabel(this);
    40. this->timer = new QTimer(this);
    41. timer->start(500);
    42. //new一个监控模式布局
    43. this->monitor = new Main_MonitorWidget();
    44. //开始解码显示监控画面
    45. monitor->startdecode();
    46. //将监控模式布局放到堆栈布局里面
    47. this->bottomWidget->addWidget(monitor);
    48. //new一个回放模式布局
    49. this->replay = new Main_ReplayWidget();
    50. //将回放模式布局放到堆栈布局里面
    51. this->bottomWidget->addWidget(replay);
    52. //设置当前布局为监控模式
    53. this->bottomWidget->setCurrentWidget(monitor);
    54. //顶部导航栏布局
    55. this->topLayout->addStretch(0);//弹簧
    56. this->topLayout->setSpacing(18);//各个控件之间上下间距
    57. this->topLayout->addWidget(this->play_btn);
    58. this->topLayout->addWidget(this->replay_btn);
    59. this->topLayout->addWidget(this->log_btn);
    60. this->topLayout->addWidget(this->setting_btn);
    61. this->topLayout->addWidget(this->time_label);
    62. this->topWidget->setLayout(topLayout);//顶部布局设置
    63. this->totalLayout->addWidget(topWidget,1);//比例设计
    64. this->totalLayout->addWidget(bottomWidget,9);//比例设计
    65. this->setLayout(totalLayout);
    66. }
    67. //连接函数--按钮信号槽函数
    68. void Main_Widget::init_connect()
    69. {
    70. //获取当前时间
    71. connect(timer, SIGNAL(timeout()), this, SLOT(qtimeSlot()));
    72. //跳转到设置窗
    73. connect(setting_btn, SIGNAL(clicked()), this, SLOT(Tosetting()));
    74. //跳转到回放窗
    75. connect(replay_btn, SIGNAL(clicked()), this, SLOT(Toreplay()));
    76. //跳转到监控窗
    77. connect(play_btn, SIGNAL(clicked()), this, SLOT(Tomonitor()));
    78. }
    79. //获取当前时间函数
    80. void Main_Widget::qtimeSlot()
    81. {
    82. QDateTime date_time =QDateTime::currentDateTime();
    83. QString current_date =date_time.toString(" yyyy.MM.dd \nhh:mm:ss ddd");
    84. this->time_label->setText (current_date);
    85. }
    86. //跳转到设置窗口函数
    87. void Main_Widget::Tosetting()
    88. {
    89. //如果没有登录过就显示登录窗口-登录成功栈窗到相应界面
    90. if(this->status==0)
    91. {
    92. //登录成功状态为1
    93. this->loginwidget = new loginWidget;
    94. this->loginwidget->show();
    95. }
    96. else
    97. {
    98. this->setting = new SetWidget();
    99. this->setting->show();
    100. }
    101. }
    102. //跳转到回放模式函数
    103. void Main_Widget::Toreplay()
    104. {
    105. //如果没有登录过显示登录窗口
    106. if(this->status==0)
    107. {
    108. //登录成功状态为1
    109. this->loginwidget = new loginWidget;
    110. this->loginwidget->show();
    111. }
    112. else
    113. {
    114. this->replay->videolist();
    115. this->replay->init_connect();
    116. this->bottomWidget->setCurrentWidget(replay);
    117. }
    118. }
    119. //跳转到监控模式函数
    120. void Main_Widget::Tomonitor()
    121. {
    122. //如果没有登录过显示登录窗口
    123. if(this->status==0)
    124. {
    125. //登录成功状态为1
    126. this->loginwidget = new loginWidget;
    127. this->loginwidget->show();
    128. }
    129. else
    130. {
    131. this->bottomWidget->setCurrentWidget(monitor);
    132. }
    133. }
    134. //关闭设置窗口函数
    135. void Main_Widget::Tomain()
    136. {
    137. this->setting->close();
    138. }

    20.Main_MonitorWidget.h .cpp

    1. #ifndef MAIN_MONITORWIDGET_H
    2. #define MAIN_MONITORWIDGET_H
    3. #include <QWidget>
    4. #include <QLabel>//标签
    5. #include <QPushButton>//按钮
    6. #include <QHBoxLayout>//水平布局
    7. #include <QVBoxLayout>//垂直布局
    8. #include<QGridLayout>//网格布局-实现监控器田字布局
    9. #include <QPaintEvent>//重绘事件
    10. #include<QList>//链表
    11. #include<QImage>//图像
    12. #include<QPixmap>//嵌入图
    13. #include "decode.h"//解码
    14. #include<QListWidgetItem>//窗口图元项
    15. class Main_MonitorWidget : public QWidget
    16. {
    17. Q_OBJECT
    18. public:
    19. // explicit Main_MonitorWidget(QWidget *parent = 0);
    20. explicit Main_MonitorWidget(QWidget *parent = nullptr);
    21. void init_control();//控件布局设置1
    22. void init_control2();//控件布局设置2
    23. void init_connect();//按钮-信号槽机制
    24. void startdecode();//解码操作
    25. Decode *decodeThread;//声明解码线程
    26. private:
    27. QWidget *rightWidget,*leftWidget,*rightBottomWidget,*righttopWidget;//窗口布局设计
    28. QVBoxLayout *leftLayout,*rightLayout;//垂直布局设计
    29. QHBoxLayout *rightBottomLayout,*totalLayout;//水平布局设计
    30. QGridLayout *righttopLayout;//布局比例设计
    31. QPushButton *single_screen_btn,*multi_screen_btn;//按钮
    32. QLabel *video1_label,*video2_label,*video3_label,*video4_label;//标签文本
    33. QList <QString> camera;//摄像头
    34. QImage image;//图片
    35. protected:
    36. void paintEvent(QPaintEvent *);//重绘事件-接收图片监控显示
    37. signals:
    38. public slots:
    39. void receiveImg(QImage img);//接收图片函数
    40. void ToSingle();//切换单画面模式
    41. void ToFour();//切换多画面模式
    42. };
    43. #endif // MAIN_MONITORWIDGET_H
    1. #include "main_monitorwidget.h"
    2. //构造
    3. Main_MonitorWidget::Main_MonitorWidget(QWidget *parent) : QWidget(parent)
    4. {
    5. setWindowFlags(Qt::FramelessWindowHint); //无边框
    6. setAttribute(Qt::WA_TranslucentBackground);//背景透明
    7. init_control();//控件布局
    8. init_connect();//按钮-信号槽机制
    9. }
    10. //监控界面控件布局
    11. void Main_MonitorWidget::init_control()
    12. {
    13. this->totalLayout = new QHBoxLayout();//水平
    14. this->leftLayout = new QVBoxLayout();//垂直
    15. this->rightLayout = new QVBoxLayout();//垂直
    16. this->leftWidget =new QWidget();
    17. this->rightWidget =new QWidget();
    18. this->rightBottomWidget =new QWidget();
    19. this->righttopWidget =new QWidget();
    20. this->rightBottomLayout=new QHBoxLayout();//水平
    21. this->righttopLayout = new QGridLayout();//网格
    22. this->leftWidget->setStyleSheet("background-color: rgb(252,157,154)");//背景颜色
    23. QListWidget *playList = new QListWidget;//视频列表
    24. //设置QListWidget的显示模式
    25. playList->setViewMode (QListView::IconMode) ;
    26. //设置QListWidget中单元项的间距
    27. playList->setSpacing(0) ;
    28. //设置自动适应布局调整(Adjust适应 Fixed不适应)--默认不适应设置
    29. playList->setResizeMode (QListWidget::Adjust);
    30. //设置不能移动
    31. playList->setMovement (QListWidget::Static);
    32. playList->setStyleSheet("border:none;font-size:15px");//边框尺寸15号字体
    33. //默认无背景--直到摄像头加入
    34. camera = Decode::getcamera();
    35. for(int i = 0;i<camera.size();i++)
    36. {
    37. //定义QListWidgetItem对象
    38. QListWidgetItem *playItem = new QListWidgetItem;
    39. //为单元项设置属性
    40. //设置文本相关
    41. playItem->setTextColor("white");
    42. playItem->setText(camera.at(i));
    43. //重新设置单元项图片的宽度和高度
    44. playItem->setSizeHint(QSize(200,50));
    45. //将单元项添加到QListWidget中
    46. playList->addItem(playItem);
    47. this->leftLayout->addWidget(playList);
    48. }
    49. this->leftWidget->setLayout(leftLayout);//左边布局设计
    50. //右上布局设计
    51. this->video1_label = new QLabel(this);//不适应设置--开启摄像头后适应窗口
    52. this->video1_label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    53. this->video1_label->setMinimumSize(100,30);//设置最大和最小窗口
    54. //label显示画面控件初始化--默认其他窗口的没有摄像头情况不显示监控
    55. this->video2_label = new QLabel(this);
    56. this->video2_label->setStyleSheet("background-color: rgb(252,157,154)");
    57. this->video3_label = new QLabel(this);
    58. this->video3_label->setStyleSheet("background-color: rgb(252,157,154)");
    59. this->video4_label = new QLabel(this);
    60. this->video4_label->setStyleSheet("background-color: rgb(252,157,154)");
    61. //添加到布局,田字格布局--网格布局设计
    62. this->righttopLayout->addWidget(video1_label,0,0);
    63. this->righttopLayout->addWidget(video2_label,0,1);
    64. this->righttopLayout->addWidget(video3_label,1,0);
    65. this->righttopLayout->addWidget(video4_label,1,1);
    66. //弹簧设计
    67. this->righttopLayout->setRowStretch(0,1);
    68. this->righttopLayout->setRowStretch(1,1);
    69. this->righttopLayout->setColumnStretch(0,1);
    70. this->righttopLayout->setColumnStretch(1,1);
    71. this->righttopWidget->setLayout(righttopLayout);//设置右上田字监控布局
    72. //右下按钮控件的布局设计
    73. this->single_screen_btn = new QPushButton("单",this);
    74. this->multi_screen_btn = new QPushButton("双",this);
    75. this->rightBottomLayout->addWidget(single_screen_btn);
    76. this->rightBottomLayout->addWidget(multi_screen_btn);
    77. this->rightBottomLayout->addStretch(0);//弹簧设计
    78. this->rightBottomWidget->setLayout(rightBottomLayout);//设置右下按钮控件布局
    79. //右边布局-比例设计
    80. this->rightLayout->addWidget(righttopWidget,95);//右上窗口比例
    81. this->rightLayout->addWidget(rightBottomWidget,5);//右下控件窗口比例
    82. this->rightWidget->setLayout(rightLayout);//设置布局
    83. //整体布局-比例设计
    84. this->totalLayout ->setSpacing(0);//表示各个控件之间的上下间距
    85. this->totalLayout->setMargin(0);//表示控件与窗体的左右边距
    86. this->totalLayout->addWidget(leftWidget,17);//左右窗口比例设计
    87. this->totalLayout->addWidget(rightWidget,83);//左右窗口比例设计
    88. this->setLayout(totalLayout);//设置布局
    89. }
    90. //连接函数-按钮信号槽机制
    91. void Main_MonitorWidget::init_connect()
    92. {
    93. connect(this->single_screen_btn,SIGNAL(clicked()),this,SLOT(ToSingle()));//单通道按钮
    94. connect(this->multi_screen_btn,SIGNAL(clicked()),this,SLOT(ToFour()));//多通道按钮
    95. }
    96. //实时显示监控画面解码函数
    97. void Main_MonitorWidget::startdecode()
    98. {
    99. this->decodeThread =new Decode();
    100. decodeThread->start();//启动解码线程
    101. connect(decodeThread,SIGNAL(sendImg(QImage)),this,SLOT(receiveImg(QImage)));//发送接收图片信号
    102. }
    103. //接收图片函数
    104. void Main_MonitorWidget::receiveImg(QImage img)
    105. {
    106. this->image =img;
    107. this->update();
    108. }
    109. //监控界面label控件接收图片事件--重绘事件实现开启摄像头窗口自适应显示画面
    110. void Main_MonitorWidget::paintEvent(QPaintEvent *)
    111. {
    112. //如果这个图片不为空
    113. if(!this->image.isNull())
    114. {
    115. //画面图片显示在label载体上
    116. QPixmap *image = new QPixmap(QPixmap::fromImage(this->image));
    117. image->scaled(video1_label->size(),Qt::KeepAspectRatio);
    118. video1_label->setPixmap(QPixmap::fromImage(this->image));
    119. video1_label->setScaledContents(true);
    120. }
    121. }
    122. //切换单画面模式
    123. void Main_MonitorWidget::ToSingle()
    124. {
    125. //关闭其他监控窗口
    126. this->righttopLayout->removeWidget(video2_label);
    127. this->righttopLayout->removeWidget(video3_label);
    128. this->righttopLayout->removeWidget(video4_label);
    129. this->video2_label->setVisible(false);//数据模型构造完毕
    130. this->video3_label->setVisible(false);//数据模型构造完毕
    131. this->video4_label->setVisible(false);//数据模型构造完毕
    132. this->video1_label->setMinimumSize(1109,703);//监控摄像头最大最小窗口设计之单画面
    133. }
    134. //切换多画面模式--网格布局
    135. void Main_MonitorWidget::ToFour()
    136. {
    137. this->video1_label->setMinimumSize(100,30);//监控摄像头最大最小窗口设计之多画面
    138. this->righttopLayout->addWidget(video2_label);
    139. this->righttopLayout->addWidget(video3_label);
    140. this->righttopLayout->addWidget(video4_label);
    141. this->video2_label->setVisible(true);//数据模型构造完毕
    142. this->video3_label->setVisible(true);//数据模型构造完毕
    143. this->video4_label->setVisible(true);//数据模型构造完毕
    144. //网格布局-田字
    145. this->righttopLayout->addWidget(video1_label,0,0);
    146. this->righttopLayout->addWidget(video2_label,0,1);
    147. this->righttopLayout->addWidget(video3_label,1,0);
    148. this->righttopLayout->addWidget(video4_label,1,1);
    149. //弹簧设计
    150. this->righttopLayout->setRowStretch(0,1);
    151. this->righttopLayout->setRowStretch(1,1);
    152. this->righttopLayout->setColumnStretch(0,1);
    153. this->righttopLayout->setColumnStretch(1,1);
    154. }

    21.Main_ReplayWidget.h .cpp

    1. #ifndef MAIN_REPLAYWIDGET_H
    2. #define MAIN_REPLAYWIDGET_H
    3. #include <QWidget>
    4. #include <QLabel>//标签文本
    5. #include <QPushButton>//按钮
    6. #include <QHBoxLayout>//水平
    7. #include <QVBoxLayout>//垂直
    8. #include<QGridLayout>//网格
    9. #include <QPaintEvent>//绘图事件
    10. #include<QList>//链表
    11. #include<QImage>//图像
    12. #include<QPixmap>//嵌入图
    13. #include<QStackedWidget>//栈窗口
    14. #include<QListWidget>//窗口列表
    15. #include<QDebug>//调试
    16. #include <QCalendarWidget>//日历窗口
    17. #include <QDateEdit>//编辑日期
    18. #include <QFile>//文件操作
    19. #include "videocontrol.h"//视频控制层
    20. #include "imagecontrol.h"//图像控制层
    21. #include "videomodel.h"//视频模型层
    22. #include "imagemodel.h"//图像模型层
    23. #include "play_widget.h"//视频播放窗
    24. #include "image_widget.h"//图像显示窗
    25. //#include"decode_replay.h"//回放解码
    26. class Main_ReplayWidget : public QWidget
    27. {
    28. Q_OBJECT
    29. public:
    30. // explicit Main_ReplayWidget(QWidget *parent = 0);
    31. explicit Main_ReplayWidget(QWidget *parent = nullptr);//构造
    32. void init_UI();//UI窗口
    33. void init_connect();//控件布局
    34. void videolist();//更新视频列表函数
    35. void imagelist();//更新图片列表函数
    36. void lastvideo_play();//回放最后一个视频函数
    37. private:
    38. QWidget *leftWidget,*rightWidget,*rightWidget2,*midWidget,*rightBottomWidget,*righttopWidget;//窗口布局
    39. QVBoxLayout *leftLayout,*rightLayout,*righttopLayout,*midLayout;//垂直布局
    40. QStackedWidget *StackedWidget;//栈窗口
    41. QHBoxLayout *rightBottomLayout,*totalLayout,*rightLayout2;//水平布局
    42. QPushButton *Inquire_btn,*Next_btn,*Previous_btn,*video_btn,*image_btn;//按钮
    43. QLabel *video_label,*video_label2;//标签文本
    44. QImage image;//图像
    45. QListWidget *playList,*image_List;//列表窗口
    46. Play_Widget *replayWidget;//播放窗口
    47. Image_Widget *ImageWidget;//图像窗口
    48. QWidget *leftWidget1,*bottomWidget,*rightWidget3,*rightWidget4,*topWidget;//窗口布局
    49. QVBoxLayout *leftLayout1,*rightLayout3;//垂直布局
    50. QHBoxLayout *rightLayout4,*bottomLayout;//水平布局
    51. QGridLayout *topLayout;//网格布局
    52. QLabel *name_label,*size_label,*resolution_label;//文本
    53. Decode_Replay *decodeThread;//回放解码线程
    54. int page;//页数
    55. QDateEdit *date;//日期编辑框
    56. QString *date_time;//日期
    57. QImage Image;//图像
    58. QImage image_size;//图像
    59. protected:
    60. void paintEvent(QPaintEvent *);//重绘事件--视频回放界面label控件接收图片事件
    61. signals:
    62. public slots:
    63. void click_video(QListWidgetItem *item);//点击视频列表播放视频
    64. void tovideo();//切换视频列表函数
    65. void toimage();//切换图片列表函数
    66. void next();//图片列表下一页函数
    67. void previous();//图片列表上一页函数
    68. void calendar_query();//日历查询函数
    69. void receiveimg(QImage img);//视频回放界面接收图片函数
    70. void click_image(QListWidgetItem *item);//点击图片槽函数
    71. };
    72. #endif // MAIN_REPLAYWIDGET_H
    1. #include "main_replaywidget.h"
    2. //构造
    3. Main_ReplayWidget::Main_ReplayWidget(QWidget *parent) : QWidget(parent)
    4. {
    5. this->page=1;//页数初始化
    6. init_UI();//UI窗口
    7. }
    8. //界面布局
    9. void Main_ReplayWidget::init_UI()
    10. {
    11. //视频回放布局初始化
    12. this->totalLayout = new QHBoxLayout();//水平
    13. this->leftLayout = new QVBoxLayout();//垂直
    14. this->leftWidget = new QWidget();
    15. this->rightLayout = new QVBoxLayout();//垂直
    16. this->rightWidget = new QWidget();
    17. this->rightLayout2 = new QHBoxLayout();//水平
    18. this->rightWidget2 = new QWidget();
    19. this->midLayout = new QVBoxLayout();//垂直
    20. this->midWidget = new QWidget();
    21. this->rightBottomWidget =new QWidget();
    22. this->rightBottomLayout = new QHBoxLayout();//水平
    23. this->righttopWidget =new QWidget();
    24. this->righttopLayout= new QVBoxLayout();//垂直
    25. this->StackedWidget =new QStackedWidget();//栈窗口
    26. this->video_btn = new QPushButton("视频回放",this);//视频控件
    27. this->image_btn = new QPushButton("图片列表",this);//图像控件
    28. //视频回放---设置左边和右边背景颜色
    29. this->leftWidget->setStyleSheet("background-color: rgb(252,157,154)");
    30. this->righttopWidget->setStyleSheet("background-color: rgb(252,157,154)");
    31. //视频回放---右边视频回放、图片回放按钮布局
    32. this->leftLayout->addWidget(video_btn);
    33. this->leftLayout->addWidget(image_btn);
    34. //视频回放---设置弹簧,使两个按钮放到顶部
    35. this->leftLayout->addStretch(0);
    36. this->leftWidget->setLayout(leftLayout);
    37. //视频回放---中间布局
    38. this->video_label = new QLabel();
    39. this->video_label2 = new QLabel();
    40. this->midLayout->addWidget(video_label,7);//比例设计
    41. this->midLayout->addWidget(video_label2,3);//比例设计
    42. this->video_label->setMinimumSize(750,420);//最大最小尺寸
    43. this->midWidget->setLayout(midLayout);//放置中间布局
    44. //视频回放---右边视频列表布局
    45. this->playList = new QListWidget;
    46. //设置QListWidget中单元项的间距
    47. playList->setSpacing(0);//各个控件间的上下间距
    48. //设置自动适应布局调整(Adjust适应, Fixed不适应),默认不适应
    49. playList->setResizeMode(QListWidget::Adjust);
    50. //设置不能移动
    51. playList->setMovement(QListWidget::Static);
    52. playList->setStyleSheet("border:none;font-size:15px");
    53. playList->setIconSize(QSize(120,130));
    54. QList<QString> titleList;
    55. QList<QString> coverList;
    56. //从数据库获取视频信息,返回qres
    57. char **qres;
    58. qres=VideoControl::getInstance()->getVideoPath();
    59. //用List存视频路径,跳过表头,自增2存一次
    60. for(int i=VideoModel::col;i<(VideoModel::row+1)*VideoModel::col;i+=2)
    61. {
    62. titleList<<qres[i];
    63. }
    64. //用List存封面路径,跳过表头,自增2存一次
    65. for(int i=VideoModel::col+1;i<(VideoModel::row+1)*VideoModel::col;i+=2)
    66. {
    67. coverList<<qres[i];
    68. }
    69. //将得到的list添加到QListWidgetItem单元项里面
    70. for (int i=0;i<titleList.size();i++)
    71. {
    72. //定义QListWidgetItem对象
    73. QListWidgetItem *playItem = new QListWidgetItem ;
    74. //为单元项设置属性
    75. //设置
    76. playItem->setIcon(QIcon(coverList[i]));
    77. playItem->setTextColor("white");
    78. playItem->setText(titleList.at(i));
    79. //重新设置单元项图片的宽度和高度
    80. playItem->setSizeHint(QSize(150,170));
    81. //将单元项添加到QListWidget中
    82. playList->addItem(playItem);
    83. }
    84. //将视频列表添加到布局里
    85. this->righttopLayout->addWidget(playList) ;
    86. this->righttopWidget->setLayout(righttopLayout);
    87. //视频回放---右边日历查询布局
    88. this->Inquire_btn = new QPushButton("查询",this);
    89. //日历控件初始化
    90. this->date = new QDateEdit();
    91. this->date->setCalendarPopup(true);
    92. this->date->setDate(QDate::currentDate());
    93. this->date->setFixedSize(160,40);
    94. //查询和日历控件添加到布局里
    95. this->rightBottomLayout->addWidget(date);
    96. this->rightBottomLayout->addWidget(Inquire_btn);
    97. this->rightBottomWidget->setLayout(rightBottomLayout);
    98. //日历查询布局和视频列表布局比例为1:9
    99. this->rightLayout->addWidget(rightBottomWidget,1);
    100. this->rightLayout->addWidget(righttopWidget,9);
    101. this->rightWidget->setLayout(rightLayout);
    102. //视频播放布局和视频列表布局比例为7:3
    103. this->rightLayout2->addWidget(midWidget,7);
    104. this->rightLayout2->addWidget(rightWidget,3);
    105. this->rightWidget2->setLayout(rightLayout2);
    106. //将视频回放布局添加到堆栈布局里
    107. this->StackedWidget->addWidget(rightWidget2);
    108. //图片回放布局初始化
    109. this->leftWidget1=new QWidget();
    110. this->bottomWidget=new QWidget();
    111. this->rightWidget3=new QWidget();
    112. this->rightWidget4=new QWidget();
    113. this->topWidget=new QWidget();
    114. this->leftLayout1=new QVBoxLayout();//垂直
    115. this->bottomLayout=new QHBoxLayout();//水平
    116. this->rightLayout3=new QVBoxLayout();//垂直
    117. this->rightLayout4=new QHBoxLayout();//水平
    118. this->topLayout=new QGridLayout();//网格
    119. //图片回放控件初始化
    120. this->name_label=new QLabel("照片名称:",this);
    121. this->size_label=new QLabel("照片大小:",this);
    122. this->resolution_label=new QLabel("照片尺寸:",this);
    123. this->Next_btn = new QPushButton("下一页",this);
    124. this->Previous_btn = new QPushButton("上一页",this);
    125. //图片回放---中间图片列表布局
    126. this->image_List = new QListWidget;
    127. //设置QListWidget的显示模式
    128. image_List->setViewMode (QListView::IconMode);
    129. //设置QListWidget中单元项的间距
    130. image_List->setSpacing(4);
    131. //设置自动适应布局调整(Adjust适应, Fixed不适应),默认不适应
    132. image_List->setResizeMode (QListWidget::Adjust) ;
    133. //设置不能移动
    134. image_List->setMovement (QListWidget::Static);
    135. image_List->setStyleSheet("border:none;font-size:15px");
    136. image_List->setIconSize(QSize(230,230));
    137. QList<QString> ImageList;
    138. QList<QString> nameList;
    139. //从数据库获取图片信息,返回qres
    140. char **qres2;
    141. qres2=ImageControl::getInstance()->getImagePath(page);
    142. //用List存视频路径,跳过表头,自增2存一次
    143. for(int i=ImageModel::col;i<(ImageModel::row+1)*ImageModel::col;i+=2)
    144. {
    145. ImageList<<qres2[i];
    146. }
    147. //用List存视频名称,跳过表头,自增2存一次
    148. for(int i=ImageModel::col+1;i<(ImageModel::row+1)*ImageModel::col;i+=2)
    149. {
    150. nameList<<qres2[i];
    151. }
    152. //将得到的list添加到QListWidgetItem单元项里面
    153. for (int i=0;i<ImageList.size();i++)
    154. {
    155. //定义QListWidgetItem对象
    156. QListWidgetItem *imageItem = new QListWidgetItem;
    157. //为单元项设置属性
    158. //设置
    159. imageItem->setIcon(QIcon(ImageList[i]));
    160. imageItem->setText(nameList.at(i));
    161. //重新设置单元项图片的宽度和高度
    162. imageItem->setSizeHint(QSize(220,220));
    163. //将单元项添加到QListWidget中
    164. image_List->addItem(imageItem);
    165. }
    166. //将图片列表添加到布局里
    167. this->topLayout->addWidget(image_List);
    168. this->topWidget->setLayout(topLayout);
    169. //图片回放---中间下边翻页布局
    170. this->bottomLayout->addWidget(Previous_btn);//上一页
    171. this->bottomLayout->addWidget(Next_btn);//下一页
    172. this->bottomWidget->setLayout(bottomLayout);//控件窗口布局
    173. //图片回放---中间图片列表布局和下边翻页布局比例为95:5
    174. this->leftLayout1->addWidget(topWidget,95);
    175. this->leftLayout1->addWidget(bottomWidget,5);
    176. this->leftWidget1->setLayout(leftLayout1);
    177. //图片回放---右边图片信息布局
    178. this->rightLayout3->addWidget(name_label);
    179. this->rightLayout3->addWidget(size_label);
    180. this->rightLayout3->addWidget(resolution_label);
    181. //图片回放---用弹簧把label设置到布局顶部
    182. this->rightLayout3->addStretch(0);//弹簧
    183. this->rightWidget3->setLayout(rightLayout3);
    184. //图片列表布局和图片信息布局比例为8:2
    185. this->rightLayout4->addWidget(leftWidget1,8);
    186. this->rightLayout4->addWidget(rightWidget3,2);
    187. this->rightWidget4->setLayout(rightLayout4);
    188. //堆栈窗口
    189. this->StackedWidget->addWidget(rightWidget4);
    190. this->StackedWidget->setCurrentWidget(rightWidget2);
    191. //总布局
    192. this->totalLayout ->setSpacing(0);//表示各个控件之间的上下间距
    193. this->totalLayout->setMargin(0);//表示控件与窗体的左右边距
    194. this->totalLayout->addWidget(leftWidget,15);//比例
    195. this->totalLayout->addWidget(StackedWidget,85);//比例
    196. this->setLayout(totalLayout);
    197. }
    198. //连接函数-按钮信号槽机制
    199. void Main_ReplayWidget::init_connect()
    200. {
    201. //点击视频列表播放视频
    202. connect(playList,SIGNAL(itemClicked(QListWidgetItem *)),this,SLOT(click_video(QListWidgetItem *)));
    203. //切换视频列表
    204. connect(video_btn,SIGNAL(clicked()),this,SLOT(tovideo()));
    205. //切换图片列表
    206. connect(image_btn,SIGNAL(clicked()),this,SLOT(toimage()));
    207. //图片列表上一页
    208. connect(Previous_btn,SIGNAL(clicked()),this,SLOT(previous()));
    209. //图片列表下一页
    210. connect(Next_btn,SIGNAL(clicked()),this,SLOT(next()));
    211. //日历查询
    212. connect(Inquire_btn,SIGNAL(clicked()),this,SLOT(calendar_query()));
    213. //视频回放界面接收图片
    214. connect(decodeThread, SIGNAL(sendImg2(QImage)), this, SLOT(receiveimg(QImage)));
    215. //点击图片
    216. connect(image_List, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(click_image(QListWidgetItem *)));
    217. }
    218. //更新视频列表函数
    219. void Main_ReplayWidget::videolist()
    220. {
    221. //更新视频列表 删去所有item
    222. this->playList->deleteLater();
    223. this->playList =new QListWidget();
    224. this->righttopLayout->deleteLater();
    225. this->righttopLayout= new QVBoxLayout();
    226. this->righttopWidget->deleteLater();
    227. this->righttopWidget=new QWidget();
    228. //设置QListWidget的显示模式
    229. playList-> setSpacing(0) ;//设置QListWidget中单元项的间距
    230. //设置自动适应布局调整(Adjust适应,Fixed不适应)--默认不适应
    231. playList-> setResizeMode (QListWidget::Adjust) ;
    232. //设置不能移动
    233. playList-> setMovement (QListWidget::Static) ;
    234. playList->setStyleSheet("border:none;font-size:15px");
    235. playList->setIconSize(QSize(120,130));
    236. char **qres;
    237. qres=VideoControl::getInstance()->getVideoPath();
    238. QList<QString> titleList;
    239. QList<QString> coverList;
    240. for(int i=VideoModel::col;i<(VideoModel::row+1)*VideoModel::col;i+=2)
    241. {
    242. titleList<<qres[i];
    243. }
    244. for(int i=VideoModel::col+1;i<(VideoModel::row+1)*VideoModel::col;i+=2)
    245. {
    246. coverList<<qres[i];
    247. }
    248. for (int i=0;i<titleList.size();i++)
    249. {
    250. //定义QListWidgetItem对象
    251. QListWidgetItem *playItem = new QListWidgetItem ;
    252. //为单元项设置属性
    253. playItem->setIcon(QIcon(coverList[i]));
    254. playItem->setText(titleList.at(i));
    255. //重新设置单元项图片的宽度和高度
    256. playItem->setSizeHint(QSize(150,170));
    257. //将单元项添加到QListWidget中
    258. playList->addItem(playItem);
    259. }
    260. this->righttopLayout->addWidget(playList);
    261. this->righttopWidget->setLayout(righttopLayout);
    262. this->righttopWidget->setStyleSheet("background-color: rgb(252,157,154)");
    263. this->rightLayout->addWidget(righttopWidget,9);
    264. connect(playList,SIGNAL(itemClicked(QListWidgetItem *)),this,SLOT(click_video(QListWidgetItem *)));
    265. }
    266. //更新图片列表函数
    267. void Main_ReplayWidget::imagelist()
    268. {
    269. //更新视频列表 删去所有item
    270. this->image_List->deleteLater();
    271. this->image_List =new QListWidget();
    272. this->topLayout->deleteLater();
    273. this->topLayout= new QGridLayout();
    274. this->topWidget->deleteLater();
    275. this->topWidget=new QWidget();
    276. //设置QListWidget的显示模式
    277. image_List-> setViewMode (QListView::IconMode);
    278. //设置QListWidget中单元项的间距
    279. image_List-> setSpacing(4);
    280. //设置自动适应布局调整(Adjust适应, Fixed不适应),默认不适应
    281. image_List-> setResizeMode (QListWidget::Adjust) ;
    282. //设置不能移动
    283. image_List-> setMovement (QListWidget::Static) ;
    284. image_List->setStyleSheet("border:none;font-size:15px");
    285. image_List->setIconSize(QSize(230,230));
    286. QList<QString> ImageList;
    287. QList<QString> nameList;
    288. char **qres2;
    289. qres2=ImageControl::getInstance()->getImagePath(this->page);
    290. for(int i=ImageModel::col;i<(ImageModel::row+1)*ImageModel::col;i+=2)
    291. {
    292. ImageList<<qres2[i];
    293. }
    294. for(int i=ImageModel::col+1;i<(ImageModel::row+1)*ImageModel::col;i+=2)
    295. {
    296. nameList<<qres2[i];
    297. }
    298. for (int i=0;i<ImageList.size();i++)
    299. {
    300. //定义QListWidgetItem对象
    301. QListWidgetItem *imageItem = new QListWidgetItem;
    302. //为单元项设置属性
    303. //设置
    304. imageItem->setIcon(QIcon(ImageList[i]));
    305. imageItem->setText(nameList.at(i));
    306. //重新设置单元项图片的宽度和高度
    307. imageItem->setSizeHint(QSize(220,220));
    308. //将单元项添加到QListWidget中
    309. image_List->addItem(imageItem);
    310. }
    311. //重新添加到布局里面
    312. this->topLayout->addWidget(image_List);
    313. this->topWidget->setLayout(topLayout);
    314. this->leftLayout1->addWidget(topWidget,95);
    315. this->leftLayout1->addWidget(bottomWidget,5);
    316. connect(image_List, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(click_image(QListWidgetItem *)));
    317. }
    318. //回放最后一个视频函数
    319. void Main_ReplayWidget::lastvideo_play()
    320. {
    321. //从数据库获取最后一个视频路径
    322. char**res;
    323. res=VideoModel::getInstance()->getLastvideo();
    324. QString lastvdieo =res[1];
    325. //如果没有就返回
    326. if(lastvdieo.length()==0)
    327. {
    328. QMessageBox::warning(this, tr("提示!"),tr("暂无视频可播放!"),QMessageBox::Yes);
    329. return;
    330. }
    331. //找到就传路径给解码线程并且打开
    332. this->decodeThread=new Decode_Replay(lastvdieo);
    333. this->decodeThread->start();
    334. }
    335. //槽函数--点击视频列表播放视频
    336. void Main_ReplayWidget::click_video(QListWidgetItem *item)
    337. {
    338. //通过点击item获取对应的text,也就是视频名称,再传给control层去查询数据库
    339. char **qres=VideoControl::getInstance()->getVideo(item->text());
    340. replayWidget =new Play_Widget(qres[1]);
    341. replayWidget->show();
    342. }
    343. //点击图片槽函数
    344. void Main_ReplayWidget::click_image(QListWidgetItem *item)
    345. {
    346. //获取该item的text,即图片名字,然后到数据库查询图片路径
    347. int size;
    348. char **qres=ImageControl::getInstance()->getimage(item->text());
    349. QFile myfile(qres[1]);
    350. //获取图片大小
    351. if(myfile.open(QIODevice::ReadOnly))
    352. {
    353. size = myfile.size();
    354. myfile.close();
    355. }
    356. //获取图片宽高
    357. this->image_size.load(qres[1]);
    358. this->name_label->setText("图片名称:"+item->text());
    359. this->size_label->setText("图片大小:"+QString::number(size/1024)+" KB");
    360. this->resolution_label->setText("照片尺寸:"+QString::number(image_size.height())
    361. +" X "+QString::number(image_size.width()));
    362. //获得图片路径,加载出图片放大窗口
    363. this->ImageWidget=new Image_Widget(qres[1]);
    364. this->ImageWidget->show();
    365. }
    366. //切换视频列表函数
    367. void Main_ReplayWidget::tovideo()
    368. {
    369. //用堆栈布局显示视频列表布局
    370. this->StackedWidget->setCurrentWidget(rightWidget2);
    371. }
    372. //切换图片列表函数
    373. void Main_ReplayWidget::toimage()
    374. {
    375. //用堆栈布局显示图片列表布局
    376. this->StackedWidget->setCurrentWidget(rightWidget4);
    377. imagelist();
    378. }
    379. //图片列表下一页函数
    380. void Main_ReplayWidget::next()
    381. { //先判断数据库下一个区间是否还有图片
    382. this->page++;
    383. char **qres3;
    384. QList<QString> ImageList;
    385. qres3=ImageControl::getInstance()->getImagePath(this->page);
    386. for(int i=ImageModel::col;i<(ImageModel::row+1)*ImageModel::col;i+=1)
    387. {
    388. ImageList<<qres3[i];
    389. }
    390. //如果没有就提示,并恢复原来页数
    391. if(ImageList.size()==0)
    392. {
    393. QMessageBox::warning(this, tr("提示!"),tr("已经是最后一页!"),QMessageBox::Yes);
    394. this->page--;
    395. }
    396. //否则加加载图片
    397. else
    398. {
    399. imagelist();
    400. }
    401. }
    402. //图片列表上一页函数
    403. void Main_ReplayWidget::previous()
    404. {
    405. //如果页数不是第一页就继续加载图片
    406. if(this->page>1)
    407. {
    408. this->page--;
    409. imagelist();
    410. }
    411. //如果页数是第一页就提示
    412. else
    413. {
    414. QMessageBox::warning(this, tr("提示!"),tr("已经是第一页!"),QMessageBox::Yes);
    415. }
    416. }
    417. //日历查询函数
    418. void Main_ReplayWidget::calendar_query()
    419. {
    420. //获取日历控件的参数,并修改格式yyyyMMdd
    421. QString time = date->dateTime().toString("yyyyMMdd");
    422. //control层传参查询数据库是否有该日期视频
    423. char **qres;
    424. qres=VideoControl::getInstance()->calendar_query(time);
    425. QList<QString> titleList;
    426. QList<QString> coverList;
    427. for(int i=VideoModel::col;i<(VideoModel::row+1)*VideoModel::col;i+=2)
    428. {
    429. titleList<<qres[i];
    430. }
    431. //如果没有就提示,并返回
    432. if(titleList.size()==0)
    433. {
    434. QMessageBox::warning(this, tr("提示!"),tr("没有该日期视频数据!"),QMessageBox::Yes);
    435. return;
    436. }
    437. //如果有就删除布局,并重新new出来
    438. this->playList->deleteLater();
    439. this->playList =new QListWidget();
    440. this->righttopLayout->deleteLater();
    441. this->righttopLayout= new QVBoxLayout();
    442. this->righttopWidget->deleteLater();
    443. this->righttopWidget=new QWidget();
    444. playList->setSpacing(0);
    445. //设置自动适应布局调整(Adjust适应, Fixed不适应),默认不适应
    446. playList->setResizeMode (QListWidget::Adjust);
    447. //设置不能移动
    448. playList->setMovement (QListWidget::Static);
    449. playList->setStyleSheet("border:none;font-size:15px");
    450. playList->setIconSize(QSize(110,120));
    451. for(int i=VideoModel::col+1;i<(VideoModel::row+1)*VideoModel::col;i+=2)
    452. {
    453. coverList<<qres[i];
    454. }
    455. for (int i=0;i<titleList.size();i++)
    456. {
    457. //定义QListWidgetItem对象
    458. QListWidgetItem *playItem = new QListWidgetItem;
    459. //为单元项设置属性
    460. playItem->setIcon(QIcon(coverList[i]));
    461. playItem->setText(titleList.at(i));
    462. //重新设置单元项图片的宽度和高度
    463. playItem->setSizeHint(QSize(150,250));
    464. //将单元项添加到QListWidget中
    465. playList->addItem(playItem);
    466. }
    467. this->righttopLayout->addWidget(playList);
    468. this->righttopWidget->setLayout(righttopLayout);
    469. this->righttopWidget->setStyleSheet("background-color: rgb(252,157,154)");
    470. this->rightLayout->addWidget(righttopWidget,9);
    471. connect(playList,SIGNAL(itemClicked(QListWidgetItem *)),this,SLOT(click_video(QListWidgetItem *)));
    472. }
    473. //视频回放界面接收图片函数
    474. void Main_ReplayWidget::receiveimg(QImage img)
    475. {
    476. this->Image =img;
    477. this->update();
    478. }
    479. //视频回放界面label控件接收图片事件
    480. void Main_ReplayWidget::paintEvent(QPaintEvent *)
    481. {
    482. if(!this->Image.isNull())
    483. {
    484. QPixmap *image = new QPixmap(QPixmap::fromImage(this->Image));
    485. image->scaled(video_label->size(),Qt::KeepAspectRatio);
    486. //控件接收图片
    487. video_label->setPixmap(QPixmap::fromImage(this->Image));
    488. video_label->setScaledContents(true);
    489. }
    490. }

    22.Play_Widget.h .cpp

    1. #ifndef PLAY_WIDGET_H
    2. #define PLAY_WIDGET_H
    3. #include <QWidget>
    4. #include <QLabel>//标签文本
    5. #include <QPushButton>//按钮
    6. #include <QHBoxLayout>//水平
    7. #include <QVBoxLayout>//垂直
    8. #include <QPaintEvent>//重绘
    9. #include<QComboBox>//下拉框
    10. #include<QImage>//图像
    11. #include<QPixmap>//嵌入图
    12. #include "decode_replay.h"//解码回放
    13. #include "ftrancetomp4.h"//转码
    14. #include<QMessageBox>//消息框
    15. class Play_Widget : public QWidget
    16. {
    17. Q_OBJECT
    18. public:
    19. explicit Play_Widget(QString PATH,QWidget *parent = nullptr);//构造
    20. void init_UI();//UI窗口
    21. void init_control();//控件布局
    22. void init_connect();//按钮-信号槽机制
    23. Decode_Replay *decodeThread;//解码回放
    24. static QString path;//路径
    25. private:
    26. QVBoxLayout *totalLayout;//垂直布局
    27. QWidget *bottomWidget,*topWidget;//窗口布局
    28. QHBoxLayout *bottomLayout,*topLayout;//水平布局
    29. QLabel *video_label;//标签文本
    30. QPushButton *play_btn,*screenshots_btn,*export_btn;//按钮
    31. QComboBox *Timesthespeed_box;//下拉框
    32. QImage Image;//图片
    33. FTranceTomp4 *trance;//转码
    34. int mark;//标志位--播放暂停
    35. protected:
    36. void paintEvent(QPaintEvent *);//重绘事件--监控界面label控件接收图片事件
    37. signals:
    38. public slots:
    39. void receiveimg(QImage img);//接收图片槽函数
    40. void continue_stop();//视频暂停函数
    41. void screenshots();//截图函数
    42. void trancetomp4();//转码导出视频函数
    43. };
    44. #endif // PLAY_WIDGET_H
    1. #include "play_widget.h"
    2. QString Play_Widget::path=nullptr;//路径初始化
    3. //播放界面构造函数
    4. Play_Widget::Play_Widget(QString PATH,QWidget *parent) : QWidget(parent)
    5. {
    6. this->mark = 1;//mark为暂停标记,1表示继续播放,0 表示暂停
    7. init_UI();//UI窗口
    8. init_control();//控件布局
    9. //path为视频路径
    10. this->path=PATH;
    11. //创建一个解码线程
    12. this->decodeThread=new Decode_Replay(path);
    13. //启动线程
    14. this->decodeThread->start();
    15. init_connect();//按钮-信号槽机制
    16. }
    17. //播放界面参数设置
    18. void Play_Widget::init_UI()
    19. {
    20. this->setWindowTitle("播放界面");
    21. this->setFixedSize(900,675);
    22. this->totalLayout = new QVBoxLayout();
    23. }
    24. //播放界面控件布局
    25. void Play_Widget::init_control()
    26. {
    27. this->bottomWidget=new QWidget();
    28. this->topWidget=new QWidget();
    29. this->bottomLayout=new QHBoxLayout();
    30. this->topLayout=new QHBoxLayout();
    31. this->video_label=new QLabel();
    32. this->play_btn=new QPushButton("暂停/播放",this);
    33. this->screenshots_btn=new QPushButton("截图",this);
    34. this->export_btn=new QPushButton("导出",this);
    35. //下拉框
    36. this->Timesthespeed_box = new QComboBox(this);
    37. this->Timesthespeed_box->clear();
    38. this->Timesthespeed_box->addItem("1X");
    39. this->Timesthespeed_box->addItem("0.5X");
    40. this->Timesthespeed_box->addItem("1.5X");
    41. this->Timesthespeed_box->addItem("2X");
    42. //放置画面
    43. this->video_label->setStyleSheet("background-color: rgb(252,157,154)");
    44. //放置画面-接收画面加载
    45. this->video_label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//可拓展
    46. this->video_label->setMinimumSize(850,638);//最大最小尺寸
    47. this->topLayout->addWidget(video_label);
    48. this->topWidget->setLayout(topLayout);
    49. //控件设计
    50. this->bottomLayout->addWidget(play_btn);
    51. this->bottomLayout->addStretch(0);//弹簧
    52. this->bottomLayout->addWidget(Timesthespeed_box);
    53. this->bottomLayout->addWidget(screenshots_btn);
    54. this->bottomLayout->addWidget(export_btn);
    55. this->bottomWidget->setLayout(bottomLayout);//控件布局设计
    56. //整个布局比例
    57. this->totalLayout->addWidget(topWidget,9);//比例设计
    58. this->totalLayout->addWidget(bottomWidget,1);//比例设计
    59. this->setLayout(totalLayout);//整体布局
    60. }
    61. //按钮-信号槽机制
    62. void Play_Widget::init_connect()
    63. {
    64. //解码线程
    65. connect(Timesthespeed_box,SIGNAL(activated(QString)),decodeThread,SLOT(setSpeed(QString)));
    66. //视频暂停
    67. connect(play_btn, SIGNAL(clicked()), this, SLOT(continue_stop()));
    68. //接收图片
    69. connect(decodeThread, SIGNAL(sendImg2(QImage)), this, SLOT(receiveimg(QImage)));
    70. //截图
    71. connect(screenshots_btn, SIGNAL(clicked()), this, SLOT(screenshots()));
    72. //转码导出视频函数
    73. connect(export_btn, SIGNAL(clicked()), this, SLOT(trancetomp4()));
    74. }
    75. //接收图片槽函数
    76. void Play_Widget::receiveimg(QImage img)
    77. {
    78. this->Image =img;
    79. this->update();
    80. }
    81. //视频暂停函数
    82. void Play_Widget::continue_stop()
    83. {
    84. //如果标记为0,视频就开始
    85. if(this->mark==0)
    86. {
    87. decodeThread->status=0;
    88. this->mark=1;
    89. }
    90. //如果标记为1,视频就暂停
    91. else if(this->mark==1)
    92. {
    93. decodeThread->status=1;
    94. this->mark=0;
    95. }
    96. }
    97. //截图函数
    98. void Play_Widget::screenshots()
    99. {
    100. decodeThread->screenshots_mark=1;
    101. QMessageBox::warning(this, tr("提示!"),tr("截图成功!"),QMessageBox::Yes);
    102. }
    103. //转码导出视频函数
    104. void Play_Widget::trancetomp4()
    105. {
    106. //创建一个解码对象
    107. this->trance=new FTranceTomp4();
    108. //将视频路径传到解码
    109. this->trance->openH264File(path);
    110. this->trance->coverTomp4();
    111. QMessageBox::warning(this, tr("提示!"),tr("导出成功!"),QMessageBox::Yes);
    112. }
    113. //监控界面label控件接收图片事件
    114. void Play_Widget::paintEvent(QPaintEvent *)
    115. {
    116. if(!this->Image.isNull())
    117. {
    118. QPixmap *image = new QPixmap(QPixmap::fromImage(this->Image));
    119. image->scaled(video_label->size(),Qt::KeepAspectRatio);
    120. video_label->setPixmap(QPixmap::fromImage(this->Image));
    121. video_label->setScaledContents(true);
    122. }
    123. }

    23.Image_Widget.h .cpp

    1. #ifndef IMAGE_WIDGET_H
    2. #define IMAGE_WIDGET_H
    3. #include <QWidget>
    4. #include <QLabel>//标签文本
    5. #include <QHBoxLayout>//水平布局
    6. #include <QString>//字符串
    7. #include <QImage>//图片
    8. class Image_Widget : public QWidget
    9. {
    10. Q_OBJECT
    11. public:
    12. // explicit Image_Widget(QWidget *parent = 0);
    13. explicit Image_Widget(QString image_path,QWidget *parent = nullptr);//图片放大函数
    14. private:
    15. QLabel *image_label;//标签文本
    16. QHBoxLayout *totalLayout;//水平布局
    17. signals:
    18. public slots:
    19. };
    20. #endif // IMAGE_WIDGET_H
    1. #include "image_widget.h"
    2. //Image_Widget::Image_Widget(QWidget *parent) : QWidget(parent)
    3. //{
    4. //}
    5. //图片放大-构造函数
    6. Image_Widget::Image_Widget(QString image_path, QWidget *parent)
    7. {
    8. this->setWindowTitle("播放窗口画面");
    9. this->setFixedSize(640,481);
    10. this->totalLayout = new QHBoxLayout();//水平
    11. this->image_label = new QLabel();//放置画面
    12. QImage *image = new QImage(image_path);//获取画面
    13. this->image_label->setPixmap(QPixmap::fromImage(*image));//画面自适应载体
    14. this->image_label->setScaledContents(true);//图片自适应窗口控件大小
    15. this->totalLayout->addWidget(image_label);//播放窗口布局
    16. this->setLayout(totalLayout);//设置全局布局
    17. }

    main.cpp

    1. #include "setwidget.h"//设置界面
    2. #include"myview.h"//开始动画设置
    3. #include <QApplication>
    4. #include"loginwidget.h"//登录界面
    5. #include"registerwidget.h"//注册界面
    6. #include"main_monitorwidget.h"//监控界面
    7. #include"main_replaywidget.h"//回放界面
    8. #include"play_widget.h"//播放界面
    9. #include"main_widget.h"//主界面
    10. #include"image_widget.h"//图像界面
    11. #include<QDebug>//测试
    12. #include"sqlite3.h"//数据库
    13. //当前C++兼容C语言
    14. extern "C"
    15. {
    16. //avcodec:编解码(最重要的库)
    17. #include <libavcodec/avcodec.h>
    18. //avformat:封装格式处理
    19. #include <libavformat/avformat.h>
    20. //swscale:视频像素数据格式转换
    21. #include <libswscale/swscale.h>
    22. //avdevice:各种设备的输入输出
    23. #include <libavdevice/avdevice.h>
    24. //avutil:工具库(大部分库都需要这个库的支持)
    25. #include <libavutil/avutil.h>
    26. }
    27. int main(int argc, char *argv[])
    28. {
    29. QApplication a(argc, argv);
    30. // //测试环境是否成功搭建
    31. // qDebug()<<"sqlite3版本"<<sqlite3_libversion();
    32. // qDebug("-------------------------------------------------------------------");
    33. // qDebug("%s", avcodec_configuration());
    34. // qDebug("version: %d", avcodec_version());
    35. // qDebug("-------------------------------------------------------------------");
    36. //开机动画
    37. myView kaiji;//对象创建
    38. kaiji.show();//调用方法
    39. return a.exec();
    40. }
  • 相关阅读:
    [杂记]C++中移动语义与完美转发的一些理解
    通过自定义注解 +AOP 切片实现敏感词的过滤
    Shiro框架-史上详解
    电脑开机速度慢怎么解决?
    K8S Pod
    口感鲜美的健康饮品,随时补充营养恢复活力,厘盏蛋白银耳燕窝体验
    【CPP】CMake
    Azure Kubernetes(AKS)部署及查看应用资源
    CORS跨域资源共享+CORS的一系列响应头
    【754. 到达终点数字】
  • 原文地址:https://blog.csdn.net/m0_56051805/article/details/125283370