SingleCameraOperationWnd.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. #include "SingleCameraOperationWnd.h"
  2. #include "ui_SingleCameraOperationWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QDebug>
  7. #include <QTimer>
  8. #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
  9. SingleCameraOperationWnd::SingleCameraOperationWnd(QWidget *parent)
  10. : QMainWindow(parent)
  11. , ui(new Ui::SingleCameraOperationWnd), scaleFactor(1.0)
  12. {
  13. ui->setupUi(this);
  14. isShow = true;
  15. liveClick = true;
  16. initFrom();
  17. }
  18. SingleCameraOperationWnd::~SingleCameraOperationWnd()
  19. {
  20. delete ui;
  21. }
  22. void SingleCameraOperationWnd::initFrom() {
  23. QTimer *timer = new QTimer(this);
  24. connect(timer, &QTimer::timeout, this, &SingleCameraOperationWnd::checkSettings);
  25. timer->start(100);
  26. ui->label_Percentage->setAlignment(Qt::AlignCenter);
  27. // 设置右下部分
  28. // loadSliderStates();
  29. initSliders();
  30. initLineEdits();
  31. initProgressBar();
  32. // 连接 QSlider 的 valueChanged 信号到 QProgressBar 的 setValue 槽
  33. connect(ui->RedLightverticalSlider, &QSlider::valueChanged, ui->RedLightprogressBar, &QProgressBar::setValue);
  34. connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar, &QProgressBar::setValue);
  35. connect(ui->GreenLightverticalSlider, &QSlider::valueChanged, ui->GreenLightprogressBar, &QProgressBar::setValue);
  36. connect(ui->DotLightverticalSlider, &QSlider::valueChanged, ui->DotLightprogressBar, &QProgressBar::setValue);
  37. connectSliderAndLineEdit(ui->RedLightverticalSlider, ui->RedLightlineEdit);
  38. connectSliderAndLineEdit(ui->GreenLightverticalSlider, ui->GreenLightlineEdit);
  39. connectSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit);
  40. connectSliderAndLineEdit(ui->DotLightverticalSlider, ui->DotLightlineEdit);
  41. connect(ui->LiveButton,&QPushButton::clicked,this,&SingleCameraOperationWnd::loadLiveVedio);
  42. connect(ui->Operatewidget,&ImageWidget::sendDoubleClicksignal,this,&SingleCameraOperationWnd::handleDoubleClick);
  43. // 设置右上部分
  44. QWidget *viewport = ui->scrollArea->viewport();
  45. QWidget *container = new QWidget(viewport);
  46. QVBoxLayout *layout = new QVBoxLayout(container);
  47. layout->setSpacing(16); // 设置Group之间的间隔距离
  48. layout->setMargin(0);
  49. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  50. QList<Group*> widgets;
  51. for (int i = 0; i < numbers.size(); ++i) {
  52. int num = numbers[i];
  53. CameraImageHandler* manager = new CameraImageHandler(num);
  54. Group* widget = manager->getGroup();
  55. connect(widget,&Group::send_button_Signal,this,&SingleCameraOperationWnd::showAndHideButton);
  56. connect(widget,&Group::send_ComboBox_singal,this,&SingleCameraOperationWnd::handleComBoxChange);
  57. if (widget != nullptr) {
  58. layout->addWidget(widget);
  59. widgets.append(widget);
  60. groupMap[num] = widget;
  61. }
  62. if(manager->getWafer()) {
  63. waferMap.insert(num, manager->getWafer());
  64. }
  65. if(manager->getWafer()) {
  66. waffleMap.insert(num, manager->getWaffle());
  67. }
  68. if(manager->getMaterialBox()){
  69. materialBoxMap.insert(num,manager->getMaterialBox());
  70. }
  71. delete manager;
  72. }
  73. // 设置控件的最小高度和最大宽度
  74. int minHeight = 162;
  75. int maxWidth = 244;
  76. for (Group* w : widgets) {
  77. w->setMinimumHeight(minHeight);
  78. w->setMaximumWidth(maxWidth);
  79. }
  80. container->setLayout(layout);
  81. ui->scrollArea->setWidget(container);
  82. ui->scrollArea->resize(261, 700);
  83. ui->Operatewidget->setMouseTracking(true);
  84. connect(ui->Operatewidget,&ImageWidget::sendDoubleClicksignal,this,&SingleCameraOperationWnd::handleDoubleClick);
  85. connect(ui->DatacomboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
  86. this, &SingleCameraOperationWnd::on_DatacomboBox_currentIndexChanged);
  87. }
  88. void SingleCameraOperationWnd::closeEvent(QCloseEvent *event) {
  89. // 保存滑块状态
  90. // saveSliderStates();
  91. // 确保调用基类的 closeEvent 处理其他关闭逻辑
  92. QMainWindow::closeEvent(event);
  93. }
  94. void SingleCameraOperationWnd::initSliders() {
  95. QList<QSlider*> sliders = {
  96. ui->RedLightverticalSlider, ui->GreenLightverticalSlider,
  97. ui->BlueLightverticalSlider, ui->DotLightverticalSlider
  98. };
  99. QList<int> initialValues = {22, 11, 0, 0};
  100. for (int i = 0; i < sliders.size(); ++i) {
  101. sliders[i]->setMinimum(0);
  102. sliders[i]->setMaximum(100);
  103. sliders[i]->setValue(initialValues[i]);
  104. }
  105. }
  106. void SingleCameraOperationWnd::initLineEdits() {
  107. QList<QLineEdit*> lineEdits = {
  108. ui->RedLightlineEdit, ui->GreenLightlineEdit,
  109. ui->BlueLightlineEdit, ui->DotLightlineEdit,
  110. };
  111. for (QLineEdit* lineEdit : lineEdits) {
  112. lineEdit->setAlignment(Qt::AlignCenter);
  113. }
  114. }
  115. void SingleCameraOperationWnd::initProgressBar(){
  116. QList<int> initialValues = {22, 11, 0, 0};
  117. QList<QProgressBar*> progressBar = {
  118. ui->RedLightprogressBar,ui->GreenLightprogressBar,
  119. ui->BlueLightprogressBar,ui->DotLightprogressBar
  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 SingleCameraOperationWnd::saveSliderStates() {
  128. // QSettings settings("YourCompany", "YourApp");
  129. // settings.beginGroup("SliderStates");
  130. // settings.setValue("verticalSlider", ui->verticalSlider->value());
  131. // settings.setValue("verticalSlider_2", ui->verticalSlider_2->value());
  132. // settings.setValue("verticalSlider_3", ui->verticalSlider_3->value());
  133. // settings.setValue("verticalSlider_4", ui->verticalSlider_4->value());
  134. // settings.setValue("verticalSlider_5", ui->verticalSlider_5->value());
  135. // settings.setValue("verticalSlider_6", ui->verticalSlider_6->value());
  136. // settings.endGroup();
  137. // }
  138. // void SingleCameraOperationWnd::loadSliderStates() {
  139. // QSettings settings("YourCompany", "YourApp");
  140. // settings.beginGroup("SliderStates");
  141. // ui->verticalSlider->setValue(settings.value("verticalSlider", 11).toInt());
  142. // ui->verticalSlider_2->setValue(settings.value("verticalSlider_2", 22).toInt());
  143. // ui->verticalSlider_3->setValue(settings.value("verticalSlider_3", 9).toInt());
  144. // ui->verticalSlider_4->setValue(settings.value("verticalSlider_4", 11).toInt());
  145. // ui->verticalSlider_5->setValue(settings.value("verticalSlider_5", 0).toInt());
  146. // ui->verticalSlider_6->setValue(settings.value("verticalSlider_6", 0).toInt());
  147. // settings.endGroup();
  148. // }
  149. // QSlider 和 QLineEdit 的联动
  150. void SingleCameraOperationWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  151. {
  152. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  153. lineEdit->setValidator(validator);
  154. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  155. lineEdit->setText(QString::number(value));
  156. });
  157. connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
  158. bool ok;
  159. int value = text.toInt(&ok);
  160. if (ok && value >= slider->minimum() && value <= slider->maximum()) {
  161. slider->setValue(value);
  162. } else if (!text.isEmpty()) {
  163. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  164. slider->setValue(closestValue);
  165. }
  166. });
  167. }
  168. void SingleCameraOperationWnd::checkSettings() {
  169. QSettings settings("YourCompany", "YourApplication_");
  170. int groupId = settings.value("GroupId", 0).toInt();
  171. int index = settings.value("Index", 0).toInt();
  172. if (groupId != lastGroupId || index != lastIndex) {
  173. lastGroupId = groupId;
  174. lastIndex = index;
  175. loadSettings();
  176. }
  177. }
  178. void SingleCameraOperationWnd::loadSettings()
  179. {
  180. QSettings settings("YourCompany", "YourApplication_");
  181. int groupId = settings.value("GroupId", 0).toInt();
  182. int index = settings.value("Index", 0).toInt();
  183. loadGroupSettings(groupId, index);
  184. }
  185. void SingleCameraOperationWnd::loadGroupSettings(int Id, int Index) {
  186. QSettings settings("YourOrganization", "YourApplication");
  187. settings.beginGroup(QString::number(Id));
  188. QString imagePath1 = settings.value("ImagePath1").toString();
  189. int materialWndType = settings.value("MaterialWndType").toInt();
  190. QStringList textList = settings.value("TextList").toStringList();
  191. settings.endGroup();
  192. QSize size = ui->Operatewidget->size();
  193. QPixmap newPixmap;
  194. // 判断是实时图片还是物料窗口
  195. if (Index == 1) {
  196. clearLayout();
  197. newPixmap = QPixmap(imagePath1);
  198. QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  199. currentMode = ModeImage;
  200. currentPixmap = scaledPixmap;
  201. scaleFactor = 1.0;
  202. previousScaleFactor = 1.0;
  203. ui->Operatewidget->setPixmap(scaledPixmap);
  204. double percentage = scaleFactor * 100;
  205. QString percentageStr = QString::number((int)percentage);
  206. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  207. } else if (Index == 2) {
  208. if (materialWndType == 1) {
  209. clearLayout();
  210. ui->Operatewidget->clearPixmap();
  211. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  212. waferMap.value(Id)->initFrom(ui->Operatewidget);
  213. layout->setContentsMargins(0, 0, 0, 0);
  214. layout->addWidget(waferMap.value(Id)->view);
  215. ui->Operatewidget->setLayout(layout);
  216. currentMode = ModeView;
  217. currentView = waferMap.value(Id)->view;
  218. scaleFactor = 1.0;
  219. applyScale();
  220. } else if (materialWndType == 2) {
  221. clearLayout();
  222. ui->Operatewidget->clearPixmap();
  223. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  224. waffleMap.value(Id)->initFrom(ui->Operatewidget);
  225. layout->setContentsMargins(0, 0, 0, 0);
  226. layout->addWidget(waffleMap.value(Id)->view);
  227. ui->Operatewidget->setLayout(layout);
  228. currentMode = ModeView;
  229. currentView = waffleMap.value(Id)->view;
  230. scaleFactor = 1.0;
  231. applyScale();
  232. } else if (materialWndType == 3) {
  233. clearLayout();
  234. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  235. materialBoxMap.value(Id)->initFrom(ui->Operatewidget);
  236. layout->setContentsMargins(0, 0, 0, 0);
  237. layout->addWidget(materialBoxMap.value(Id)->view);
  238. ui->Operatewidget->setLayout(layout);
  239. currentMode = ModeView;
  240. currentView = materialBoxMap.value(Id)->view;
  241. scaleFactor = 1.0;
  242. applyScale();
  243. // MaterialBoxWidget();
  244. }
  245. }
  246. //QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  247. //ui->Operatewidget->setPixmap(scaledPixmap);
  248. // 更新当前图片的成员变量
  249. //currentPixmap = scaledPixmap;
  250. //scaleFactor = 1.0;
  251. //ui->label_Percentage->setText("100%");
  252. ui->DatacomboBox->clear();
  253. ui->DatacomboBox->addItems(textList);
  254. // qDebug() << "ComboBox items added:" << ui->DatacomboBox->count();
  255. // connect(ui->DatacomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SingleCameraOperationWnd::onComboBoxIndexChanged(int)));
  256. }
  257. // 清除大窗口上当前的布局
  258. void SingleCameraOperationWnd::clearLayout() {
  259. // 获取当前布局
  260. QLayout* layout = ui->Operatewidget->layout();
  261. if (layout) {
  262. QLayoutItem *child;
  263. while ((child = layout->takeAt(0)) != nullptr) {
  264. if (child->widget() != nullptr) {
  265. delete child->widget(); // 删除控件
  266. }
  267. delete child; // 删除布局项
  268. }
  269. delete layout; // 删除布局本身
  270. }
  271. }
  272. // 圆晶
  273. void SingleCameraOperationWnd::WaferWidget() {
  274. // QGridLayout *layout = new QGridLayout(ui->Operatewidget);
  275. // wafer = new Wafer(2, ui->Operatewidget);
  276. // wafer->initFrom(ui->Operatewidget);
  277. // layout->setContentsMargins(0, 0, 0, 0);
  278. // layout->addWidget(wafer->globalWidget);
  279. // ui->Operatewidget->setLayout(layout);
  280. // ui->Operatewidget->setFixedSize(786, 786);
  281. }
  282. // 华夫盒
  283. void SingleCameraOperationWnd::WaffleWidget() {
  284. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  285. waffle = new Waffle(2, ui->Operatewidget);
  286. layout->setContentsMargins(0, 0, 0, 0);
  287. layout->addWidget(waffle);
  288. ui->Operatewidget->setLayout(layout);
  289. ui->Operatewidget->setFixedSize(786, 786);
  290. }
  291. // 料盒
  292. void SingleCameraOperationWnd::MaterialBoxWidget() {
  293. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  294. materialbox = new MaterialBox(2, ui->Operatewidget);
  295. layout->setContentsMargins(0, 0, 0, 0);
  296. layout->addWidget(materialbox);
  297. ui->Operatewidget->setLayout(layout);
  298. ui->Operatewidget->setFixedSize(786, 786);
  299. }
  300. // 更新缩放比例
  301. void SingleCameraOperationWnd::updateScale(double newScaleFactor) {
  302. if (newScaleFactor >= 1.0) {
  303. scaleFactor = newScaleFactor;
  304. } else {
  305. scaleFactor = 1.0; // 最小缩放比例为 1.0
  306. }
  307. applyScale(); // 应用缩放
  308. }
  309. // 应用缩放
  310. void SingleCameraOperationWnd::applyScale() {
  311. if (currentMode == ModeImage) {
  312. // 图片模式:缩放图片
  313. int newWidth = currentPixmap.width() * scaleFactor;
  314. int newHeight = currentPixmap.height() * scaleFactor;
  315. QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  316. ui->Operatewidget->setPixmapAndPoint(scaledImage, previousScaleFactor, scaleFactor, mousePos);
  317. previousScaleFactor = scaleFactor;
  318. } else if (currentMode == ModeView && currentView) {
  319. // View 模式:缩放 view
  320. QTransform transform;
  321. transform.scale(scaleFactor, scaleFactor);
  322. currentView->setTransform(transform);
  323. }
  324. // 更新百分比显示
  325. double percentage = scaleFactor * 100;
  326. QString percentageStr = QString::number((int)percentage);
  327. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  328. }
  329. void SingleCameraOperationWnd::on_ZoomUpButton_clicked() {
  330. mousePos = ui->Operatewidget->geometry().center();
  331. updateScale(scaleFactor * 1.1);
  332. }
  333. void SingleCameraOperationWnd::on_ZoomOutButton_clicked() {
  334. mousePos = ui->Operatewidget->geometry().center();
  335. updateScale(scaleFactor * 0.9);
  336. }
  337. void SingleCameraOperationWnd::on_RulerButton_clicked(){
  338. // 创建初始线段(示例长度200像素)
  339. // DraggableLine* line = new DraggableLine;
  340. // line->setLine(0, 0, 200, 0); // 水平线段
  341. // if (currentView != nullptr) {
  342. // currentView->scene()->addItem(line);
  343. // line->setPos(20, 20);
  344. // currentView->viewport()->update();
  345. // }
  346. }
  347. void SingleCameraOperationWnd::wheelEvent(QWheelEvent *event)
  348. {
  349. mousePos = ui->Operatewidget->mapFromGlobal(event->globalPos());
  350. if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
  351. if (event->angleDelta().y() > 0) {
  352. updateScale(scaleFactor * 1.1); // 放大
  353. } else {
  354. updateScale(scaleFactor * 0.9); // 缩小
  355. }
  356. }
  357. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  358. // 获取 QScrollArea 的横向滚动条
  359. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  360. // 根据滚轮滚动方向改变滚动条的值
  361. if (event->angleDelta().y() > 0) {
  362. scrollBar->setValue(scrollBar->value() - 50);
  363. } else {
  364. scrollBar->setValue(scrollBar->value() + 50);
  365. }
  366. }
  367. QMainWindow::wheelEvent(event);
  368. }
  369. void SingleCameraOperationWnd::onComboBoxIndexChanged(int index) {
  370. // 根据index获取图片路径
  371. QString imagePath = getImagePathFromIndex(index);
  372. if (!imagePath.isEmpty()) {
  373. QPixmap newPixmap(imagePath);
  374. QPixmap scaledPixmap = newPixmap.scaled(ui->Operatewidget->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  375. ui->Operatewidget->setPixmap(scaledPixmap);
  376. // 更新当前图片的成员变量
  377. currentPixmap = scaledPixmap;
  378. scaleFactor = 1.0;
  379. ui->label_Percentage->setText("100%");
  380. }
  381. }
  382. QString SingleCameraOperationWnd::getImagePathFromIndex(int index) {
  383. QStringList imagePaths = {
  384. ":/images/test_image/image.png",
  385. ":/images/test_image/image_2.png",
  386. };
  387. if (index >= 0 && index < imagePaths.size()) {
  388. return imagePaths[index];
  389. }
  390. return ":/images/test_image/image.png";
  391. }
  392. void SingleCameraOperationWnd::showEvent(QShowEvent *event) {
  393. QMainWindow::showEvent(event);
  394. loadSettings();
  395. }
  396. void SingleCameraOperationWnd::hideEvent(QHideEvent *event) {
  397. QMainWindow::hideEvent(event);
  398. }
  399. void SingleCameraOperationWnd::handleDoubleClick(){
  400. if (currentMode == ModeImage) {
  401. QPixmap scaledImage = currentPixmap.scaled(currentPixmap.width(), currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  402. ui->Operatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
  403. } else if (currentMode == ModeView && currentView) {
  404. QTransform transform;
  405. transform.scale(1, 1);
  406. currentView->setTransform(transform);
  407. }
  408. scaleFactor = 1.0;
  409. previousScaleFactor = 1.0;
  410. ui->label_Percentage->setText("100%");
  411. }
  412. void SingleCameraOperationWnd::showAndHideButton(){
  413. if(isShow == true){
  414. isShow = false;
  415. }else{
  416. isShow = true;
  417. }
  418. QList<QLineEdit*> lineEdits = {
  419. ui->RedLightlineEdit, ui->GreenLightlineEdit,
  420. ui->BlueLightlineEdit, ui->DotLightlineEdit,
  421. };
  422. QList<QSlider*> sliders = {
  423. ui->RedLightverticalSlider, ui->GreenLightverticalSlider,
  424. ui->BlueLightverticalSlider, ui->DotLightverticalSlider
  425. };
  426. QList<QProgressBar*> progressBar = {
  427. ui->RedLightprogressBar,ui->GreenLightprogressBar,
  428. ui->BlueLightprogressBar,ui->DotLightprogressBar
  429. };
  430. if(isShow == true){
  431. for (QLineEdit* lineEdit : lineEdits) {
  432. lineEdit->show();
  433. }
  434. for (int i = 0; i < sliders.size(); ++i) {
  435. sliders[i]->show();
  436. }
  437. for (int i = 0; i < progressBar.size(); ++i) {
  438. progressBar[i]->show();
  439. }
  440. ui->BlueLight->show();
  441. ui->RedLight->show();
  442. ui->DotLight->show();
  443. ui->GreenLight->show();
  444. ui->BlueLightlabel->show();
  445. ui->RedLightlabel->show();
  446. ui->DotLightlabel->show();
  447. ui->GreenLightlabel->show();
  448. }else{
  449. for (QLineEdit* lineEdit : lineEdits) {
  450. lineEdit->hide();
  451. }
  452. for (int i = 0; i < sliders.size(); ++i) {
  453. sliders[i]->hide();
  454. }
  455. for (int i = 0; i < progressBar.size(); ++i) {
  456. progressBar[i]->hide();
  457. }
  458. ui->BlueLight->hide();
  459. ui->RedLight->hide();
  460. ui->DotLight->hide();
  461. ui->GreenLight->hide();
  462. ui->BlueLightlabel->hide();
  463. ui->RedLightlabel->hide();
  464. ui->DotLightlabel->hide();
  465. ui->GreenLightlabel->hide();
  466. }
  467. }
  468. void SingleCameraOperationWnd::startCamera(int cameraId) {
  469. m_grabber = new ImageGrabber(cameraId);
  470. connect(m_grabber, &ImageGrabber::imageGrabbed,
  471. this, &SingleCameraOperationWnd::updateImage);
  472. m_grabber->start();
  473. }
  474. void SingleCameraOperationWnd::stopCamera(int cameraId){
  475. m_grabber->stop();
  476. }
  477. void SingleCameraOperationWnd::on_DatacomboBox_currentIndexChanged(int index){
  478. QSettings settings("YourCompany", "YourApplication_");
  479. int groupId = settings.value("GroupId", 0).toInt();
  480. if (groupMap.contains(groupId)) {
  481. Group* group = groupMap[groupId];
  482. // 修改属性
  483. group->setDatacomboBox(index);
  484. } else {
  485. qDebug() << "Group with id" << groupId << "not found.";
  486. }
  487. }
  488. void SingleCameraOperationWnd::handleComBoxChange(int groupId,int index){
  489. QSettings settings("YourCompany", "YourApplication_");
  490. int currentGroupId = settings.value("GroupId", 0).toInt();
  491. if(currentGroupId == groupId){
  492. ui->DatacomboBox->setCurrentIndex(index);
  493. }
  494. }
  495. void SingleCameraOperationWnd::updateImage(const QImage&image){
  496. QPixmap pixmap = QPixmap::fromImage(image);
  497. QSize size = ui->Operatewidget->size();
  498. // QPixmap scaledPixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  499. QPixmap scaledPixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  500. ui->Operatewidget->setPixmap(scaledPixmap);
  501. }
  502. void SingleCameraOperationWnd::loadLiveVedio(){
  503. if(liveClick == true){
  504. startCamera(0);
  505. liveClick = false;
  506. }else{
  507. stopCamera(0);
  508. liveClick = true;
  509. }
  510. }