ControlOperationPage.cpp 20 KB

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