LightJoystickSwitchPage.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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, bool bUpdate /*= true*/)
  140. {
  141. m_pCameraBind = pCameraBind;
  142. if (bUpdate)
  143. {
  144. UpdataLightVal();
  145. }
  146. }
  147. void LightJoystickSwitchPage::UpdatemPageGroup(Group* pGroup)
  148. {
  149. m_pPageSwitchGroup = pGroup;
  150. }
  151. void LightJoystickSwitchPage::SwitchJoystickPage(bool bSwitch)
  152. {
  153. ResetIdleTimer(bSwitch);
  154. int newIndex = (ui->switchTabWidget->currentIndex() + 1) % ui->switchTabWidget->count();
  155. ui->switchTabWidget->setCurrentIndex(newIndex);
  156. }
  157. void LightJoystickSwitchPage::HideOrShowPage(bool isHide)
  158. {
  159. ui->switchTabWidget->setVisible(isHide);
  160. }
  161. void LightJoystickSwitchPage::SetMoveJoystickInfo(const ST_MOVE_AXIS& movInfo)
  162. {
  163. m_moveAxisInfo.ModuleType = movInfo.ModuleType;
  164. m_moveAxisInfo.AxisType = movInfo.AxisType;
  165. m_moveAxisInfo.pos = movInfo.pos; // 这个距离可能会变动// 根据摇杆区分等级
  166. // 点击摇杆的时候开启定时器,然后3秒关闭
  167. SwitchJoystickPage(true);
  168. ui->JTabShowLable->setText(CombiningStr());
  169. }
  170. void LightJoystickSwitchPage::timerEvent(QTimerEvent* event)
  171. {
  172. int nID = event->timerId();
  173. if (m_nTimeShowPos == nID)
  174. {
  175. RealTimeUpdatesToU();
  176. }
  177. else if (m_idleTimer == nID)
  178. {
  179. SwitchJoystickPage(false);
  180. }
  181. }
  182. QString LightJoystickSwitchPage::CombiningStr(bool isUpdate /*= false*/)
  183. {
  184. double pos = m_moveAxisInfo.pos;
  185. QString strShow = tr("Currently selected mode:", "当前选中模式:");
  186. if (isUpdate)
  187. {
  188. strShow = tr("Move Pos:","移动点:");
  189. if (m_pCameraBind)
  190. {
  191. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, pos);
  192. }
  193. }
  194. strShow += m_moveAxisInfo.ModuleType.c_str();
  195. strShow += " ";
  196. strShow += m_moveAxisInfo.AxisType.c_str();
  197. strShow += " ";
  198. strShow += QString::number(pos, 'f', 2);
  199. return strShow;
  200. }
  201. void LightJoystickSwitchPage::RealTimeUpdatesToU()
  202. {
  203. if (m_pCameraBind)
  204. {
  205. ui->JTabShowLableLoop->setText(CombiningStr(true));
  206. }
  207. }
  208. void LightJoystickSwitchPage::ResetIdleTimer(bool bStart /*= false*/)
  209. {
  210. if (bStart)
  211. {
  212. if (isActiveWindow())
  213. {
  214. m_idleTimer = startTimer(3000);
  215. }
  216. }
  217. else
  218. {
  219. killTimer(m_idleTimer);
  220. m_idleTimer = -1;
  221. }
  222. }
  223. void LightJoystickSwitchPage::MoveJoystick()
  224. {
  225. if (m_pCameraBind)
  226. {
  227. m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, m_moveAxisInfo.pos);
  228. }
  229. }
  230. void LightJoystickSwitchPage::UpdataLightVal()
  231. {
  232. if (m_pCameraBind->m_pCViewInterface == nullptr)
  233. {
  234. return;
  235. }
  236. if (m_pPageSwitchGroup)
  237. {
  238. int niD = m_pPageSwitchGroup->m_nGroupId;
  239. //if (niD == 1)
  240. {
  241. auto Fun = [&](QWidget* pWidget, QSlider* pSlider, int nVal) {
  242. if (nVal < 0)
  243. {
  244. // 设置不可用
  245. pWidget->setEnabled(false);
  246. pWidget->hide();
  247. }
  248. else
  249. {
  250. pSlider->setValue(nVal);
  251. }
  252. };
  253. // 切换灯光
  254. ST_LIGHT_VAL _val = m_pCameraBind->JGetLight(niD);
  255. Fun(ui->RedLight, ui->RedLightverticalSlider, _val.redLightValue);
  256. Fun(ui->GreenLight, ui->GreenLightverticalSlider, _val.greenLightValue);
  257. Fun(ui->BlueLight, ui->BlueLightverticalSlider, _val.blueLightValue);
  258. Fun(ui->DotLight, ui->DotLightverticalSlider, _val.pointLightValue);
  259. }
  260. }
  261. }
  262. EN_LIGHT_INDEX LightJoystickSwitchPage::MatchSelectedLightIndex(QLineEdit* lineEdit)
  263. {
  264. EN_LIGHT_INDEX nIndex = EN_LIGHT_INDEX::Red;
  265. if (lineEdit == ui->RedLightlineEdit)
  266. {
  267. nIndex = EN_LIGHT_INDEX::Red;
  268. }
  269. else if (lineEdit == ui->GreenLightlineEdit)
  270. {
  271. nIndex = EN_LIGHT_INDEX::Green;
  272. }
  273. else if (lineEdit == ui->BlueLightlineEdit)
  274. {
  275. nIndex = EN_LIGHT_INDEX::Blue;
  276. }
  277. else if (lineEdit == ui->DotLightlineEdit)
  278. {
  279. nIndex = EN_LIGHT_INDEX::Point;
  280. }
  281. return nIndex;
  282. }
  283. void LightJoystickSwitchPage::resizeSingleUI() {
  284. //ui->resize(265, 240)
  285. ui->switchTabWidget->setGeometry(QRect(0, 0, 265, 240));
  286. ui->GreenLightTab->setGeometry(QRect(0, 0, 60, 32));
  287. ui->JoystickTab->setGeometry(QRect(0, 0, 259, 215));
  288. ui->RedLight->setGeometry(QRect(0, 0, 61, 114));
  289. ui->RedLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  290. ui->RedLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  291. ui->RedLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  292. ui->RedLightlabel->setGeometry(QRect(39, 22, 10, 34));
  293. ui->GreenLight->setGeometry(QRect(70, 0, 61, 114));
  294. ui->GreenLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  295. ui->GreenLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  296. ui->GreenLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  297. ui->GreenLightlabel->setGeometry(QRect(36, 22, 10, 34));
  298. ui->BlueLight->setGeometry(QRect(140, 0, 61, 114));
  299. ui->BlueLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  300. ui->BlueLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  301. ui->BlueLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  302. ui->BlueLightlabel->setGeometry(QRect(32, 22, 19, 34));
  303. ui->DotLight->setGeometry(QRect(200, 0, 61, 114));
  304. ui->DotLightlineEdit->setGeometry(QRect(10, 78, 40, 24));
  305. ui->DotLightprogressBar->setGeometry(QRect(32, 15, 18, 51));
  306. ui->DotLightverticalSlider->setGeometry(QRect(10, 12, 18, 56));
  307. ui->DotLightlabel->setGeometry(QRect(32, 22, 19, 34));
  308. ui->groupBox->setGeometry(QRect(0, 100, 141, 111));
  309. ui->left_Button->setGeometry(QRect(10, 40, 41, 31));
  310. ui->right_Button->setGeometry(QRect(90, 40, 41, 31));
  311. ui->up_Button->setGeometry(QRect(50, 10, 41, 31));
  312. ui->down_Button->setGeometry(QRect(50, 70, 41, 31));
  313. ui->move_Button->setGeometry(QRect(170, 130, 60, 23));
  314. ui->JTabShowLableLoop->setGeometry(QRect(10, 50, 200, 41));
  315. ui->moveTo_Button->setGeometry(QRect(170, 170, 60, 23));
  316. ui->valLineEdit->setGeometry(QRect(160, 100, 71, 21));
  317. ui->JTabShowLable->setGeometry(QRect(10, 0, 200, 40));
  318. }