ControlOperationPage.cpp 20 KB

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