MainAndSecondaryCamerasWnd.cpp 24 KB

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