ControlOperationPage.cpp 21 KB

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