MainAndSecondaryCamerasWnd.cpp 28 KB

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