MainAndSecondaryCamerasWnd.cpp 28 KB

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