ControlOperationPage.cpp 20 KB

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