MainAndSecondaryCamerasWnd.cpp 28 KB

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