LightJoystickSwitchPage.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #include "LightJoystickSwitchPage.h"
  2. #include "ui_LightJoystickSwitchPage.h"
  3. LightJoystickSwitchPage::LightJoystickSwitchPage(QWidget *parent)
  4. : QWidget(parent)
  5. , ui(new Ui::LightJoystickSwitchPage)
  6. {
  7. ui->setupUi(this);
  8. InitForm();
  9. }
  10. LightJoystickSwitchPage::~LightJoystickSwitchPage()
  11. {
  12. delete ui;
  13. }
  14. void LightJoystickSwitchPage::InitForm()
  15. {
  16. m_nTimeShowPos = startTimer(900);
  17. InitLineEdits();
  18. SliderBind();
  19. }
  20. void LightJoystickSwitchPage::SliderBind(){
  21. connect(ui->RedLightverticalSlider, &QSlider::valueChanged, ui->RedLightprogressBar, &QProgressBar::setValue);
  22. connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar, &QProgressBar::setValue);
  23. connect(ui->GreenLightverticalSlider, &QSlider::valueChanged, ui->GreenLightprogressBar, &QProgressBar::setValue);
  24. connect(ui->DotLightverticalSlider, &QSlider::valueChanged, ui->DotLightprogressBar, &QProgressBar::setValue);
  25. BondSliderAndLineEdit(ui->RedLightverticalSlider, ui->RedLightlineEdit);
  26. BondSliderAndLineEdit(ui->GreenLightverticalSlider, ui->GreenLightlineEdit);
  27. BondSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit);
  28. BondSliderAndLineEdit(ui->DotLightverticalSlider, ui->DotLightlineEdit);
  29. }
  30. void LightJoystickSwitchPage::InitLineEdits()
  31. {
  32. ui->switchTabWidget->tabBar()->hide();
  33. QList<QLineEdit*> lineEdits = {
  34. ui->RedLightlineEdit, ui->GreenLightlineEdit,
  35. ui->BlueLightlineEdit, ui->DotLightlineEdit,
  36. };
  37. for (QLineEdit* lineEdit : lineEdits)
  38. {
  39. QRegExp regExp("^(0|([1-9]\\d?)|(1\\d{2})|(2[0-5]\\d))$");
  40. QRegExpValidator* validator = new QRegExpValidator(regExp, lineEdit);
  41. lineEdit->setValidator(validator);
  42. lineEdit->setAlignment(Qt::AlignCenter);
  43. }
  44. }
  45. void LightJoystickSwitchPage::BondSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  46. {
  47. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  48. lineEdit->setValidator(validator);
  49. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  50. lineEdit->setText(QString::number(value));
  51. });
  52. connect(lineEdit, &QLineEdit::textChanged, [&, slider, lineEdit](const QString& text)
  53. {
  54. bool ok;
  55. int value = text.toInt(&ok);
  56. if (ok && value >= slider->minimum() && value <= slider->maximum())
  57. {
  58. slider->setValue(value);
  59. }
  60. else if (!text.isEmpty())
  61. {
  62. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  63. slider->setValue(closestValue);
  64. }
  65. if (m_pPageSwitchGroup)
  66. {
  67. // 执行匹配灯光
  68. int niD = m_pPageSwitchGroup->m_nGroupId;
  69. if (niD == 1)
  70. {
  71. // 相机窗口
  72. if (m_pCameraBind)
  73. {
  74. m_pCameraBind->JSetRedLight(niD, MatchSelectedLightIndex(lineEdit), value);
  75. }
  76. }
  77. }
  78. });
  79. }
  80. void LightJoystickSwitchPage::setLigthValue(int redLight,int greenLight,int blueLight,int dotLight)
  81. {
  82. setLightWidget(redLight, ui->RedLight, ui->RedLightlineEdit, ui->RedLightverticalSlider, ui->RedLightprogressBar, ui->RedLightlabel);
  83. setLightWidget(greenLight, ui->GreenLight, ui->GreenLightlineEdit, ui->GreenLightverticalSlider, ui->GreenLightprogressBar, ui->GreenLightlabel);
  84. setLightWidget(blueLight, ui->BlueLight, ui->BlueLightlineEdit, ui->BlueLightverticalSlider, ui->BlueLightprogressBar, ui->BlueLightlabel);
  85. setLightWidget(dotLight, ui->DotLight, ui->DotLightlineEdit, ui->DotLightverticalSlider, ui->DotLightprogressBar, ui->DotLightlabel);
  86. }
  87. void LightJoystickSwitchPage::setLightWidget(int value, QWidget *lightWidget, QLineEdit *lineEdit, QSlider *slider, QProgressBar *progressBar, QLabel *label)
  88. {
  89. if (0 <= value && value <= 100)
  90. {
  91. lightWidget->show();
  92. lineEdit->show();
  93. slider->show();
  94. progressBar->show();
  95. label->show();
  96. lineEdit->setText(QString::number(value));
  97. progressBar->setValue(value);
  98. slider->setValue(value);
  99. }
  100. else if (value == -1)
  101. {
  102. lightWidget->hide();
  103. lineEdit->hide();
  104. slider->hide();
  105. progressBar->hide();
  106. label->hide();
  107. }
  108. }
  109. void LightJoystickSwitchPage::on_move_Button_clicked()
  110. {
  111. }
  112. void LightJoystickSwitchPage::on_moveTo_Button_clicked()
  113. {
  114. if (m_pCameraBind)
  115. {
  116. // m_pCameraBind->YGetAxisPosition();
  117. }
  118. }
  119. void LightJoystickSwitchPage::on_left_Button_clicked()
  120. {
  121. m_moveAxisInfo.AxisType = "X";
  122. MoveJoystick();
  123. }
  124. void LightJoystickSwitchPage::on_up_Button_clicked()
  125. {
  126. m_moveAxisInfo.AxisType = "Y";
  127. MoveJoystick();
  128. }
  129. void LightJoystickSwitchPage::on_right_Button_clicked()
  130. {
  131. m_moveAxisInfo.AxisType = "X";
  132. MoveJoystick();
  133. }
  134. void LightJoystickSwitchPage::on_down_Button_clicked()
  135. {
  136. m_moveAxisInfo.AxisType = "Y";
  137. MoveJoystick();
  138. }
  139. void LightJoystickSwitchPage::InitMainCameraBind(CameraBind* pCameraBind)
  140. {
  141. m_pCameraBind.reset(pCameraBind);
  142. UpdataLightVal();
  143. }
  144. void LightJoystickSwitchPage::UpdatemPageGroup(Group* pGroup)
  145. {
  146. m_pPageSwitchGroup = pGroup;
  147. }
  148. void LightJoystickSwitchPage::SwitchJoystickPage(bool bSwitch)
  149. {
  150. ResetIdleTimer(bSwitch);
  151. int newIndex = (ui->switchTabWidget->currentIndex() + 1) % ui->switchTabWidget->count();
  152. ui->switchTabWidget->setCurrentIndex(newIndex);
  153. }
  154. void LightJoystickSwitchPage::HideOrShowPage(bool isHide)
  155. {
  156. ui->switchTabWidget->setVisible(isHide);
  157. }
  158. void LightJoystickSwitchPage::SetMoveJoystickInfo(const ST_MOVE_AXIS& movInfo)
  159. {
  160. m_moveAxisInfo.ModuleType = movInfo.ModuleType;
  161. m_moveAxisInfo.AxisType = movInfo.AxisType;
  162. m_moveAxisInfo.pos = movInfo.pos; // 这个距离可能会变动// 根据摇杆区分等级
  163. // 点击摇杆的时候开启定时器,然后3秒关闭
  164. SwitchJoystickPage(true);
  165. ui->JTabShowLable->setText(CombiningStr());
  166. }
  167. void LightJoystickSwitchPage::timerEvent(QTimerEvent* event)
  168. {
  169. int nID = event->timerId();
  170. if (m_nTimeShowPos == nID)
  171. {
  172. RealTimeUpdatesToU();
  173. }
  174. else if (m_idleTimer == nID)
  175. {
  176. SwitchJoystickPage(false);
  177. }
  178. }
  179. QString LightJoystickSwitchPage::CombiningStr(bool isUpdate /*= false*/)
  180. {
  181. double pos = m_moveAxisInfo.pos;
  182. QString strShow = tr("Currently selected mode:", "当前选中模式:");
  183. if (isUpdate)
  184. {
  185. strShow = tr("Move Pos:","移动点:");
  186. if (m_pCameraBind)
  187. {
  188. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, pos);
  189. }
  190. }
  191. strShow += m_moveAxisInfo.ModuleType.c_str();
  192. strShow += " ";
  193. strShow += m_moveAxisInfo.AxisType.c_str();
  194. strShow += " ";
  195. strShow += QString::number(pos, 'f', 2);
  196. return strShow;
  197. }
  198. void LightJoystickSwitchPage::RealTimeUpdatesToU()
  199. {
  200. if (m_pCameraBind)
  201. {
  202. ui->JTabShowLableLoop->setText(CombiningStr(true));
  203. }
  204. }
  205. void LightJoystickSwitchPage::ResetIdleTimer(bool bStart /*= false*/)
  206. {
  207. if (bStart)
  208. {
  209. if (isActiveWindow())
  210. {
  211. m_idleTimer = startTimer(3000);
  212. }
  213. }
  214. else
  215. {
  216. killTimer(m_idleTimer);
  217. m_idleTimer = -1;
  218. }
  219. }
  220. void LightJoystickSwitchPage::MoveJoystick()
  221. {
  222. if (m_pCameraBind)
  223. {
  224. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, m_moveAxisInfo.pos);
  225. }
  226. }
  227. void LightJoystickSwitchPage::UpdataLightVal()
  228. {
  229. if (m_pPageSwitchGroup)
  230. {
  231. int niD = m_pPageSwitchGroup->m_nGroupId;
  232. //if (niD == 1)
  233. {
  234. auto Fun = [&](QWidget* pWidget, QSlider* pSlider, int nVal) {
  235. if (nVal < 0)
  236. {
  237. // 设置不可用
  238. pWidget->setEnabled(false);
  239. pWidget->hide();
  240. }
  241. else
  242. {
  243. pSlider->setValue(nVal);
  244. }
  245. };
  246. // 切换灯光
  247. ST_LIGHT_VAL _val = m_pCameraBind->JGetLight(niD);
  248. Fun(ui->RedLight, ui->RedLightverticalSlider, _val.redLightValue);
  249. Fun(ui->GreenLight, ui->GreenLightverticalSlider, _val.greenLightValue);
  250. Fun(ui->BlueLight, ui->BlueLightverticalSlider, _val.blueLightValue);
  251. Fun(ui->DotLight, ui->DotLightverticalSlider, _val.pointLightValue);
  252. }
  253. }
  254. }
  255. EN_LIGHT_INDEX LightJoystickSwitchPage::MatchSelectedLightIndex(QLineEdit* lineEdit)
  256. {
  257. EN_LIGHT_INDEX nIndex = EN_LIGHT_INDEX::Red;
  258. if (lineEdit == ui->RedLightlineEdit)
  259. {
  260. nIndex = EN_LIGHT_INDEX::Red;
  261. }
  262. else if (lineEdit == ui->GreenLightlineEdit)
  263. {
  264. nIndex = EN_LIGHT_INDEX::Green;
  265. }
  266. else if (lineEdit == ui->BlueLightlineEdit)
  267. {
  268. nIndex = EN_LIGHT_INDEX::Blue;
  269. }
  270. else if (lineEdit == ui->DotLightlineEdit)
  271. {
  272. nIndex = EN_LIGHT_INDEX::Point;
  273. }
  274. return nIndex;
  275. }