123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- #include "SingleCameraOperationWnd.h"
- #include "ui_SingleCameraOperationWnd.h"
- #include <QSettings>
- #include <QCloseEvent>
- #include <QVBoxLayout>
- #include <QDebug>
- #include <QTimer>
- #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
- SingleCameraOperationWnd::SingleCameraOperationWnd(QWidget *parent)
- : JOriginalMainWnd(parent)
- , ui(new Ui::SingleCameraOperationWnd), scaleFactor(1.0)
- {
- ui->setupUi(this);
- ui->viewwidgetgroup->resizeSingleUI();
- isShow = true;
- liveClick = true;
- initFrom();
- }
- SingleCameraOperationWnd::~SingleCameraOperationWnd()
- {
- delete ui;
- }
- void SingleCameraOperationWnd::initFrom() {
- QTimer *timer = new QTimer(this);
- connect(timer, &QTimer::timeout, this, &SingleCameraOperationWnd::checkSettings);
- timer->start(100);
- // 设置右上部分
- QWidget *viewport = ui->scrollArea->viewport();
- QWidget *container = new QWidget(viewport);
- QVBoxLayout *layout = new QVBoxLayout(container);
- layout->setSpacing(16); // 设置Group之间的间隔距离
- layout->setMargin(0);
- QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
- QList<Group*> 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,&SingleCameraOperationWnd::showAndHideButton);
- //connect(widget,&Group::send_ComboBox_singal,this,&SingleCameraOperationWnd::handleComBoxChange);
- if (widget != nullptr) {
- layout->addWidget(widget);
- widgets.append(widget);
- groupMap[num] = 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;
- for (Group* w : widgets) {
- w->setMinimumHeight(minHeight);
- w->setMaximumWidth(maxWidth);
- }
- container->setLayout(layout);
- ui->scrollArea->setWidget(container);
- ui->scrollArea->resize(261, 700);
- }
- void SingleCameraOperationWnd::closeEvent(QCloseEvent *event) {
- // 保存滑块状态
- // saveSliderStates();
- // 确保调用基类的 closeEvent 处理其他关闭逻辑
- QMainWindow::closeEvent(event);
- }
- void SingleCameraOperationWnd::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 SingleCameraOperationWnd::loadSettings()
- {
- QSettings settings("YourCompany", "YourApplication_");
- int groupId = settings.value("GroupId", 0).toInt();
- int index = settings.value("Index", 0).toInt();
- loadGroupSettings(groupId, index);
- }
- void SingleCameraOperationWnd::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 SingleCameraOperationWnd::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 SingleCameraOperationWnd::InitMainCameraBind(CameraBind* pCameraBind)
- {
- }
- void SingleCameraOperationWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
- {
- }
- void SingleCameraOperationWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
- {
- }
- void SingleCameraOperationWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
- {
- }
- void SingleCameraOperationWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
- {
- }
- void SingleCameraOperationWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
- {
- }
- void SingleCameraOperationWnd::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 SingleCameraOperationWnd::onComboBoxIndexChanged(int index) {
- // // 根据index获取图片路径
- // QString imagePath = getImagePathFromIndex(index);
- // if (!imagePath.isEmpty()) {
- // QPixmap newPixmap(imagePath);
- // QPixmap scaledPixmap = newPixmap.scaled(ui->viewwidgetgroup->getOperatewidget()->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
- // ui->viewwidgetgroup->getOperatewidget()->setPixmap(scaledPixmap);
- // // 更新当前图片的成员变量
- // currentPixmap = scaledPixmap;
- // scaleFactor = 1.0;
- // ui->viewwidgetgroup->label_Percentage->setText("100%");
- // }
- //}
- QString SingleCameraOperationWnd::getImagePathFromIndex(int index) {
- QStringList imagePaths = {
- ":/images/test_image/image.png",
- ":/images/test_image/image_2.png",
- };
- if (index >= 0 && index < imagePaths.size()) {
- return imagePaths[index];
- }
- return ":/images/test_image/image.png";
- }
- void SingleCameraOperationWnd::showEvent(QShowEvent *event) {
- QMainWindow::showEvent(event);
- loadSettings();
- }
- void SingleCameraOperationWnd::hideEvent(QHideEvent *event) {
- QMainWindow::hideEvent(event);
- }
- void SingleCameraOperationWnd::startCamera(int cameraId) {
- m_grabber = new ImageGrabber(cameraId);
- connect(m_grabber, &ImageGrabber::imageGrabbed,
- this, &SingleCameraOperationWnd::updateImage);
- m_grabber->start();
- }
- void SingleCameraOperationWnd::stopCamera(int cameraId){
- m_grabber->stop();
- }
- void SingleCameraOperationWnd::on_DatacomboBox_currentIndexChanged(int index){
- QSettings settings("YourCompany", "YourApplication_");
- int groupId = settings.value("GroupId", 0).toInt();
- if (groupMap.contains(groupId)) {
- Group* group = groupMap[groupId];
- // 修改属性
- group->setDatacomboBox(index);
- } else {
- qDebug() << "Group with id" << groupId << "not found.";
- }
- }
- //void SingleCameraOperationWnd::handleComBoxChange(int groupId,int index){
- // QSettings settings("YourCompany", "YourApplication_");
- // int currentGroupId = settings.value("GroupId", 0).toInt();
- // if(currentGroupId == groupId){
- // ui->viewwidgetgroup->DataSources->setCurrentIndex(index);
- // }
- //}
- void SingleCameraOperationWnd::updateImage(const QImage&image){
- QPixmap pixmap = QPixmap::fromImage(image);
- QSize size = ui->viewwidgetgroup->getOperatewidget()->size();
- // QPixmap scaledPixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- QPixmap scaledPixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- ui->viewwidgetgroup->getOperatewidget()->setPixmap(scaledPixmap);
- }
- void SingleCameraOperationWnd::loadLiveVedio(){
- if(liveClick == true){
- startCamera(0);
- liveClick = false;
- }else{
- stopCamera(0);
- liveClick = true;
- }
- }
|