LightJoystickSwitchPage.cpp 11 KB

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