#include "ChartsAndCamerasWnd.h" #include "ui_ChartsAndCamerasWnd.h" #include #include #include #include #include "chartline.h" #include #include #include #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h" ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget *parent) : JOriginalMainWnd(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 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(); isShow = true; } ChartsAndCamerasWnd::~ChartsAndCamerasWnd() { m_pMainCameraBind = nullptr; delete ui; } void ChartsAndCamerasWnd::initializeSeriesInfo() { // 初始化系列信息,使用 DataSeries 结构体 m_seriesMap["GreenDiamond"] = DataSeries{ "GreenDiamond", QColor("#00FF00"), // 绿色 QPixmap(":/images/Participation display/GreenDiamond.png"), QList() // 初始为空 }; m_seriesMap["YellowDiamond"] = DataSeries{ "YellowDiamond", QColor("#FFFF00"), // 黄色 QPixmap(":/images/Participation display/YellowDiamond.png"), QList() }; m_seriesMap["BlackDiamond"] = DataSeries{ "BlackDiamond", QColor("#000000"), // 黑色 QPixmap(":/images/Participation display/BlackDiamond.png"), QList() }; m_seriesMap["BlueDiamond"] = DataSeries{ "BlueDiamond", QColor("#0000FF"), // 蓝色 QPixmap(":/images/Participation display/BlueDiamond.png"), QList() }; m_seriesMap["BlueHorizontalLine"] = DataSeries{ "BlueHorizontalLine", QColor("#0000FF"), QPixmap(":/images/Participation display/Blue_horizontal_line.png"), QList() }; m_seriesMap["BlueVerticalBar"] = DataSeries{ "BlueVerticalBar", QColor("#0000FF"), QPixmap(":/images/Participation display/Blue_vertical_bar.png"), QList() }; m_seriesMap["GreenVerticalBar"] = DataSeries{ "GreenVerticalBar", QColor("#00FF00"), QPixmap(":/images/Participation display/Green_vertical_bar.png"), QList() }; m_seriesMap["PurpleVerticalBar"] = DataSeries{ "PurpleVerticalBar", QColor("#800080"), QPixmap(":/images/Participation display/Purple_vertical_bar.png"), QList() }; m_seriesMap["RedDiamond"] = DataSeries{ "RedDiamond", QColor("#FF0000"), // 红色 QPixmap(":/images/Participation display/RedDiamond.png"), QList() }; m_seriesMap["RedHorizontalLine"] = DataSeries{ "RedHorizontalLine", QColor("#FF0000"), QPixmap(":/images/Participation display/Red_horizontal_line.png"), QList() }; m_seriesMap["WhiteVerticalBar"] = DataSeries{ "WhiteVerticalBar", QColor("#FFFFFF"), // 白色 QPixmap(":/images/Participation display/White_vertical_bar.png"), QList() }; } #if 0 void ChartsAndCamerasWnd::on_CheckBox_clicked() { // 获取发送信号的复选框 QCheckBox* checkBox = qobject_cast(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 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; } } #endif void ChartsAndCamerasWnd::initFrom() { QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::checkSettings); timer->start(100); QWidget *viewport = ui->scrollArea->viewport(); QWidget *container = new QWidget(viewport); QHBoxLayout *layout = new QHBoxLayout(container); layout->setSpacing(16); // 设置Group之间的间隔距离 layout->setMargin(0); QList numbers = {1, 2, 3, 4, 5, 6, 7, 8}; QList widgets; for (int i = 0; i < numbers.size(); ++i) { int num = numbers[i]; CameraImageHandler* manager = new CameraImageHandler(num); Group* widget = manager->getGroup(); //connect(widget,&Group::send_button_Signal,this,&ChartsAndCamerasWnd::showAndHide); if (widget != nullptr) { layout->addWidget(widget); widgets.append(widget); } if(manager->getWafer()) { waferMap.insert(num, manager->getWafer()); } if(manager->getWafer()) { waffleMap.insert(num, manager->getWaffle()); } if(manager->getMaterialBox()) { materialBoxMap.insert(num,manager->getMaterialBox()); } delete manager; } // 设置控件的最小高度和最大宽度 int minHeight = 162; int maxWidth = 244; int num = -16; for (Group* w : widgets) { w->setMinimumHeight(minHeight); w->setMaximumWidth(maxWidth); num = num + 260; } container->setMinimumSize(num, 162); container->setLayout(layout); ui->scrollArea->setWidget(container); ui->scrollArea->resize(508, 177); } 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 imagePath = settings.value("ImagePath1").toString(); int materialWndType = settings.value("MaterialWndType").toInt(); QStringList textList = settings.value("TextList").toStringList(); settings.endGroup(); QPixmap newPixmap; // 判断是实时图片还是物料窗口 if (Index == 1) { newPixmap = QPixmap(imagePath); QStringList test = { "1","2" }; ui->viewwidgetgroup->updateOperateWidget(newPixmap, test); }else if (Index == 2) { updateMaterialWidget(materialWndType, Id); } } void ChartsAndCamerasWnd::updateMaterialWidget( int materialWndType, int groupId){ switch (materialWndType) { case 1: ui->viewwidgetgroup->setWafer(waferMap.value(lastGroupId)); break; case 2: ui->viewwidgetgroup->setWaffle(waffleMap.value(lastGroupId)); break; case 3: ui->viewwidgetgroup->setMaterialBox(materialBoxMap.value(lastGroupId)); break; } } void ChartsAndCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind) { m_pMainCameraBind = pCameraBind; initFrom(); } void ChartsAndCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData) { } void ChartsAndCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData) { } void ChartsAndCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData) { } void ChartsAndCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData) { } void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData) { } //void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData) //{ // //} void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event) { mousePos = ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos()); if (ui->viewwidgetgroup->getOperatewidget()->rect().contains(ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos()))) { if (event->angleDelta().y() > 0) { ui->viewwidgetgroup->updateScale(scaleFactor * 1.1); // 放大 } else { ui->viewwidgetgroup->updateScale(scaleFactor * 0.9); // 缩小 } } if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) { // 获取 QScrollArea 的横向滚动条 QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar(); // 根据滚轮滚动方向改变滚动条的值 if (event->angleDelta().y() > 0) { scrollBar->setValue(scrollBar->value() - 50); } else { scrollBar->setValue(scrollBar->value() + 50); } } QMainWindow::wheelEvent(event); } void ChartsAndCamerasWnd::showEvent(QShowEvent *event) { QMainWindow::showEvent(event); loadSettings(); // initFrom(); } void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) { QMainWindow::hideEvent(event); }