compareitemdialog.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #include "compareitemdialog.h"
  2. #include "ui_compareitemwidget.h"
  3. #include "UIStyleManager.h"
  4. #include "SoundCardData.h"
  5. #include "tipwidget.h"
  6. CompareItemDialog::CompareItemDialog(QWidget *parent)
  7. : DialogBase(parent)
  8. , ui(new Ui::CompareItemWidget)
  9. {
  10. QWidget *widgetContent = new QWidget(this);
  11. ui->setupUi(widgetContent);
  12. /* 设置内容 */
  13. setContentWidget(widgetContent);
  14. /* 设置标题 */
  15. setTitle("对比项信息", QSize(120, 18));
  16. /* 连接信号和槽 */
  17. connect(ui->pBtn_add, &QPushButton::clicked, this, &CompareItemDialog::do_pBtn_add_clicked);
  18. /* 连接静音、过载、反相三个按钮的开关 */
  19. connect(ui->checkBoxMute, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
  20. connect(ui->checkBoxOverload, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
  21. connect(ui->checkBoxPhase, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
  22. /* 设置默认开启 */
  23. ui->checkBoxMute->setChecked(true);
  24. ui->checkBoxOverload->setChecked(true);
  25. ui->checkBoxPhase->setChecked(true);
  26. /* 设置已有两个通道的可选录音通道 */
  27. ui->widget_mainRoad->setSoundCardRoadList(SoundCards.getSoundCardRoadList());
  28. ui->widget_secondRoad->setSoundCardRoadList(SoundCards.getSoundCardRoadList());
  29. /* 设置样式 */
  30. setQSS();
  31. }
  32. CompareItemDialog::~CompareItemDialog()
  33. {
  34. delete ui;
  35. }
  36. /* 获取生成的对比项信息 */
  37. CompareItemInfo_t& CompareItemDialog::getCompareItemInfo()
  38. {
  39. return m_compareItemInfo;
  40. }
  41. /* 新增通道 */
  42. void CompareItemDialog::do_pBtn_add_clicked()
  43. {
  44. QVBoxLayout* pLayout = qobject_cast<QVBoxLayout*>(ui->scrollAreaWidgetContents->layout());
  45. if(pLayout)
  46. {
  47. SingleCompareRoadWidget *pWgt = new SingleCompareRoadWidget(this);
  48. connect(pWgt, &SingleCompareRoadWidget::deleted, this, &CompareItemDialog::do_CompareRoadWgtDeleted);
  49. pWgt->setIndex(m_listOtherRoadWgt.size() + 3);
  50. pWgt->setDelBtnVisible(true);
  51. /* 设置可选通道列表 */
  52. pWgt->setSoundCardRoadList(SoundCards.getSoundCardRoadList());
  53. pWgt->setStyleSheet(m_qssRecordRoad);
  54. pLayout->insertWidget(m_listOtherRoadWgt.size(), pWgt);
  55. m_listOtherRoadWgt.append(pWgt);
  56. }
  57. }
  58. /* 删除通道 */
  59. void CompareItemDialog::do_CompareRoadWgtDeleted(int nIndex)
  60. {
  61. int nRealIndex = nIndex - 3;
  62. if(nRealIndex < m_listOtherRoadWgt.size())
  63. {
  64. SingleCompareRoadWidget *pWgt = m_listOtherRoadWgt.at(nRealIndex);
  65. m_listOtherRoadWgt.removeOne(pWgt);
  66. delete pWgt;
  67. pWgt = nullptr;
  68. }
  69. for(int i = nRealIndex; i < m_listOtherRoadWgt.size(); i++)
  70. {
  71. m_listOtherRoadWgt.at(i)->setIndex(i + 3);
  72. }
  73. }
  74. /* 静音、过载、反相检测条件开关 */
  75. void CompareItemDialog::do_checkBox_MOP_clicked(bool checked)
  76. {
  77. /* 获取信号发送者 */
  78. QCheckBox *checkBox = qobject_cast<QCheckBox*>(sender());
  79. checkBox->setText(checked ? "开启" : "关闭");
  80. if(checkBox == ui->checkBoxMute)
  81. {
  82. setMOPEditable(EDBType::DBType_Mute, checked);
  83. }
  84. else if(checkBox == ui->checkBoxOverload)
  85. {
  86. setMOPEditable(EDBType::DBType_Overload, checked);
  87. }
  88. else if(checkBox == ui->checkBoxPhase)
  89. {
  90. setMOPEditable(EDBType::DBType_Phase, checked);
  91. }
  92. }
  93. /* 设置样式表 */
  94. void CompareItemDialog::setQSS()
  95. {
  96. QString qssPath = UIStyle.getQSSPath() + "/compareitemwidget.qss";
  97. QFile file(qssPath);
  98. if(file.open(QFile::ReadOnly))
  99. {
  100. QString qss = file.readAll();
  101. file.close();
  102. /* 这里设置的是内容容器样式表,this是最外层的 */
  103. getContentWidget()->setStyleSheet(qss);
  104. ui->scrollArea->setStyleSheet(qss);
  105. ui->scrollAreaWidgetContents->setStyleSheet(qss);
  106. } else
  107. {
  108. SPDLOG_LOGGER_ERROR(m_logger, "打开QSS文件失败: {}", qssPath.toStdString());
  109. SPDLOG_LOGGER_ERROR(m_logger, "错误信息: {}", file.errorString().toStdString());
  110. }
  111. /* 清除父类的qss */
  112. // this->setStyleSheet("");
  113. // SPDLOG_LOGGER_INFO(m_logger, "qss: {}", getContentWidget()->styleSheet().toStdString());
  114. // ui->scrollArea->viewport()->setStyleSheet("background-color: #FFFFFF;"); // 设置滚动区域背景透明
  115. file.setFileName(UIStyle.getQSSPath() + "/singlecompareroadwidget.qss");
  116. if(file.open(QFile::ReadOnly))
  117. {
  118. m_qssRecordRoad = file.readAll();
  119. file.close();
  120. } else
  121. {
  122. SPDLOG_LOGGER_ERROR(m_logger, "打开QSS文件失败: {}", file.fileName().toStdString());
  123. SPDLOG_LOGGER_ERROR(m_logger, "错误信息: {}", file.errorString().toStdString());
  124. }
  125. ui->widget_mainRoad->setStyleSheet(m_qssRecordRoad);
  126. ui->widget_secondRoad->setStyleSheet(m_qssRecordRoad);
  127. }
  128. /* 设置静音过载反相可编辑 */
  129. void CompareItemDialog::setMOPEditable(EDBType type, bool editable)
  130. {
  131. if(type == EDBType::DBType_Mute)
  132. {
  133. if(editable)
  134. {
  135. ui->lineEditMuteLen->setEnabled(true);
  136. ui->lineEditMuteSensibility->setEnabled(true);
  137. ui->lineEditMuteThreshold->setEnabled(true);
  138. }else {
  139. ui->lineEditMuteLen->setEnabled(false);
  140. ui->lineEditMuteSensibility->setEnabled(false);
  141. ui->lineEditMuteThreshold->setEnabled(false);
  142. }
  143. }
  144. else if(type == EDBType::DBType_Overload)
  145. {
  146. if(editable)
  147. {
  148. ui->lineEditOverloadLen->setEnabled(true);
  149. ui->lineEditOverloadSensibility->setEnabled(true);
  150. ui->lineEditOverloadThreshold->setEnabled(true);
  151. }else {
  152. ui->lineEditOverloadLen->setEnabled(false);
  153. ui->lineEditOverloadSensibility->setEnabled(false);
  154. ui->lineEditOverloadThreshold->setEnabled(false);
  155. }
  156. }
  157. else if(type == EDBType::DBType_Phase)
  158. {
  159. if(editable)
  160. {
  161. ui->lineEditPhaseLen->setEnabled(true);
  162. ui->lineEditPhaseSensibility->setEnabled(true);
  163. ui->lineEditPhaseThreshold->setEnabled(true);
  164. }else {
  165. ui->lineEditPhaseLen->setEnabled(false);
  166. ui->lineEditPhaseSensibility->setEnabled(false);
  167. ui->lineEditPhaseThreshold->setEnabled(false);
  168. }
  169. }
  170. }
  171. /* 重载按下关闭按钮之前的操作 */
  172. bool CompareItemDialog::isOKClicked()
  173. {
  174. /* 获取对比项的信息 */
  175. if(!getCompareItemBaseInfo(m_compareItemInfo))
  176. {
  177. return false;
  178. }
  179. /* 获取录音通道信息 */
  180. if(!getCompareRoadInfo(m_compareItemInfo))
  181. {
  182. return false;
  183. }
  184. /* 获取音频检测信息 */
  185. return true;
  186. }
  187. /* 获取对比项的基础信息 */
  188. bool CompareItemDialog::getCompareItemBaseInfo(CompareItemInfo_t& compareItemInfo)
  189. {
  190. if(ui->lineEdit_compareItmName->text().isEmpty())
  191. {
  192. TipWidget::display(TipWidget::OPERATOR_WARN, "对比项名称不能为空");
  193. return false;
  194. }
  195. compareItemInfo.strName = ui->lineEdit_compareItmName->text();
  196. compareItemInfo.isEnable = ui->checkBox_enable->isChecked();
  197. return true;
  198. }
  199. /* 获取各个通道信息 */
  200. bool CompareItemDialog::getCompareRoadInfo(CompareItemInfo_t& compareItemInfo)
  201. {
  202. compareItemInfo.listRoads.clear();
  203. /* 获取主通道信息 */
  204. CompareItemRoadInfo_t mainRoadInfo;
  205. mainRoadInfo.nCompareRoadNum = 1;
  206. mainRoadInfo.strCompareRoadName = ui->widget_mainRoad->getRoadName();
  207. if(mainRoadInfo.strCompareRoadName.isEmpty())
  208. {
  209. TipWidget::display(TipWidget::OPERATOR_WARN, "主通道名称不能为空");
  210. return false;
  211. }
  212. return true;
  213. }
  214. /* 获取音频检测信息 */
  215. bool CompareItemDialog::getAudioDetectInfo(CompareItemInfo_t& compareItemInfo)
  216. {
  217. return true;
  218. }