MainAndSecondaryCamerasWnd.cpp 23 KB

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