MainAndSecondaryCamerasWnd.cpp 31 KB

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