MainAndSecondaryCamerasWnd.cpp 28 KB

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