MainAndSecondaryCamerasWnd.cpp 22 KB

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