|
- #include "VideoParse.h"
-
- #include <utility> /**< std::pair */
-
- #include "MyButton.h"
-
- VideoParse::VideoParse(QWidget* parent)
- : QWidget(parent)
- , m_pScrollLayout(nullptr)
- , m_pStandardItemModel(nullptr)
- , m_pSingleton(nullptr)
- , m_strExePath("")
- , m_uiParseStatus(0)
- {
- ui.setupUi(this);
- m_pSingleton = Singleton::CreateInstance();
- initParamList(); // 初始化参数列表
- initScrollArea(); // 初始化滚动区域
- }
-
- VideoParse::~VideoParse()
- {
- delete m_pScrollLayout;
- m_pScrollLayout = nullptr;
-
- ClearVideoWidgets();
- }
-
- // 初始化参数列表
- void VideoParse::initParamList()
- {
- if (m_pStandardItemModel) {
- m_pStandardItemModel->clear();
- delete m_pStandardItemModel;
- m_pStandardItemModel = nullptr;
- }
- m_pStandardItemModel = new QStandardItemModel();
- m_pStandardItemModel->setColumnCount(4);
- m_pStandardItemModel->setHorizontalHeaderLabels(
- {"参数名称", "参数代号", "执行操作", "编号索引"});
- ui.tv_videoList->setModel(m_pStandardItemModel);
- ui.tv_videoList->setColumnWidth(0, 120); // 第一列
- ui.tv_videoList->setColumnWidth(1, 80); // 第二列
- ui.tv_videoList->setColumnWidth(2, 80); // 第三列
- ui.tv_videoList->setColumnWidth(3, 80); // 第四列
- ui.tv_videoList->header()->setDefaultAlignment(Qt::AlignCenter); // 设置表头居中
- ui.tv_videoList->setColumnHidden(3, true); // 编号索引列隐藏
- // 树状结构样式表
- ui.tv_videoList->setStyleSheet("QTreeView::item{min-height:30px;align:center;}");
- }
-
- void VideoParse::initScrollArea()
- {
- m_pScrollLayout = new QGridLayout(ui.sa_wgtContent);
- }
-
- void VideoParse::ClearVideoWidgets()
- {
- for (auto curveWidget : m_mapIntVideoWidget) {
- if (curveWidget.second) {
- curveWidget.second->close();
- delete curveWidget.second;
- curveWidget.second = nullptr;
- }
- }
- m_mapIntVideoWidget.clear();
- }
-
- void VideoParse::switchModelType(QString modeltype)
- {
- ClearVideoWidgets();
-
- QMutexLocker locker(&m_mutex);
- m_mapStrConfigInfo = m_pSingleton->getConfigInfo();
- initParamList(); // 初始化参数列表
-
- int count = 1;
- auto configIter = m_mapStrConfigInfo.find(modeltype);
- if (configIter != m_mapStrConfigInfo.end()) {
- // 添加节点信息
- QStandardItem* m_frameItem = new QStandardItem(configIter->first);
- m_pStandardItemModel->appendRow(m_frameItem);
- m_frameItem->setCheckable(false);
- for (auto param : configIter->second->m_mapUIntParam) {
- if (param.second->m_usModel != 3) {
- continue;
- }
- // 参数名称
- QString strTitle = param.second->m_strTitle;
- QStandardItem* m_pTitleItem = new QStandardItem(strTitle);
- m_frameItem->appendRow(m_pTitleItem);
- // 参数代号
- QString strCode = param.second->m_strCode;
- QStandardItem* m_pCodeItem = new QStandardItem(strCode);
- m_frameItem->setChild(m_pTitleItem->index().row(), 1, m_pCodeItem);
- // 执行操作
- QStandardItem* m_pOperaItem = new QStandardItem("");
- m_frameItem->setChild(m_pTitleItem->index().row(), 2, m_pOperaItem);
- MyButton* m_pOperaBtn = new MyButton(m_pOperaItem, this); // 显示操作
- m_pOperaBtn->setFixedSize(50, 20);
- m_pOperaBtn->setText("图像");
- m_pOperaBtn->setStyleSheet(
- "font-size:14px;\n"
- "border:solid 1px;\n"
- "background:white;\n"
- "font-family:PingFangSC-Regular,PingFang SC;\n"
- "font-weight:400;\n"
- "color:#155bd4;\n"
- "line-height:20px;");
- connect(m_pOperaBtn, &MyButton::onSingleClick, this, &VideoParse::operateItem);
- QHBoxLayout* m_pHBoxLayout = new QHBoxLayout();
- m_pHBoxLayout->setMargin(5);
- // m_pHBoxLayout->addStretch(); //拉伸
- m_pHBoxLayout->addWidget(m_pOperaBtn);
- // m_pHBoxLayout->addStretch(); //拉伸
- QWidget* m_pOperaWidget = new QWidget();
- m_pOperaWidget->setFixedSize(60, 30);
- m_pOperaWidget->setLayout(m_pHBoxLayout);
- ui.tv_videoList->setIndexWidget(m_pOperaItem->index(), m_pOperaWidget);
- // 创建视频窗口
- {
- if ("图像" == m_pOperaBtn->text()) {
- VideoWidget* m_pVideoWidget = new VideoWidget(ui.sa_wgtContent);
- connect(m_pVideoWidget, &VideoWidget::popupVideoWidget, this,
- &VideoParse::popupVideoWidget);
- connect(m_pVideoWidget, &VideoWidget::hideVideoWidget, this,
- &VideoParse::hideVideoWidget);
- connect(this, &VideoParse::setParseStatus, m_pVideoWidget,
- &VideoWidget::setParseStatus);
- m_pVideoWidget->setParam(strTitle, count);
- m_pVideoWidget->setWidgetEmbedded(true); // 窗口内嵌
- m_pVideoWidget->getFfmpegDecode()->setParam(param.second->m_usFormat,
- param.second->m_uiWidth,
- param.second->m_uiHeight);
- m_pVideoWidget->getFfmpegDecode()->init();
- m_pVideoWidget->setVisible(false);
- m_mapIntVideoWidget.insert(pair<int, VideoWidget*>(count, m_pVideoWidget));
- param.second->setVideoWidget(m_pVideoWidget);
- }
- }
- // 编号索引
- QStandardItem* m_pIndexItem = new QStandardItem(QString::number(count));
- m_frameItem->setChild(m_pTitleItem->index().row(), 3, m_pIndexItem);
- m_pIndexItem->setTextAlignment(Qt::AlignCenter);
- ++count;
- }
- } else {
- qDebug() << "The model type(" << modeltype << ") is unsupported!";
- }
- }
-
- void VideoParse::operateItem(QStandardItem* item, QPushButton* button)
- {
- QModelIndex index = item->index();
- // 参数名称
- QString strTitle = index.sibling(index.row(), 0).data().toString();
- // 编号索引
- int count = index.sibling(index.row(), 3).data().toInt();
- if ("图像" == button->text()) { // 图像
- for (auto iter : m_mapIntVideoWidget) {
- m_pScrollLayout->removeWidget(iter.second);
- }
-
- // Relayout
- size_t i = 0;
- for (auto iter : m_mapIntVideoWidget) {
- if (count == iter.first) {
- iter.second->setVisible(!iter.second->isVisible());
- }
-
- if (iter.second->isVisible()) {
- m_pScrollLayout->addWidget(iter.second, i / 2, i % 2);
- i++;
- }
- }
- }
- }
-
- void VideoParse::popupVideoWidget(QString title, int count, bool embedded)
- {
- auto mapIter = m_mapIntVideoWidget.begin();
- while (mapIter != m_mapIntVideoWidget.end()) {
- VideoWidget* videoWidget = mapIter->second;
- if (title == videoWidget->getTitle() && count == videoWidget->getCount()) {
- if (embedded == true) {
- // 将窗口的父窗口改为桌面
- videoWidget->setParent(nullptr);
- videoWidget->setWidgetEmbedded(false);
- WgtRect wgtRect = videoWidget->getWgtRect();
- int iWgtPosX = (wgtRect.m_iMaxWidth - wgtRect.m_iWgtWidth) / 2;
- int iWgtPosY = (wgtRect.m_iMaxHeight - wgtRect.m_iWgtHeight) / 2;
- videoWidget->setGeometry(iWgtPosX, iWgtPosY, wgtRect.m_iWgtWidth,
- wgtRect.m_iWgtHeight);
- videoWidget->show();
- videoWidget->fitInView();
- } else if (embedded == false) {
- // 将窗口的父窗口改为桌面
- videoWidget->setParent(ui.sa_wgtContent);
- videoWidget->setWidgetEmbedded(true);
- videoWidget->show();
- }
- break;
- }
- ++mapIter;
- }
- }
-
- void VideoParse::hideVideoWidget(int count)
- {
- // 移除所关闭的视频窗口
- m_mapIntVideoWidget.at(count)->hide();
- }
-
- void VideoParse::parseStatus(unsigned int status)
- {
- m_uiParseStatus = status;
- emit setParseStatus(m_uiParseStatus);
- }
|