ChartsAndCamerasWnd.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #include "ChartsAndCamerasWnd.h"
  2. #include "ui_ChartsAndCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include "Group.h"
  6. #include <QVBoxLayout>
  7. #include <QTimer>
  8. #include "chartline.h"
  9. #include <QRandomGenerator>
  10. #include <qDebug>
  11. ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget *parent) :
  12. QMainWindow(parent),
  13. ui(new Ui::ChartsAndCamerasWnd),
  14. chartLine(new ChartLine(this)),
  15. chartLine1(new ChartLine(this)),
  16. chartLine2(new ChartLine(this))
  17. {
  18. ui->setupUi(this);
  19. // 设置 ChartLine 的位置和大小
  20. chartLine->setParent(ui->Leftwidget);
  21. chartLine->setGeometry(0, 0, 560, 280);
  22. chartLine->setChartLabels("Combined Placement", "Number of Samples", "Device Align");
  23. // 设置 ChartLine1 的位置和大小
  24. chartLine1->setParent(ui->Leftwidget);
  25. chartLine1->setGeometry(0, 245, 560, 280);
  26. chartLine1->setChartLabels("Y placement", "Number of samples", "Y device align");
  27. // 设置 ChartLine2 的位置和大小
  28. chartLine2->setParent(ui->Leftwidget);
  29. chartLine2->setGeometry(0, 490, 560, 280);
  30. chartLine2->setChartLabels("Theta placement", "Number of samples", "Theta device align");
  31. // 初始化系列信息
  32. initializeSeriesInfo();
  33. // 连接所有复选框的 clicked 信号到通用槽函数
  34. QList<QCheckBox*> checkBoxes = {
  35. ui->GreenDiamondcheckBox,
  36. ui->YellowDiamondcheckBox,
  37. ui->BlackDiamondcheckBox,
  38. ui->BlueDiamondcheckBox,
  39. ui->BlueHorizontalLinecheckBox,
  40. ui->BlueVerticalBarcheckBox,
  41. ui->GreenVerticalBarcheckBox,
  42. ui->PurpleVerticalBarcheckBox,
  43. ui->RedDiamondcheckBox,
  44. ui->RedHorizontalLinecheckBox,
  45. ui->WhiteVerticalBarcheckBox
  46. };
  47. for (QCheckBox* cb : checkBoxes) {
  48. cb->setCheckable(true);
  49. connect(cb, &QCheckBox::clicked, this, &ChartsAndCamerasWnd::on_CheckBox_clicked);
  50. }
  51. initFrom();
  52. }
  53. ChartsAndCamerasWnd::~ChartsAndCamerasWnd()
  54. {
  55. delete ui;
  56. }
  57. void ChartsAndCamerasWnd::initializeSeriesInfo()
  58. {
  59. // 初始化系列信息,使用 DataSeries 结构体
  60. m_seriesMap["GreenDiamond"] = DataSeries{
  61. "GreenDiamond",
  62. QColor("#00FF00"), // 绿色
  63. QPixmap(":/images/Participation display/GreenDiamond.png"),
  64. QList<QPointF>() // 初始为空
  65. };
  66. m_seriesMap["YellowDiamond"] = DataSeries{
  67. "YellowDiamond",
  68. QColor("#FFFF00"), // 黄色
  69. QPixmap(":/images/Participation display/YellowDiamond.png"),
  70. QList<QPointF>()
  71. };
  72. m_seriesMap["BlackDiamond"] = DataSeries{
  73. "BlackDiamond",
  74. QColor("#000000"), // 黑色
  75. QPixmap(":/images/Participation display/BlackDiamond.png"),
  76. QList<QPointF>()
  77. };
  78. m_seriesMap["BlueDiamond"] = DataSeries{
  79. "BlueDiamond",
  80. QColor("#0000FF"), // 蓝色
  81. QPixmap(":/images/Participation display/BlueDiamond.png"),
  82. QList<QPointF>()
  83. };
  84. m_seriesMap["BlueHorizontalLine"] = DataSeries{
  85. "BlueHorizontalLine",
  86. QColor("#0000FF"),
  87. QPixmap(":/images/Participation display/Blue_horizontal_line.png"),
  88. QList<QPointF>()
  89. };
  90. m_seriesMap["BlueVerticalBar"] = DataSeries{
  91. "BlueVerticalBar",
  92. QColor("#0000FF"),
  93. QPixmap(":/images/Participation display/Blue_vertical_bar.png"),
  94. QList<QPointF>()
  95. };
  96. m_seriesMap["GreenVerticalBar"] = DataSeries{
  97. "GreenVerticalBar",
  98. QColor("#00FF00"),
  99. QPixmap(":/images/Participation display/Green_vertical_bar.png"),
  100. QList<QPointF>()
  101. };
  102. m_seriesMap["PurpleVerticalBar"] = DataSeries{
  103. "PurpleVerticalBar",
  104. QColor("#800080"),
  105. QPixmap(":/images/Participation display/Purple_vertical_bar.png"),
  106. QList<QPointF>()
  107. };
  108. m_seriesMap["RedDiamond"] = DataSeries{
  109. "RedDiamond",
  110. QColor("#FF0000"), // 红色
  111. QPixmap(":/images/Participation display/RedDiamond.png"),
  112. QList<QPointF>()
  113. };
  114. m_seriesMap["RedHorizontalLine"] = DataSeries{
  115. "RedHorizontalLine",
  116. QColor("#FF0000"),
  117. QPixmap(":/images/Participation display/Red_horizontal_line.png"),
  118. QList<QPointF>()
  119. };
  120. m_seriesMap["WhiteVerticalBar"] = DataSeries{
  121. "WhiteVerticalBar",
  122. QColor("#FFFFFF"), // 白色
  123. QPixmap(":/images/Participation display/White_vertical_bar.png"),
  124. QList<QPointF>()
  125. };
  126. }
  127. void ChartsAndCamerasWnd::on_CheckBox_clicked()
  128. {
  129. // 获取发送信号的复选框
  130. QCheckBox* checkBox = qobject_cast<QCheckBox*>(sender());
  131. if (!checkBox)
  132. return;
  133. QString checkBoxName = checkBox->objectName();
  134. QString seriesName = checkBoxName;
  135. // 移除末尾的 "checkBox"
  136. if (seriesName.endsWith("checkBox")) {
  137. seriesName.chop(QString("checkBox").length());
  138. } else if (seriesName.endsWith("CheckBox")) {
  139. seriesName.chop(QString("CheckBox").length());
  140. }
  141. qDebug() << "Checkbox clicked:" << seriesName << (checkBox->isChecked() ? "Checked" : "Unchecked");
  142. if (!m_seriesMap.contains(seriesName)) {
  143. qDebug() << "No series info for:" << seriesName;
  144. return;
  145. }
  146. DataSeries &seriesInfo = m_seriesMap[seriesName];
  147. if (checkBox->isChecked()) {
  148. // 生成随机数据
  149. QList<QPointF> data;
  150. for (int i = 0; i <= 40; i += 4) {
  151. data.append(QPointF(i, QRandomGenerator::global()->bounded(-30, 80)));
  152. }
  153. seriesInfo.data = data;
  154. // 添加到 ChartLine 实例
  155. chartLine->addDataSeries(seriesInfo);
  156. chartLine1->addDataSeries(seriesInfo);
  157. chartLine2->addDataSeries(seriesInfo);
  158. qDebug() << "Added series:" << seriesName;
  159. }
  160. else {
  161. // 从 ChartLine 实例中移除
  162. chartLine->removeDataSeries(seriesName);
  163. chartLine1->removeDataSeries(seriesName);
  164. chartLine2->removeDataSeries(seriesName);
  165. qDebug() << "Removed series:" << seriesName;
  166. }
  167. }
  168. void ChartsAndCamerasWnd::initFrom() {
  169. QTimer *timer = new QTimer(this);
  170. connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::checkSettings);
  171. timer->start(100);
  172. ui->label_Percentage->setAlignment(Qt::AlignCenter);
  173. // 设置右下部分
  174. // loadSliderStates();
  175. initSliders();
  176. initLineEdits();
  177. connectSliderAndLineEdit(ui->verticalSlider, ui->lineEdit);
  178. connectSliderAndLineEdit(ui->verticalSlider_2, ui->lineEdit_2);
  179. connectSliderAndLineEdit(ui->verticalSlider_3, ui->lineEdit_3);
  180. connectSliderAndLineEdit(ui->verticalSlider_4, ui->lineEdit_4);
  181. connectSliderAndLineEdit(ui->verticalSlider_7, ui->lineEdit_7);
  182. connectSliderAndLineEdit(ui->verticalSlider_8, ui->lineEdit_8);
  183. QWidget *viewport = ui->scrollArea->viewport();
  184. QWidget *container = new QWidget(viewport);
  185. // 创建水平布局
  186. QHBoxLayout *mainLayout = new QHBoxLayout(container);
  187. // 创建两个垂直布局,分别用于左右两排
  188. QVBoxLayout *leftLayout = new QVBoxLayout();
  189. QVBoxLayout *rightLayout = new QVBoxLayout();
  190. leftLayout->setSpacing(16); // 设置Group之间的间隔距离
  191. leftLayout->setMargin(0);
  192. rightLayout->setSpacing(16); // 设置Group之间的间隔距离
  193. rightLayout->setMargin(0);
  194. // 添加控件到左侧布局
  195. QStringList dispmodel;
  196. dispmodel << "P die align" << "D device align";
  197. Group *widget = new Group(6, ":/images/test_image/image_1.png", ":/images/test_image/image_2.png", dispmodel, this);
  198. leftLayout->addWidget(widget);
  199. QStringList dispmodel1;
  200. dispmodel1 << "D device align" << "P die align";
  201. Group *widget_1 = new Group(7, ":/images/test_image/image_3.png", ":/images/test_image/image_4.png", dispmodel1, this);
  202. leftLayout->addWidget(widget_1);
  203. // 添加控件到右侧布局
  204. QStringList dispmodel2;
  205. dispmodel2 << "B device align" << "P die align";
  206. Group *widget_2 = new Group(8, ":/images/test_image/image_5.png", ":/images/test_image/image_6.png", dispmodel2, this);
  207. rightLayout->addWidget(widget_2);
  208. QStringList dispmodel3;
  209. dispmodel3 << "U die align" << "D device align";
  210. Group *widget_3 = new Group(9, ":/images/test_image/image_7.png", ":/images/test_image/image_8.png", dispmodel3, this);
  211. rightLayout->addWidget(widget_3);
  212. // 添加最后一个控件到左侧布局
  213. // Group *widget_4 = new Group(5, ":/images/test_image/image.png", ":/images/test_image/image_2.png", dispmodel, this);
  214. // leftLayout->addWidget(widget_4);
  215. // 设置控件的最小高度和最大宽度
  216. int minHeight = 162;
  217. int maxWidth = 244;
  218. QWidgetList widgets = {widget, widget_1, widget_2, widget_3, /*widget_4*/};
  219. for (QWidget *w : widgets) {
  220. w->setMinimumHeight(minHeight);
  221. w->setMaximumWidth(maxWidth);
  222. }
  223. mainLayout->addLayout(leftLayout);
  224. mainLayout->addSpacing(8);
  225. mainLayout->addLayout(rightLayout);
  226. mainLayout->setContentsMargins(0, 0, 0, 0);
  227. container->setLayout(mainLayout);
  228. ui->scrollArea->setWidget(container);
  229. ui->scrollArea->resize(521, 162);
  230. ui->Operatewidget->setMouseTracking(true);
  231. }
  232. void ChartsAndCamerasWnd::initSliders() {
  233. QList<QSlider*> sliders = {
  234. ui->verticalSlider, ui->verticalSlider_2, ui->verticalSlider_3,
  235. ui->verticalSlider_4, ui->verticalSlider_7, ui->verticalSlider_8
  236. };
  237. QList<int> initialValues = {11, 22, 9, 11, 0, 0};
  238. for (int i = 0; i < sliders.size(); ++i) {
  239. sliders[i]->setMinimum(0);
  240. sliders[i]->setMaximum(100);
  241. sliders[i]->setValue(initialValues[i]);
  242. }
  243. }
  244. void ChartsAndCamerasWnd::initLineEdits() {
  245. QList<QLineEdit*> lineEdits = {
  246. ui->lineEdit, ui->lineEdit_2, ui->lineEdit_3,
  247. ui->lineEdit_4, ui->lineEdit_7, ui->lineEdit_8
  248. };
  249. for (QLineEdit* lineEdit : lineEdits) {
  250. lineEdit->setAlignment(Qt::AlignCenter);
  251. }
  252. }
  253. void ChartsAndCamerasWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
  254. {
  255. QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
  256. lineEdit->setValidator(validator);
  257. connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
  258. lineEdit->setText(QString::number(value));
  259. });
  260. connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
  261. bool ok;
  262. int value = text.toInt(&ok);
  263. if (ok && value >= slider->minimum() && value <= slider->maximum()) {
  264. slider->setValue(value);
  265. } else if (!text.isEmpty()) {
  266. int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
  267. slider->setValue(closestValue);
  268. }
  269. });
  270. }
  271. void ChartsAndCamerasWnd::checkSettings() {
  272. QSettings settings("YourCompany", "YourApplication_");
  273. int groupId = settings.value("GroupId", 0).toInt();
  274. int index = settings.value("Index", 0).toInt();
  275. if (groupId != lastGroupId || index != lastIndex) {
  276. lastGroupId = groupId;
  277. lastIndex = index;
  278. loadSettings();
  279. }
  280. }
  281. void ChartsAndCamerasWnd::loadSettings()
  282. {
  283. QSettings settings("YourCompany", "YourApplication_");
  284. int groupId = settings.value("GroupId", 0).toInt();
  285. int index = settings.value("Index", 0).toInt();
  286. loadGroupSettings(groupId, index);
  287. }
  288. void ChartsAndCamerasWnd::loadGroupSettings(int Id, int Index) {
  289. QSettings settings("YourOrganization", "YourApplication");
  290. settings.beginGroup(QString::number(Id));
  291. QString imagePath1 = settings.value("ImagePath1").toString();
  292. QString imagePath2 = settings.value("ImagePath2").toString();
  293. QStringList textList = settings.value("TextList").toStringList();
  294. settings.endGroup();
  295. QSize size = ui->Operatewidget->size();
  296. QPixmap newPixmap;
  297. if (Index == 1) {
  298. newPixmap = QPixmap(imagePath1);
  299. } else if (Index == 2) {
  300. newPixmap = QPixmap(imagePath2);
  301. } else {
  302. newPixmap = QPixmap(":/images/test_image/image.png");
  303. }
  304. QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  305. ui->Operatewidget->setPixmap(scaledPixmap);
  306. // 更新当前图片的成员变量
  307. currentPixmap = scaledPixmap;
  308. scaleFactor = 1.0;
  309. ui->label_Percentage->setText("100%");
  310. ui->DatacomboBox->clear();
  311. ui->DatacomboBox->addItems(textList);
  312. // connect(ui->DatacomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Demo001_3::onComboBoxIndexChanged(int)));
  313. }
  314. void ChartsAndCamerasWnd::on_ZoomUpButton_clicked()
  315. {
  316. if (scaleFactor < 3.0) {
  317. scaleFactor *= 1.1;
  318. }
  319. int newWidth = currentPixmap.width() * scaleFactor;
  320. int newHeight = currentPixmap.height() * scaleFactor;
  321. QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  322. ui->Operatewidget->setPixmap(scaledImage);
  323. double percentage = scaleFactor * 100;
  324. QString percentageStr = QString::number((int)percentage);
  325. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  326. }
  327. void ChartsAndCamerasWnd::on_ZoomOutButton_clicked()
  328. {
  329. if (scaleFactor > 0.25) {
  330. scaleFactor *= 0.9;
  331. }
  332. int newWidth = currentPixmap.width() * scaleFactor;
  333. int newHeight = currentPixmap.height() * scaleFactor;
  334. QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  335. ui->Operatewidget->setPixmap(scaledImage);
  336. double percentage = scaleFactor * 100;
  337. QString percentageStr = QString::number((int)percentage);
  338. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  339. }
  340. void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event)
  341. {
  342. if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
  343. if (event->angleDelta().y() > 0) {
  344. if (scaleFactor < 3.0) {
  345. scaleFactor *= 1.1;
  346. }
  347. } else {
  348. if (scaleFactor > 0.25) {
  349. scaleFactor *= 0.9;
  350. }
  351. }
  352. int newWidth = currentPixmap.width() * scaleFactor;
  353. int newHeight = currentPixmap.height() * scaleFactor;
  354. QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  355. ui->Operatewidget->setPixmap(scaledImage);
  356. double percentage = scaleFactor * 100;
  357. QString percentageStr = QString::number((int)percentage);
  358. ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
  359. }
  360. QMainWindow::wheelEvent(event);
  361. }
  362. void ChartsAndCamerasWnd::showEvent(QShowEvent *event) {
  363. QMainWindow::showEvent(event);
  364. loadSettings();
  365. // initFrom();
  366. }
  367. void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) {
  368. QMainWindow::hideEvent(event);
  369. }