MainAndSecondaryCamerasWnd.cpp 21 KB

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