MainAndSecondaryCamerasWnd.cpp 22 KB

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