MainAndSecondaryCamerasWnd.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. #include "MainAndSecondaryCamerasWnd.h"
  2. #include "ui_MainAndSecondaryCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QTimer>
  7. #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
  8. #include <qDebug.h>
  9. #include <QScrollBar>
  10. MainAndSecondaryCamerasWnd::MainAndSecondaryCamerasWnd(QWidget *parent)
  11. : QMainWindow(parent)
  12. , ui(new Ui::MainAndSecondaryCamerasWnd)
  13. {
  14. ui->setupUi(this);
  15. QSettings settings("YourOrganization", "YourApplication");
  16. settings.beginGroup("LastSettings");
  17. lastRightPixmap = settings.value("LastRightPixmap").value<QPixmap>();
  18. lasttextList = settings.value("LasttextList").toStringList();
  19. lastLastRightPixmap = settings.value("LastLastRightPixmap").value<QPixmap>();
  20. lastLasttextList = settings.value("LastLasttextList").toStringList();
  21. lastLastIndex = settings.value("LastLastIndex", 0).toInt();
  22. lastLastGroupId = settings.value("LastLastGroupId", 0).toInt();
  23. settings.endGroup();
  24. initFrom();
  25. isShow_R = true;
  26. isShow_L = true;
  27. }
  28. MainAndSecondaryCamerasWnd::~MainAndSecondaryCamerasWnd()
  29. {
  30. delete ui;
  31. }
  32. void MainAndSecondaryCamerasWnd::initFrom()
  33. {
  34. QTimer *timer = new QTimer(this);
  35. connect(timer, &QTimer::timeout, this, &MainAndSecondaryCamerasWnd::checkSettings);
  36. timer->start(100);
  37. ui->Leftlabel_Percentage->setAlignment(Qt::AlignCenter);
  38. ui->Rightlabel_Percentage->setAlignment(Qt::AlignCenter);
  39. initSliders();
  40. initLineEdits();
  41. initProgressBar();
  42. // 连接 QSlider 的 valueChanged 信号到 QProgressBar 的 setValue 槽
  43. connect(ui->RedLightverticalSlider_2, &QSlider::valueChanged, ui->RedLightprogressBar_2, &QProgressBar::setValue);
  44. connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar_2, &QProgressBar::setValue);
  45. connect(ui->GreenLightverticalSlider_5, &QSlider::valueChanged, ui->GreenLightprogressBar_5, &QProgressBar::setValue);
  46. connect(ui->DotLightverticalSlider_2, &QSlider::valueChanged, ui->DotLightprogressBar_2, &QProgressBar::setValue);
  47. connect(ui->RedLightverticalSlider_L, &QSlider::valueChanged, ui->RedLightprogressBar_L, &QProgressBar::setValue);
  48. connect(ui->BlueLightverticalSlider_L, &QSlider::valueChanged, ui->BlueLightprogressBar_L, &QProgressBar::setValue);
  49. connect(ui->GreenLightverticalSlider_L, &QSlider::valueChanged, ui->GreenLightprogressBar_L, &QProgressBar::setValue);
  50. connect(ui->DotLightverticalSlider_L, &QSlider::valueChanged, ui->DotLightprogressBar_L, &QProgressBar::setValue);
  51. connectSliderAndLineEdit(ui->RedLightverticalSlider_2, ui->RedLightlineEdit_2);
  52. connectSliderAndLineEdit(ui->GreenLightverticalSlider_5, ui->GreenLightlineEdit_5);
  53. connectSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit_2);
  54. connectSliderAndLineEdit(ui->DotLightverticalSlider_2, ui->DotLightlineEdit_2);
  55. connectSliderAndLineEdit(ui->RedLightverticalSlider_L, ui->RedLightlineEdit_L);
  56. connectSliderAndLineEdit(ui->GreenLightverticalSlider_L, ui->GreenLightlineEdit_L);
  57. connectSliderAndLineEdit(ui->BlueLightverticalSlider_L, ui->BlueLightlineEdit_L);
  58. connectSliderAndLineEdit(ui->DotLightverticalSlider_L, ui->DotLightlineEdit_L);
  59. connect(ui->LeftOperatewidget,&ImageWidget::sendDoubleClicksignal,this,&MainAndSecondaryCamerasWnd::handleDoubleClick);
  60. connect(ui->RightOperatewidget,&ImageWidget::sendDoubleClicksignal,this,&MainAndSecondaryCamerasWnd::handleDoubleClick);
  61. QWidget *viewport = ui->scrollArea->viewport();
  62. QWidget *container = new QWidget(viewport);
  63. QHBoxLayout *mainLayout = new QHBoxLayout(container);
  64. mainLayout->setSpacing(28);
  65. mainLayout->setMargin(0);
  66. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  67. QList<Group*> widgets;
  68. for (int i = 0; i < numbers.size(); ++i) {
  69. int num = numbers[i];
  70. CameraImageHandler* manager = new CameraImageHandler(num);
  71. Group* widget = manager->getGroup();
  72. connect(widget,&Group::send_button_Signal,this,&MainAndSecondaryCamerasWnd::CheckIs);
  73. if (widget != nullptr) {
  74. mainLayout->addWidget(widget);
  75. widgets.append(widget);
  76. }
  77. if(manager->getWafer()) {
  78. waferMap.insert(num, manager->getWafer());
  79. }
  80. if(manager->getWafer()) {
  81. waffleMap.insert(num, manager->getWaffle());
  82. }
  83. if(manager->getMaterialBox()){
  84. materialBoxMap.insert(num,manager->getMaterialBox());
  85. }
  86. delete manager;
  87. }
  88. // 设置控件的最小高度和最大宽度
  89. int minHeight = 162;
  90. int maxWidth = 244;
  91. int num = -28;
  92. for (Group* w : widgets) {
  93. w->setMinimumHeight(minHeight);
  94. w->setMaximumWidth(maxWidth);
  95. num = num + 272;
  96. }
  97. container->setMinimumSize(num, 162);
  98. container->setLayout(mainLayout);
  99. ui->scrollArea->setWidget(container);
  100. ui->scrollArea->resize(1062, 177);
  101. ui->LeftOperatewidget->setMouseTracking(true);
  102. ui->RightOperatewidget->setMouseTracking(true);
  103. QSettings settings2("YourOrganization", "YourApplication_lastWndType");
  104. int lastWndType = settings2.value("LastWndType").toInt();
  105. int LastGroup = settings2.value("LastGroup").toInt();
  106. lastIndex = lastWndType;
  107. lastGroupId = LastGroup;
  108. }
  109. void MainAndSecondaryCamerasWnd::initSliders() {
  110. QList<QSlider*> sliders = {
  111. ui->RedLightverticalSlider_2, ui->GreenLightverticalSlider_5,
  112. ui->BlueLightverticalSlider, ui->DotLightverticalSlider_2,
  113. ui->RedLightverticalSlider_L, ui->GreenLightverticalSlider_L,
  114. ui->BlueLightverticalSlider_L, ui->DotLightverticalSlider_L
  115. };
  116. QList<int> initialValues = {22, 11, 0, 0, 22, 11, 0, 0};
  117. for (int i = 0; i < sliders.size(); ++i) {
  118. sliders[i]->setMinimum(0);
  119. sliders[i]->setMaximum(100);
  120. sliders[i]->setValue(initialValues[i]);
  121. }
  122. }
  123. void MainAndSecondaryCamerasWnd::initProgressBar(){
  124. QList<int> initialValues = {22, 11, 0, 0, 22, 11, 0, 0};
  125. QList<QProgressBar*> progressBar = {
  126. ui->RedLightprogressBar_2,ui->GreenLightprogressBar_5,
  127. ui->BlueLightprogressBar_2,ui->DotLightprogressBar_2,
  128. ui->RedLightprogressBar_L,ui->GreenLightprogressBar_L,
  129. ui->BlueLightprogressBar_L,ui->DotLightprogressBar_L
  130. };
  131. for (int i = 0; i < progressBar.size(); ++i) {
  132. progressBar[i]->setMinimum(0);
  133. progressBar[i]->setMaximum(100);
  134. progressBar[i]->setValue(initialValues[i]);
  135. }
  136. }
  137. void MainAndSecondaryCamerasWnd::handleDoubleClick(){
  138. QPoint globalMousePos = QCursor::pos(); // 获取当前鼠标的全局位置
  139. QPoint leftWidgetLocalPos = ui->LeftOperatewidget->mapFromGlobal(globalMousePos);
  140. QPoint rightWidgetLocalPos = ui->RightOperatewidget->mapFromGlobal(globalMousePos);
  141. if (ui->LeftOperatewidget->rect().contains(leftWidgetLocalPos)){
  142. if (Left_currentMode == ModeImage) {
  143. QPixmap scaledImage = Left_currentPixmap.scaled(Left_currentPixmap.width(), Left_currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  144. ui->LeftOperatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
  145. } else if (Left_currentMode == ModeView && Left_currentView) {
  146. QTransform transform;
  147. transform.scale(1, 1);
  148. Left_currentView->setTransform(transform);
  149. }
  150. Left_scaleFactor = 1.0;
  151. Left_previousScaleFactor = 1.0;
  152. ui->Leftlabel_Percentage->setText("100%");
  153. }
  154. if(ui->RightOperatewidget->rect().contains(rightWidgetLocalPos)){
  155. if (Right_currentMode == ModeImage) {
  156. QPixmap scaledImage = Right_currentPixmap.scaled(Right_currentPixmap.width(), Right_currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  157. ui->RightOperatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
  158. } else if (Right_currentMode == ModeView && Right_currentView) {
  159. QTransform transform;
  160. transform.scale(1, 1);
  161. Right_currentView->setTransform(transform);
  162. }
  163. Right_scaleFactor = 1.0;
  164. Right_previousScaleFactor = 1.0;
  165. ui->Rightlabel_Percentage->setText("100%");
  166. }
  167. }
  168. void MainAndSecondaryCamerasWnd::initLineEdits() {
  169. QList<QLineEdit*> lineEdits = {
  170. ui->RedLightlineEdit_2, ui->GreenLightlineEdit_5,
  171. ui->BlueLightlineEdit_2, ui->DotLightlineEdit_2,
  172. ui->RedLightlineEdit_L, ui->GreenLightlineEdit_L,
  173. ui->BlueLightlineEdit_L, ui->DotLightlineEdit_L
  174. };
  175. for (QLineEdit* lineEdit : lineEdits) {
  176. lineEdit->setAlignment(Qt::AlignCenter);
  177. }
  178. }
  179. void MainAndSecondaryCamerasWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  180. {
  181. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  182. lineEdit->setValidator(validator);
  183. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  184. lineEdit->setText(QString::number(value));
  185. });
  186. connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
  187. bool ok;
  188. int value = text.toInt(&ok);
  189. if (ok && value >= slider->minimum() && value <= slider->maximum()) {
  190. slider->setValue(value);
  191. } else if (!text.isEmpty()) {
  192. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  193. slider->setValue(closestValue);
  194. }
  195. });
  196. }
  197. void MainAndSecondaryCamerasWnd::checkSettings() {
  198. QSettings settings("YourCompany", "YourApplication_");
  199. int groupId = settings.value("GroupId", 0).toInt();
  200. int index = settings.value("Index", 0).toInt();
  201. if (groupId != lastGroupId || index != lastIndex) {
  202. loadSettings();
  203. lastGroupId = groupId;
  204. lastIndex = index;
  205. }
  206. }
  207. void MainAndSecondaryCamerasWnd::loadSettings()
  208. {
  209. QSettings settings("YourCompany", "YourApplication_");
  210. int groupId = settings.value("GroupId", 0).toInt();
  211. int index = settings.value("Index", 0).toInt();
  212. loadGroupSettings(groupId, index);
  213. }
  214. void MainAndSecondaryCamerasWnd::loadGroupSettings(int Id, int Index) {
  215. // isUpdatingSettings = true;
  216. QSettings settings("YourOrganization", "YourApplication");
  217. settings.beginGroup(QString::number(Id));
  218. QString imagePath1 = settings.value("ImagePath1").toString();
  219. int materialWndType = settings.value("MaterialWndType").toInt();
  220. QStringList textList = settings.value("TextList").toStringList();
  221. settings.endGroup();
  222. QSettings Last_settings("YourOrganization", "YourApplication");
  223. settings.beginGroup(QString::number(lastGroupId));
  224. QString Last_imagePath1 = settings.value("ImagePath1").toString();
  225. int Last_materialWndType = settings.value("MaterialWndType").toInt();
  226. QStringList Last_textList = settings.value("TextList").toStringList();
  227. settings.endGroup();
  228. // QString lastRightImage = settings.value("LastRightImage").toString();
  229. QSize size_left = ui->LeftOperatewidget->size();
  230. QSize size_right = ui->RightOperatewidget->size();
  231. QPixmap newPixmap;
  232. QPixmap Last_newPixmap;
  233. if (Index == 1) {
  234. isShow_R = true;
  235. clearLayout(1);
  236. clearLayout(0);
  237. qDebug()<<imagePath1;
  238. newPixmap = QPixmap(imagePath1);
  239. QPixmap scaledPixmap = newPixmap.scaled(size_right, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  240. Right_currentMode = ModeImage;
  241. Right_currentPixmap = scaledPixmap;
  242. Right_scaleFactor = 1.0;
  243. Right_previousScaleFactor = 1.0;
  244. ui->RightOperatewidget->setPixmap(scaledPixmap);
  245. double percentage = Right_scaleFactor * 100;
  246. QString percentageStr = QString::number((int)percentage);
  247. ui->Rightlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  248. applyScale(1);
  249. // imageWidget(imagePath1,current_right,size_right);
  250. if (lastIndex == 1) {
  251. isShow_L = true;
  252. Last_newPixmap = QPixmap(Last_imagePath1);
  253. QPixmap scaledPixmap = Last_newPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  254. Left_currentMode = ModeImage;
  255. Left_currentPixmap = scaledPixmap;
  256. Left_scaleFactor = 1.0;
  257. Left_previousScaleFactor = 1.0;
  258. ui->LeftOperatewidget->setPixmap(scaledPixmap);
  259. double percentage = Left_scaleFactor * 100;
  260. QString percentageStr = QString::number((int)percentage);
  261. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  262. // imageWidget(Last_imagePath1,last_left,size_left);
  263. } else if (lastIndex == 2) {
  264. isShow_L = false;
  265. // clearLayout(0);
  266. if (Last_materialWndType == 1) {
  267. KindsofWidget(last_left,lastGroupId,wafer_kind);
  268. } else if (Last_materialWndType == 2) {
  269. KindsofWidget(last_left,lastGroupId,waffle_kind);
  270. } else if (Last_materialWndType == 3) {
  271. KindsofWidget(last_left,lastGroupId,materialbox_kind);
  272. }
  273. }
  274. } else if (Index == 2) {
  275. isShow_R = false;
  276. clearLayout(1);
  277. clearLayout(0);
  278. if (lastIndex == 1) {
  279. // clearLayout(0);
  280. Last_newPixmap = QPixmap(Last_imagePath1);
  281. QPixmap scaledPixmap = Last_newPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  282. Left_currentMode = ModeImage;
  283. Left_currentPixmap = scaledPixmap;
  284. Left_scaleFactor = 1.0;
  285. Left_previousScaleFactor = 1.0;
  286. ui->LeftOperatewidget->setPixmap(scaledPixmap);
  287. double percentage = Left_scaleFactor * 100;
  288. QString percentageStr = QString::number((int)percentage);
  289. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  290. isShow_L = true;
  291. }
  292. if (materialWndType == 1) {
  293. if (lastIndex == 1) {
  294. Last_newPixmap = QPixmap(Last_imagePath1);
  295. QPixmap scaledPixmap = Last_newPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  296. Left_currentMode = ModeImage;
  297. Left_currentPixmap = scaledPixmap;
  298. Left_scaleFactor = 1.0;
  299. Left_previousScaleFactor = 1.0;
  300. ui->LeftOperatewidget->setPixmap(scaledPixmap);
  301. double percentage = Left_scaleFactor * 100;
  302. QString percentageStr = QString::number((int)percentage);
  303. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  304. } else if (lastIndex == 2) {
  305. isShow_L = false;
  306. // clearLayout(0);
  307. if (Last_materialWndType == 1) {
  308. KindsofWidget(last_left,lastGroupId,wafer_kind);
  309. } else if (Last_materialWndType == 2) {
  310. KindsofWidget(last_left,lastGroupId,waffle_kind);
  311. } else if (Last_materialWndType == 3) {
  312. KindsofWidget(last_left,lastGroupId,materialbox_kind);
  313. }
  314. }
  315. KindsofWidget(current_right,Id,wafer_kind);
  316. } else if (materialWndType == 2) {
  317. if (lastIndex == 1) {
  318. Last_newPixmap = QPixmap(Last_imagePath1);
  319. QPixmap scaledPixmap = Last_newPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  320. Left_currentMode = ModeImage;
  321. Left_currentPixmap = scaledPixmap;
  322. Left_scaleFactor = 1.0;
  323. Left_previousScaleFactor = 1.0;
  324. ui->LeftOperatewidget->setPixmap(scaledPixmap);
  325. double percentage = Left_scaleFactor * 100;
  326. QString percentageStr = QString::number((int)percentage);
  327. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  328. } else if (lastIndex == 2) {
  329. isShow_L = false;
  330. if (Last_materialWndType == 1) {
  331. KindsofWidget(last_left,lastGroupId,wafer_kind);
  332. } else if (Last_materialWndType == 2) {
  333. KindsofWidget(last_left,lastGroupId,waffle_kind);
  334. } else if (Last_materialWndType == 3) {
  335. KindsofWidget(last_left,lastGroupId,materialbox_kind);
  336. }
  337. }
  338. KindsofWidget(current_right,Id,waffle_kind);
  339. } else if (materialWndType == 3) {
  340. if (lastIndex == 1) {
  341. Last_newPixmap = QPixmap(Last_imagePath1);
  342. QPixmap scaledPixmap = Last_newPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  343. Left_currentMode = ModeImage;
  344. Left_currentPixmap = scaledPixmap;
  345. Left_scaleFactor = 1.0;
  346. Left_previousScaleFactor = 1.0;
  347. ui->LeftOperatewidget->setPixmap(scaledPixmap);
  348. double percentage = Left_scaleFactor * 100;
  349. QString percentageStr = QString::number((int)percentage);
  350. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  351. } else if (lastIndex == 2) {
  352. isShow_L = false;
  353. if (Last_materialWndType == 1) {
  354. KindsofWidget(last_left,lastGroupId,wafer_kind);
  355. } else if (Last_materialWndType == 2) {
  356. KindsofWidget(last_left,lastGroupId,waffle_kind);
  357. } else if (Last_materialWndType == 3) {
  358. KindsofWidget(last_left,lastGroupId,materialbox_kind);
  359. }
  360. }
  361. KindsofWidget(current_right,Id,materialbox_kind);
  362. }
  363. }
  364. showAndHide();
  365. showAndHide_L();
  366. QSettings settings2("YourOrganization", "YourApplication_lastWndType");
  367. settings2.setValue("LastWndType", lastIndex);
  368. settings2.setValue("LastGroup", lastGroupId);
  369. QPixmap scaledPixmap_right = newPixmap.scaled(size_right, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  370. ui->RightOperatewidget->setPixmap(scaledPixmap_right);
  371. QPixmap scaledPixmap_left = lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  372. ui->LeftOperatewidget->setPixmap(scaledPixmap_left);
  373. // 更新当前图片的成员变量
  374. // Left_currentPixmap = scaledPixmap_left;
  375. // Left_scaleFactor = 1.0;
  376. // Right_currentPixmap = scaledPixmap_right;
  377. // Right_scaleFactor = 1.0;
  378. // ui->Leftlabel_Percentage->setText("100%");
  379. // ui->Rightlabel_Percentage->setText("100%");
  380. // ui->LeftDataSources->clear();
  381. // ui->LeftDataSources->addItems(lasttextList);
  382. // ui->RightDataSources->clear();
  383. // ui->RightDataSources->addItems(textList);
  384. // 保存到 QSettings
  385. // settings.beginGroup("LastSettings");
  386. // settings.setValue("LastRightPixmap", lastRightPixmap);
  387. // settings.setValue("LasttextList", lasttextList);
  388. // settings.setValue("LastLastRightPixmap", lastLastRightPixmap);
  389. // settings.setValue("LastLasttextList", lastLasttextList);
  390. // settings.setValue("LastLastIndex", lastLastIndex);
  391. // settings.setValue("LastLastGroupId", lastLastGroupId);
  392. // settings.endGroup();
  393. if (isUpdatingSettings) {
  394. lastLastRightPixmap = lastRightPixmap;
  395. lastLasttextList = lasttextList;
  396. lastRightPixmap = scaledPixmap_right;
  397. lasttextList = textList;
  398. lastLastIndex = lastIndex;
  399. lastLastGroupId = lastGroupId;
  400. }
  401. }
  402. void MainAndSecondaryCamerasWnd::clearLayout(int flag) {
  403. QWidget* widget = (flag == 1) ? ui->RightOperatewidget : ui->LeftOperatewidget;
  404. QLayout* layout = widget->layout();
  405. if (layout) {
  406. QLayoutItem *child;
  407. while ((child = layout->takeAt(0)) != nullptr) {
  408. if (child->widget() != nullptr) {
  409. delete child->widget(); // 删除控件
  410. }
  411. delete child; // 删除布局项
  412. }
  413. delete layout; // 删除布局本身
  414. }
  415. }
  416. //相机
  417. void MainAndSecondaryCamerasWnd::imageWidget(QString path,int flag,QSize size){
  418. QPixmap newPixmap;
  419. QPixmap Last_newPixmap;
  420. if(flag == 0){
  421. isShow_L = true;
  422. Last_newPixmap = QPixmap(path);
  423. QPixmap scaledPixmap = Last_newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  424. Left_currentMode = ModeImage;
  425. Left_currentPixmap = scaledPixmap;
  426. Left_scaleFactor = 1.0;
  427. Left_previousScaleFactor = 1.0;
  428. ui->LeftOperatewidget->setPixmap(scaledPixmap);
  429. double percentage = Left_scaleFactor * 100;
  430. QString percentageStr = QString::number((int)percentage);
  431. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  432. applyScale(0);
  433. }else if(flag == 1){
  434. isShow_R = true;
  435. qDebug()<<path;
  436. newPixmap = QPixmap(":/images/test_image/image_1.png");
  437. QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  438. Right_currentMode = ModeImage;
  439. Right_currentPixmap = scaledPixmap;
  440. Right_scaleFactor = 1.0;
  441. Right_previousScaleFactor = 1.0;
  442. ui->RightOperatewidget->setPixmap(scaledPixmap);
  443. double percentage = Right_scaleFactor * 100;
  444. QString percentageStr = QString::number((int)percentage);
  445. ui->Rightlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  446. applyScale(1);
  447. }else{
  448. qDebug()<<"parameter has problem";
  449. }
  450. }
  451. // 圆晶
  452. void MainAndSecondaryCamerasWnd::KindsofWidget(int flag,int groupId,kinds kind) {
  453. if(flag == 0){
  454. ui->LeftOperatewidget->clearPixmap();
  455. QVBoxLayout *layout = new QVBoxLayout(ui->LeftOperatewidget);
  456. layout->setContentsMargins(0, 0, 0, 0);
  457. if(kind == wafer_kind){
  458. waferMap.value(groupId)->initFrom(ui->LeftOperatewidget);
  459. layout->addWidget(waferMap.value(groupId)->view);
  460. Left_currentView = waferMap.value(groupId)->view;
  461. }else if(kind == waffle_kind){
  462. waffleMap.value(groupId)->initFrom(ui->LeftOperatewidget);
  463. layout->addWidget(waffleMap.value(groupId)->view);
  464. Left_currentView = waffleMap.value(groupId)->view;
  465. }else if(kind == materialbox_kind){
  466. materialBoxMap.value(groupId)->initFrom(ui->LeftOperatewidget);
  467. layout->addWidget(materialBoxMap.value(groupId)->view);
  468. Left_currentView = materialBoxMap.value(groupId)->view;
  469. }else{
  470. }
  471. ui->LeftOperatewidget->setLayout(layout);
  472. Left_currentMode = ModeView;
  473. Left_scaleFactor = 1.0;
  474. applyScale(0);
  475. }else if(flag == 1){
  476. ui->RightOperatewidget->clearPixmap();
  477. QVBoxLayout *layout = new QVBoxLayout(ui->RightOperatewidget);
  478. layout->setContentsMargins(0, 0, 0, 0);
  479. if(kind == wafer_kind){
  480. waferMap.value(groupId)->initFrom(ui->RightOperatewidget);
  481. layout->addWidget(waferMap.value(groupId)->view);
  482. Right_currentView = waferMap.value(groupId)->view;
  483. }else if(kind == waffle_kind){
  484. waffleMap.value(groupId)->initFrom(ui->RightOperatewidget);
  485. layout->addWidget(waffleMap.value(groupId)->view);
  486. Right_currentView = waffleMap.value(groupId)->view;
  487. }else if(kind == materialbox_kind){
  488. materialBoxMap.value(groupId)->initFrom(ui->RightOperatewidget);
  489. layout->addWidget(materialBoxMap.value(groupId)->view);
  490. Right_currentView = materialBoxMap.value(groupId)->view;
  491. }else{
  492. }
  493. ui->RightOperatewidget->setLayout(layout);
  494. Right_currentMode = ModeView;
  495. Right_scaleFactor = 1.0;
  496. applyScale(1);
  497. }else{
  498. qDebug()<<"parameter has problem";
  499. }
  500. }
  501. // 更新缩放比例
  502. void MainAndSecondaryCamerasWnd::updateScale(double newScaleFactor, int flag) {
  503. if (flag == 0) {
  504. if (newScaleFactor >= 1.0) {
  505. Left_scaleFactor = newScaleFactor;
  506. } else {
  507. Left_scaleFactor = 1.0; // 最小缩放比例为 1.0
  508. }
  509. } else if (flag == 1) {
  510. if (newScaleFactor >= 1.0) {
  511. Right_scaleFactor = newScaleFactor;
  512. } else {
  513. Right_scaleFactor = 1.0; // 最小缩放比例为 1.0
  514. }
  515. }
  516. applyScale(flag); // 应用缩放
  517. }
  518. // 应用缩放
  519. void MainAndSecondaryCamerasWnd::applyScale(int flag) {
  520. if (flag == 0) {
  521. if (Left_currentMode == ModeImage) {
  522. // 图片模式:缩放图片
  523. int newWidth = Left_currentPixmap.width() * Left_scaleFactor;
  524. int newHeight = Left_currentPixmap.height() * Left_scaleFactor;
  525. QPixmap scaledImage = Left_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  526. ui->LeftOperatewidget->setPixmapAndPoint(scaledImage, Left_previousScaleFactor, Left_scaleFactor, mousePos);
  527. Left_previousScaleFactor = Left_scaleFactor;
  528. } else if (Left_currentMode == ModeView && Left_currentView) {
  529. // View 模式:缩放 view
  530. QTransform transform;
  531. transform.scale(Left_scaleFactor, Left_scaleFactor);
  532. Left_currentView->setTransform(transform);
  533. }
  534. // 更新百分比显示
  535. double percentage = Left_scaleFactor * 100;
  536. QString percentageStr = QString::number((int)percentage);
  537. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  538. } else if (flag == 1) {
  539. if (Right_currentMode == ModeImage) {
  540. // 图片模式:缩放图片
  541. int newWidth = Right_currentPixmap.width() * Right_scaleFactor;
  542. int newHeight = Right_currentPixmap.height() * Right_scaleFactor;
  543. QPixmap scaledImage = Right_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  544. ui->RightOperatewidget->setPixmapAndPoint(scaledImage, Right_previousScaleFactor, Right_scaleFactor, mousePos);
  545. Right_previousScaleFactor = Right_scaleFactor;
  546. } else if (Right_currentMode == ModeView && Right_currentView) {
  547. // View 模式:缩放 view
  548. QTransform transform;
  549. transform.scale(Right_scaleFactor, Right_scaleFactor);
  550. Right_currentView->setTransform(transform);
  551. }
  552. // 更新百分比显示
  553. double percentage = Right_scaleFactor * 100;
  554. QString percentageStr = QString::number((int)percentage);
  555. ui->Rightlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  556. }
  557. }
  558. void MainAndSecondaryCamerasWnd::on_LeftZoomUpButton_clicked()
  559. {
  560. mousePos = ui->LeftOperatewidget->geometry().center();
  561. updateScale(Left_scaleFactor * 1.1, 0);
  562. }
  563. void MainAndSecondaryCamerasWnd::on_RightZoomUpButton_clicked()
  564. {
  565. mousePos = ui->RightOperatewidget->geometry().center();
  566. updateScale(Right_scaleFactor * 1.1, 1);
  567. }
  568. void MainAndSecondaryCamerasWnd::on_LeftZoomOutButton_clicked()
  569. {
  570. mousePos = ui->LeftOperatewidget->geometry().center();
  571. updateScale(Left_scaleFactor * 0.9, 0);
  572. }
  573. void MainAndSecondaryCamerasWnd::on_RightZoomOutButton_clicked()
  574. {
  575. mousePos = ui->RightOperatewidget->geometry().center();
  576. updateScale(Right_scaleFactor * 0.9, 1);
  577. }
  578. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent *event)
  579. {
  580. if (ui->LeftOperatewidget->rect().contains(ui->LeftOperatewidget->mapFromGlobal(event->globalPos()))) {
  581. mousePos = ui->LeftOperatewidget->mapFromGlobal(event->globalPos());
  582. if (event->angleDelta().y() > 0) {
  583. updateScale(Left_scaleFactor * 1.1, 0); // 放大
  584. } else {
  585. updateScale(Left_scaleFactor * 0.9, 0); // 缩小
  586. }
  587. }
  588. if (ui->RightOperatewidget->rect().contains(ui->RightOperatewidget->mapFromGlobal(event->globalPos()))) {
  589. mousePos = ui->RightOperatewidget->mapFromGlobal(event->globalPos());
  590. if (event->angleDelta().y() > 0) {
  591. updateScale(Right_scaleFactor * 1.1, 1); // 放大
  592. } else {
  593. updateScale(Right_scaleFactor * 0.9, 1); // 缩小
  594. }
  595. }
  596. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  597. // 获取 QScrollArea 的横向滚动条
  598. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  599. // 根据滚轮滚动方向改变滚动条的值
  600. if (event->angleDelta().y() > 0) {
  601. scrollBar->setValue(scrollBar->value() - 50);
  602. } else {
  603. scrollBar->setValue(scrollBar->value() + 50);
  604. }
  605. }
  606. QMainWindow::wheelEvent(event);
  607. }
  608. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent *event) {
  609. isUpdatingSettings = false;
  610. QMainWindow::showEvent(event);
  611. loadSettings();
  612. isUpdatingSettings = true;
  613. }
  614. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent *event) {
  615. isUpdatingSettings = false;
  616. QMainWindow::hideEvent(event);
  617. }
  618. void MainAndSecondaryCamerasWnd::CheckIs()
  619. {
  620. QSettings settings("YourCompany", "YourApplication_Button");
  621. int groupId = settings.value("GroupId_button", 0).toInt();
  622. if (groupId == lastGroupId) {
  623. if (lastIndex == 1 ) {
  624. if(isShow_R == true){
  625. isShow_R = false;
  626. } else {
  627. isShow_R = true;
  628. }
  629. }
  630. if (lastLastIndex == 1 && groupId == lastLastGroupId) {
  631. if(isShow_L == true){
  632. isShow_L = false;
  633. } else {
  634. isShow_L = true;
  635. }
  636. }
  637. showAndHide();
  638. showAndHide_L();
  639. } else if (groupId == lastLastGroupId) {
  640. if (lastLastIndex == 1) {
  641. if(isShow_L == true){
  642. isShow_L = false;
  643. } else {
  644. isShow_L = true;
  645. }
  646. }
  647. showAndHide_L();
  648. }
  649. }
  650. void MainAndSecondaryCamerasWnd::showAndHide(){
  651. QList<QLineEdit*> lineEdits = {
  652. ui->RedLightlineEdit_2, ui->GreenLightlineEdit_5,
  653. ui->BlueLightlineEdit_2, ui->DotLightlineEdit_2
  654. };
  655. QList<QSlider*> sliders = {
  656. ui->RedLightverticalSlider_2, ui->GreenLightverticalSlider_5,
  657. ui->BlueLightverticalSlider, ui->DotLightverticalSlider_2
  658. };
  659. QList<QProgressBar*> progressBar = {
  660. ui->RedLightprogressBar_2,ui->GreenLightprogressBar_5,
  661. ui->BlueLightprogressBar_2,ui->DotLightprogressBar_2
  662. };
  663. if(isShow_R == true){
  664. for (QLineEdit* lineEdit : lineEdits) {
  665. lineEdit->show();
  666. }
  667. for (int i = 0; i < sliders.size(); ++i) {
  668. sliders[i]->show();
  669. }
  670. for (int i = 0; i < progressBar.size(); ++i) {
  671. progressBar[i]->show();
  672. }
  673. ui->BlueLight->show();
  674. ui->RedLight->show();
  675. ui->DotLight->show();
  676. ui->GreenLight->show();
  677. ui->BlueLightlabel_2->show();
  678. ui->RedLightlabel_2->show();
  679. ui->DotLightlabel_2->show();
  680. ui->GreenLightlabel_5->show();
  681. }else{
  682. for (QLineEdit* lineEdit : lineEdits) {
  683. lineEdit->hide();
  684. }
  685. for (int i = 0; i < sliders.size(); ++i) {
  686. sliders[i]->hide();
  687. }
  688. for (int i = 0; i < progressBar.size(); ++i) {
  689. progressBar[i]->hide();
  690. }
  691. ui->BlueLight->hide();
  692. ui->RedLight->hide();
  693. ui->DotLight->hide();
  694. ui->GreenLight->hide();
  695. ui->BlueLightlabel_2->hide();
  696. ui->RedLightlabel_2->hide();
  697. ui->DotLightlabel_2->hide();
  698. ui->GreenLightlabel_5->hide();
  699. }
  700. }
  701. void MainAndSecondaryCamerasWnd::showAndHide_L(){
  702. QList<QLineEdit*> lineEdits = {
  703. ui->RedLightlineEdit_L, ui->GreenLightlineEdit_L,
  704. ui->BlueLightlineEdit_L, ui->DotLightlineEdit_L
  705. };
  706. QList<QSlider*> sliders = {
  707. ui->RedLightverticalSlider_L, ui->GreenLightverticalSlider_L,
  708. ui->BlueLightverticalSlider_L, ui->DotLightverticalSlider_L
  709. };
  710. QList<QProgressBar*> progressBar = {
  711. ui->RedLightprogressBar_L,ui->GreenLightprogressBar_L,
  712. ui->BlueLightprogressBar_L,ui->DotLightprogressBar_L
  713. };
  714. if(isShow_L == true){
  715. for (QLineEdit* lineEdit : lineEdits) {
  716. lineEdit->show();
  717. }
  718. for (int i = 0; i < sliders.size(); ++i) {
  719. sliders[i]->show();
  720. }
  721. for (int i = 0; i < progressBar.size(); ++i) {
  722. progressBar[i]->show();
  723. }
  724. ui->BlueLight_L->show();
  725. ui->RedLight_L->show();
  726. ui->DotLight_L->show();
  727. ui->GreenLight_L->show();/*
  728. ui->BlueLightlabel_2->show();
  729. ui->RedLightlabel_2->show();
  730. ui->DotLightlabel_2->show();
  731. ui->GreenLightlabel_5->show();*/
  732. }else{
  733. for (QLineEdit* lineEdit : lineEdits) {
  734. lineEdit->hide();
  735. }
  736. for (int i = 0; i < sliders.size(); ++i) {
  737. sliders[i]->hide();
  738. }
  739. for (int i = 0; i < progressBar.size(); ++i) {
  740. progressBar[i]->hide();
  741. }
  742. ui->BlueLight_L->hide();
  743. ui->RedLight_L->hide();
  744. ui->DotLight_L->hide();
  745. ui->GreenLight_L->hide();
  746. // ui->BlueLightlabel_2->hide();
  747. // ui->RedLightlabel_2->hide();
  748. // ui->DotLightlabel_2->hide();
  749. // ui->GreenLightlabel_5->hide();
  750. }
  751. }