LightJoystickSwitchPage.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. #include "LightJoystickSwitchPage.h"
  2. #include "ui_LightJoystickSwitchPage.h"
  3. #include "../common/JMessageTip.h"
  4. #include "../common/JQCommon.h"
  5. LightJoystickSwitchPage::LightJoystickSwitchPage(QWidget *parent)
  6. : QWidget(parent)
  7. , ui(new Ui::LightJoystickSwitchPage)
  8. {
  9. ui->setupUi(this);
  10. InitForm();
  11. }
  12. LightJoystickSwitchPage::~LightJoystickSwitchPage()
  13. {
  14. delete ui;
  15. }
  16. void LightJoystickSwitchPage::InitForm()
  17. {
  18. m_nTimeShowPos = startTimer(900);
  19. InitLineEdits();
  20. SliderBind();
  21. JQCommon::SetQLineEditLimit(ui->valLineEdit);
  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. m_isSlots = true;
  144. SetMoveJoystickInfo(_module);
  145. }
  146. void LightJoystickSwitchPage::InitMainCameraBind(CameraBind* pCameraBind, bool bUpdate /*= true*/)
  147. {
  148. m_pCameraBind = pCameraBind;
  149. if (bUpdate)
  150. {
  151. UpdataLightVal();
  152. }
  153. }
  154. void LightJoystickSwitchPage::UpdatemPageGroup(Group* pGroup)
  155. {
  156. m_pPageSwitchGroup = pGroup;
  157. }
  158. void LightJoystickSwitchPage::SwitchJoystickPage(bool bSwitch)
  159. {
  160. ResetIdleTimer(bSwitch);
  161. //int newIndex = (ui->switchTabWidget->currentIndex() + 1) % ui->switchTabWidget->count();
  162. if (m_isSlots)
  163. {
  164. ui->switchTabWidget->setCurrentIndex(1);
  165. }
  166. else
  167. {
  168. ui->switchTabWidget->setCurrentIndex(0);
  169. }
  170. m_isSlots = false;
  171. }
  172. void LightJoystickSwitchPage::HideOrShowPage(bool isHide)
  173. {
  174. ui->switchTabWidget->setVisible(isHide);
  175. }
  176. void LightJoystickSwitchPage::SetMoveJoystickInfo(const ST_MOVE_AXIS& movInfo)
  177. {
  178. //m_moveAxisInfo.ModuleType = movInfo.ModuleType;
  179. //m_moveAxisInfo.AxisType = movInfo.AxisType;
  180. //m_moveAxisInfo.pos = movInfo.pos; // 这个距离可能会变动// 根据摇杆区分等级
  181. m_moveAxisInfo = movInfo;
  182. if (m_moveAxisInfo.isSwitch)
  183. {
  184. // 点击摇杆的时候开启定时器,然后3秒关闭
  185. SwitchJoystickPage(true);
  186. }
  187. ui->JTabShowLable->setText(CombiningStr());
  188. }
  189. void LightJoystickSwitchPage::timerEvent(QTimerEvent* event)
  190. {
  191. int nID = event->timerId();
  192. if (m_nTimeShowPos == nID)
  193. {
  194. RealTimeUpdatesToU();
  195. }
  196. else if (m_idleTimer == nID)
  197. {
  198. SwitchJoystickPage(false);
  199. }
  200. }
  201. QString LightJoystickSwitchPage::CombiningStr(bool isUpdate /*= false*/)
  202. {
  203. double pos = m_moveAxisInfo.pos;
  204. QString strShow = tr("Currently selected mode:", "当前选中模式:");
  205. if (isUpdate)
  206. {
  207. strShow = tr("Move Pos:","移动点:");
  208. if (m_pCameraBind)
  209. {
  210. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, pos);
  211. }
  212. }
  213. strShow += m_moveAxisInfo.ModuleType.c_str();
  214. strShow += " ";
  215. strShow += m_moveAxisInfo.AxisType.c_str();
  216. strShow += " ";
  217. strShow += QString::number(pos, 'f', 2);
  218. return strShow;
  219. }
  220. void LightJoystickSwitchPage::RealTimeUpdatesToU()
  221. {
  222. if (m_pCameraBind)
  223. {
  224. ui->JTabShowLableLoop->setText(CombiningStr(true));
  225. }
  226. }
  227. void LightJoystickSwitchPage::ResetIdleTimer(bool bStart /*= false*/)
  228. {
  229. if (bStart)
  230. {
  231. if (m_idleTimer != -1)
  232. {
  233. // 计时器没关,关闭重新打开
  234. ResetIdleTimer(false);
  235. ResetIdleTimer(true);
  236. }
  237. if (isActiveWindow())
  238. {
  239. m_idleTimer = startTimer(g_unnSuspensionWaitingTime);
  240. }
  241. }
  242. else
  243. {
  244. killTimer(m_idleTimer);
  245. m_idleTimer = -1;
  246. }
  247. }
  248. void LightJoystickSwitchPage::MoveJoystick()
  249. {
  250. if (m_pCameraBind)
  251. {
  252. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, m_moveAxisInfo.pos);
  253. }
  254. }
  255. void LightJoystickSwitchPage::RunMoveOrMoveTo(bool isMoveTo)
  256. {
  257. QString strErrInfo = {};
  258. QString strNum = ui->valLineEdit->text().trimmed();
  259. if (strNum.isEmpty())
  260. {
  261. strErrInfo = tr("please input value","请输入值");
  262. }
  263. else
  264. {
  265. double doNum = strNum.toDouble();
  266. if (m_moveAxisInfo.ModuleType != "")
  267. {
  268. if (m_moveAxisInfo.AxisType != "")
  269. {
  270. m_pCameraBind->SetModuleMove(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, doNum, isMoveTo);
  271. }
  272. else
  273. {
  274. strErrInfo = tr("AxisType is Empty", "AxisType 为空");
  275. }
  276. }
  277. else
  278. {
  279. strErrInfo = tr("ModuleType is Empty", "ModuleType 为空");
  280. }
  281. }
  282. if (!strErrInfo.isEmpty())
  283. {
  284. JMessageTip::Message_question(strErrInfo);
  285. }
  286. }
  287. void LightJoystickSwitchPage::UpdataLightVal()
  288. {
  289. if (m_pCameraBind->m_pCViewInterface == nullptr)
  290. {
  291. return;
  292. }
  293. if (m_pPageSwitchGroup)
  294. {
  295. int niD = m_pPageSwitchGroup->m_nGroupId;
  296. //if (niD == 1)
  297. {
  298. // 切换灯光
  299. ST_LIGHT_VAL _val = m_pCameraBind->JGetLight(niD);
  300. setLigthValue(_val.redLightValue, _val.greenLightValue, _val.blueLightValue, _val.pointLightValue);
  301. }
  302. }
  303. }
  304. EN_LIGHT_INDEX LightJoystickSwitchPage::MatchSelectedLightIndex(QLineEdit* lineEdit)
  305. {
  306. EN_LIGHT_INDEX nIndex = EN_LIGHT_INDEX::Red;
  307. if (lineEdit == ui->RedLightlineEdit)
  308. {
  309. nIndex = EN_LIGHT_INDEX::Red;
  310. }
  311. else if (lineEdit == ui->GreenLightlineEdit)
  312. {
  313. nIndex = EN_LIGHT_INDEX::Green;
  314. }
  315. else if (lineEdit == ui->BlueLightlineEdit)
  316. {
  317. nIndex = EN_LIGHT_INDEX::Blue;
  318. }
  319. else if (lineEdit == ui->DotLightlineEdit)
  320. {
  321. nIndex = EN_LIGHT_INDEX::Point;
  322. }
  323. return nIndex;
  324. }
  325. void LightJoystickSwitchPage::resizeSingleUI() {
  326. //ui->resize(265, 240)
  327. ui->switchTabWidget->setGeometry(QRect(0, 0, 265, 240));
  328. ui->GreenLightTab->setGeometry(QRect(0, 0, 60, 32));
  329. ui->JoystickTab->setGeometry(QRect(0, 0, 259, 215));
  330. ui->RedLight->setGeometry(QRect(0, 0, 61, 114));
  331. ui->RedLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  332. ui->RedLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  333. ui->RedLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  334. ui->RedLightlabel->setGeometry(QRect(39, 22, 10, 34));
  335. ui->GreenLight->setGeometry(QRect(70, 0, 61, 114));
  336. ui->GreenLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  337. ui->GreenLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  338. ui->GreenLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  339. ui->GreenLightlabel->setGeometry(QRect(36, 22, 10, 34));
  340. ui->BlueLight->setGeometry(QRect(140, 0, 61, 114));
  341. ui->BlueLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  342. ui->BlueLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  343. ui->BlueLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  344. ui->BlueLightlabel->setGeometry(QRect(32, 22, 19, 34));
  345. ui->DotLight->setGeometry(QRect(200, 0, 61, 114));
  346. ui->DotLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  347. ui->DotLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  348. ui->DotLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  349. ui->DotLightlabel->setGeometry(QRect(32, 22, 19, 34));
  350. ui->groupBox->setGeometry(QRect(0, 100, 141, 111));
  351. ui->left_Button->setGeometry(QRect(10, 40, 41, 31));
  352. ui->right_Button->setGeometry(QRect(90, 40, 41, 31));
  353. ui->up_Button->setGeometry(QRect(50, 10, 41, 31));
  354. ui->down_Button->setGeometry(QRect(50, 70, 41, 31));
  355. ui->move_Button->setGeometry(QRect(170, 130, 60, 23));
  356. ui->JTabShowLableLoop->setGeometry(QRect(10, 50, 200, 41));
  357. ui->moveTo_Button->setGeometry(QRect(170, 170, 60, 23));
  358. ui->valLineEdit->setGeometry(QRect(160, 100, 71, 21));
  359. ui->JTabShowLable->setGeometry(QRect(10, 0, 200, 40));
  360. }