MainAndSecondaryCamerasWnd.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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 = 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. // 连接 QSlider 的 valueChanged 信号到 QProgressBar 的 setValue 槽
  42. connect(ui->RedLightverticalSlider_2, &QSlider::valueChanged, ui->RedLightprogressBar_2, &QProgressBar::setValue);
  43. connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar_2, &QProgressBar::setValue);
  44. connect(ui->GreenLightverticalSlider_5, &QSlider::valueChanged, ui->GreenLightprogressBar_5, &QProgressBar::setValue);
  45. connect(ui->DotLightverticalSlider_2, &QSlider::valueChanged, ui->DotLightprogressBar_2, &QProgressBar::setValue);
  46. connect(ui->RedLightverticalSlider_L, &QSlider::valueChanged, ui->RedLightprogressBar_L, &QProgressBar::setValue);
  47. connect(ui->BlueLightverticalSlider_L, &QSlider::valueChanged, ui->BlueLightprogressBar_L, &QProgressBar::setValue);
  48. connect(ui->GreenLightverticalSlider_L, &QSlider::valueChanged, ui->GreenLightprogressBar_L, &QProgressBar::setValue);
  49. connect(ui->DotLightverticalSlider_L, &QSlider::valueChanged, ui->DotLightprogressBar_L, &QProgressBar::setValue);
  50. connectSliderAndLineEdit(ui->RedLightverticalSlider_2, ui->RedLightlineEdit_2);
  51. connectSliderAndLineEdit(ui->GreenLightverticalSlider_5, ui->GreenLightlineEdit_5);
  52. connectSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit_2);
  53. connectSliderAndLineEdit(ui->DotLightverticalSlider_2, ui->DotLightlineEdit_2);
  54. connectSliderAndLineEdit(ui->RedLightverticalSlider_L, ui->RedLightlineEdit_L);
  55. connectSliderAndLineEdit(ui->GreenLightverticalSlider_L, ui->GreenLightlineEdit_L);
  56. connectSliderAndLineEdit(ui->BlueLightverticalSlider_L, ui->BlueLightlineEdit_L);
  57. connectSliderAndLineEdit(ui->DotLightverticalSlider_L, ui->DotLightlineEdit_L);
  58. connect(ui->LeftOperatewidget,&ImageWidget::sendDoubleClicksignal,this,&MainAndSecondaryCamerasWnd::handleDoubleClick);
  59. connect(ui->RightOperatewidget,&ImageWidget::sendDoubleClicksignal,this,&MainAndSecondaryCamerasWnd::handleDoubleClick);
  60. QWidget *viewport = ui->scrollArea->viewport();
  61. QWidget *container = new QWidget(viewport);
  62. QHBoxLayout *mainLayout = new QHBoxLayout(container);
  63. mainLayout->setSpacing(28);
  64. mainLayout->setMargin(0);
  65. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  66. QList<Group*> widgets;
  67. for (int i = 0; i < numbers.size(); ++i) {
  68. int num = numbers[i];
  69. CameraImageHandler* manager = new CameraImageHandler(num);
  70. Group* widget = manager->getGroup();
  71. connect(widget,&Group::send_button_Signal,this,&MainAndSecondaryCamerasWnd::CheckIs);
  72. if (widget != nullptr) {
  73. mainLayout->addWidget(widget);
  74. widgets.append(widget);
  75. }
  76. delete manager;
  77. }
  78. // 设置控件的最小高度和最大宽度
  79. int minHeight = 162;
  80. int maxWidth = 244;
  81. int num = -28;
  82. for (Group* w : widgets) {
  83. w->setMinimumHeight(minHeight);
  84. w->setMaximumWidth(maxWidth);
  85. num = num + 272;
  86. }
  87. container->setMinimumSize(num, 162);
  88. container->setLayout(mainLayout);
  89. ui->scrollArea->setWidget(container);
  90. ui->scrollArea->resize(1062, 177);
  91. ui->LeftOperatewidget->setMouseTracking(true);
  92. ui->RightOperatewidget->setMouseTracking(true);
  93. QSettings settings2("YourOrganization", "YourApplication_lastWndType");
  94. int lastWndType = settings2.value("LastWndType").toInt();
  95. int LastGroup = settings2.value("LastGroup").toInt();
  96. lastIndex = lastWndType;
  97. lastGroupId = LastGroup;
  98. }
  99. void MainAndSecondaryCamerasWnd::initSliders() {
  100. QList<QSlider*> sliders = {
  101. ui->RedLightverticalSlider_2, ui->GreenLightverticalSlider_5,
  102. ui->BlueLightverticalSlider, ui->DotLightverticalSlider_2,
  103. ui->RedLightverticalSlider_L, ui->GreenLightverticalSlider_L,
  104. ui->BlueLightverticalSlider_L, ui->DotLightverticalSlider_L
  105. };
  106. QList<int> initialValues = {22, 11, 0, 0, 22, 11, 0, 0};
  107. for (int i = 0; i < sliders.size(); ++i) {
  108. sliders[i]->setMinimum(0);
  109. sliders[i]->setMaximum(100);
  110. sliders[i]->setValue(initialValues[i]);
  111. }
  112. }
  113. void MainAndSecondaryCamerasWnd::initProgressBar(){
  114. QList<int> initialValues = {22, 11, 0, 0, 22, 11, 0, 0};
  115. QList<QProgressBar*> progressBar = {
  116. ui->RedLightprogressBar_2,ui->GreenLightprogressBar_5,
  117. ui->BlueLightprogressBar_2,ui->DotLightprogressBar_2,
  118. ui->RedLightprogressBar_L,ui->GreenLightprogressBar_L,
  119. ui->BlueLightprogressBar_L,ui->DotLightprogressBar_L
  120. };
  121. for (int i = 0; i < progressBar.size(); ++i) {
  122. progressBar[i]->setMinimum(0);
  123. progressBar[i]->setMaximum(100);
  124. progressBar[i]->setValue(initialValues[i]);
  125. }
  126. }
  127. void MainAndSecondaryCamerasWnd::handleDoubleClick(){
  128. QPoint globalMousePos = QCursor::pos(); // 获取当前鼠标的全局位置
  129. QPoint leftWidgetLocalPos = ui->LeftOperatewidget->mapFromGlobal(globalMousePos);
  130. QPoint rightWidgetLocalPos = ui->RightOperatewidget->mapFromGlobal(globalMousePos);
  131. if (ui->LeftOperatewidget->rect().contains(leftWidgetLocalPos)){
  132. QPixmap scaledImage = Left_currentPixmap.scaled(Left_currentPixmap.width(), Left_currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  133. ui->LeftOperatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
  134. Left_scaleFactor = 1.0;
  135. ui->Leftlabel_Percentage->setText("100%");
  136. }
  137. if(ui->RightOperatewidget->rect().contains(rightWidgetLocalPos)){
  138. QPixmap scaledImage = Right_currentPixmap.scaled(Right_currentPixmap.width(), Right_currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  139. ui->RightOperatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
  140. Right_scaleFactor = 1.0;
  141. ui->Rightlabel_Percentage->setText("100%");
  142. }
  143. }
  144. void MainAndSecondaryCamerasWnd::initLineEdits() {
  145. QList<QLineEdit*> lineEdits = {
  146. ui->RedLightlineEdit_2, ui->GreenLightlineEdit_5,
  147. ui->BlueLightlineEdit_2, ui->DotLightlineEdit_2,
  148. ui->RedLightlineEdit_L, ui->GreenLightlineEdit_L,
  149. ui->BlueLightlineEdit_L, ui->DotLightlineEdit_L
  150. };
  151. for (QLineEdit* lineEdit : lineEdits) {
  152. lineEdit->setAlignment(Qt::AlignCenter);
  153. }
  154. }
  155. void MainAndSecondaryCamerasWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  156. {
  157. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  158. lineEdit->setValidator(validator);
  159. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  160. lineEdit->setText(QString::number(value));
  161. });
  162. connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
  163. bool ok;
  164. int value = text.toInt(&ok);
  165. if (ok && value >= slider->minimum() && value <= slider->maximum()) {
  166. slider->setValue(value);
  167. } else if (!text.isEmpty()) {
  168. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  169. slider->setValue(closestValue);
  170. }
  171. });
  172. }
  173. void MainAndSecondaryCamerasWnd::checkSettings() {
  174. QSettings settings("YourCompany", "YourApplication_");
  175. int groupId = settings.value("GroupId", 0).toInt();
  176. int index = settings.value("Index", 0).toInt();
  177. if (groupId != lastGroupId || index != lastIndex) {
  178. loadSettings();
  179. lastGroupId = groupId;
  180. lastIndex = index;
  181. }
  182. }
  183. void MainAndSecondaryCamerasWnd::loadSettings()
  184. {
  185. QSettings settings("YourCompany", "YourApplication_");
  186. int groupId = settings.value("GroupId", 0).toInt();
  187. int index = settings.value("Index", 0).toInt();
  188. loadGroupSettings(groupId, index);
  189. }
  190. void MainAndSecondaryCamerasWnd::loadGroupSettings(int Id, int Index) {
  191. // isUpdatingSettings = true;
  192. QSettings settings("YourOrganization", "YourApplication");
  193. settings.beginGroup(QString::number(Id));
  194. QString imagePath1 = settings.value("ImagePath1").toString();
  195. int materialWndType = settings.value("MaterialWndType").toInt();
  196. QStringList textList = settings.value("TextList").toStringList();
  197. settings.endGroup();
  198. QString lastRightImage = settings.value("LastRightImage").toString();
  199. QSize size_left = ui->LeftOperatewidget->size();
  200. QSize size_right = ui->RightOperatewidget->size();
  201. QPixmap newPixmap;
  202. if (Index == 1) {
  203. isShow = true;
  204. newPixmap = QPixmap(imagePath1);
  205. clearLayout(1);
  206. if (lastIndex == 1) {
  207. clearLayout(0);
  208. isShow_L = true;
  209. } else if (lastIndex == 2) {
  210. isShow_L = false;
  211. clearLayout(0);
  212. if (lastGroupId == 1) {
  213. WaferWidget(0);
  214. } else if (lastGroupId == 2) {
  215. WaffleWidget(0);
  216. } else if (lastGroupId == 3) {
  217. MaterialBoxWidget(0);
  218. }
  219. }
  220. } else if (Index == 2) {
  221. isShow = false;
  222. clearLayout(1);
  223. clearLayout(0);
  224. if (lastIndex == 1) {
  225. isShow_L = true;
  226. }
  227. if (materialWndType == 1) {
  228. if (lastIndex == 2) {
  229. isShow_L = false;
  230. if (lastGroupId == 1) {
  231. WaferWidget(0);
  232. } else if (lastGroupId == 2) {
  233. WaffleWidget(0);
  234. } else if (lastGroupId == 3) {
  235. MaterialBoxWidget(0);
  236. }
  237. }
  238. WaferWidget(1);
  239. } else if (materialWndType == 2) {
  240. if (lastIndex == 2) {
  241. isShow_L = false;
  242. if (lastGroupId == 1) {
  243. WaferWidget(0);
  244. } else if (lastGroupId == 2) {
  245. WaffleWidget(0);
  246. } else if (lastGroupId == 3) {
  247. MaterialBoxWidget(0);
  248. }
  249. }
  250. WaffleWidget(1);
  251. } else if (materialWndType == 3) {
  252. if (lastIndex == 2) {
  253. isShow_L = false;
  254. if (lastGroupId == 1) {
  255. WaferWidget(0);
  256. } else if (lastGroupId == 2) {
  257. WaffleWidget(0);
  258. } else if (lastGroupId == 3) {
  259. MaterialBoxWidget(0);
  260. }
  261. }
  262. MaterialBoxWidget(1);
  263. }
  264. }
  265. showAndHide();
  266. showAndHide_L();
  267. QSettings settings2("YourOrganization", "YourApplication_lastWndType");
  268. settings2.setValue("LastWndType", lastIndex);
  269. settings2.setValue("LastGroup", lastGroupId);
  270. QPixmap scaledPixmap_right = newPixmap.scaled(size_right, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  271. ui->RightOperatewidget->setPixmap(scaledPixmap_right);
  272. QPixmap scaledPixmap_left = lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  273. ui->LeftOperatewidget->setPixmap(scaledPixmap_left);
  274. // 更新当前图片的成员变量
  275. Left_currentPixmap = scaledPixmap_left;
  276. Left_scaleFactor = 1.0;
  277. Right_currentPixmap = scaledPixmap_right;
  278. Right_scaleFactor = 1.0;
  279. ui->Leftlabel_Percentage->setText("100%");
  280. ui->Rightlabel_Percentage->setText("100%");
  281. ui->LeftDataSources->clear();
  282. ui->LeftDataSources->addItems(lasttextList);
  283. ui->RightDataSources->clear();
  284. ui->RightDataSources->addItems(textList);
  285. // 保存到 QSettings
  286. settings.beginGroup("LastSettings");
  287. settings.setValue("LastRightPixmap", lastRightPixmap);
  288. settings.setValue("LasttextList", lasttextList);
  289. settings.setValue("LastLastRightPixmap", lastLastRightPixmap);
  290. settings.setValue("LastLasttextList", lastLasttextList);
  291. settings.setValue("LastLastIndex", lastLastIndex);
  292. settings.setValue("LastLastGroupId", lastLastGroupId);
  293. settings.endGroup();
  294. if (isUpdatingSettings) {
  295. lastLastRightPixmap = lastRightPixmap;
  296. lastLasttextList = lasttextList;
  297. lastRightPixmap = scaledPixmap_right;
  298. lasttextList = textList;
  299. lastLastIndex = lastIndex;
  300. lastLastGroupId = lastGroupId;
  301. }
  302. }
  303. void MainAndSecondaryCamerasWnd::clearLayout(int flag) {
  304. QWidget* widget = (flag == 1) ? ui->RightOperatewidget : ui->LeftOperatewidget;
  305. QLayout* layout = widget->layout();
  306. if (layout) {
  307. QLayoutItem *child;
  308. while ((child = layout->takeAt(0)) != nullptr) {
  309. if (child->widget() != nullptr) {
  310. delete child->widget(); // 删除控件
  311. }
  312. delete child; // 删除布局项
  313. }
  314. delete layout; // 删除布局本身
  315. }
  316. }
  317. // 圆晶
  318. void MainAndSecondaryCamerasWnd::WaferWidget(int flag) {
  319. // QWidget *operatewidget = ui->LeftOperatewidget;
  320. // if (flag == 1) {
  321. // operatewidget = ui->RightOperatewidget;
  322. // }
  323. // QGridLayout *layout = new QGridLayout(operatewidget);
  324. // wafer = new Wafer(1, operatewidget);
  325. // wafer->initFrom(operatewidget);
  326. // layout->setContentsMargins(0, 0, 0, 0);
  327. // layout->addWidget(wafer->globalWidget);
  328. // operatewidget->setLayout(layout);
  329. // operatewidget->setFixedSize(476, 476);
  330. }
  331. // 华夫盒
  332. void MainAndSecondaryCamerasWnd::WaffleWidget(int flag) {
  333. QWidget *operatewidget = ui->LeftOperatewidget;
  334. if (flag == 1) {
  335. operatewidget = ui->RightOperatewidget;
  336. }
  337. QVBoxLayout *layout = new QVBoxLayout(operatewidget);
  338. waffle = new Waffle(1, operatewidget);
  339. layout->setContentsMargins(0, 0, 0, 0);
  340. layout->addWidget(waffle);
  341. operatewidget->setLayout(layout);
  342. operatewidget->setFixedSize(476, 476);
  343. }
  344. // 料盒
  345. void MainAndSecondaryCamerasWnd::MaterialBoxWidget(int flag) {
  346. QWidget *operatewidget = ui->LeftOperatewidget;
  347. if (flag == 1) {
  348. operatewidget = ui->RightOperatewidget;
  349. }
  350. QVBoxLayout *layout = new QVBoxLayout(operatewidget);
  351. materialbox = new MaterialBox(1, operatewidget);
  352. layout->setContentsMargins(0, 0, 0, 0);
  353. layout->addWidget(materialbox);
  354. operatewidget->setLayout(layout);
  355. operatewidget->setFixedSize(476, 476);
  356. }
  357. void MainAndSecondaryCamerasWnd::on_LeftZoomUpButton_clicked()
  358. {
  359. Left_scaleFactor *= 1.1;
  360. int newWidth = Left_currentPixmap.width() * Left_scaleFactor;
  361. int newHeight = Left_currentPixmap.height() * Left_scaleFactor;
  362. QPixmap scaledImage = Left_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  363. ui->LeftOperatewidget->setPixmap(scaledImage);
  364. double percentage = (Left_scaleFactor * 100);
  365. QString percentageStr = QString::number((int)percentage);
  366. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  367. }
  368. void MainAndSecondaryCamerasWnd::on_RightZoomUpButton_clicked()
  369. {
  370. Right_scaleFactor *= 1.1;
  371. int newWidth = Right_currentPixmap.width() * Right_scaleFactor;
  372. int newHeight = Right_currentPixmap.height() * Right_scaleFactor;
  373. QPixmap scaledImage = Right_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  374. ui->RightOperatewidget->setPixmap(scaledImage);
  375. double percentage = (Right_scaleFactor * 100);
  376. QString percentageStr = QString::number((int)percentage);
  377. ui->Rightlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  378. }
  379. void MainAndSecondaryCamerasWnd::on_LeftZoomOutButton_clicked()
  380. {
  381. double Left_newScaleFactor = Left_scaleFactor * 0.9;
  382. if (Left_newScaleFactor >= 1.0) {
  383. Left_scaleFactor = Left_newScaleFactor;
  384. } else {
  385. Left_scaleFactor = 1.0;
  386. }
  387. int newWidth = Left_currentPixmap.width() * Left_scaleFactor;
  388. int newHeight = Left_currentPixmap.height() * Left_scaleFactor;
  389. QPixmap scaledImage = Left_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  390. ui->LeftOperatewidget->setPixmap(scaledImage);
  391. double percentage = (Left_scaleFactor * 100);
  392. QString percentageStr = QString::number((int)percentage);
  393. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  394. }
  395. void MainAndSecondaryCamerasWnd::on_RightZoomOutButton_clicked()
  396. {
  397. double Right_newScaleFactor = Right_scaleFactor * 0.9;
  398. if (Right_newScaleFactor >= 1.0) {
  399. Right_scaleFactor = Right_newScaleFactor;
  400. } else {
  401. Right_scaleFactor = 1.0;
  402. }
  403. int newWidth = Right_currentPixmap.width() * Right_scaleFactor;
  404. int newHeight = Right_currentPixmap.height() * Right_scaleFactor;
  405. QPixmap scaledImage = Right_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  406. ui->RightOperatewidget->setPixmap(scaledImage);
  407. double percentage = (Right_scaleFactor * 100);
  408. QString percentageStr = QString::number((int)percentage);
  409. ui->Rightlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  410. }
  411. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent *event)
  412. {
  413. if (ui->LeftOperatewidget->rect().contains(ui->LeftOperatewidget->mapFromGlobal(event->globalPosition().toPoint()))) {
  414. if (event->angleDelta().y() > 0) {
  415. Left_scaleFactor *= 1.1;
  416. } else {
  417. double Left_newScaleFactor = Left_scaleFactor * 0.9;
  418. if (Left_newScaleFactor >= 1.0) {
  419. Left_scaleFactor = Left_newScaleFactor;
  420. } else {
  421. Left_scaleFactor = 1.0;
  422. }
  423. }
  424. int newWidth_left = Left_currentPixmap.width() * Left_scaleFactor;
  425. int newHeight_left = Left_currentPixmap.height() * Left_scaleFactor;
  426. QPixmap scaledImage_left = Left_currentPixmap.scaled(newWidth_left, newHeight_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  427. // ui->LeftOperatewidget->setPixmap(scaledImage_left);
  428. // ui->LeftOperatewidget->setPixmapAndPoint(scaledImage_left);
  429. double percentage_left = Left_scaleFactor * 100;
  430. QString percentageStr_left = QString::number((int)percentage_left);
  431. ui->Leftlabel_Percentage->setText(QString("%1%").arg(percentageStr_left));
  432. }
  433. if (ui->RightOperatewidget->rect().contains(ui->RightOperatewidget->mapFromGlobal(event->globalPosition().toPoint()))) {
  434. if (event->angleDelta().y() > 0) {
  435. Right_scaleFactor *= 1.1;
  436. } else {
  437. double Right_newScaleFactor = Right_scaleFactor * 0.9;
  438. if (Right_newScaleFactor >= 1.0) {
  439. Right_scaleFactor = Right_newScaleFactor;
  440. } else {
  441. Right_scaleFactor = 1.0;
  442. }
  443. }
  444. int newWidth = Right_currentPixmap.width() * Right_scaleFactor;
  445. int newHeight = Right_currentPixmap.height() * Right_scaleFactor;
  446. QPixmap scaledImage = Right_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  447. // ui->RightOperatewidget->setPixmap(scaledImage);
  448. // ui->RightOperatewidget->setPixmapAndPoint(scaledImage);
  449. double percentage = Right_scaleFactor * 100;
  450. QString percentageStr = QString::number((int)percentage);
  451. ui->Rightlabel_Percentage->setText(QString("%1%").arg(percentageStr));
  452. }
  453. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  454. // 获取 QScrollArea 的横向滚动条
  455. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  456. // 根据滚轮滚动方向改变滚动条的值
  457. if (event->angleDelta().y() > 0) {
  458. scrollBar->setValue(scrollBar->value() - 50);
  459. } else {
  460. scrollBar->setValue(scrollBar->value() + 50);
  461. }
  462. }
  463. QMainWindow::wheelEvent(event);
  464. }
  465. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent *event) {
  466. isUpdatingSettings = false;
  467. QMainWindow::showEvent(event);
  468. loadSettings();
  469. isUpdatingSettings = true;
  470. }
  471. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent *event) {
  472. isUpdatingSettings = false;
  473. QMainWindow::hideEvent(event);
  474. }
  475. void MainAndSecondaryCamerasWnd::CheckIs()
  476. {
  477. QSettings settings("YourCompany", "YourApplication_Button");
  478. int groupId = settings.value("GroupId_button", 0).toInt();
  479. if (groupId == lastGroupId) {
  480. if (lastIndex == 1 ) {
  481. if(isShow == true){
  482. isShow = false;
  483. } else {
  484. isShow = true;
  485. }
  486. }
  487. if (lastLastIndex == 1 && groupId == lastLastGroupId) {
  488. if(isShow_L == true){
  489. isShow_L = false;
  490. } else {
  491. isShow_L = true;
  492. }
  493. }
  494. showAndHide();
  495. showAndHide_L();
  496. } else if (groupId == lastLastGroupId) {
  497. if (lastLastIndex == 1) {
  498. if(isShow_L == true){
  499. isShow_L = false;
  500. } else {
  501. isShow_L = true;
  502. }
  503. }
  504. showAndHide_L();
  505. }
  506. }
  507. void MainAndSecondaryCamerasWnd::showAndHide(){
  508. QList<QLineEdit*> lineEdits = {
  509. ui->RedLightlineEdit_2, ui->GreenLightlineEdit_5,
  510. ui->BlueLightlineEdit_2, ui->DotLightlineEdit_2
  511. };
  512. QList<QSlider*> sliders = {
  513. ui->RedLightverticalSlider_2, ui->GreenLightverticalSlider_5,
  514. ui->BlueLightverticalSlider, ui->DotLightverticalSlider_2
  515. };
  516. QList<QProgressBar*> progressBar = {
  517. ui->RedLightprogressBar_2,ui->GreenLightprogressBar_5,
  518. ui->BlueLightprogressBar_2,ui->DotLightprogressBar_2
  519. };
  520. if(isShow == true){
  521. for (QLineEdit* lineEdit : lineEdits) {
  522. lineEdit->show();
  523. }
  524. for (int i = 0; i < sliders.size(); ++i) {
  525. sliders[i]->show();
  526. }
  527. for (int i = 0; i < progressBar.size(); ++i) {
  528. progressBar[i]->show();
  529. }
  530. ui->BlueLight->show();
  531. ui->RedLight->show();
  532. ui->DotLight->show();
  533. ui->GreenLight->show();
  534. ui->BlueLightlabel_2->show();
  535. ui->RedLightlabel_2->show();
  536. ui->DotLightlabel_2->show();
  537. ui->GreenLightlabel_5->show();
  538. }else{
  539. for (QLineEdit* lineEdit : lineEdits) {
  540. lineEdit->hide();
  541. }
  542. for (int i = 0; i < sliders.size(); ++i) {
  543. sliders[i]->hide();
  544. }
  545. for (int i = 0; i < progressBar.size(); ++i) {
  546. progressBar[i]->hide();
  547. }
  548. ui->BlueLight->hide();
  549. ui->RedLight->hide();
  550. ui->DotLight->hide();
  551. ui->GreenLight->hide();
  552. ui->BlueLightlabel_2->hide();
  553. ui->RedLightlabel_2->hide();
  554. ui->DotLightlabel_2->hide();
  555. ui->GreenLightlabel_5->hide();
  556. }
  557. }
  558. void MainAndSecondaryCamerasWnd::showAndHide_L(){
  559. QList<QLineEdit*> lineEdits = {
  560. ui->RedLightlineEdit_L, ui->GreenLightlineEdit_L,
  561. ui->BlueLightlineEdit_L, ui->DotLightlineEdit_L
  562. };
  563. QList<QSlider*> sliders = {
  564. ui->RedLightverticalSlider_L, ui->GreenLightverticalSlider_L,
  565. ui->BlueLightverticalSlider_L, ui->DotLightverticalSlider_L
  566. };
  567. QList<QProgressBar*> progressBar = {
  568. ui->RedLightprogressBar_L,ui->GreenLightprogressBar_L,
  569. ui->BlueLightprogressBar_L,ui->DotLightprogressBar_L
  570. };
  571. if(isShow_L == true){
  572. for (QLineEdit* lineEdit : lineEdits) {
  573. lineEdit->show();
  574. }
  575. for (int i = 0; i < sliders.size(); ++i) {
  576. sliders[i]->show();
  577. }
  578. for (int i = 0; i < progressBar.size(); ++i) {
  579. progressBar[i]->show();
  580. }
  581. ui->BlueLight_L->show();
  582. ui->RedLight_L->show();
  583. ui->DotLight_L->show();
  584. ui->GreenLight_L->show();/*
  585. ui->BlueLightlabel_2->show();
  586. ui->RedLightlabel_2->show();
  587. ui->DotLightlabel_2->show();
  588. ui->GreenLightlabel_5->show();*/
  589. }else{
  590. for (QLineEdit* lineEdit : lineEdits) {
  591. lineEdit->hide();
  592. }
  593. for (int i = 0; i < sliders.size(); ++i) {
  594. sliders[i]->hide();
  595. }
  596. for (int i = 0; i < progressBar.size(); ++i) {
  597. progressBar[i]->hide();
  598. }
  599. ui->BlueLight_L->hide();
  600. ui->RedLight_L->hide();
  601. ui->DotLight_L->hide();
  602. ui->GreenLight_L->hide();
  603. // ui->BlueLightlabel_2->hide();
  604. // ui->RedLightlabel_2->hide();
  605. // ui->DotLightlabel_2->hide();
  606. // ui->GreenLightlabel_5->hide();
  607. }
  608. }