MainAndSecondaryCamerasWnd.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. #include "MainAndSecondaryCamerasWnd.h"
  2. #include "ui_MainAndSecondaryCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QTimer>
  7. #include <QScrollBar>
  8. #include <QDoubleValidator>
  9. #include "CameraDistribute.h"
  10. #include "Src/common/JMessageTip.h"
  11. MainAndSecondaryCamerasWnd::MainAndSecondaryCamerasWnd(QWidget* parent)
  12. : JOriginalMainWnd(parent)
  13. , ui(new Ui::MainAndSecondaryCamerasWnd)
  14. {
  15. ui->setupUi(this);
  16. ui->control_r->HideOrShowPage(false);
  17. ui->control_L->HideOrShowPage(false);
  18. ui->viewwidgetgroup_L->setBlueBord();
  19. connect(ui->viewwidgetgroup_L, &ControlOperationPage::send_ComboBox_singal, this, &MainAndSecondaryCamerasWnd::HandleComboxchange_L);
  20. connect(ui->viewwidgetgroup_R, &ControlOperationPage::send_ComboBox_singal, this, &MainAndSecondaryCamerasWnd::HandleComboxchange_R);
  21. qApp->installEventFilter(this);
  22. m_veCurrentSelectGroup_R.isInitialed = false;
  23. m_veCurrentSelectGroup_L.isInitialed = false;
  24. m_veCurrentSelectGroup_R.isBond = false;
  25. m_veCurrentSelectGroup_L.isBond = false;
  26. }
  27. MainAndSecondaryCamerasWnd::~MainAndSecondaryCamerasWnd()
  28. {
  29. UnCameraBind();
  30. delete ui;
  31. }
  32. void MainAndSecondaryCamerasWnd::initFrom()
  33. {
  34. {
  35. // 界面刷新
  36. InitPage();
  37. //STR_TEMPLATE strFun = {};
  38. //strFun.pView = ui->scrollArea;
  39. //strFun.veSignalFun.emplace_back(std::bind(&MainAndSecondaryCamerasWnd::UpdateCameraDisplay0, this, std::placeholders::_1, std::placeholders::_2));
  40. //strFun.veSignalFun.emplace_back(std::bind(&MainAndSecondaryCamerasWnd::UpdateCameraDisplay1, this, std::placeholders::_1, std::placeholders::_2));
  41. ////strFun.veSlotFun.emplace_back([this]() { CheckIs(); });
  42. //strFun.veSlotFun.emplace_back(std::bind(&MainAndSecondaryCamerasWnd::CheckIs, this));
  43. //InitAllCamerPage(strFun, this);
  44. //CameraImageHandlera<MainAndSecondaryCamerasWnd, STR_TEMPLATE> A(this, strFun);
  45. //SwitchToConfigAAAAA<MainAndSecondaryCamerasWnd, STR_TEMPLATE>();
  46. }
  47. //ui->LeftOperatewidget->setMouseTracking(true);
  48. //ui->RightOperatewidget->setMouseTracking(true);
  49. }
  50. void MainAndSecondaryCamerasWnd::InitPage()
  51. {
  52. QWidget* viewport = ui->scrollArea->viewport();
  53. QWidget* container = new QWidget(viewport);
  54. QHBoxLayout* mainLayout = new QHBoxLayout(container);
  55. mainLayout->setSpacing(28);
  56. mainLayout->setMargin(0);
  57. int nSize = 0;
  58. if (m_pMainCameraBind != nullptr)
  59. {
  60. nSize = m_pMainCameraBind->m_vecCamera.size();
  61. if (nSize == 0) // 针对获取不到的情况
  62. {
  63. nSize = 5;
  64. //JMessageTip::Message_warning("a");
  65. }
  66. QList<int> numbers;
  67. for (int i = 1; i <= nSize; i++)
  68. {
  69. numbers.push_back(i);
  70. }
  71. for (int i = 0; i < numbers.size(); ++i)
  72. {
  73. int num = numbers[i];
  74. CameraInfo test;
  75. test.iCameraId = i;
  76. test.name = ("camera" + QString::number(i)).toStdString();
  77. test.eType = MATERIAL_WAFER;
  78. CameraImageHandler* manager = new CameraImageHandler(num,test);
  79. Group* widget = manager->getGroup();
  80. CameraConnectUpdateImageFun(i, widget);
  81. connect(widget, &Group::sendUpdateGroupState,
  82. this, &MainAndSecondaryCamerasWnd::checkSettings);
  83. connect(widget, &Group::send_ComboBox_singal,
  84. this, &MainAndSecondaryCamerasWnd::GetGroupComboxChanged);
  85. if (widget != nullptr)
  86. {
  87. mainLayout->addWidget(widget);
  88. m_allGroup.append(widget);
  89. }
  90. if (manager->getWafer())
  91. {
  92. m_mapWaferMap.insert(num, manager->getWafer());
  93. }
  94. if (manager->getWaffle()) {
  95. m_mapWaffleMap.insert(num, manager->getWaffle());
  96. }
  97. if (manager->getMaterialBox()) {
  98. m_mapMaterialBoxMap.insert(num, manager->getMaterialBox());
  99. }
  100. if (manager->getBond()) {
  101. m_mapBondMap.insert(num, manager->getBond());
  102. }
  103. if(!manager->getFileList().isEmpty()){
  104. m_mapFileListMap.insert(num, manager->getFileList());
  105. }
  106. delete manager;
  107. }
  108. // 设置控件的最小高度和最大宽度
  109. int minHeight = 162;
  110. int maxWidth = 244;
  111. int num = -28;
  112. for (Group* w : m_allGroup)
  113. {
  114. w->setMinimumHeight(minHeight);
  115. w->setMaximumWidth(maxWidth);
  116. num = num + 272;
  117. }
  118. container->setMinimumSize(num, 162);
  119. container->setLayout(mainLayout);
  120. ui->scrollArea->setWidget(container);
  121. ui->scrollArea->resize(1062, 177);
  122. initLeftAndRightWidget();
  123. //// 只有一个相机的情况,直接绑定
  124. //if (numbers.size() == 1)
  125. //{
  126. // Group* pGroup = m_allGroup[0];
  127. // connect(pGroup, &Group::SetUpDataImageShowSig,
  128. // this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  129. // ST_CURRENT_SELECT_GROUP _curr;
  130. // _curr.isBond = true;
  131. // _curr.pSelectGroup = pGroup;
  132. // _curr.nCurrentCameraId = pGroup->m_nGroupId;
  133. // _curr.nSelectLeft1 = 1;
  134. // m_veCurrentSelectGroup.push_back(_curr);
  135. // UpdataLightJoystickSwitchPage();
  136. //}
  137. }
  138. }
  139. void MainAndSecondaryCamerasWnd::CameraConnectUpdateImageFun(int nIndex, Group* widget, bool isUnCameraBind /*= false*/)
  140. {
  141. auto BinCamerasImage = [&](void (MainAndSecondaryCamerasWnd::* pCamerasImage)(const QPixmap& imageData))
  142. {
  143. if (isUnCameraBind)
  144. {
  145. disconnect(widget, &Group::SetCurrentSelectSig, this, &MainAndSecondaryCamerasWnd::GetCurrentSelectSlots);
  146. disconnect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots);
  147. }
  148. else
  149. {
  150. //共用函数
  151. //connect(widget, &Group::send_button_Signal, this, &MainAndSecondaryCamerasWnd::CheckIs);
  152. // connect(widget, &Group::SetCurrentSelectSig, this, &MainAndSecondaryCamerasWnd::GetCurrentSelectSlots);
  153. connect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots);
  154. }
  155. };
  156. if (nIndex == 0)
  157. {
  158. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals0);
  159. }
  160. else if (nIndex == 1)
  161. {
  162. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals1);
  163. }
  164. else if (nIndex == 2)
  165. {
  166. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals2);
  167. }
  168. else if (nIndex == 3)
  169. {
  170. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals3);
  171. }
  172. else if (nIndex == 4)
  173. {
  174. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals4);
  175. }
  176. }
  177. void MainAndSecondaryCamerasWnd::initLeftAndRightWidget() {
  178. //初始化当前页面的信息
  179. QSettings settings("YourOrganization", "YourApplication");
  180. lastLastIndex = settings.value("DoubleLastLastIndex", 2).toInt();
  181. lastLastGroupId = settings.value("DoubleLastLastGroupId", 1).toInt();
  182. lastIndex = settings.value("DoubleLastIndex", 1).toInt();
  183. lastGroupId = settings.value("DoubleLastGroupId", 1).toInt();
  184. //处理各种情况的初始化
  185. if (m_pMainCameraBind == nullptr || m_allGroup.size() == 0)
  186. {
  187. return;
  188. }
  189. if (m_allGroup.size() < lastGroupId || m_allGroup.size() < lastLastGroupId) {
  190. //重置记录
  191. lastGroupId = 1;
  192. lastIndex = 1;
  193. lastLastGroupId = 1;
  194. lastLastIndex = 2;
  195. }
  196. m_veCurrentSelectGroup_R.isInitialed = true;
  197. m_veCurrentSelectGroup_L.isInitialed = true;
  198. if (m_allGroup.size() == 1) {
  199. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  200. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  201. m_veCurrentSelectGroup_L.pSelectGroup->initBorderStyle(lastLastIndex,0);
  202. m_veCurrentSelectGroup_R.pSelectGroup->initBorderStyle(lastIndex, 1);
  203. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  204. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId],currentLeftComboBoxIndex);
  205. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  206. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId],currentRightComboBoxIndex);
  207. if (lastIndex != lastLastIndex) {
  208. if (lastIndex == 1) {
  209. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  210. ui->viewwidgetgroup_R->setEnableControls(true);
  211. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  212. ui->viewwidgetgroup_L->setEnableControls(false);
  213. }
  214. else {
  215. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  216. ui->viewwidgetgroup_R->setEnableControls(false);
  217. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  218. ui->viewwidgetgroup_L->setEnableControls(true);
  219. }
  220. }
  221. else {
  222. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  223. ui->viewwidgetgroup_R->setEnableControls(true);
  224. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  225. ui->viewwidgetgroup_L->setEnableControls(false);
  226. }
  227. }
  228. else {
  229. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastLastGroupId - 1);
  230. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  231. m_veCurrentSelectGroup_L.pSelectGroup->initBorderStyle(lastLastIndex, 0);
  232. m_veCurrentSelectGroup_R.pSelectGroup->initBorderStyle(lastIndex, 1);
  233. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  234. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId],currentLeftComboBoxIndex);
  235. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  236. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId],currentRightComboBoxIndex);
  237. if (lastLastIndex == 1) {
  238. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  239. ui->viewwidgetgroup_L->setEnableControls(true);
  240. }
  241. else {
  242. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  243. ui->viewwidgetgroup_L->setEnableControls(false);
  244. }
  245. if (lastIndex == 1) {
  246. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  247. ui->viewwidgetgroup_R->setEnableControls(true);
  248. }
  249. else {
  250. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  251. ui->viewwidgetgroup_R->setEnableControls(false);
  252. }
  253. }
  254. }
  255. void MainAndSecondaryCamerasWnd::BindImageOrMaterial(int location, int index) {
  256. if (location == m_nLastLeft) {
  257. if (index == m_nImageIndex) {
  258. m_veCurrentSelectGroup_L.isBond = true;
  259. connect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  260. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  261. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, true);
  262. }
  263. else {
  264. //左边更新物料窗口
  265. QSettings settings("YourOrganization", "YourApplication");
  266. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  267. int lastMaterialWndType = settings.value("MaterialWndType").toInt();
  268. settings.endGroup();
  269. m_veCurrentSelectGroup_L.isBond = false;
  270. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, false);
  271. updateMaterialWidget(m_nLastLeft, lastMaterialWndType, m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId);
  272. }
  273. }
  274. else {
  275. if (index == m_nImageIndex) {
  276. m_veCurrentSelectGroup_R.isBond = true;
  277. connect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  278. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  279. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, true);
  280. }
  281. else {
  282. //右边更新物料窗口
  283. QSettings settings("YourOrganization", "YourApplication");
  284. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  285. int materialWndType = settings.value("MaterialWndType").toInt();
  286. settings.endGroup();
  287. m_veCurrentSelectGroup_R.isBond = false;
  288. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, false);
  289. updateMaterialWidget(m_nCurrentRight, materialWndType, m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId);
  290. }
  291. }
  292. }
  293. void MainAndSecondaryCamerasWnd::checkSettings(int groupId, int index) {
  294. if (groupId != lastGroupId || index != lastIndex) {
  295. GetCurrentSelectSlots(groupId, index);
  296. lastLastGroupId = lastGroupId;
  297. lastLastIndex = lastIndex;
  298. lastGroupId = groupId;
  299. lastIndex = index;
  300. saveInfoOfLast();
  301. }
  302. }
  303. void MainAndSecondaryCamerasWnd::saveInfoOfLast() {
  304. QSettings settings("YourOrganization", "YourApplication");
  305. settings.setValue("DoubleLastIndex", lastIndex);
  306. settings.setValue("DoubleLastGroupId", lastGroupId);
  307. settings.setValue("DoubleLastLastIndex", lastLastIndex);
  308. settings.setValue("DoubleLastLastGroupId", lastLastGroupId);
  309. }
  310. void MainAndSecondaryCamerasWnd::updateMaterialWidget(int side, int materialWndType, int groupId) {
  311. if (side == m_nLastLeft) {
  312. switch (materialWndType) {
  313. case 1: ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(groupId)); break;
  314. case 2: ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(groupId)); break;
  315. case 3: ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  316. case 4: ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(groupId)); break;
  317. }
  318. }
  319. else if (side == m_nCurrentRight) {
  320. switch (materialWndType) {
  321. case 1: ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(groupId)); break;
  322. case 2: ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(groupId)); break;
  323. case 3: ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  324. case 4: ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(groupId)); break;
  325. }
  326. }
  327. }
  328. void MainAndSecondaryCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  329. {
  330. m_pMainCameraBind = pCameraBind;
  331. initFrom();
  332. }
  333. void MainAndSecondaryCamerasWnd::UnCameraBind()
  334. {
  335. for (size_t i = 0; i < m_allGroup.size(); i++)
  336. {
  337. CameraConnectUpdateImageFun(i, m_allGroup[i], true);
  338. }
  339. }
  340. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  341. {
  342. // TODO: 这里需要改动
  343. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  344. ui->viewwidgetgroup_L->getOperatewidget()->setGeometry(ui->viewwidgetgroup_L->getOperatewidget()->pos().x(),
  345. ui->viewwidgetgroup_L->getOperatewidget()->pos().y(),
  346. ui->viewwidgetgroup_L->getOperatewidget()->width(),
  347. ui->viewwidgetgroup_L->getOperatewidget()->height());
  348. //ui->LeftOperatewidget->setPixmap(QPixmap::fromImage(image));
  349. emit UpDataImageShowSignals0(QPixmap::fromImage(image));
  350. }
  351. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  352. {
  353. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  354. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  355. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  356. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  357. ui->viewwidgetgroup_R->getOperatewidget()->height());
  358. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  359. emit UpDataImageShowSignals1(QPixmap::fromImage(image));
  360. }
  361. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  362. {
  363. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  364. emit UpDataImageShowSignals2(QPixmap::fromImage(image));
  365. }
  366. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  367. {
  368. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  369. emit UpDataImageShowSignals3(QPixmap::fromImage(image));
  370. }
  371. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  372. {
  373. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  374. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  375. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  376. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  377. ui->viewwidgetgroup_R->getOperatewidget()->height());
  378. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  379. emit UpDataImageShowSignals4(QPixmap::fromImage(image));
  380. }
  381. void MainAndSecondaryCamerasWnd::HideLayout(QHBoxLayout* layout, bool isHide)
  382. {
  383. for (int i = 0; i < layout->count(); ++i)
  384. {
  385. QWidget* widget = layout->itemAt(i)->widget();
  386. if (widget)
  387. {
  388. if (isHide)
  389. {
  390. widget->hide();
  391. }
  392. else
  393. {
  394. widget->show();
  395. }
  396. }
  397. }
  398. }
  399. void MainAndSecondaryCamerasWnd::UpdataLightJoystickSwitchPage(int groupId, int index, bool isShow)
  400. {
  401. auto Fun = [&](Group* pGroup, LightJoystickSwitchPage* p, ControlOperationPage* pContPage, bool bShow)
  402. {
  403. p->UpdatemPageGroup(pGroup);
  404. p->InitMainCameraBind(m_pMainCameraBind, bShow);
  405. p->HideOrShowPage(bShow);
  406. if (bShow)
  407. {
  408. pContPage->UpDateCameraBind(m_pMainCameraBind);
  409. }
  410. else
  411. {
  412. pContPage->setSwitchJoystickButEnable(bShow);
  413. }
  414. };
  415. if (index == 1)
  416. {
  417. disconnect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  418. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  419. Group* currGroup = m_allGroup.at(groupId - 1);
  420. Fun(currGroup, ui->control_L, ui->viewwidgetgroup_L, isShow);
  421. connect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  422. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  423. }
  424. else if (index == 2)
  425. {
  426. disconnect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  427. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  428. Group* currGroup = m_allGroup.at(groupId - 1);
  429. Fun(currGroup, ui->control_r, ui->viewwidgetgroup_R, isShow);
  430. connect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  431. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  432. }
  433. }
  434. void MainAndSecondaryCamerasWnd::timerEvent(QTimerEvent* event)
  435. {
  436. int nID = event->timerId();
  437. }
  438. void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex)
  439. {
  440. int nOnClickGroupId = groupId - 1; // 这里new 有些是0,有些是1 暂时选择
  441. if (m_pMainCameraBind == nullptr || m_allGroup.size() < groupId)
  442. {
  443. return;
  444. }
  445. //判断更新前的左窗口是否是绑定相机
  446. if (m_veCurrentSelectGroup_L.isBond == true) {
  447. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  448. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  449. }
  450. //判断更新前的右窗口是否是绑定相机
  451. if (m_veCurrentSelectGroup_R.isBond == true) {
  452. //解绑
  453. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  454. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  455. }
  456. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  457. //判断更新前的右窗口的index是相机还是物料
  458. if (lastIndex == 1) {
  459. //左窗口绑定
  460. //更新左边的下拉框内容同步小窗口索引
  461. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  462. ui->viewwidgetgroup_L->setEnableControls(true);
  463. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId],currentLeftComboBoxIndex);
  464. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  465. QPixmap pixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  466. GetGroupImageShowSignalsTo_L(pixmap);
  467. }
  468. else {
  469. ui->viewwidgetgroup_L->setEnableControls(false);
  470. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  471. }
  472. //右边更新物料窗口
  473. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  474. //判断当前index是相机还是物料
  475. if (nIndex == 2) {
  476. ui->viewwidgetgroup_R->setEnableControls(false);
  477. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  478. }
  479. else if (nIndex == 1) {//当前切换时相机序号
  480. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  481. ui->viewwidgetgroup_R->setEnableControls(true);
  482. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId],currentRightComboBoxIndex);
  483. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  484. QPixmap pixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(currentRightComboBoxIndex);
  485. GetGroupImageShowSignalsTo_R(pixmap);
  486. }
  487. }
  488. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L(const QPixmap& imageData)
  489. {
  490. QSize size_left = ui->viewwidgetgroup_L->getOperatewidget()->size();
  491. QPixmap scaledPixmap_left = m_lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  492. ui->viewwidgetgroup_L->setScaleFactorSize(scaledPixmap_left);
  493. m_lastRightPixmap = imageData;
  494. }
  495. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R(const QPixmap& imageData)
  496. {
  497. QSize size_left = ui->viewwidgetgroup_R->getOperatewidget()->size();
  498. QPixmap scaledPixmap_right = imageData.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  499. ui->viewwidgetgroup_R->setScaleFactorSize(scaledPixmap_right);
  500. m_lastRightPixmap = imageData;
  501. }
  502. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent* event)
  503. {
  504. //if (ui->viewwidgetgroup_L->getOperatewidget()->rect().contains(ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  505. // mousePos = ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos());
  506. // if (event->angleDelta().y() > 0) {
  507. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 1.1); // 放大
  508. // } else {
  509. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 0.9); // 缩小
  510. // }
  511. //}
  512. //if (ui->viewwidgetgroup_R->getOperatewidget()->rect().contains(ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  513. // mousePos = ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos());
  514. // if (event->angleDelta().y() > 0) {
  515. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 1.1); // 放大
  516. // } else {
  517. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 0.9); // 缩小
  518. // }
  519. //}
  520. //if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  521. // // 获取 QScrollArea 的横向滚动条
  522. // QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  523. // // 根据滚轮滚动方向改变滚动条的值
  524. // if (event->angleDelta().y() > 0) {
  525. // scrollBar->setValue(scrollBar->value() - 50);
  526. // } else {
  527. // scrollBar->setValue(scrollBar->value() + 50);
  528. // }
  529. //}
  530. QMainWindow::wheelEvent(event);
  531. }
  532. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent* event) {
  533. isUpdatingSettings = false;
  534. QMainWindow::showEvent(event);
  535. isUpdatingSettings = false;
  536. }
  537. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent* event) {
  538. isUpdatingSettings = false;
  539. QMainWindow::hideEvent(event);
  540. }
  541. void MainAndSecondaryCamerasWnd::GetGroupComboxChanged(int groupId,int comboxIndex){
  542. m_allGroup.at(groupId - 1);
  543. if(comboxIndex == 0){
  544. CameraConnectUpdateImageFun(groupId - 1,m_allGroup.at(groupId - 1),false);
  545. }else{
  546. CameraConnectUpdateImageFun(groupId - 1,m_allGroup.at(groupId - 1),true);
  547. }
  548. m_allGroup.at(groupId - 1)->setCurrentCombox(comboxIndex);
  549. if(groupId == m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId && lastLastIndex == 1){
  550. if(comboxIndex != 0){//图片
  551. QPixmap updatePixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(comboxIndex);
  552. m_veCurrentSelectGroup_L.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  553. }
  554. }else if(groupId == m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId && lastIndex == 1){
  555. if(comboxIndex != 0){//图片
  556. QPixmap updatePixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(comboxIndex);
  557. m_veCurrentSelectGroup_R.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  558. }
  559. }
  560. }
  561. void MainAndSecondaryCamerasWnd::HandleComboxchange_L(int index) {
  562. if (index == 0) {
  563. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId-1, m_allGroup.at(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1), false);
  564. }
  565. else {
  566. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1), true);
  567. QPixmap updatePixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(index);
  568. m_veCurrentSelectGroup_L.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  569. }
  570. }
  571. void MainAndSecondaryCamerasWnd::HandleComboxchange_R(int index) {
  572. if (index == 0) {
  573. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1), false);
  574. }
  575. else {
  576. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1), true);
  577. QPixmap updatePixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(index);
  578. m_veCurrentSelectGroup_R.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  579. }
  580. }