ChartsAndCamerasWnd.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. #include "ChartsAndCamerasWnd.h"
  2. #include "ui_ChartsAndCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QTimer>
  7. #include "chartline.h"
  8. #include <QRandomGenerator>
  9. #include <QScrollBar>
  10. #include <qDebug>
  11. // #include "CInterface.h"
  12. #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
  13. ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget *parent) :
  14. QMainWindow(parent),
  15. ui(new Ui::ChartsAndCamerasWnd),
  16. chartLine(new ChartLine(this)),
  17. chartLine1(new ChartLine(this)),
  18. chartLine2(new ChartLine(this))
  19. {
  20. ui->setupUi(this);
  21. // 设置 ChartLine 的位置和大小
  22. chartLine->setParent(ui->Leftwidget);
  23. chartLine->setGeometry(0, 0, 560, 280);
  24. chartLine->setChartLabels("Combined Placement", "Number of Samples", "Device Align");
  25. // 设置 ChartLine1 的位置和大小
  26. chartLine1->setParent(ui->Leftwidget);
  27. chartLine1->setGeometry(0, 245, 560, 280);
  28. chartLine1->setChartLabels("Y placement", "Number of samples", "Y device align");
  29. // 设置 ChartLine2 的位置和大小
  30. chartLine2->setParent(ui->Leftwidget);
  31. chartLine2->setGeometry(0, 490, 560, 280);
  32. chartLine2->setChartLabels("Theta placement", "Number of samples", "Theta device align");
  33. // 初始化系列信息
  34. initializeSeriesInfo();
  35. // 连接所有复选框的 clicked 信号到通用槽函数
  36. QList<QCheckBox*> checkBoxes = {
  37. ui->GreenDiamondcheckBox,
  38. ui->YellowDiamondcheckBox,
  39. ui->BlackDiamondcheckBox,
  40. ui->BlueDiamondcheckBox,
  41. ui->BlueHorizontalLinecheckBox,
  42. ui->BlueVerticalBarcheckBox,
  43. ui->GreenVerticalBarcheckBox,
  44. ui->PurpleVerticalBarcheckBox,
  45. ui->RedDiamondcheckBox,
  46. ui->RedHorizontalLinecheckBox,
  47. ui->WhiteVerticalBarcheckBox
  48. };
  49. for (QCheckBox* cb : checkBoxes) {
  50. cb->setCheckable(true);
  51. connect(cb, &QCheckBox::clicked, this, &ChartsAndCamerasWnd::on_CheckBox_clicked);
  52. }
  53. initFrom();
  54. isShow = true;
  55. }
  56. ChartsAndCamerasWnd::~ChartsAndCamerasWnd()
  57. {
  58. delete ui;
  59. }
  60. void ChartsAndCamerasWnd::initializeSeriesInfo()
  61. {
  62. // 初始化系列信息,使用 DataSeries 结构体
  63. m_seriesMap["GreenDiamond"] = DataSeries{
  64. "GreenDiamond",
  65. QColor("#00FF00"), // 绿色
  66. QPixmap(":/images/Participation display/GreenDiamond.png"),
  67. QList<QPointF>() // 初始为空
  68. };
  69. m_seriesMap["YellowDiamond"] = DataSeries{
  70. "YellowDiamond",
  71. QColor("#FFFF00"), // 黄色
  72. QPixmap(":/images/Participation display/YellowDiamond.png"),
  73. QList<QPointF>()
  74. };
  75. m_seriesMap["BlackDiamond"] = DataSeries{
  76. "BlackDiamond",
  77. QColor("#000000"), // 黑色
  78. QPixmap(":/images/Participation display/BlackDiamond.png"),
  79. QList<QPointF>()
  80. };
  81. m_seriesMap["BlueDiamond"] = DataSeries{
  82. "BlueDiamond",
  83. QColor("#0000FF"), // 蓝色
  84. QPixmap(":/images/Participation display/BlueDiamond.png"),
  85. QList<QPointF>()
  86. };
  87. m_seriesMap["BlueHorizontalLine"] = DataSeries{
  88. "BlueHorizontalLine",
  89. QColor("#0000FF"),
  90. QPixmap(":/images/Participation display/Blue_horizontal_line.png"),
  91. QList<QPointF>()
  92. };
  93. m_seriesMap["BlueVerticalBar"] = DataSeries{
  94. "BlueVerticalBar",
  95. QColor("#0000FF"),
  96. QPixmap(":/images/Participation display/Blue_vertical_bar.png"),
  97. QList<QPointF>()
  98. };
  99. m_seriesMap["GreenVerticalBar"] = DataSeries{
  100. "GreenVerticalBar",
  101. QColor("#00FF00"),
  102. QPixmap(":/images/Participation display/Green_vertical_bar.png"),
  103. QList<QPointF>()
  104. };
  105. m_seriesMap["PurpleVerticalBar"] = DataSeries{
  106. "PurpleVerticalBar",
  107. QColor("#800080"),
  108. QPixmap(":/images/Participation display/Purple_vertical_bar.png"),
  109. QList<QPointF>()
  110. };
  111. m_seriesMap["RedDiamond"] = DataSeries{
  112. "RedDiamond",
  113. QColor("#FF0000"), // 红色
  114. QPixmap(":/images/Participation display/RedDiamond.png"),
  115. QList<QPointF>()
  116. };
  117. m_seriesMap["RedHorizontalLine"] = DataSeries{
  118. "RedHorizontalLine",
  119. QColor("#FF0000"),
  120. QPixmap(":/images/Participation display/Red_horizontal_line.png"),
  121. QList<QPointF>()
  122. };
  123. m_seriesMap["WhiteVerticalBar"] = DataSeries{
  124. "WhiteVerticalBar",
  125. QColor("#FFFFFF"), // 白色
  126. QPixmap(":/images/Participation display/White_vertical_bar.png"),
  127. QList<QPointF>()
  128. };
  129. }
  130. void ChartsAndCamerasWnd::on_CheckBox_clicked()
  131. {
  132. // 获取发送信号的复选框
  133. QCheckBox* checkBox = qobject_cast<QCheckBox*>(sender());
  134. if (!checkBox)
  135. return;
  136. QString checkBoxName = checkBox->objectName();
  137. QString seriesName = checkBoxName;
  138. // 移除末尾的 "checkBox"
  139. if (seriesName.endsWith("checkBox")) {
  140. seriesName.chop(QString("checkBox").length());
  141. } else if (seriesName.endsWith("CheckBox")) {
  142. seriesName.chop(QString("CheckBox").length());
  143. }
  144. qDebug() << "Checkbox clicked:" << seriesName << (checkBox->isChecked() ? "Checked" : "Unchecked");
  145. if (!m_seriesMap.contains(seriesName)) {
  146. qDebug() << "No series info for:" << seriesName;
  147. return;
  148. }
  149. DataSeries &seriesInfo = m_seriesMap[seriesName];
  150. if (checkBox->isChecked()) {
  151. // 生成随机数据
  152. QList<QPointF> data;
  153. for (int i = 0; i <= 40; i += 4) {
  154. data.append(QPointF(i, QRandomGenerator::global()->bounded(-30, 80)));
  155. }
  156. seriesInfo.data = data;
  157. // 添加到 ChartLine 实例
  158. chartLine->addDataSeries(seriesInfo);
  159. chartLine1->addDataSeries(seriesInfo);
  160. chartLine2->addDataSeries(seriesInfo);
  161. qDebug() << "Added series:" << seriesName;
  162. }
  163. else {
  164. // 从 ChartLine 实例中移除
  165. chartLine->removeDataSeries(seriesName);
  166. chartLine1->removeDataSeries(seriesName);
  167. chartLine2->removeDataSeries(seriesName);
  168. qDebug() << "Removed series:" << seriesName;
  169. }
  170. }
  171. void ChartsAndCamerasWnd::initFrom() {
  172. QTimer *timer = new QTimer(this);
  173. connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::checkSettings);
  174. timer->start(100);
  175. ui->label_Percentage->setAlignment(Qt::AlignCenter);
  176. initSliders();
  177. initLineEdits();
  178. initProgressBar();
  179. // 连接 QSlider 的 valueChanged 信号到 QProgressBar 的 setValue 槽
  180. connect(ui->RedLightverticalSlider, &QSlider::valueChanged, ui->RedLightprogressBar, &QProgressBar::setValue);
  181. connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar, &QProgressBar::setValue);
  182. connect(ui->GreenLightverticalSlider, &QSlider::valueChanged, ui->GreenLightprogressBar, &QProgressBar::setValue);
  183. connect(ui->DotLightverticalSlider, &QSlider::valueChanged, ui->DotLightprogressBar, &QProgressBar::setValue);
  184. connectSliderAndLineEdit(ui->RedLightverticalSlider, ui->RedLightlineEdit);
  185. connectSliderAndLineEdit(ui->GreenLightverticalSlider, ui->GreenLightlineEdit);
  186. connectSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit);
  187. connectSliderAndLineEdit(ui->DotLightverticalSlider, ui->DotLightlineEdit);
  188. connect(ui->Operatewidget,&ImageWidget::sendDoubleClicksignal,this,&ChartsAndCamerasWnd::handleDoubleClick);
  189. QWidget *viewport = ui->scrollArea->viewport();
  190. QWidget *container = new QWidget(viewport);
  191. QHBoxLayout *layout = new QHBoxLayout(container);
  192. layout->setSpacing(16); // 设置Group之间的间隔距离
  193. layout->setMargin(0);
  194. // CInterface interface;
  195. // ImageInfo image;
  196. // long result = interface.GrabImage(1, image);
  197. // if (result == 0) {
  198. // qDebug() << "Image width: " << image.width;
  199. // qDebug() << "Image height: " << image.height;
  200. // qDebug() << "Image width: " << image.format;
  201. // QImage img;
  202. // // 根据图像格式转换
  203. // switch (image.format) {
  204. // case GRAY8:
  205. // img = QImage(image.data, image.width, image.height, QImage::Format_Grayscale8);
  206. // break;
  207. // case RGB888:
  208. // img = QImage(image.data, image.width, image.height, QImage::Format_RGB888);
  209. // break;
  210. // case ARGB8888:
  211. // img = QImage(image.data, image.width, image.height, QImage::Format_ARGB32);
  212. // break;
  213. // case RGB32:
  214. // img = QImage(image.data, image.width, image.height, QImage::Format_RGB32);
  215. // break;
  216. // case YUV422:
  217. // // YUV422 需要额外的转换逻辑
  218. // // 这里假设你有转换函数 convertYUV422ToRGB
  219. // // img = convertYUV422ToRGB(image.data, image.width, image.height);
  220. // break;
  221. // default:
  222. // qDebug() << "Unsupported image format";
  223. // }
  224. // } else {
  225. // qDebug() << "Failed to grab image, error code: " << result;
  226. // }
  227. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  228. QList<Group*> widgets;
  229. for (int i = 0; i < numbers.size(); ++i) {
  230. int num = numbers[i];
  231. CameraImageHandler* manager = new CameraImageHandler(num);
  232. Group* widget = manager->getGroup();
  233. connect(widget,&Group::send_button_Signal,this,&ChartsAndCamerasWnd::showAndHide);
  234. if (widget != nullptr) {
  235. layout->addWidget(widget);
  236. widgets.append(widget);
  237. }
  238. if(manager->getWafer()) {
  239. waferMap.insert(num, manager->getWafer());
  240. }
  241. if(manager->getWafer()) {
  242. waffleMap.insert(num, manager->getWaffle());
  243. }
  244. if(manager->getMaterialBox()){
  245. materialBoxMap.insert(num,manager->getMaterialBox());
  246. }
  247. delete manager;
  248. }
  249. // 设置控件的最小高度和最大宽度
  250. int minHeight = 162;
  251. int maxWidth = 244;
  252. int num = -16;
  253. for (Group* w : widgets) {
  254. w->setMinimumHeight(minHeight);
  255. w->setMaximumWidth(maxWidth);
  256. num = num + 260;
  257. }
  258. container->setMinimumSize(num, 162);
  259. container->setLayout(layout);
  260. ui->scrollArea->setWidget(container);
  261. ui->scrollArea->resize(508, 177);
  262. ui->Operatewidget->setMouseTracking(true);
  263. }
  264. void ChartsAndCamerasWnd::initSliders() {
  265. QList<QSlider*> sliders = {
  266. ui->RedLightverticalSlider, ui->GreenLightverticalSlider,
  267. ui->BlueLightverticalSlider, ui->DotLightverticalSlider
  268. };
  269. QList<int> initialValues = {22, 11, 0, 0};
  270. for (int i = 0; i < sliders.size(); ++i) {
  271. sliders[i]->setMinimum(0);
  272. sliders[i]->setMaximum(100);
  273. sliders[i]->setValue(initialValues[i]);
  274. }
  275. }
  276. void ChartsAndCamerasWnd::initLineEdits() {
  277. QList<QLineEdit*> lineEdits = {
  278. ui->RedLightlineEdit, ui->GreenLightlineEdit,
  279. ui->BlueLightlineEdit, ui->DotLightlineEdit
  280. };
  281. for (QLineEdit* lineEdit : lineEdits) {
  282. lineEdit->setAlignment(Qt::AlignCenter);
  283. }
  284. }
  285. void ChartsAndCamerasWnd::initProgressBar(){
  286. QList<int> initialValues = {22, 11, 0, 0};
  287. QList<QProgressBar*> progressBar = {
  288. ui->RedLightprogressBar,ui->GreenLightprogressBar,
  289. ui->BlueLightprogressBar,ui->DotLightprogressBar
  290. };
  291. for (int i = 0; i < progressBar.size(); ++i) {
  292. progressBar[i]->setMinimum(0);
  293. progressBar[i]->setMaximum(100);
  294. progressBar[i]->setValue(initialValues[i]);
  295. }
  296. }
  297. void ChartsAndCamerasWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  298. {
  299. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  300. lineEdit->setValidator(validator);
  301. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  302. lineEdit->setText(QString::number(value));
  303. });
  304. connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
  305. bool ok;
  306. int value = text.toInt(&ok);
  307. if (ok && value >= slider->minimum() && value <= slider->maximum()) {
  308. slider->setValue(value);
  309. } else if (!text.isEmpty()) {
  310. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  311. slider->setValue(closestValue);
  312. }
  313. });
  314. }
  315. void ChartsAndCamerasWnd::checkSettings() {
  316. QSettings settings("YourCompany", "YourApplication_");
  317. int groupId = settings.value("GroupId", 0).toInt();
  318. int index = settings.value("Index", 0).toInt();
  319. if (groupId != lastGroupId || index != lastIndex) {
  320. lastGroupId = groupId;
  321. lastIndex = index;
  322. loadSettings();
  323. }
  324. }
  325. void ChartsAndCamerasWnd::loadSettings()
  326. {
  327. QSettings settings("YourCompany", "YourApplication_");
  328. int groupId = settings.value("GroupId", 0).toInt();
  329. int index = settings.value("Index", 0).toInt();
  330. loadGroupSettings(groupId, index);
  331. }
  332. void ChartsAndCamerasWnd::loadGroupSettings(int Id, int Index) {
  333. QSettings settings("YourOrganization", "YourApplication");
  334. settings.beginGroup(QString::number(Id));
  335. QString imagePath1 = settings.value("ImagePath1").toString();
  336. int materialWndType = settings.value("MaterialWndType").toInt();
  337. QStringList textList = settings.value("TextList").toStringList();
  338. settings.endGroup();
  339. QSize size = ui->Operatewidget->size();
  340. QPixmap newPixmap;
  341. // 判断是实时图片还是物料窗口
  342. if (Index == 1) {
  343. clearLayout();
  344. newPixmap = QPixmap(imagePath1);
  345. QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  346. currentMode = ModeImage;
  347. currentPixmap = scaledPixmap;
  348. scaleFactor = 1.0;
  349. previousScaleFactor = 1.0;
  350. ui->Operatewidget->setPixmap(scaledPixmap);
  351. double percentage = scaleFactor * 100;
  352. QString percentageStr = QString::number((int)percentage);
  353. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  354. } else if (Index == 2) {
  355. if (materialWndType == 1) {
  356. clearLayout();
  357. // WaferWidget(Id);
  358. ui->Operatewidget->clearPixmap();
  359. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  360. waferMap.value(Id)->initFrom(ui->Operatewidget);
  361. layout->setContentsMargins(0, 0, 0, 0);
  362. layout->addWidget(waferMap.value(Id)->view);
  363. ui->Operatewidget->setLayout(layout);
  364. currentMode = ModeView;
  365. currentView = waferMap.value(Id)->view;
  366. scaleFactor = 1.0;
  367. applyScale();
  368. } else if (materialWndType == 2) {
  369. clearLayout();
  370. ui->Operatewidget->clearPixmap();
  371. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  372. waffleMap.value(Id)->initFrom(ui->Operatewidget);
  373. layout->setContentsMargins(0, 0, 0, 0);
  374. layout->addWidget(waffleMap.value(Id)->view);
  375. ui->Operatewidget->setLayout(layout);
  376. currentMode = ModeView;
  377. currentView = waffleMap.value(Id)->view;
  378. scaleFactor = 1.0;
  379. applyScale();
  380. } else if (materialWndType == 3) {
  381. clearLayout();
  382. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  383. materialBoxMap.value(Id)->initFrom(ui->Operatewidget);
  384. layout->setContentsMargins(0, 0, 0, 0);
  385. layout->addWidget(materialBoxMap.value(Id)->view);
  386. ui->Operatewidget->setLayout(layout);
  387. currentMode = ModeView;
  388. currentView = materialBoxMap.value(Id)->view;
  389. scaleFactor = 1.0;
  390. applyScale();
  391. }
  392. }
  393. // QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  394. // ui->Operatewidget->setPixmap(scaledPixmap);
  395. // // 更新当前图片的成员变量
  396. // currentPixmap = scaledPixmap;
  397. // scaleFactor = 1.0;
  398. // ui->label_Percentage->setText("100%");
  399. ui->DatacomboBox->clear();
  400. ui->DatacomboBox->addItems(textList);
  401. // connect(ui->DatacomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Demo001_3::onComboBoxIndexChanged(int)));
  402. }
  403. void ChartsAndCamerasWnd::clearLayout() {
  404. // 获取当前布局
  405. QLayout* layout = ui->Operatewidget->layout();
  406. if (layout) {
  407. QLayoutItem *child;
  408. while ((child = layout->takeAt(0)) != nullptr) {
  409. if (child->widget() != nullptr) {
  410. delete child->widget(); // 删除控件
  411. }
  412. delete child; // 删除布局项
  413. }
  414. delete layout; // 删除布局本身
  415. }
  416. }
  417. // 圆晶
  418. void ChartsAndCamerasWnd::WaferWidget(int Id) {
  419. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  420. waferMap.value(Id)->initFrom(ui->Operatewidget);
  421. layout->setContentsMargins(0, 0, 0, 0);
  422. layout->addWidget(waferMap.value(Id)->view);
  423. ui->Operatewidget->setLayout(layout);
  424. ui->Operatewidget->setFixedSize(480, 480);
  425. }
  426. // 华夫盒
  427. void ChartsAndCamerasWnd::WaffleWidget() {
  428. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  429. waffle = new Waffle(1, ui->Operatewidget);
  430. layout->setContentsMargins(0, 0, 0, 0);
  431. layout->addWidget(waffle);
  432. ui->Operatewidget->setLayout(layout);
  433. ui->Operatewidget->setFixedSize(480, 480);
  434. }
  435. // 料盒
  436. void ChartsAndCamerasWnd::MaterialBoxWidget() {
  437. QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
  438. materialbox = new MaterialBox(1, ui->Operatewidget);
  439. layout->setContentsMargins(0, 0, 0, 0);
  440. layout->addWidget(materialbox);
  441. ui->Operatewidget->setLayout(layout);
  442. ui->Operatewidget->setFixedSize(480, 480);
  443. }
  444. void ChartsAndCamerasWnd::handleDoubleClick(){
  445. if (currentMode == ModeImage) {
  446. QPixmap scaledImage = currentPixmap.scaled(currentPixmap.width(), currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  447. ui->Operatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
  448. } else if (currentMode == ModeView && currentView) {
  449. QTransform transform;
  450. transform.scale(1, 1);
  451. currentView->setTransform(transform);
  452. }
  453. scaleFactor = 1.0;
  454. previousScaleFactor = 1.0;
  455. ui->label_Percentage->setText("100%");
  456. }
  457. // 更新缩放比例
  458. void ChartsAndCamerasWnd::updateScale(double newScaleFactor) {
  459. if (newScaleFactor >= 1.0) {
  460. scaleFactor = newScaleFactor;
  461. } else {
  462. scaleFactor = 1.0; // 最小缩放比例为 1.0
  463. }
  464. applyScale(); // 应用缩放
  465. }
  466. // 应用缩放
  467. void ChartsAndCamerasWnd::applyScale() {
  468. if (currentMode == ModeImage) {
  469. // 图片模式:缩放图片
  470. int newWidth = currentPixmap.width() * scaleFactor;
  471. int newHeight = currentPixmap.height() * scaleFactor;
  472. QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  473. ui->Operatewidget->setPixmapAndPoint(scaledImage, previousScaleFactor, scaleFactor, mousePos);
  474. previousScaleFactor = scaleFactor;
  475. } else if (currentMode == ModeView && currentView) {
  476. // View 模式:缩放 view
  477. QTransform transform;
  478. transform.scale(scaleFactor, scaleFactor);
  479. currentView->setTransform(transform);
  480. }
  481. // 更新百分比显示
  482. double percentage = scaleFactor * 100;
  483. QString percentageStr = QString::number((int)percentage);
  484. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  485. }
  486. void ChartsAndCamerasWnd::on_ZoomUpButton_clicked()
  487. {
  488. mousePos = ui->Operatewidget->geometry().center();
  489. updateScale(scaleFactor * 1.1);
  490. }
  491. void ChartsAndCamerasWnd::on_ZoomOutButton_clicked()
  492. {
  493. mousePos = ui->Operatewidget->geometry().center();
  494. updateScale(scaleFactor * 0.9);
  495. }
  496. void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event)
  497. {
  498. mousePos = ui->Operatewidget->mapFromGlobal(event->globalPos());
  499. if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
  500. if (event->angleDelta().y() > 0) {
  501. updateScale(scaleFactor * 1.1); // 放大
  502. } else {
  503. updateScale(scaleFactor * 0.9); // 缩小
  504. }
  505. }
  506. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  507. // 获取 QScrollArea 的横向滚动条
  508. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  509. // 根据滚轮滚动方向改变滚动条的值
  510. if (event->angleDelta().y() > 0) {
  511. scrollBar->setValue(scrollBar->value() - 50);
  512. } else {
  513. scrollBar->setValue(scrollBar->value() + 50);
  514. }
  515. }
  516. QMainWindow::wheelEvent(event);
  517. }
  518. void ChartsAndCamerasWnd::showEvent(QShowEvent *event) {
  519. QMainWindow::showEvent(event);
  520. loadSettings();
  521. // initFrom();
  522. }
  523. void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) {
  524. QMainWindow::hideEvent(event);
  525. }
  526. void ChartsAndCamerasWnd::showAndHide(){
  527. if(isShow == true){
  528. isShow = false;
  529. }else{
  530. isShow = true;
  531. }
  532. QList<QLineEdit*> lineEdits = {
  533. ui->RedLightlineEdit, ui->GreenLightlineEdit,
  534. ui->BlueLightlineEdit, ui->DotLightlineEdit,
  535. };
  536. QList<QSlider*> sliders = {
  537. ui->RedLightverticalSlider, ui->GreenLightverticalSlider,
  538. ui->BlueLightverticalSlider, ui->DotLightverticalSlider
  539. };
  540. QList<QProgressBar*> progressBar = {
  541. ui->RedLightprogressBar,ui->GreenLightprogressBar,
  542. ui->BlueLightprogressBar,ui->DotLightprogressBar
  543. };
  544. if(isShow == true){
  545. for (QLineEdit* lineEdit : lineEdits) {
  546. lineEdit->show();
  547. }
  548. for (int i = 0; i < sliders.size(); ++i) {
  549. sliders[i]->show();
  550. }
  551. for (int i = 0; i < progressBar.size(); ++i) {
  552. progressBar[i]->show();
  553. }
  554. ui->BlueLight->show();
  555. ui->RedLight->show();
  556. ui->DotLight->show();
  557. ui->GreenLight->show();
  558. }else{
  559. for (QLineEdit* lineEdit : lineEdits) {
  560. lineEdit->hide();
  561. }
  562. for (int i = 0; i < sliders.size(); ++i) {
  563. sliders[i]->hide();
  564. }
  565. for (int i = 0; i < progressBar.size(); ++i) {
  566. progressBar[i]->hide();
  567. }
  568. ui->BlueLight->hide();
  569. ui->RedLight->hide();
  570. ui->DotLight->hide();
  571. ui->GreenLight->hide();
  572. }
  573. }