LightJoystickSwitchPage.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #include "LightJoystickSwitchPage.h"
  2. #include "ui_LightJoystickSwitchPage.h"
  3. #include "../common/JMessageTip.h"
  4. LightJoystickSwitchPage::LightJoystickSwitchPage(QWidget *parent)
  5. : QWidget(parent)
  6. , ui(new Ui::LightJoystickSwitchPage)
  7. {
  8. ui->setupUi(this);
  9. InitForm();
  10. }
  11. LightJoystickSwitchPage::~LightJoystickSwitchPage()
  12. {
  13. delete ui;
  14. }
  15. void LightJoystickSwitchPage::InitForm()
  16. {
  17. m_nTimeShowPos = startTimer(900);
  18. InitLineEdits();
  19. SliderBind();
  20. QDoubleValidator* validator = new QDoubleValidator(-1e12, 1e12, 6, this);
  21. ui->valLineEdit->setValidator(validator);
  22. }
  23. void LightJoystickSwitchPage::SliderBind()
  24. {
  25. connect(ui->RedLightverticalSlider, &QSlider::valueChanged, ui->RedLightprogressBar, &QProgressBar::setValue);
  26. connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar, &QProgressBar::setValue);
  27. connect(ui->GreenLightverticalSlider, &QSlider::valueChanged, ui->GreenLightprogressBar, &QProgressBar::setValue);
  28. connect(ui->DotLightverticalSlider, &QSlider::valueChanged, ui->DotLightprogressBar, &QProgressBar::setValue);
  29. BondSliderAndLineEdit(ui->RedLightverticalSlider, ui->RedLightlineEdit);
  30. BondSliderAndLineEdit(ui->GreenLightverticalSlider, ui->GreenLightlineEdit);
  31. BondSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit);
  32. BondSliderAndLineEdit(ui->DotLightverticalSlider, ui->DotLightlineEdit);
  33. }
  34. void LightJoystickSwitchPage::InitLineEdits()
  35. {
  36. ui->switchTabWidget->tabBar()->hide();
  37. QList<QLineEdit*> lineEdits = {
  38. ui->RedLightlineEdit, ui->GreenLightlineEdit,
  39. ui->BlueLightlineEdit, ui->DotLightlineEdit,
  40. };
  41. for (QLineEdit* lineEdit : lineEdits)
  42. {
  43. QRegExp regExp("^(0|([1-9]\\d?)|(1\\d{2})|(2[0-5]\\d))$");
  44. QRegExpValidator* validator = new QRegExpValidator(regExp, lineEdit);
  45. lineEdit->setValidator(validator);
  46. lineEdit->setAlignment(Qt::AlignCenter);
  47. }
  48. }
  49. void LightJoystickSwitchPage::BondSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  50. {
  51. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  52. lineEdit->setValidator(validator);
  53. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  54. lineEdit->setText(QString::number(value));
  55. });
  56. connect(lineEdit, &QLineEdit::textChanged, [&, slider, lineEdit](const QString& text)
  57. {
  58. bool ok;
  59. int value = text.toInt(&ok);
  60. if (ok && value >= slider->minimum() && value <= slider->maximum())
  61. {
  62. slider->setValue(value);
  63. }
  64. else if (!text.isEmpty())
  65. {
  66. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  67. slider->setValue(closestValue);
  68. }
  69. if (m_pPageSwitchGroup)
  70. {
  71. // 执行匹配灯光
  72. int niD = m_pPageSwitchGroup->m_nGroupId;
  73. if (niD == 1)
  74. {
  75. // 相机窗口
  76. if (m_pCameraBind)
  77. {
  78. m_pCameraBind->JSetRedLight(niD, MatchSelectedLightIndex(lineEdit), value);
  79. }
  80. }
  81. }
  82. });
  83. }
  84. void LightJoystickSwitchPage::setLigthValue(int redLight,int greenLight,int blueLight,int dotLight)
  85. {
  86. setLightWidget(redLight, ui->RedLight, ui->RedLightlineEdit, ui->RedLightverticalSlider, ui->RedLightprogressBar, ui->RedLightlabel);
  87. setLightWidget(greenLight, ui->GreenLight, ui->GreenLightlineEdit, ui->GreenLightverticalSlider, ui->GreenLightprogressBar, ui->GreenLightlabel);
  88. setLightWidget(blueLight, ui->BlueLight, ui->BlueLightlineEdit, ui->BlueLightverticalSlider, ui->BlueLightprogressBar, ui->BlueLightlabel);
  89. setLightWidget(dotLight, ui->DotLight, ui->DotLightlineEdit, ui->DotLightverticalSlider, ui->DotLightprogressBar, ui->DotLightlabel);
  90. }
  91. void LightJoystickSwitchPage::setLightWidget(int value, QWidget *lightWidget, QLineEdit *lineEdit, QSlider *slider, QProgressBar *progressBar, QLabel *label)
  92. {
  93. if (0 <= value && value <= 100)
  94. {
  95. lightWidget->show();
  96. lineEdit->show();
  97. slider->show();
  98. progressBar->show();
  99. label->show();
  100. lineEdit->setText(QString::number(value));
  101. progressBar->setValue(value);
  102. slider->setValue(value);
  103. }
  104. else if (value == -1)
  105. {
  106. lightWidget->hide();
  107. lineEdit->hide();
  108. slider->hide();
  109. progressBar->hide();
  110. label->hide();
  111. }
  112. }
  113. void LightJoystickSwitchPage::on_move_Button_clicked()
  114. {
  115. RunMoveOrMoveTo(false);
  116. }
  117. void LightJoystickSwitchPage::on_moveTo_Button_clicked()
  118. {
  119. RunMoveOrMoveTo(true);
  120. }
  121. void LightJoystickSwitchPage::on_left_Button_clicked()
  122. {
  123. m_moveAxisInfo.AxisType = "X";
  124. MoveJoystick();
  125. }
  126. void LightJoystickSwitchPage::on_up_Button_clicked()
  127. {
  128. m_moveAxisInfo.AxisType = "Y";
  129. MoveJoystick();
  130. }
  131. void LightJoystickSwitchPage::on_right_Button_clicked()
  132. {
  133. m_moveAxisInfo.AxisType = "X";
  134. MoveJoystick();
  135. }
  136. void LightJoystickSwitchPage::on_down_Button_clicked()
  137. {
  138. m_moveAxisInfo.AxisType = "Y";
  139. MoveJoystick();
  140. }
  141. void LightJoystickSwitchPage::GetModuleTypeSlots(const ST_MOVE_AXIS& _module)
  142. {
  143. SetMoveJoystickInfo(_module);
  144. }
  145. void LightJoystickSwitchPage::InitMainCameraBind(CameraBind* pCameraBind, bool bUpdate /*= true*/)
  146. {
  147. m_pCameraBind = pCameraBind;
  148. if (bUpdate)
  149. {
  150. UpdataLightVal();
  151. }
  152. }
  153. void LightJoystickSwitchPage::UpdatemPageGroup(Group* pGroup)
  154. {
  155. m_pPageSwitchGroup = pGroup;
  156. }
  157. void LightJoystickSwitchPage::SwitchJoystickPage(bool bSwitch)
  158. {
  159. ResetIdleTimer(bSwitch);
  160. int newIndex = (ui->switchTabWidget->currentIndex() + 1) % ui->switchTabWidget->count();
  161. ui->switchTabWidget->setCurrentIndex(newIndex);
  162. }
  163. void LightJoystickSwitchPage::HideOrShowPage(bool isHide)
  164. {
  165. ui->switchTabWidget->setVisible(isHide);
  166. }
  167. void LightJoystickSwitchPage::SetMoveJoystickInfo(const ST_MOVE_AXIS& movInfo)
  168. {
  169. //m_moveAxisInfo.ModuleType = movInfo.ModuleType;
  170. //m_moveAxisInfo.AxisType = movInfo.AxisType;
  171. //m_moveAxisInfo.pos = movInfo.pos; // 这个距离可能会变动// 根据摇杆区分等级
  172. m_moveAxisInfo = movInfo;
  173. if (m_moveAxisInfo.isSwitch)
  174. {
  175. // 点击摇杆的时候开启定时器,然后3秒关闭
  176. SwitchJoystickPage(true);
  177. }
  178. ui->JTabShowLable->setText(CombiningStr());
  179. }
  180. void LightJoystickSwitchPage::timerEvent(QTimerEvent* event)
  181. {
  182. int nID = event->timerId();
  183. if (m_nTimeShowPos == nID)
  184. {
  185. RealTimeUpdatesToU();
  186. }
  187. else if (m_idleTimer == nID)
  188. {
  189. SwitchJoystickPage(false);
  190. }
  191. }
  192. QString LightJoystickSwitchPage::CombiningStr(bool isUpdate /*= false*/)
  193. {
  194. double pos = m_moveAxisInfo.pos;
  195. QString strShow = tr("Currently selected mode:", "当前选中模式:");
  196. if (isUpdate)
  197. {
  198. strShow = tr("Move Pos:","移动点:");
  199. if (m_pCameraBind)
  200. {
  201. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, pos);
  202. }
  203. }
  204. strShow += m_moveAxisInfo.ModuleType.c_str();
  205. strShow += " ";
  206. strShow += m_moveAxisInfo.AxisType.c_str();
  207. strShow += " ";
  208. strShow += QString::number(pos, 'f', 2);
  209. return strShow;
  210. }
  211. void LightJoystickSwitchPage::RealTimeUpdatesToU()
  212. {
  213. if (m_pCameraBind)
  214. {
  215. ui->JTabShowLableLoop->setText(CombiningStr(true));
  216. }
  217. }
  218. void LightJoystickSwitchPage::ResetIdleTimer(bool bStart /*= false*/)
  219. {
  220. if (bStart)
  221. {
  222. if (m_idleTimer != -1)
  223. {
  224. // 计时器没关,关闭重新打开
  225. ResetIdleTimer(false);
  226. ResetIdleTimer(true);
  227. }
  228. if (isActiveWindow())
  229. {
  230. m_idleTimer = startTimer(g_unnSuspensionWaitingTime);
  231. }
  232. }
  233. else
  234. {
  235. killTimer(m_idleTimer);
  236. m_idleTimer = -1;
  237. }
  238. }
  239. void LightJoystickSwitchPage::MoveJoystick()
  240. {
  241. if (m_pCameraBind)
  242. {
  243. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, m_moveAxisInfo.pos);
  244. }
  245. }
  246. void LightJoystickSwitchPage::RunMoveOrMoveTo(bool isMoveTo)
  247. {
  248. QString strErrInfo = {};
  249. QString strNum = ui->valLineEdit->text().trimmed();
  250. if (strNum.isEmpty())
  251. {
  252. strErrInfo = tr("","请输入值");
  253. }
  254. else
  255. {
  256. double doNum = strNum.toDouble();
  257. if (m_moveAxisInfo.ModuleType != "")
  258. {
  259. if (m_moveAxisInfo.AxisType != "")
  260. {
  261. m_pCameraBind->SetModuleMove(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, doNum, isMoveTo);
  262. }
  263. else
  264. {
  265. strErrInfo = tr("AxisType is Empty", "AxisType 为空");
  266. }
  267. }
  268. else
  269. {
  270. strErrInfo = tr("ModuleType is Empty", "ModuleType 为空");
  271. }
  272. }
  273. if (!strErrInfo.isEmpty())
  274. {
  275. JMessageTip::Message_question(strErrInfo);
  276. }
  277. }
  278. void LightJoystickSwitchPage::UpdataLightVal()
  279. {
  280. if (m_pCameraBind->m_pCViewInterface == nullptr)
  281. {
  282. return;
  283. }
  284. if (m_pPageSwitchGroup)
  285. {
  286. int niD = m_pPageSwitchGroup->m_nGroupId;
  287. //if (niD == 1)
  288. {
  289. // 切换灯光
  290. ST_LIGHT_VAL _val = m_pCameraBind->JGetLight(niD);
  291. setLigthValue(_val.redLightValue, _val.greenLightValue, _val.blueLightValue, _val.pointLightValue);
  292. }
  293. }
  294. }
  295. EN_LIGHT_INDEX LightJoystickSwitchPage::MatchSelectedLightIndex(QLineEdit* lineEdit)
  296. {
  297. EN_LIGHT_INDEX nIndex = EN_LIGHT_INDEX::Red;
  298. if (lineEdit == ui->RedLightlineEdit)
  299. {
  300. nIndex = EN_LIGHT_INDEX::Red;
  301. }
  302. else if (lineEdit == ui->GreenLightlineEdit)
  303. {
  304. nIndex = EN_LIGHT_INDEX::Green;
  305. }
  306. else if (lineEdit == ui->BlueLightlineEdit)
  307. {
  308. nIndex = EN_LIGHT_INDEX::Blue;
  309. }
  310. else if (lineEdit == ui->DotLightlineEdit)
  311. {
  312. nIndex = EN_LIGHT_INDEX::Point;
  313. }
  314. return nIndex;
  315. }
  316. void LightJoystickSwitchPage::resizeSingleUI() {
  317. //ui->resize(265, 240)
  318. ui->switchTabWidget->setGeometry(QRect(0, 0, 265, 240));
  319. ui->GreenLightTab->setGeometry(QRect(0, 0, 60, 32));
  320. ui->JoystickTab->setGeometry(QRect(0, 0, 259, 215));
  321. ui->RedLight->setGeometry(QRect(0, 0, 61, 114));
  322. ui->RedLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  323. ui->RedLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  324. ui->RedLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  325. ui->RedLightlabel->setGeometry(QRect(39, 22, 10, 34));
  326. ui->GreenLight->setGeometry(QRect(70, 0, 61, 114));
  327. ui->GreenLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  328. ui->GreenLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  329. ui->GreenLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  330. ui->GreenLightlabel->setGeometry(QRect(36, 22, 10, 34));
  331. ui->BlueLight->setGeometry(QRect(140, 0, 61, 114));
  332. ui->BlueLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  333. ui->BlueLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  334. ui->BlueLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  335. ui->BlueLightlabel->setGeometry(QRect(32, 22, 19, 34));
  336. ui->DotLight->setGeometry(QRect(200, 0, 61, 114));
  337. ui->DotLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  338. ui->DotLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  339. ui->DotLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  340. ui->DotLightlabel->setGeometry(QRect(32, 22, 19, 34));
  341. ui->groupBox->setGeometry(QRect(0, 100, 141, 111));
  342. ui->left_Button->setGeometry(QRect(10, 40, 41, 31));
  343. ui->right_Button->setGeometry(QRect(90, 40, 41, 31));
  344. ui->up_Button->setGeometry(QRect(50, 10, 41, 31));
  345. ui->down_Button->setGeometry(QRect(50, 70, 41, 31));
  346. ui->move_Button->setGeometry(QRect(170, 130, 60, 23));
  347. ui->JTabShowLableLoop->setGeometry(QRect(10, 50, 200, 41));
  348. ui->moveTo_Button->setGeometry(QRect(170, 170, 60, 23));
  349. ui->valLineEdit->setGeometry(QRect(160, 100, 71, 21));
  350. ui->JTabShowLable->setGeometry(QRect(10, 0, 200, 40));
  351. }