ControlOperationPage.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. #include "ControlOperationPage.h"
  2. #include "ui_ControlOperationPage.h"
  3. #include "JoystickPage.h"
  4. ControlOperationPage::ControlOperationPage(QWidget* parent)
  5. : QWidget(parent)
  6. , ui(new Ui::ControlOperationPage)
  7. {
  8. ui->setupUi(this);
  9. m_isEnable = false;
  10. m_bRuler = false;
  11. updateOperateWidget(QPixmap());
  12. InitWnd();
  13. initForm();
  14. }
  15. ControlOperationPage::~ControlOperationPage()
  16. {
  17. delete ui;
  18. }
  19. void ControlOperationPage::updateOperateWidget(const QPixmap& pixmap)
  20. {
  21. QPixmap scaledPixmap = SetQPixmapScaled(pixmap);
  22. clearLayout();
  23. ImageView* customView = new ImageView(ui->Operatewidget);
  24. customView->setPixmap(scaledPixmap);
  25. QVBoxLayout* layout = new QVBoxLayout(ui->Operatewidget);
  26. layout->setContentsMargins(0, 0, 0, 0);
  27. layout->addWidget(customView);
  28. ui->Operatewidget->setLayout(layout);
  29. m_currentPixmap = scaledPixmap;
  30. m_scaleFactor = 1.0;
  31. m_previousScaleFactor = 1.0;
  32. ui->label_Percentage->setText("100%");
  33. m_currentMode = ModeImage;
  34. m_currentImageView = customView;
  35. applyScale();
  36. }
  37. void ControlOperationPage::initImage() {
  38. clearLayout();
  39. ImageView* customView = new ImageView(ui->Operatewidget);
  40. QVBoxLayout* layout = new QVBoxLayout(ui->Operatewidget);
  41. layout->setContentsMargins(0, 0, 0, 0);
  42. layout->addWidget(customView);
  43. ui->Operatewidget->setLayout(layout);
  44. m_scaleFactor = 1.0;
  45. m_previousScaleFactor = 1.0;
  46. ui->label_Percentage->setText("100%");
  47. m_currentMode = ModeImage;
  48. m_currentImageView = customView;
  49. applyScale();
  50. }
  51. void ControlOperationPage::setDataSources(const QStringList& textList) {
  52. ui->DataSources->clear();
  53. ui->DataSources->addItems(textList);
  54. }
  55. // 清除大窗口上当前的布局
  56. void ControlOperationPage::clearLayout()
  57. {
  58. // 获取当前布局
  59. QLayout* layout = ui->Operatewidget->layout();
  60. if (layout)
  61. {
  62. QLayoutItem* child;
  63. while ((child = layout->takeAt(0)) != nullptr)
  64. {
  65. if (child->widget() != nullptr)
  66. {
  67. delete child->widget(); // 删除控件
  68. }
  69. delete child; // 删除布局项
  70. }
  71. delete layout; // 删除布局本身
  72. }
  73. }
  74. void ControlOperationPage::on_ZoomUpButton_clicked()
  75. {
  76. m_mousePos = ui->Operatewidget->geometry().center();
  77. updateScale(m_scaleFactor * 1.1);
  78. }
  79. void ControlOperationPage::on_ZoomOutButton_clicked()
  80. {
  81. m_mousePos = ui->Operatewidget->geometry().center();
  82. updateScale(m_scaleFactor * 0.9);
  83. }
  84. // 更新缩放比例
  85. void ControlOperationPage::updateScale(double newScaleFactor)
  86. {
  87. if (newScaleFactor >= 1.0)
  88. {
  89. m_scaleFactor = newScaleFactor;
  90. }
  91. else {
  92. m_scaleFactor = 1.0; // 最小缩放比例为 1.0
  93. }
  94. applyScale(); // 应用缩放
  95. }
  96. // 应用缩放
  97. void ControlOperationPage::applyScale()
  98. {
  99. if (m_currentMode == ModeImage && m_currentImageView)
  100. {
  101. // 图片模式:缩放图片
  102. QTransform transform;
  103. transform.scale(m_scaleFactor, m_scaleFactor);
  104. m_currentImageView->setTransform(transform);
  105. }
  106. else if (m_currentMode == ModeView && m_currentView)
  107. {
  108. // View 模式:缩放 view
  109. QTransform transform;
  110. transform.scale(m_scaleFactor, m_scaleFactor);
  111. m_currentView->setTransform(transform);
  112. }
  113. // 更新百分比显示
  114. double percentage = m_scaleFactor * 100;
  115. QString percentageStr = QString::number((int)percentage);
  116. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  117. }
  118. void ControlOperationPage::handleDoubleClick() {
  119. if (m_currentMode == ModeImage && m_currentImageView)
  120. {
  121. QTransform transform;
  122. transform.scale(1, 1);
  123. m_currentImageView->setTransform(transform);
  124. }
  125. else if (m_currentMode == ModeView && m_currentView)
  126. {
  127. QTransform transform;
  128. transform.scale(1, 1);
  129. m_currentView->setTransform(transform);
  130. }
  131. m_scaleFactor = 1.0;
  132. m_previousScaleFactor = 1.0;
  133. ui->label_Percentage->setText("100%");
  134. }
  135. void ControlOperationPage::updateMaterialWidget(kinds materialWndType)
  136. {
  137. clearLayout();
  138. // 一样的?
  139. switch (materialWndType)
  140. {
  141. case wafer_kind: KindsofWidget(wafer_kind); break;
  142. case waffle_kind: KindsofWidget(waffle_kind); break;
  143. case materialbox_kind: KindsofWidget(materialbox_kind); break;
  144. case bond_kind:KindsofWidget(bond_kind); break;
  145. }
  146. }
  147. void ControlOperationPage::KindsofWidget(kinds kind)
  148. {
  149. bool isRun = false;
  150. ui->Operatewidget->clearPixmap();
  151. QVBoxLayout* layout = new QVBoxLayout(ui->Operatewidget);
  152. layout->setContentsMargins(0, 0, 0, 0);
  153. m_currentMode = ModeView;
  154. if (kind == wafer_kind)
  155. {
  156. if (m_wafer)
  157. {
  158. isRun = true;
  159. m_wafer->initFrom(ui->Operatewidget);
  160. layout->addWidget(m_wafer->m_pView);
  161. m_currentView = m_wafer->m_pView;
  162. }
  163. }
  164. else if (kind == waffle_kind)
  165. {
  166. if (m_waffle)
  167. {
  168. isRun = true;
  169. m_waffle->initFrom(ui->Operatewidget);
  170. layout->addWidget(m_waffle->view);
  171. m_currentView = m_waffle->view;
  172. }
  173. }
  174. else if (kind == materialbox_kind)
  175. {
  176. if (m_materialbox)
  177. {
  178. isRun = true;
  179. m_materialbox->initFrom(ui->Operatewidget);
  180. layout->addWidget(m_materialbox->m_pView);
  181. m_currentView = m_materialbox->m_pView;
  182. }
  183. }
  184. else if (kind == bond_kind)
  185. {
  186. if (m_bond)
  187. {
  188. isRun = true;
  189. m_bond->initFrom(ui->Operatewidget);
  190. layout->addWidget(m_bond->m_pView);
  191. m_currentView = m_bond->m_pView;
  192. }
  193. }
  194. if (isRun)
  195. {
  196. ui->Operatewidget->setLayout(layout);
  197. m_currentMode = ModeView;
  198. m_scaleFactor = 1.0;
  199. applyScale();
  200. }
  201. }
  202. Wafer* ControlOperationPage::getWafer() {
  203. return m_wafer;
  204. }
  205. Bond* ControlOperationPage::getBond() {
  206. return m_bond;
  207. }
  208. Waffle* ControlOperationPage::getWaffle() {
  209. return m_waffle;
  210. }
  211. void ControlOperationPage::UpdatemPageGroup(Group* pGroup)
  212. {
  213. m_pPageSwitchGroup = pGroup;
  214. }
  215. void ControlOperationPage::setWafer(Wafer* wafer)
  216. {
  217. m_wafer = wafer;
  218. updateMaterialWidget(wafer_kind);
  219. }
  220. void ControlOperationPage::setWaffle(Waffle* waffle)
  221. {
  222. m_waffle = waffle;
  223. updateMaterialWidget(waffle_kind);
  224. }
  225. void ControlOperationPage::setMaterialBox(MaterialBox* materialbox)
  226. {
  227. m_materialbox = materialbox;
  228. updateMaterialWidget(materialbox_kind);
  229. }
  230. void ControlOperationPage::setBond(Bond* bond)
  231. {
  232. m_bond = bond;
  233. updateMaterialWidget(bond_kind);
  234. }
  235. void ControlOperationPage::initForm()
  236. {
  237. connect(ui->Operatewidget, &ImageWidget::sendDoubleClicksignal, this, &ControlOperationPage::handleDoubleClick);
  238. ui->Operatewidget->setMouseTracking(true);
  239. connect(ui->DataSources, QOverload<int>::of(&QComboBox::currentIndexChanged),
  240. this, &ControlOperationPage::on_DataSources_currentIndexChanged);
  241. }
  242. void ControlOperationPage::on_DataSources_currentIndexChanged(int comboxIndex) {
  243. send_ComboBox_singal(comboxIndex);
  244. }
  245. ImageWidget* ControlOperationPage::getOperatewidget()
  246. {
  247. return ui->Operatewidget;
  248. }
  249. void ControlOperationPage::resizeSingleUI(bool bMax /*= false*/)
  250. {
  251. ui->DataSources->setGeometry(QRect(20, 20, 400, 32));
  252. ui->Operatewidget->setGeometry(QRect(20, 72, 786, 786));
  253. //ui->line_2->setGeometry(QRect(826, 20, 1, 953));
  254. ui->LiveButton->setGeometry(QRect(436, 20, 60, 32));
  255. ui->horizontalLayout_2->setGeometry(QRect(12, 882, 786, 32));
  256. ui->layoutWidget->setGeometry(QRect(10, 882, 790, 31));
  257. ui->ZoomUpButton->setGeometry(QRect(25, 882, 120, 32));
  258. ui->ZoomOutButton->setGeometry(QRect(155, 882, 100, 32));
  259. ui->label_Percentage->setGeometry(QRect(265, 882, 120, 32));
  260. ui->RulerButton->setGeometry(QRect(400, 882, 110, 32));
  261. ui->PenButton->setGeometry(QRect(530, 882, 100, 32));
  262. // ui->switchJoystickBut
  263. ui->horizontalLayout->setGeometry(QRect(12, 882, 786, 32));
  264. ui->BackGround->setGeometry(QRect(16, 68, 794, 794));
  265. if (bMax)
  266. {
  267. ui->Operatewidget->m_nSingleCameraOperationWnd = true;
  268. }
  269. }
  270. void ControlOperationPage::resizeChartsAndCamerasUI() {
  271. }
  272. qreal ControlOperationPage::getScaleFactorValue() {
  273. return m_scaleFactor;
  274. }
  275. void ControlOperationPage::setScaleFactorSize(QPixmap scaledImage)
  276. {
  277. SetOriginalImage(scaledImage);
  278. if (m_currentImageView == nullptr || m_currentMode == ModeView)
  279. {
  280. updateOperateWidget(scaledImage);
  281. }
  282. else
  283. {
  284. m_currentImageView->setCurPixmap(SetQPixmapScaled(scaledImage));
  285. }
  286. }
  287. QPixmap ControlOperationPage::SetQPixmapScaled(const QPixmap& image)
  288. {
  289. QSize size = ui->Operatewidget->size();
  290. QPixmap scaledPixmap = image.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  291. return scaledPixmap;
  292. }
  293. void ControlOperationPage::UpDateCameraBind(CameraBind* pCameraBind)
  294. {
  295. m_pCameraBindCopy = pCameraBind;
  296. m_isAdd = true;
  297. // 有指针了在去刷新
  298. if (m_pCameraBindCopy != nullptr)
  299. {
  300. DeduplicationBox(ui->moduleTypeComboBox, m_pCameraBindCopy->m_vecCAxis, 0);
  301. DeduplicationBox(ui->axisTypeComboBox, m_pCameraBindCopy->m_vecCAxis, 1);
  302. }
  303. m_isAdd = false;
  304. setSwitchJoystickButEnable(true);
  305. }
  306. void ControlOperationPage::setSwitchJoystickButEnable(bool isEnable)
  307. {
  308. ui->switchJoystickBut->setEnabled(isEnable);
  309. if (isEnable == false)
  310. {
  311. ResetIdleTimer(false);
  312. m_isUserOnclick = false;
  313. }
  314. }
  315. void ControlOperationPage::on_switchJoystickBut_clicked()
  316. {
  317. m_isOpenJoystick = !m_isOpenJoystick;
  318. QString str = tr("Open light page", "打开灯光页面");
  319. QString strStyle = R"(QPushButton { background-image: url()";
  320. if (m_isOpenJoystick)
  321. {
  322. str = tr("Open Joystick page", "打开摇杆页面");
  323. strStyle += ":/images/light/light.png";
  324. }
  325. else
  326. {
  327. strStyle += ":/images/light/control.png";
  328. }
  329. strStyle += R"();background-repeat: no-repeat;
  330. background-position: center;
  331. border: none;})";
  332. ui->switchJoystickBut->setStyleSheet(strStyle);
  333. ui->switchJoystickBut->setToolTip(str);
  334. // 这里目前屏蔽
  335. emit SendModuleTypeSignals({});
  336. // 目前屏蔽
  337. /* m_isUserOnclick = true;
  338. ResetIdleTimer(true);
  339. UpdataModuleType("aaa", 3);
  340. ui->switchJoystickBut->setEnabled(false);*/
  341. }
  342. void ControlOperationPage::MouseMovedSlots(const QPoint& delta)
  343. {
  344. //qDebug() << "MouseMovedSlots:" << delta;
  345. if (m_pCameraBindCopy)
  346. {
  347. m_pCameraBindCopy->JCameraMove(0, delta.x(), delta.y());
  348. }
  349. }
  350. void ControlOperationPage::RequestCursorMoveSlots(const QPoint& pos)
  351. {
  352. QCursor::setPos(pos);
  353. }
  354. void ControlOperationPage::on_moduleTypeComboBox_currentIndexChanged(int index)
  355. {
  356. m_isAdd = true;
  357. QString strMod = ui->moduleTypeComboBox->itemText(index);
  358. ui->axisTypeComboBox->clear();
  359. for (auto a : m_pCameraBindCopy->m_vecCAxis)
  360. {
  361. // 如果2个相等说明当前模组,与轴匹配
  362. if (strMod == a->GetModuleType().c_str())
  363. {
  364. ui->axisTypeComboBox->addItem(a->GetStringAxisType().c_str());
  365. }
  366. }
  367. m_isAdd = false;
  368. UpdataModuleType(strMod, 1);
  369. }
  370. void ControlOperationPage::on_axisTypeComboBox_currentIndexChanged(int index)
  371. {
  372. if (!m_isAdd)
  373. {
  374. UpdataModuleType(ui->axisTypeComboBox->itemText(index), 2);
  375. }
  376. }
  377. void ControlOperationPage::timerEvent(QTimerEvent* event)
  378. {
  379. int nID = event->timerId();
  380. if (nID == m_idleTimer)
  381. {
  382. ResetIdleTimer(false);
  383. m_isUserOnclick = false;
  384. ui->switchJoystickBut->setEnabled(true);
  385. }
  386. }
  387. //void ControlOperationPage::mousePressEvent(QMouseEvent* event)
  388. //{
  389. // if (event->button() == Qt::LeftButton)
  390. // {
  391. // LockMouse(true);
  392. // }
  393. // else if (event->button() == Qt::RightButton)
  394. // {
  395. // LockMouse(false);
  396. // }
  397. //}
  398. //
  399. //void ControlOperationPage::mouseMoveEvent(QMouseEvent* event)
  400. //{
  401. // int a = 10;
  402. //}
  403. //
  404. //bool ControlOperationPage::eventFilter(QObject* obj, QEvent* event)
  405. //{
  406. // switch (event->type())
  407. // {
  408. // case QEvent::KeyPress:
  409. // case QEvent::MouseMove:
  410. // case QEvent::MouseButtonPress:
  411. // case QEvent::MouseButtonDblClick:
  412. // case QEvent::Wheel:
  413. // {
  414. // if (m_isUserOnclick)
  415. // {
  416. // ResetIdleTimer(false);
  417. // ResetIdleTimer(true);
  418. // }
  419. // }
  420. // break;
  421. // default:
  422. // break;
  423. // }
  424. //
  425. // return QWidget::eventFilter(obj, event);
  426. //}
  427. void ControlOperationPage::wheelEvent(QWheelEvent* event) {
  428. if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
  429. m_mousePos = ui->Operatewidget->mapFromGlobal(event->globalPos());
  430. if (event->angleDelta().y() > 0) {
  431. updateScale(m_scaleFactor * 1.1); // 放大
  432. }
  433. else {
  434. updateScale(m_scaleFactor * 0.9); // 缩小
  435. }
  436. }
  437. }
  438. void ControlOperationPage::HideLayout(bool bShow)
  439. {
  440. for (int i = 0; i < ui->horizontalLayout->count(); ++i)
  441. {
  442. QWidget* widget = ui->horizontalLayout->itemAt(i)->widget();
  443. if (widget)
  444. {
  445. if (bShow)
  446. {
  447. widget->show();
  448. }
  449. else
  450. {
  451. widget->hide();
  452. }
  453. }
  454. }
  455. }
  456. void ControlOperationPage::ResetIdleTimer(bool bStart /*= false*/)
  457. {
  458. if (bStart)
  459. {
  460. if (isActiveWindow())
  461. {
  462. m_idleTimer = startTimer(g_unnSuspensionWaitingTime);
  463. }
  464. }
  465. else
  466. {
  467. killTimer(m_idleTimer);
  468. m_idleTimer = -1;
  469. }
  470. HideLayout(bStart);
  471. }
  472. void ControlOperationPage::InitWnd()
  473. {
  474. HideLayout(false);
  475. /* connect(ui->widgetPage, &JoystickPage::PositionChangedSignals, [&](qreal x, qreal y) {
  476. ui->showLabel->setText(QString("摇杆位置: (%1, %2)").arg(x, 0, 'f', 2).arg(y, 0, 'f', 2));
  477. });*/
  478. this->setMouseTracking(true);
  479. this->installEventFilter(this);
  480. ui->RulerButton->setCheckable(true);
  481. ui->PenButton->setCheckable(true);
  482. ui->RulerButton->setChecked(false);
  483. ui->RulerButton->setChecked(false);
  484. }
  485. void ControlOperationPage::CreateMouseMonitor(bool isStart)
  486. {
  487. if (isStart)
  488. {
  489. m_pMousethread = new JMouseMonitorThread(this);
  490. connect(m_pMousethread, &JMouseMonitorThread::MouseMovedSlg, this, &ControlOperationPage::MouseMovedSlots);
  491. connect(m_pMousethread, &JMouseMonitorThread::RequestCursorMoveSlg, this, &ControlOperationPage::RequestCursorMoveSlots);
  492. m_pMousethread->start();
  493. }
  494. else
  495. {
  496. m_pMousethread->stop();
  497. m_pMousethread->wait();
  498. delete m_pMousethread;
  499. m_pMousethread = nullptr;
  500. }
  501. }
  502. void ControlOperationPage::LockMouse(bool islockMouse)
  503. {
  504. if (m_pCameraBindCopy)
  505. {
  506. if (islockMouse)
  507. {
  508. if (!m_bMouseRun)
  509. {
  510. CreateMouseMonitor(true);
  511. QPoint center = rect().center();
  512. QPoint globalCenter = mapToGlobal(center);
  513. m_pMousethread->setLockCenter(globalCenter);
  514. QCursor::setPos(globalCenter);
  515. setCursor(Qt::BlankCursor);
  516. grabMouse();
  517. m_bMouseRun = true;
  518. }
  519. }
  520. else
  521. {
  522. if (m_bMouseRun)
  523. {
  524. if (m_pMousethread)
  525. {
  526. m_pMousethread->unlock();
  527. releaseMouse();
  528. unsetCursor();
  529. QCursor::setPos(mapToGlobal(rect().center()));
  530. CreateMouseMonitor(false);
  531. }
  532. m_bMouseRun = false;
  533. }
  534. }
  535. }
  536. }
  537. void ControlOperationPage::UpdataModuleType(const QString& strMode, int nIndex)
  538. {
  539. //if (nIndex == 1)
  540. //{
  541. // m_currentSelectRunAxis.ModuleType = strMode.toStdString();
  542. //}
  543. //else if (nIndex == 2)
  544. //{
  545. // m_currentSelectRunAxis.AxisType = strMode.toStdString();
  546. //}
  547. m_currentSelectRunAxis.ModuleType = ui->moduleTypeComboBox->currentText().toStdString();
  548. m_currentSelectRunAxis.AxisType = ui->axisTypeComboBox->currentText().toStdString();
  549. if (m_isAdd == false)
  550. {
  551. m_currentSelectRunAxis.isSwitch = true;
  552. emit SendModuleTypeSignals(m_currentSelectRunAxis);
  553. m_currentSelectRunAxis.isSwitch = false;
  554. }
  555. }
  556. void ControlOperationPage::UpdataRunStopCameraButTip()
  557. {
  558. QString strTip = tr("Close Camera", "关闭相机");
  559. QString str = R"(QPushButton { background-image: url()";
  560. m_isUpDataImage = !m_isUpDataImage;
  561. if (m_isUpDataImage)
  562. {
  563. str += ":/images/light/CloseCamera.png";
  564. strTip = tr("Open Camera", "打开相机");
  565. }
  566. else
  567. {
  568. str += ":/images/light/Camera.png";
  569. }
  570. str += R"();background-repeat: no-repeat;
  571. background-position: center;
  572. border: none;})";
  573. ui->runStopCameraBut->setToolTip(strTip);
  574. ui->runStopCameraBut->setStyleSheet(str);
  575. }
  576. template<class T>
  577. void ControlOperationPage::DeduplicationBox(QComboBox* pCom, const T& veTemp, int nIndex)
  578. {
  579. for (auto& a : veTemp)
  580. {
  581. QString strName;
  582. if (nIndex == 0)
  583. {
  584. strName = a->GetModuleType().c_str();
  585. }
  586. else if (nIndex == 1)
  587. {
  588. strName = a->GetStringAxisType().c_str();
  589. }
  590. QStringList items;
  591. for (int i = 0; i < pCom->count(); ++i)
  592. {
  593. items << pCom->itemText(i);
  594. }
  595. bool bMa = false; // 是否匹配
  596. for (auto b : items)
  597. {
  598. if (b == strName)
  599. {
  600. bMa = true;
  601. break;
  602. }
  603. }
  604. if (!bMa)
  605. {
  606. pCom->addItem(strName);
  607. }
  608. }
  609. }
  610. void ControlOperationPage::setEnableControls(bool enable) {
  611. ui->LiveButton->setEnabled(enable);
  612. ui->DataSources->setEnabled(enable);
  613. ui->RulerButton->setEnabled(enable);
  614. ui->PenButton->setEnabled(enable);
  615. // if (enable == true) {
  616. // ui->LiveButton->setStyleSheet(
  617. // "QPushButton:hover {"
  618. // " background-color: #45a049;"
  619. // "}"
  620. // "QPushButton:pressed {"
  621. // " background-color: #3e8e41;"
  622. // "}"
  623. // );
  624. // }
  625. // else {
  626. // ui->LiveButton->setStyleSheet("background-color: lightgray;");
  627. // }
  628. }
  629. void ControlOperationPage::setBlueBord() {
  630. ui->BackGround->setStyleSheet(QString::fromUtf8("border: 4px solid blue;"));
  631. }
  632. void ControlOperationPage::on_RulerButton_clicked()
  633. {
  634. if (nullptr == m_currentImageView)
  635. return;
  636. m_bRuler = !m_bRuler;
  637. if (m_bRuler == true) {
  638. }
  639. else {
  640. }
  641. if (ui->RulerButton->isChecked()) {
  642. m_currentImageView->addRuler();
  643. if (ui->PenButton->isChecked()) {
  644. ui->PenButton->setChecked(false);
  645. m_currentImageView->setIsDrawing(false);
  646. }
  647. }
  648. else {
  649. m_currentImageView->cancelRuler();
  650. }
  651. }
  652. void ControlOperationPage::on_PenButton_clicked() {
  653. if (nullptr == m_currentImageView)
  654. return;
  655. m_isEnable = !m_isEnable;
  656. if (m_isEnable == true) {
  657. }
  658. else {
  659. }
  660. if (ui->PenButton->isChecked()) {
  661. //ui->Operatewidget->setIsDrawing(true);
  662. m_currentImageView->setIsDrawing(true);
  663. if (ui->RulerButton->isChecked()) {
  664. ui->RulerButton->setChecked(false);
  665. m_currentImageView->cancelRuler();
  666. }
  667. }
  668. else {
  669. //ui->Operatewidget->setIsDrawing(false);
  670. m_currentImageView->setIsDrawing(false);
  671. }
  672. }
  673. void ControlOperationPage::SaveNewImage()
  674. {
  675. //// 捕获 ui->Operatewidget 的当前显示内容
  676. //QPixmap pixmap = ui->Operatewidget->grab();
  677. //// 使用当前时间生成默认文件名
  678. //QString defaultFileName = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss") + ".png";
  679. //// 弹出文件对话框,让用户选择保存路径和文件名
  680. //QString filePath = QFileDialog::getSaveFileName(
  681. // this,
  682. // tr("保存图片"),
  683. // QDir::homePath() + "/" + defaultFileName, // 默认路径为用户目录,文件名为当前时间
  684. // tr("PNG 文件 (*.png);;JPEG 文件 (*.jpg);;所有文件 (*)")
  685. //);
  686. //// 如果用户取消保存,则退出函数
  687. //if (filePath.isEmpty()) {
  688. // return;
  689. //}
  690. //if (!pixmap.save(filePath)) {
  691. // QMessageBox::warning(this, tr("保存失败"), tr("无法保存图片到指定路径。"));
  692. //}
  693. //else {
  694. // QMessageBox::information(this, tr("保存成功"), tr("图片已成功保存到:") + filePath);
  695. //}
  696. }
  697. void ControlOperationPage::SetOriginalImage(QPixmap scaledImage)
  698. {
  699. if (m_currentImageView)
  700. {
  701. m_currentImageView->setoriginalCurPixmap(scaledImage);
  702. }
  703. }
  704. void ControlOperationPage::setComboBox(const QList<QPair<QString, QString>> fileList, const int index) {
  705. ui->DataSources->clear();
  706. // 使用QList批量添加到QComboBox
  707. for (const auto& pair : fileList)
  708. {
  709. ui->DataSources->addItem(pair.first, pair.second);
  710. }
  711. ui->DataSources->setCurrentIndex(index);
  712. }
  713. QPixmap ControlOperationPage::getCurrentComboBoxPixmap(const int index) {
  714. if (index < 0)
  715. {
  716. return NULL;
  717. }
  718. // 从用户数据中获取完整路径并输出
  719. QString imagePath = ui->DataSources->itemData(index).toString();
  720. QPixmap pixmap(imagePath);
  721. return pixmap;
  722. }
  723. void ControlOperationPage::on_runStopCameraBut_clicked()
  724. {
  725. if (m_pPageSwitchGroup && m_pCameraBindCopy)
  726. {
  727. UpdataRunStopCameraButTip();
  728. int niD = m_pPageSwitchGroup->m_cameaInfo.iCameraId;
  729. m_pCameraBindCopy->JOpenOrCloseCamera(niD);
  730. }
  731. }