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