ControlOperationPage.cpp 19 KB

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