MainAndSecondaryCamerasWnd.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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. // 注册表里面没有默认值,下面2个
  191. lastLastIndex = settings.value("LastLastIndex", 0).toInt();
  192. lastLastGroupId = settings.value("LastLastGroupId", 0).toInt();
  193. settings.endGroup();
  194. QSettings settings2("YourOrganization", "YourApplication_lastWndType");
  195. int lastWndType = settings2.value("LastWndType").toInt();
  196. int LastGroup = settings2.value("LastGroup").toInt();
  197. int Last_materialWndType = settings2.value("MaterialWndType").toInt();
  198. lastIndex = lastWndType;
  199. lastGroupId = LastGroup;
  200. //处理各种情况的初始化
  201. if (m_pMainCameraBind == nullptr || m_allGroup.size() < lastGroupId || m_allGroup.size() == 0)
  202. {
  203. return;
  204. }
  205. if (m_allGroup.size() == 1) {
  206. if (LastGroup != lastLastGroupId || LastGroup == lastLastGroupId){
  207. m_veCurrentSelectGroup_R.isInitialed = true;
  208. m_veCurrentSelectGroup_L.isInitialed = true;
  209. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  210. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  211. if (lastIndex == 1) {
  212. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  213. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  214. }
  215. else {
  216. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  217. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  218. }
  219. }else {
  220. }
  221. }else {
  222. }
  223. m_veCurrentSelectGroup_R.isInitialed = true;
  224. m_veCurrentSelectGroup_L.isInitialed = true;
  225. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastLastGroupId - 1);
  226. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId -1);
  227. if (lastLastIndex == 1) {
  228. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  229. }
  230. else {
  231. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  232. }
  233. if (lastIndex == 1) {
  234. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  235. }
  236. else {
  237. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  238. m_veCurrentSelectGroup_R.isBond = false;
  239. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, false);
  240. }
  241. }
  242. void MainAndSecondaryCamerasWnd::BindImageOrMaterial(int location, int index) {
  243. if (location == m_nLastLeft) {
  244. if (index == m_nImageIndex) {
  245. m_veCurrentSelectGroup_L.isBond = true;
  246. connect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  247. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  248. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, true);
  249. }else {
  250. //左边更新物料窗口
  251. QSettings settings("YourOrganization", "YourApplication");
  252. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  253. int lastMaterialWndType = settings.value("MaterialWndType").toInt();
  254. settings.endGroup();
  255. m_veCurrentSelectGroup_L.isBond = false;
  256. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, false);
  257. updateMaterialWidget(m_nLastLeft, lastMaterialWndType, m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId);
  258. }
  259. }else {
  260. if (index == m_nImageIndex) {
  261. m_veCurrentSelectGroup_R.isBond = true;
  262. connect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  263. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  264. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, true);
  265. }
  266. else {
  267. //右边更新物料窗口
  268. QSettings settings("YourOrganization", "YourApplication");
  269. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  270. int materialWndType = settings.value("MaterialWndType").toInt();
  271. settings.endGroup();
  272. m_veCurrentSelectGroup_R.isBond = false;
  273. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, false);
  274. updateMaterialWidget(m_nCurrentRight, materialWndType, m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId);
  275. }
  276. }
  277. }
  278. void MainAndSecondaryCamerasWnd::checkSettings(int groupId,int index) {
  279. if (groupId != lastGroupId || index != lastIndex) {
  280. GetCurrentSelectSlots(groupId, index);
  281. lastLastGroupId = lastGroupId;
  282. lastLastIndex = lastIndex;
  283. lastGroupId = groupId;
  284. lastIndex = index;
  285. saveInfoOfLast();
  286. }
  287. }
  288. void MainAndSecondaryCamerasWnd::saveInfoOfLast() {
  289. QSettings lastSettings("YourOrganization", "YourApplication_lastWndType");
  290. lastSettings.setValue("LastWndType", lastIndex);
  291. lastSettings.setValue("LastGroup", lastGroupId);
  292. QSettings settings("YourOrganization", "YourApplication");
  293. settings.beginGroup("LastSettings");
  294. settings.setValue("LastLastIndex", lastLastIndex);
  295. settings.setValue("LastLastGroupId", lastLastGroupId);
  296. }
  297. void MainAndSecondaryCamerasWnd::loadGroupSettings(int Id, int Index)
  298. {
  299. QSettings settings("YourOrganization", "YourApplication");
  300. settings.beginGroup(QString::number(Id));
  301. QString imagePath = settings.value("ImagePath1").toString();
  302. int materialWndType = settings.value("MaterialWndType").toInt();
  303. QStringList textList = settings.value("TextList").toStringList();
  304. settings.endGroup();
  305. QSettings Last_settings("YourOrganization", "YourApplication");
  306. settings.beginGroup(QString::number(lastGroupId));
  307. QString Last_imagePath = settings.value("ImagePath1").toString();
  308. int Last_materialWndType = settings.value("MaterialWndType").toInt();
  309. QStringList Last_textList = settings.value("TextList").toStringList();
  310. settings.endGroup();
  311. QString lastRightImage = settings.value("LastRightImage").toString();
  312. QPixmap newPixmap;
  313. QPixmap Last_newPixmap;
  314. if (Index == 1)
  315. {
  316. newPixmap = QPixmap(imagePath);
  317. ui->viewwidgetgroup_R->updateOperateWidget(newPixmap);
  318. ui->viewwidgetgroup_R->setEnableControls(true);
  319. }
  320. if (lastIndex == 1)
  321. {
  322. Last_newPixmap = QPixmap(Last_imagePath);
  323. ui->viewwidgetgroup_L->updateOperateWidget(Last_newPixmap);
  324. ui->viewwidgetgroup_L->setEnableControls(true);
  325. }
  326. else if (lastIndex == 2)
  327. {
  328. updateMaterialWidget(m_nLastLeft,Last_materialWndType, lastGroupId);
  329. ui->viewwidgetgroup_L->setEnableControls(false);
  330. }
  331. if (Index == 2)
  332. {
  333. updateMaterialWidget(m_nCurrentRight,materialWndType, Id);
  334. ui->viewwidgetgroup_R->setEnableControls(false);
  335. }
  336. QSettings settings2("YourOrganization", "YourApplication_lastWndType");
  337. settings2.setValue("LastWndType", lastIndex);
  338. settings2.setValue("LastGroup", lastGroupId);
  339. QPixmap scaledPixmap_right = newPixmap.scaled(ui->viewwidgetgroup_R->getOperatewidget()->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  340. if (isUpdatingSettings) {
  341. lastLastRightPixmap = m_lastRightPixmap;
  342. lastLasttextList = lasttextList;
  343. m_lastRightPixmap = scaledPixmap_right;
  344. lasttextList = textList;
  345. lastLastIndex = lastIndex;
  346. lastLastGroupId = lastGroupId;
  347. }
  348. }
  349. void MainAndSecondaryCamerasWnd::updateMaterialWidget(int side,int materialWndType, int groupId) {
  350. if (side == m_nLastLeft) {
  351. switch (materialWndType) {
  352. case 1: ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(groupId)); break;
  353. case 2: ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(groupId)); break;
  354. case 3: ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  355. case 4: ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(groupId)); break;
  356. }
  357. }
  358. else if (side == m_nCurrentRight) {
  359. switch (materialWndType) {
  360. case 1: ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(groupId)); break;
  361. case 2: ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(groupId)); break;
  362. case 3: ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  363. case 4: ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(groupId)); break;
  364. }
  365. }
  366. }
  367. void MainAndSecondaryCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  368. {
  369. m_pMainCameraBind = pCameraBind;
  370. initFrom();
  371. }
  372. void MainAndSecondaryCamerasWnd::UnCameraBind()
  373. {
  374. for (size_t i = 0; i < m_allGroup.size(); i++)
  375. {
  376. CameraConnectUpdateImageFun(i, m_allGroup[i], true);
  377. }
  378. }
  379. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  380. {
  381. // TODO: 这里需要改动
  382. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  383. ui->viewwidgetgroup_L->getOperatewidget()->setGeometry(ui->viewwidgetgroup_L->getOperatewidget()->pos().x(),
  384. ui->viewwidgetgroup_L->getOperatewidget()->pos().y(),
  385. ui->viewwidgetgroup_L->getOperatewidget()->width(),
  386. ui->viewwidgetgroup_L->getOperatewidget()->height());
  387. //ui->LeftOperatewidget->setPixmap(QPixmap::fromImage(image));
  388. emit UpDataImageShowSignals0(QPixmap::fromImage(image));
  389. }
  390. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  391. {
  392. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  393. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  394. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  395. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  396. ui->viewwidgetgroup_R->getOperatewidget()->height());
  397. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  398. emit UpDataImageShowSignals1(QPixmap::fromImage(image));
  399. }
  400. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  401. {
  402. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  403. emit UpDataImageShowSignals2(QPixmap::fromImage(image));
  404. }
  405. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  406. {
  407. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  408. emit UpDataImageShowSignals3(QPixmap::fromImage(image));
  409. }
  410. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  411. {
  412. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  413. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  414. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  415. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  416. ui->viewwidgetgroup_R->getOperatewidget()->height());
  417. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  418. emit UpDataImageShowSignals4(QPixmap::fromImage(image));
  419. }
  420. void MainAndSecondaryCamerasWnd::HideLayout(QHBoxLayout* layout, bool isHide)
  421. {
  422. for (int i = 0; i < layout->count(); ++i)
  423. {
  424. QWidget* widget = layout->itemAt(i)->widget();
  425. if (widget)
  426. {
  427. if (isHide)
  428. {
  429. widget->hide();
  430. }
  431. else
  432. {
  433. widget->show();
  434. }
  435. }
  436. }
  437. }
  438. void MainAndSecondaryCamerasWnd::UpdataLightJoystickSwitchPage(int groupId, int index, bool isShow)
  439. {
  440. auto Fun = [&](Group* pGroup,LightJoystickSwitchPage* p, ControlOperationPage* pContPage, bool bShow)
  441. {
  442. p->UpdatemPageGroup(pGroup);
  443. p->InitMainCameraBind(m_pMainCameraBind, bShow);
  444. p->HideOrShowPage(bShow);
  445. if (bShow)
  446. {
  447. pContPage->UpDateCameraBind(m_pMainCameraBind);
  448. }
  449. else
  450. {
  451. pContPage->setSwitchJoystickButEnable(bShow);
  452. }
  453. };
  454. if (index == 1)
  455. {
  456. disconnect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  457. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  458. Group* currGroup = m_allGroup.at(groupId-1);
  459. Fun(currGroup, ui->control_L, ui->viewwidgetgroup_L, isShow);
  460. connect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  461. ui->control_L,&LightJoystickSwitchPage::GetModuleTypeSlots);
  462. }
  463. else if(index == 2)
  464. {
  465. disconnect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  466. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  467. Group* currGroup = m_allGroup.at(groupId-1);
  468. Fun(currGroup, ui->control_r, ui->viewwidgetgroup_R, isShow);
  469. connect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  470. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  471. }
  472. }
  473. void MainAndSecondaryCamerasWnd::timerEvent(QTimerEvent* event)
  474. {
  475. int nID = event->timerId();
  476. }
  477. void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex)
  478. {
  479. int nOnClickGroupId = groupId -1; // 这里new 有些是0,有些是1 暂时选择
  480. if (m_pMainCameraBind == nullptr || m_allGroup.size() < groupId)
  481. {
  482. return;
  483. }
  484. //判断index是相机还是物料
  485. if (nIndex == 2) {
  486. if (m_veCurrentSelectGroup_L.isBond == true) {
  487. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  488. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  489. }
  490. //判断更新前的右窗口是否是绑定相机
  491. if (m_veCurrentSelectGroup_R.isBond == true) {
  492. //解绑
  493. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  494. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  495. //左窗口绑定
  496. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  497. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  498. }
  499. else {
  500. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  501. }
  502. //右边更新物料窗口
  503. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  504. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  505. }else if (nIndex == 1) {//当前切换时相机序号
  506. if (m_veCurrentSelectGroup_L.isBond == true) {
  507. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  508. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  509. }
  510. if (m_veCurrentSelectGroup_R.isBond == true) {
  511. //解绑
  512. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  513. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  514. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  515. //换绑
  516. //左窗口绑定
  517. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  518. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  519. }
  520. else {
  521. //左边更新物料窗口
  522. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  523. QSettings settings("YourOrganization", "YourApplication");
  524. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  525. int lastMaterialWndType = settings.value("MaterialWndType").toInt();
  526. settings.endGroup();
  527. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  528. }
  529. //右窗口更新相机窗口
  530. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  531. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  532. }
  533. }
  534. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L(const QPixmap& imageData)
  535. {
  536. //lastIndex = 1;
  537. QSize size_left = ui->viewwidgetgroup_L->getOperatewidget()->size();
  538. QPixmap scaledPixmap_left = m_lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  539. //ui->viewwidgetgroup_L->getOperatewidget()->setPixmap(scaledPixmap_left);
  540. ui->viewwidgetgroup_L->setScaleFactorSize(scaledPixmap_left);
  541. m_lastRightPixmap = imageData;
  542. //UpdataGroupSettings(imageData);
  543. }
  544. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R(const QPixmap& imageData)
  545. {
  546. QSize size_left = ui->viewwidgetgroup_R->getOperatewidget()->size();
  547. QPixmap scaledPixmap_right = imageData.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  548. //ui->viewwidgetgroup_R->getOperatewidget()->setPixmap(scaledPixmap_left);
  549. ui->viewwidgetgroup_R->setScaleFactorSize(scaledPixmap_right);
  550. m_lastRightPixmap = imageData;
  551. }
  552. #if 0
  553. void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex)
  554. {
  555. int nOnClickGroupId = groupId - 1; // 这里new 有些是0,有些是1 暂时选择
  556. if (m_pMainCameraBind == nullptr || m_allGroup.size() < nOnClickGroupId)
  557. {
  558. return;
  559. }
  560. // 绑定操作,用来初始化
  561. ST_CURRENT_SELECT_GROUP _curr;
  562. _curr.isBond = true;
  563. if (m_pMainCameraBind->m_vecCamera.size() > nOnClickGroupId)
  564. {
  565. _curr.nCurrentCameraId = m_pMainCameraBind->m_vecCamera[nOnClickGroupId].iCameraId;
  566. }
  567. else
  568. {
  569. _curr.nCurrentCameraId = 0;
  570. }
  571. _curr.nSelectLeft1 = nIndex; // 是否选中窗口
  572. Group* pGroup = m_allGroup.at(nOnClickGroupId);
  573. _curr.pSelectGroup = pGroup;
  574. // 1.判断当前是否存储
  575. if (m_veCurrentSelectGroup.size() >= 2)
  576. {
  577. if (pGroup == m_veCurrentSelectGroup[1].pSelectGroup &&
  578. m_veCurrentSelectGroup[1].nSelectLeft1== nIndex)
  579. {
  580. return;
  581. }
  582. // 解绑操作,删除第0个 ,, 主要目前为了实现 相机切换
  583. disconnect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig,
  584. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  585. disconnect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig,
  586. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4);
  587. disconnect(m_veCurrentSelectGroup[1].pSelectGroup, &Group::SetUpDataImageShowSig,
  588. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  589. disconnect(m_veCurrentSelectGroup[1].pSelectGroup, &Group::SetUpDataImageShowSig,
  590. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4);
  591. m_veCurrentSelectGroup.erase(m_veCurrentSelectGroup.begin() + 0);// 0个
  592. if (m_veCurrentSelectGroup[0].nSelectLeft1 == 1)
  593. {
  594. connect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig,
  595. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  596. // 在绑定
  597. connect(pGroup, &Group::SetUpDataImageShowSig,
  598. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4);
  599. }
  600. else
  601. {
  602. // 直接复制图片?
  603. if (_curr.nSelectLeft1 == 1)
  604. {
  605. connect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig,
  606. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4);
  607. }
  608. else
  609. {
  610. //loadGroupSettings(groupId, nIndex);
  611. }
  612. }
  613. m_veCurrentSelectGroup.push_back(_curr);
  614. UpdataLightJoystickSwitchPage();
  615. }
  616. else
  617. {
  618. if (m_veCurrentSelectGroup.size() > 0)
  619. {
  620. if (m_veCurrentSelectGroup[0].pSelectGroup != _curr.pSelectGroup)
  621. {
  622. if (m_veCurrentSelectGroup.size() == 1)
  623. {
  624. connect(pGroup, &Group::SetUpDataImageShowSig,
  625. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4);
  626. }
  627. else
  628. {
  629. connect(pGroup, &Group::SetUpDataImageShowSig,
  630. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  631. }
  632. m_veCurrentSelectGroup.push_back(_curr);
  633. }
  634. else
  635. {
  636. if (m_veCurrentSelectGroup.size() == 0)
  637. {
  638. connect(pGroup, &Group::SetUpDataImageShowSig,
  639. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  640. }
  641. m_veCurrentSelectGroup.clear();
  642. m_veCurrentSelectGroup.push_back(_curr);
  643. }
  644. UpdataLightJoystickSwitchPage();
  645. }
  646. else
  647. {
  648. if (m_veCurrentSelectGroup.size() == 1)
  649. {
  650. connect(pGroup, &Group::SetUpDataImageShowSig,
  651. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4);
  652. }
  653. else
  654. {
  655. connect(pGroup, &Group::SetUpDataImageShowSig,
  656. this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0);
  657. }
  658. m_veCurrentSelectGroup.push_back(_curr);
  659. UpdataLightJoystickSwitchPage();
  660. }
  661. }
  662. }
  663. #endif
  664. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent *event)
  665. {
  666. //if (ui->viewwidgetgroup_L->getOperatewidget()->rect().contains(ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  667. // mousePos = ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos());
  668. // if (event->angleDelta().y() > 0) {
  669. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 1.1); // 放大
  670. // } else {
  671. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 0.9); // 缩小
  672. // }
  673. //}
  674. //if (ui->viewwidgetgroup_R->getOperatewidget()->rect().contains(ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  675. // mousePos = ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos());
  676. // if (event->angleDelta().y() > 0) {
  677. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 1.1); // 放大
  678. // } else {
  679. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 0.9); // 缩小
  680. // }
  681. //}
  682. //if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  683. // // 获取 QScrollArea 的横向滚动条
  684. // QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  685. // // 根据滚轮滚动方向改变滚动条的值
  686. // if (event->angleDelta().y() > 0) {
  687. // scrollBar->setValue(scrollBar->value() - 50);
  688. // } else {
  689. // scrollBar->setValue(scrollBar->value() + 50);
  690. // }
  691. //}
  692. QMainWindow::wheelEvent(event);
  693. }
  694. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent *event) {
  695. isUpdatingSettings = false;
  696. QMainWindow::showEvent(event);
  697. //loadSettings();
  698. isUpdatingSettings = false;
  699. }
  700. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent *event) {
  701. isUpdatingSettings = false;
  702. QMainWindow::hideEvent(event);
  703. }
  704. QStringList MainAndSecondaryCamerasWnd::getImageslist(const QString& path) {
  705. // 创建 QDir 对象
  706. QDir dir(path);
  707. // 检查文件夹是否存在
  708. if (!dir.exists()) {
  709. qWarning() << "Folder does not exist:" ;
  710. }
  711. // 获取文件夹中的所有图片文件
  712. QStringList filters;
  713. filters << "*.png" << "*.jpg" << "*.jpeg" << "*.bmp" << "*.gif"; // 添加你需要的图片格式
  714. QStringList fileList = dir.entryList(filters, QDir::Files);
  715. return fileList;
  716. }