MainAndSecondaryCamerasWnd.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. if (lastIndex != lastLastIndex) {
  194. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  195. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  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. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastLastGroupId - 1);
  212. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  213. if (lastLastIndex == 1) {
  214. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  215. }
  216. else {
  217. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  218. }
  219. if (lastIndex == 1) {
  220. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  221. }
  222. else {
  223. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  224. }
  225. }
  226. }
  227. void MainAndSecondaryCamerasWnd::BindImageOrMaterial(int location, int index) {
  228. if (location == m_nLastLeft) {
  229. if (index == m_nImageIndex) {
  230. m_veCurrentSelectGroup_L.isBond = true;
  231. connect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  232. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  233. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, true);
  234. }else {
  235. //左边更新物料窗口
  236. QSettings settings("YourOrganization", "YourApplication");
  237. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  238. int lastMaterialWndType = settings.value("MaterialWndType").toInt();
  239. settings.endGroup();
  240. m_veCurrentSelectGroup_L.isBond = false;
  241. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, false);
  242. updateMaterialWidget(m_nLastLeft, lastMaterialWndType, m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId);
  243. }
  244. }else {
  245. if (index == m_nImageIndex) {
  246. m_veCurrentSelectGroup_R.isBond = true;
  247. connect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  248. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  249. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, true);
  250. }
  251. else {
  252. //右边更新物料窗口
  253. QSettings settings("YourOrganization", "YourApplication");
  254. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  255. int materialWndType = settings.value("MaterialWndType").toInt();
  256. settings.endGroup();
  257. m_veCurrentSelectGroup_R.isBond = false;
  258. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, false);
  259. updateMaterialWidget(m_nCurrentRight, materialWndType, m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId);
  260. }
  261. }
  262. }
  263. void MainAndSecondaryCamerasWnd::checkSettings(int groupId,int index) {
  264. if (groupId != lastGroupId || index != lastIndex) {
  265. GetCurrentSelectSlots(groupId, index);
  266. lastLastGroupId = lastGroupId;
  267. lastLastIndex = lastIndex;
  268. lastGroupId = groupId;
  269. lastIndex = index;
  270. saveInfoOfLast();
  271. }
  272. }
  273. void MainAndSecondaryCamerasWnd::saveInfoOfLast() {
  274. QSettings settings("YourOrganization", "YourApplication");
  275. settings.setValue("DoubleLastIndex", lastIndex);
  276. settings.setValue("DoubleLastGroupId", lastGroupId);
  277. settings.setValue("DoubleLastLastIndex", lastLastIndex);
  278. settings.setValue("DoubleLastLastGroupId", lastLastGroupId);
  279. }
  280. void MainAndSecondaryCamerasWnd::updateMaterialWidget(int side,int materialWndType, int groupId) {
  281. if (side == m_nLastLeft) {
  282. switch (materialWndType) {
  283. case 1: ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(groupId)); break;
  284. case 2: ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(groupId)); break;
  285. case 3: ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  286. case 4: ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(groupId)); break;
  287. }
  288. }
  289. else if (side == m_nCurrentRight) {
  290. switch (materialWndType) {
  291. case 1: ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(groupId)); break;
  292. case 2: ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(groupId)); break;
  293. case 3: ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  294. case 4: ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(groupId)); break;
  295. }
  296. }
  297. }
  298. void MainAndSecondaryCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  299. {
  300. m_pMainCameraBind = pCameraBind;
  301. initFrom();
  302. }
  303. void MainAndSecondaryCamerasWnd::UnCameraBind()
  304. {
  305. for (size_t i = 0; i < m_allGroup.size(); i++)
  306. {
  307. CameraConnectUpdateImageFun(i, m_allGroup[i], true);
  308. }
  309. //判断更新前的左窗口是否是绑定相机
  310. if (m_veCurrentSelectGroup_L.isBond == true) {
  311. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  312. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  313. }
  314. //判断更新前的右窗口是否是绑定相机
  315. if (m_veCurrentSelectGroup_R.isBond == true) {
  316. //解绑
  317. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  318. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  319. }
  320. }
  321. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  322. {
  323. // TODO: 这里需要改动
  324. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  325. ui->viewwidgetgroup_L->getOperatewidget()->setGeometry(ui->viewwidgetgroup_L->getOperatewidget()->pos().x(),
  326. ui->viewwidgetgroup_L->getOperatewidget()->pos().y(),
  327. ui->viewwidgetgroup_L->getOperatewidget()->width(),
  328. ui->viewwidgetgroup_L->getOperatewidget()->height());
  329. //ui->LeftOperatewidget->setPixmap(QPixmap::fromImage(image));
  330. emit UpDataImageShowSignals0(QPixmap::fromImage(image));
  331. }
  332. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  333. {
  334. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  335. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  336. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  337. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  338. ui->viewwidgetgroup_R->getOperatewidget()->height());
  339. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  340. emit UpDataImageShowSignals1(QPixmap::fromImage(image));
  341. }
  342. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  343. {
  344. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  345. emit UpDataImageShowSignals2(QPixmap::fromImage(image));
  346. }
  347. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  348. {
  349. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  350. emit UpDataImageShowSignals3(QPixmap::fromImage(image));
  351. }
  352. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  353. {
  354. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  355. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  356. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  357. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  358. ui->viewwidgetgroup_R->getOperatewidget()->height());
  359. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  360. emit UpDataImageShowSignals4(QPixmap::fromImage(image));
  361. }
  362. void MainAndSecondaryCamerasWnd::HideLayout(QHBoxLayout* layout, bool isHide)
  363. {
  364. for (int i = 0; i < layout->count(); ++i)
  365. {
  366. QWidget* widget = layout->itemAt(i)->widget();
  367. if (widget)
  368. {
  369. if (isHide)
  370. {
  371. widget->hide();
  372. }
  373. else
  374. {
  375. widget->show();
  376. }
  377. }
  378. }
  379. }
  380. void MainAndSecondaryCamerasWnd::UpdataLightJoystickSwitchPage(int groupId, int index, bool isShow)
  381. {
  382. auto Fun = [&](Group* pGroup,LightJoystickSwitchPage* p, ControlOperationPage* pContPage, bool bShow)
  383. {
  384. p->UpdatemPageGroup(pGroup);
  385. p->InitMainCameraBind(m_pMainCameraBind, bShow);
  386. p->HideOrShowPage(bShow);
  387. if (bShow)
  388. {
  389. pContPage->UpDateCameraBind(m_pMainCameraBind);
  390. }
  391. else
  392. {
  393. pContPage->setSwitchJoystickButEnable(bShow);
  394. }
  395. };
  396. if (index == 1)
  397. {
  398. disconnect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  399. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  400. Group* currGroup = m_allGroup.at(groupId-1);
  401. Fun(currGroup, ui->control_L, ui->viewwidgetgroup_L, isShow);
  402. connect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  403. ui->control_L,&LightJoystickSwitchPage::GetModuleTypeSlots);
  404. }
  405. else if(index == 2)
  406. {
  407. disconnect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  408. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  409. Group* currGroup = m_allGroup.at(groupId-1);
  410. Fun(currGroup, ui->control_r, ui->viewwidgetgroup_R, isShow);
  411. connect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  412. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  413. }
  414. }
  415. void MainAndSecondaryCamerasWnd::timerEvent(QTimerEvent* event)
  416. {
  417. int nID = event->timerId();
  418. }
  419. void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex)
  420. {
  421. int nOnClickGroupId = groupId - 1; // 这里new 有些是0,有些是1 暂时选择
  422. if (m_pMainCameraBind == nullptr || m_allGroup.size() < groupId)
  423. {
  424. return;
  425. }
  426. //判断更新前的左窗口是否是绑定相机
  427. if (m_veCurrentSelectGroup_L.isBond == true) {
  428. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  429. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  430. }
  431. //判断更新前的右窗口是否是绑定相机
  432. if (m_veCurrentSelectGroup_R.isBond == true) {
  433. //解绑
  434. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  435. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  436. }
  437. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  438. //判断更新前的右窗口的index是相机还是物料
  439. if (lastIndex == 1) {
  440. //左窗口绑定
  441. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  442. }
  443. else {
  444. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  445. }
  446. //右边更新物料窗口
  447. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  448. //判断当前index是相机还是物料
  449. if (nIndex == 2) {
  450. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  451. }
  452. else if (nIndex == 1) {//当前切换时相机序号
  453. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  454. }
  455. }
  456. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L(const QPixmap& imageData)
  457. {
  458. //lastIndex = 1;
  459. QSize size_left = ui->viewwidgetgroup_L->getOperatewidget()->size();
  460. QPixmap scaledPixmap_left = m_lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  461. //ui->viewwidgetgroup_L->getOperatewidget()->setPixmap(scaledPixmap_left);
  462. ui->viewwidgetgroup_L->setScaleFactorSize(scaledPixmap_left);
  463. m_lastRightPixmap = imageData;
  464. //UpdataGroupSettings(imageData);
  465. }
  466. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R(const QPixmap& imageData)
  467. {
  468. QSize size_left = ui->viewwidgetgroup_R->getOperatewidget()->size();
  469. QPixmap scaledPixmap_right = imageData.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  470. //ui->viewwidgetgroup_R->getOperatewidget()->setPixmap(scaledPixmap_left);
  471. ui->viewwidgetgroup_R->setScaleFactorSize(scaledPixmap_right);
  472. m_lastRightPixmap = imageData;
  473. }
  474. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent *event)
  475. {
  476. //if (ui->viewwidgetgroup_L->getOperatewidget()->rect().contains(ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  477. // mousePos = ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos());
  478. // if (event->angleDelta().y() > 0) {
  479. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 1.1); // 放大
  480. // } else {
  481. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 0.9); // 缩小
  482. // }
  483. //}
  484. //if (ui->viewwidgetgroup_R->getOperatewidget()->rect().contains(ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  485. // mousePos = ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos());
  486. // if (event->angleDelta().y() > 0) {
  487. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 1.1); // 放大
  488. // } else {
  489. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 0.9); // 缩小
  490. // }
  491. //}
  492. //if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  493. // // 获取 QScrollArea 的横向滚动条
  494. // QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  495. // // 根据滚轮滚动方向改变滚动条的值
  496. // if (event->angleDelta().y() > 0) {
  497. // scrollBar->setValue(scrollBar->value() - 50);
  498. // } else {
  499. // scrollBar->setValue(scrollBar->value() + 50);
  500. // }
  501. //}
  502. QMainWindow::wheelEvent(event);
  503. }
  504. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent *event) {
  505. isUpdatingSettings = false;
  506. QMainWindow::showEvent(event);
  507. isUpdatingSettings = false;
  508. }
  509. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent *event) {
  510. isUpdatingSettings = false;
  511. QMainWindow::hideEvent(event);
  512. }
  513. QStringList MainAndSecondaryCamerasWnd::getImageslist(const QString& path) {
  514. // 创建 QDir 对象
  515. QDir dir(path);
  516. // 检查文件夹是否存在
  517. if (!dir.exists()) {
  518. qWarning() << "Folder does not exist:" ;
  519. }
  520. // 获取文件夹中的所有图片文件
  521. QStringList filters;
  522. filters << "*.png" << "*.jpg" << "*.jpeg" << "*.bmp" << "*.gif"; // 添加你需要的图片格式
  523. QStringList fileList = dir.entryList(filters, QDir::Files);
  524. return fileList;
  525. }