ControlOperationPage.cpp 20 KB

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