123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- #include "ChartsAndCamerasWnd.h"
- #include "ui_ChartsAndCamerasWnd.h"
- #include <QSettings>
- #include <QCloseEvent>
- #include "Group.h"
- #include <QVBoxLayout>
- #include <QTimer>
- #include "chartline.h"
- #include <QRandomGenerator>
- #include <qDebug>
- ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::ChartsAndCamerasWnd),
- chartLine(new ChartLine(this)),
- chartLine1(new ChartLine(this)),
- chartLine2(new ChartLine(this))
- {
- ui->setupUi(this);
- // 设置 ChartLine 的位置和大小
- chartLine->setParent(ui->Leftwidget);
- chartLine->setGeometry(0, 0, 560, 280);
- chartLine->setChartLabels("Combined Placement", "Number of Samples", "Device Align");
- // 设置 ChartLine1 的位置和大小
- chartLine1->setParent(ui->Leftwidget);
- chartLine1->setGeometry(0, 245, 560, 280);
- chartLine1->setChartLabels("Y placement", "Number of samples", "Y device align");
- // 设置 ChartLine2 的位置和大小
- chartLine2->setParent(ui->Leftwidget);
- chartLine2->setGeometry(0, 490, 560, 280);
- chartLine2->setChartLabels("Theta placement", "Number of samples", "Theta device align");
- // 初始化系列信息
- initializeSeriesInfo();
- // 连接所有复选框的 clicked 信号到通用槽函数
- QList<QCheckBox*> checkBoxes = {
- ui->GreenDiamondcheckBox,
- ui->YellowDiamondcheckBox,
- ui->BlackDiamondcheckBox,
- ui->BlueDiamondcheckBox,
- ui->BlueHorizontalLinecheckBox,
- ui->BlueVerticalBarcheckBox,
- ui->GreenVerticalBarcheckBox,
- ui->PurpleVerticalBarcheckBox,
- ui->RedDiamondcheckBox,
- ui->RedHorizontalLinecheckBox,
- ui->WhiteVerticalBarcheckBox
- };
- for (QCheckBox* cb : checkBoxes) {
- cb->setCheckable(true);
- connect(cb, &QCheckBox::clicked, this, &ChartsAndCamerasWnd::on_CheckBox_clicked);
- }
- initFrom();
- }
- ChartsAndCamerasWnd::~ChartsAndCamerasWnd()
- {
- delete ui;
- }
- void ChartsAndCamerasWnd::initializeSeriesInfo()
- {
- // 初始化系列信息,使用 DataSeries 结构体
- m_seriesMap["GreenDiamond"] = DataSeries{
- "GreenDiamond",
- QColor("#00FF00"), // 绿色
- QPixmap(":/images/Participation display/GreenDiamond.png"),
- QList<QPointF>() // 初始为空
- };
- m_seriesMap["YellowDiamond"] = DataSeries{
- "YellowDiamond",
- QColor("#FFFF00"), // 黄色
- QPixmap(":/images/Participation display/YellowDiamond.png"),
- QList<QPointF>()
- };
- m_seriesMap["BlackDiamond"] = DataSeries{
- "BlackDiamond",
- QColor("#000000"), // 黑色
- QPixmap(":/images/Participation display/BlackDiamond.png"),
- QList<QPointF>()
- };
- m_seriesMap["BlueDiamond"] = DataSeries{
- "BlueDiamond",
- QColor("#0000FF"), // 蓝色
- QPixmap(":/images/Participation display/BlueDiamond.png"),
- QList<QPointF>()
- };
- m_seriesMap["BlueHorizontalLine"] = DataSeries{
- "BlueHorizontalLine",
- QColor("#0000FF"),
- QPixmap(":/images/Participation display/Blue_horizontal_line.png"),
- QList<QPointF>()
- };
- m_seriesMap["BlueVerticalBar"] = DataSeries{
- "BlueVerticalBar",
- QColor("#0000FF"),
- QPixmap(":/images/Participation display/Blue_vertical_bar.png"),
- QList<QPointF>()
- };
- m_seriesMap["GreenVerticalBar"] = DataSeries{
- "GreenVerticalBar",
- QColor("#00FF00"),
- QPixmap(":/images/Participation display/Green_vertical_bar.png"),
- QList<QPointF>()
- };
- m_seriesMap["PurpleVerticalBar"] = DataSeries{
- "PurpleVerticalBar",
- QColor("#800080"),
- QPixmap(":/images/Participation display/Purple_vertical_bar.png"),
- QList<QPointF>()
- };
- m_seriesMap["RedDiamond"] = DataSeries{
- "RedDiamond",
- QColor("#FF0000"), // 红色
- QPixmap(":/images/Participation display/RedDiamond.png"),
- QList<QPointF>()
- };
- m_seriesMap["RedHorizontalLine"] = DataSeries{
- "RedHorizontalLine",
- QColor("#FF0000"),
- QPixmap(":/images/Participation display/Red_horizontal_line.png"),
- QList<QPointF>()
- };
- m_seriesMap["WhiteVerticalBar"] = DataSeries{
- "WhiteVerticalBar",
- QColor("#FFFFFF"), // 白色
- QPixmap(":/images/Participation display/White_vertical_bar.png"),
- QList<QPointF>()
- };
- }
- void ChartsAndCamerasWnd::on_CheckBox_clicked()
- {
- // 获取发送信号的复选框
- QCheckBox* checkBox = qobject_cast<QCheckBox*>(sender());
- if (!checkBox)
- return;
- QString checkBoxName = checkBox->objectName();
- QString seriesName = checkBoxName;
- // 移除末尾的 "checkBox"
- if (seriesName.endsWith("checkBox")) {
- seriesName.chop(QString("checkBox").length());
- } else if (seriesName.endsWith("CheckBox")) {
- seriesName.chop(QString("CheckBox").length());
- }
- qDebug() << "Checkbox clicked:" << seriesName << (checkBox->isChecked() ? "Checked" : "Unchecked");
- if (!m_seriesMap.contains(seriesName)) {
- qDebug() << "No series info for:" << seriesName;
- return;
- }
- DataSeries &seriesInfo = m_seriesMap[seriesName];
- if (checkBox->isChecked()) {
- // 生成随机数据
- QList<QPointF> data;
- for (int i = 0; i <= 40; i += 4) {
- data.append(QPointF(i, QRandomGenerator::global()->bounded(-30, 80)));
- }
- seriesInfo.data = data;
- // 添加到 ChartLine 实例
- chartLine->addDataSeries(seriesInfo);
- chartLine1->addDataSeries(seriesInfo);
- chartLine2->addDataSeries(seriesInfo);
- qDebug() << "Added series:" << seriesName;
- }
- else {
- // 从 ChartLine 实例中移除
- chartLine->removeDataSeries(seriesName);
- chartLine1->removeDataSeries(seriesName);
- chartLine2->removeDataSeries(seriesName);
- qDebug() << "Removed series:" << seriesName;
- }
- }
- void ChartsAndCamerasWnd::initFrom() {
- QTimer *timer = new QTimer(this);
- connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::checkSettings);
- timer->start(100);
- ui->label_Percentage->setAlignment(Qt::AlignCenter);
- // 设置右下部分
- // loadSliderStates();
- initSliders();
- initLineEdits();
- connectSliderAndLineEdit(ui->verticalSlider, ui->lineEdit);
- connectSliderAndLineEdit(ui->verticalSlider_2, ui->lineEdit_2);
- connectSliderAndLineEdit(ui->verticalSlider_3, ui->lineEdit_3);
- connectSliderAndLineEdit(ui->verticalSlider_4, ui->lineEdit_4);
- connectSliderAndLineEdit(ui->verticalSlider_7, ui->lineEdit_7);
- connectSliderAndLineEdit(ui->verticalSlider_8, ui->lineEdit_8);
- QWidget *viewport = ui->scrollArea->viewport();
- QWidget *container = new QWidget(viewport);
- // 创建水平布局
- QHBoxLayout *mainLayout = new QHBoxLayout(container);
- // 创建两个垂直布局,分别用于左右两排
- QVBoxLayout *leftLayout = new QVBoxLayout();
- QVBoxLayout *rightLayout = new QVBoxLayout();
- leftLayout->setSpacing(16); // 设置Group之间的间隔距离
- leftLayout->setMargin(0);
- rightLayout->setSpacing(16); // 设置Group之间的间隔距离
- rightLayout->setMargin(0);
- // 添加控件到左侧布局
- QStringList dispmodel;
- dispmodel << "P die align" << "D device align";
- Group *widget = new Group(6, ":/images/test_image/image_1.png", ":/images/test_image/image_2.png", dispmodel, this);
- leftLayout->addWidget(widget);
- QStringList dispmodel1;
- dispmodel1 << "D device align" << "P die align";
- Group *widget_1 = new Group(7, ":/images/test_image/image_3.png", ":/images/test_image/image_4.png", dispmodel1, this);
- leftLayout->addWidget(widget_1);
- // 添加控件到右侧布局
- QStringList dispmodel2;
- dispmodel2 << "B device align" << "P die align";
- Group *widget_2 = new Group(8, ":/images/test_image/image_5.png", ":/images/test_image/image_6.png", dispmodel2, this);
- rightLayout->addWidget(widget_2);
- QStringList dispmodel3;
- dispmodel3 << "U die align" << "D device align";
- Group *widget_3 = new Group(9, ":/images/test_image/image_7.png", ":/images/test_image/image_8.png", dispmodel3, this);
- rightLayout->addWidget(widget_3);
- // 添加最后一个控件到左侧布局
- // Group *widget_4 = new Group(5, ":/images/test_image/image.png", ":/images/test_image/image_2.png", dispmodel, this);
- // leftLayout->addWidget(widget_4);
- // 设置控件的最小高度和最大宽度
- int minHeight = 162;
- int maxWidth = 244;
- QWidgetList widgets = {widget, widget_1, widget_2, widget_3, /*widget_4*/};
- for (QWidget *w : widgets) {
- w->setMinimumHeight(minHeight);
- w->setMaximumWidth(maxWidth);
- }
- mainLayout->addLayout(leftLayout);
- mainLayout->addSpacing(8);
- mainLayout->addLayout(rightLayout);
- mainLayout->setContentsMargins(0, 0, 0, 0);
- container->setLayout(mainLayout);
- ui->scrollArea->setWidget(container);
- ui->scrollArea->resize(521, 162);
- ui->Operatewidget->setMouseTracking(true);
- }
- void ChartsAndCamerasWnd::initSliders() {
- QList<QSlider*> sliders = {
- ui->verticalSlider, ui->verticalSlider_2, ui->verticalSlider_3,
- ui->verticalSlider_4, ui->verticalSlider_7, ui->verticalSlider_8
- };
- QList<int> initialValues = {11, 22, 9, 11, 0, 0};
- for (int i = 0; i < sliders.size(); ++i) {
- sliders[i]->setMinimum(0);
- sliders[i]->setMaximum(100);
- sliders[i]->setValue(initialValues[i]);
- }
- }
- void ChartsAndCamerasWnd::initLineEdits() {
- QList<QLineEdit*> lineEdits = {
- ui->lineEdit, ui->lineEdit_2, ui->lineEdit_3,
- ui->lineEdit_4, ui->lineEdit_7, ui->lineEdit_8
- };
- for (QLineEdit* lineEdit : lineEdits) {
- lineEdit->setAlignment(Qt::AlignCenter);
- }
- }
- void ChartsAndCamerasWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
- {
- QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
- lineEdit->setValidator(validator);
- connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
- lineEdit->setText(QString::number(value));
- });
- connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
- bool ok;
- int value = text.toInt(&ok);
- if (ok && value >= slider->minimum() && value <= slider->maximum()) {
- slider->setValue(value);
- } else if (!text.isEmpty()) {
- int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
- slider->setValue(closestValue);
- }
- });
- }
- void ChartsAndCamerasWnd::checkSettings() {
- QSettings settings("YourCompany", "YourApplication_");
- int groupId = settings.value("GroupId", 0).toInt();
- int index = settings.value("Index", 0).toInt();
- if (groupId != lastGroupId || index != lastIndex) {
- lastGroupId = groupId;
- lastIndex = index;
- loadSettings();
- }
- }
- void ChartsAndCamerasWnd::loadSettings()
- {
- QSettings settings("YourCompany", "YourApplication_");
- int groupId = settings.value("GroupId", 0).toInt();
- int index = settings.value("Index", 0).toInt();
- loadGroupSettings(groupId, index);
- }
- void ChartsAndCamerasWnd::loadGroupSettings(int Id, int Index) {
- QSettings settings("YourOrganization", "YourApplication");
- settings.beginGroup(QString::number(Id));
- QString imagePath1 = settings.value("ImagePath1").toString();
- QString imagePath2 = settings.value("ImagePath2").toString();
- QStringList textList = settings.value("TextList").toStringList();
- settings.endGroup();
- QSize size = ui->Operatewidget->size();
- QPixmap newPixmap;
- if (Index == 1) {
- newPixmap = QPixmap(imagePath1);
- } else if (Index == 2) {
- newPixmap = QPixmap(imagePath2);
- } else {
- newPixmap = QPixmap(":/images/test_image/image.png");
- }
- QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- ui->Operatewidget->setPixmap(scaledPixmap);
- // 更新当前图片的成员变量
- currentPixmap = scaledPixmap;
- scaleFactor = 1.0;
- ui->label_Percentage->setText("100%");
- ui->DatacomboBox->clear();
- ui->DatacomboBox->addItems(textList);
- // connect(ui->DatacomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Demo001_3::onComboBoxIndexChanged(int)));
- }
- void ChartsAndCamerasWnd::on_ZoomUpButton_clicked()
- {
- if (scaleFactor < 3.0) {
- scaleFactor *= 1.1;
- }
- int newWidth = currentPixmap.width() * scaleFactor;
- int newHeight = currentPixmap.height() * scaleFactor;
- QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- ui->Operatewidget->setPixmap(scaledImage);
- double percentage = scaleFactor * 100;
- QString percentageStr = QString::number((int)percentage);
- ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
- }
- void ChartsAndCamerasWnd::on_ZoomOutButton_clicked()
- {
- if (scaleFactor > 0.25) {
- scaleFactor *= 0.9;
- }
- int newWidth = currentPixmap.width() * scaleFactor;
- int newHeight = currentPixmap.height() * scaleFactor;
- QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- ui->Operatewidget->setPixmap(scaledImage);
- double percentage = scaleFactor * 100;
- QString percentageStr = QString::number((int)percentage);
- ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
- }
- void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event)
- {
- if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
- if (event->angleDelta().y() > 0) {
- if (scaleFactor < 3.0) {
- scaleFactor *= 1.1;
- }
- } else {
- if (scaleFactor > 0.25) {
- scaleFactor *= 0.9;
- }
- }
- int newWidth = currentPixmap.width() * scaleFactor;
- int newHeight = currentPixmap.height() * scaleFactor;
- QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- ui->Operatewidget->setPixmap(scaledImage);
- double percentage = scaleFactor * 100;
- QString percentageStr = QString::number((int)percentage);
- ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
- }
- QMainWindow::wheelEvent(event);
- }
- void ChartsAndCamerasWnd::showEvent(QShowEvent *event) {
- QMainWindow::showEvent(event);
- loadSettings();
- // initFrom();
- }
- void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) {
- QMainWindow::hideEvent(event);
- }
|