MainAndSecondaryCamerasWnd.cpp 22 KB

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