You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoParse.cpp 8.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #include "VideoParse.h"
  2. #include <utility> /**< std::pair */
  3. #include "MyButton.h"
  4. VideoParse::VideoParse(QWidget* parent)
  5. : QWidget(parent)
  6. , m_pScrollLayout(nullptr)
  7. , m_pStandardItemModel(nullptr)
  8. , m_pSingleton(nullptr)
  9. , m_strExePath("")
  10. , m_uiParseStatus(0)
  11. {
  12. ui.setupUi(this);
  13. m_pSingleton = Singleton::CreateInstance();
  14. initParamList(); // 初始化参数列表
  15. initScrollArea(); // 初始化滚动区域
  16. }
  17. VideoParse::~VideoParse()
  18. {
  19. delete m_pScrollLayout;
  20. m_pScrollLayout = nullptr;
  21. ClearVideoWidgets();
  22. }
  23. // 初始化参数列表
  24. void VideoParse::initParamList()
  25. {
  26. if (m_pStandardItemModel) {
  27. m_pStandardItemModel->clear();
  28. delete m_pStandardItemModel;
  29. m_pStandardItemModel = nullptr;
  30. }
  31. m_pStandardItemModel = new QStandardItemModel();
  32. m_pStandardItemModel->setColumnCount(4);
  33. m_pStandardItemModel->setHorizontalHeaderLabels(
  34. {"参数名称", "参数代号", "执行操作", "编号索引"});
  35. ui.tv_videoList->setModel(m_pStandardItemModel);
  36. ui.tv_videoList->setColumnWidth(0, 120); // 第一列
  37. ui.tv_videoList->setColumnWidth(1, 80); // 第二列
  38. ui.tv_videoList->setColumnWidth(2, 80); // 第三列
  39. ui.tv_videoList->setColumnWidth(3, 80); // 第四列
  40. ui.tv_videoList->header()->setDefaultAlignment(Qt::AlignCenter); // 设置表头居中
  41. ui.tv_videoList->setColumnHidden(3, true); // 编号索引列隐藏
  42. // 树状结构样式表
  43. ui.tv_videoList->setStyleSheet("QTreeView::item{min-height:30px;align:center;}");
  44. }
  45. void VideoParse::initScrollArea()
  46. {
  47. m_pScrollLayout = new QGridLayout(ui.sa_wgtContent);
  48. }
  49. void VideoParse::ClearVideoWidgets()
  50. {
  51. for (auto curveWidget : m_mapIntVideoWidget) {
  52. if (curveWidget.second) {
  53. curveWidget.second->close();
  54. delete curveWidget.second;
  55. curveWidget.second = nullptr;
  56. }
  57. }
  58. m_mapIntVideoWidget.clear();
  59. }
  60. void VideoParse::switchModelType(QString modeltype)
  61. {
  62. ClearVideoWidgets();
  63. QMutexLocker locker(&m_mutex);
  64. m_mapStrConfigInfo = m_pSingleton->getConfigInfo();
  65. initParamList(); // 初始化参数列表
  66. int count = 1;
  67. auto configIter = m_mapStrConfigInfo.find(modeltype);
  68. if (configIter != m_mapStrConfigInfo.end()) {
  69. // 添加节点信息
  70. QStandardItem* m_frameItem = new QStandardItem(configIter->first);
  71. m_pStandardItemModel->appendRow(m_frameItem);
  72. m_frameItem->setCheckable(false);
  73. for (auto param : configIter->second->m_mapUIntParam) {
  74. if (param.second->m_usModel != 3) {
  75. continue;
  76. }
  77. // 参数名称
  78. QString strTitle = param.second->m_strTitle;
  79. QStandardItem* m_pTitleItem = new QStandardItem(strTitle);
  80. m_frameItem->appendRow(m_pTitleItem);
  81. // 参数代号
  82. QString strCode = param.second->m_strCode;
  83. QStandardItem* m_pCodeItem = new QStandardItem(strCode);
  84. m_frameItem->setChild(m_pTitleItem->index().row(), 1, m_pCodeItem);
  85. // 执行操作
  86. QStandardItem* m_pOperaItem = new QStandardItem("");
  87. m_frameItem->setChild(m_pTitleItem->index().row(), 2, m_pOperaItem);
  88. MyButton* m_pOperaBtn = new MyButton(m_pOperaItem, this); // 显示操作
  89. m_pOperaBtn->setFixedSize(50, 20);
  90. m_pOperaBtn->setText("图像");
  91. m_pOperaBtn->setStyleSheet(
  92. "font-size:14px;\n"
  93. "border:solid 1px;\n"
  94. "background:white;\n"
  95. "font-family:PingFangSC-Regular,PingFang SC;\n"
  96. "font-weight:400;\n"
  97. "color:#155bd4;\n"
  98. "line-height:20px;");
  99. connect(m_pOperaBtn, &MyButton::onSingleClick, this, &VideoParse::operateItem);
  100. QHBoxLayout* m_pHBoxLayout = new QHBoxLayout();
  101. m_pHBoxLayout->setMargin(5);
  102. // m_pHBoxLayout->addStretch(); //拉伸
  103. m_pHBoxLayout->addWidget(m_pOperaBtn);
  104. // m_pHBoxLayout->addStretch(); //拉伸
  105. QWidget* m_pOperaWidget = new QWidget();
  106. m_pOperaWidget->setFixedSize(60, 30);
  107. m_pOperaWidget->setLayout(m_pHBoxLayout);
  108. ui.tv_videoList->setIndexWidget(m_pOperaItem->index(), m_pOperaWidget);
  109. // 创建视频窗口
  110. {
  111. if ("图像" == m_pOperaBtn->text()) {
  112. VideoWidget* m_pVideoWidget = new VideoWidget(ui.sa_wgtContent);
  113. connect(m_pVideoWidget, &VideoWidget::popupVideoWidget, this,
  114. &VideoParse::popupVideoWidget);
  115. connect(m_pVideoWidget, &VideoWidget::hideVideoWidget, this,
  116. &VideoParse::hideVideoWidget);
  117. connect(this, &VideoParse::setParseStatus, m_pVideoWidget,
  118. &VideoWidget::setParseStatus);
  119. m_pVideoWidget->setParam(strTitle, count);
  120. m_pVideoWidget->setWidgetEmbedded(true); // 窗口内嵌
  121. m_pVideoWidget->getFfmpegDecode()->setParam(param.second->m_usFormat,
  122. param.second->m_uiWidth,
  123. param.second->m_uiHeight);
  124. m_pVideoWidget->getFfmpegDecode()->init();
  125. m_pVideoWidget->setVisible(false);
  126. m_mapIntVideoWidget.insert(pair<int, VideoWidget*>(count, m_pVideoWidget));
  127. param.second->setVideoWidget(m_pVideoWidget);
  128. }
  129. }
  130. // 编号索引
  131. QStandardItem* m_pIndexItem = new QStandardItem(QString::number(count));
  132. m_frameItem->setChild(m_pTitleItem->index().row(), 3, m_pIndexItem);
  133. m_pIndexItem->setTextAlignment(Qt::AlignCenter);
  134. ++count;
  135. }
  136. } else {
  137. qDebug() << "The model type(" << modeltype << ") is unsupported!";
  138. }
  139. }
  140. void VideoParse::operateItem(QStandardItem* item, QPushButton* button)
  141. {
  142. QModelIndex index = item->index();
  143. // 参数名称
  144. QString strTitle = index.sibling(index.row(), 0).data().toString();
  145. // 编号索引
  146. int count = index.sibling(index.row(), 3).data().toInt();
  147. if ("图像" == button->text()) { // 图像
  148. for (auto iter : m_mapIntVideoWidget) {
  149. m_pScrollLayout->removeWidget(iter.second);
  150. }
  151. // Relayout
  152. size_t i = 0;
  153. for (auto iter : m_mapIntVideoWidget) {
  154. if (count == iter.first) {
  155. iter.second->setVisible(!iter.second->isVisible());
  156. }
  157. if (iter.second->isVisible()) {
  158. m_pScrollLayout->addWidget(iter.second, i / 2, i % 2);
  159. i++;
  160. }
  161. }
  162. }
  163. }
  164. void VideoParse::popupVideoWidget(QString title, int count, bool embedded)
  165. {
  166. auto mapIter = m_mapIntVideoWidget.begin();
  167. while (mapIter != m_mapIntVideoWidget.end()) {
  168. VideoWidget* videoWidget = mapIter->second;
  169. if (title == videoWidget->getTitle() && count == videoWidget->getCount()) {
  170. if (embedded == true) {
  171. // 将窗口的父窗口改为桌面
  172. videoWidget->setParent(nullptr);
  173. videoWidget->setWidgetEmbedded(false);
  174. WgtRect wgtRect = videoWidget->getWgtRect();
  175. int iWgtPosX = (wgtRect.m_iMaxWidth - wgtRect.m_iWgtWidth) / 2;
  176. int iWgtPosY = (wgtRect.m_iMaxHeight - wgtRect.m_iWgtHeight) / 2;
  177. videoWidget->setGeometry(iWgtPosX, iWgtPosY, wgtRect.m_iWgtWidth,
  178. wgtRect.m_iWgtHeight);
  179. videoWidget->show();
  180. videoWidget->fitInView();
  181. } else if (embedded == false) {
  182. // 将窗口的父窗口改为桌面
  183. videoWidget->setParent(ui.sa_wgtContent);
  184. videoWidget->setWidgetEmbedded(true);
  185. videoWidget->show();
  186. }
  187. break;
  188. }
  189. ++mapIter;
  190. }
  191. }
  192. void VideoParse::hideVideoWidget(int count)
  193. {
  194. // 移除所关闭的视频窗口
  195. m_mapIntVideoWidget.at(count)->hide();
  196. }
  197. void VideoParse::parseStatus(unsigned int status)
  198. {
  199. m_uiParseStatus = status;
  200. emit setParseStatus(m_uiParseStatus);
  201. }