#include "MainAndSecondaryCamerasWnd.h" #include "ui_MainAndSecondaryCamerasWnd.h" #include #include #include #include #include #include #include "CameraDistribute.h" #include "Src/common/JMessageTip.h" MainAndSecondaryCamerasWnd::MainAndSecondaryCamerasWnd(QWidget *parent) : JOriginalMainWnd(parent) , ui(new Ui::MainAndSecondaryCamerasWnd) { ui->setupUi(this); QSettings settings("YourOrganization", "YourApplication"); settings.beginGroup("LastSettings"); m_lastRightPixmap = settings.value("LastRightPixmap").value(); lasttextList = settings.value("LasttextList").toStringList(); lastLastRightPixmap = settings.value("LastLastRightPixmap").value(); lastLasttextList = settings.value("LastLasttextList").toStringList(); lastLastIndex = settings.value("LastLastIndex", 0).toInt(); lastLastGroupId = settings.value("LastLastGroupId", 0).toInt(); settings.endGroup(); ui->control_r->HideOrShowPage(false); ui->control_L->HideOrShowPage(false); //initFrom(); qApp->installEventFilter(this); } MainAndSecondaryCamerasWnd::~MainAndSecondaryCamerasWnd() { m_pMainCameraBind = nullptr; delete ui; } void MainAndSecondaryCamerasWnd::initFrom() { { // 界面刷新 InitPage(); //STR_TEMPLATE strFun = {}; //strFun.pView = ui->scrollArea; //strFun.veSignalFun.emplace_back(std::bind(&MainAndSecondaryCamerasWnd::UpdateCameraDisplay0, this, std::placeholders::_1, std::placeholders::_2)); //strFun.veSignalFun.emplace_back(std::bind(&MainAndSecondaryCamerasWnd::UpdateCameraDisplay1, this, std::placeholders::_1, std::placeholders::_2)); ////strFun.veSlotFun.emplace_back([this]() { CheckIs(); }); //strFun.veSlotFun.emplace_back(std::bind(&MainAndSecondaryCamerasWnd::CheckIs, this)); //InitAllCamerPage(strFun, this); //CameraImageHandlera A(this, strFun); //SwitchToConfigAAAAA(); } //ui->LeftOperatewidget->setMouseTracking(true); //ui->RightOperatewidget->setMouseTracking(true); QSettings settings2("YourOrganization", "YourApplication_lastWndType"); int lastWndType = settings2.value("LastWndType").toInt(); int LastGroup = settings2.value("LastGroup").toInt(); lastIndex = lastWndType; lastGroupId = LastGroup; QTimer* timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &MainAndSecondaryCamerasWnd::checkSettings); timer->start(100); } void MainAndSecondaryCamerasWnd::InitPage() { QWidget* viewport = ui->scrollArea->viewport(); QWidget* container = new QWidget(viewport); QHBoxLayout* mainLayout = new QHBoxLayout(container); mainLayout->setSpacing(28); mainLayout->setMargin(0); int nSize = 0; if (m_pMainCameraBind != nullptr) { nSize = m_pMainCameraBind->m_vecCamera.size(); if (nSize == 0) // 针对获取不到的情况 { nSize = 5; //JMessageTip::Message_warning("a"); } QList numbers; for (int i = 1; i <= nSize; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); ++i) { int num = numbers[i]; CameraImageHandler* manager = new CameraImageHandler(num); Group* widget = manager->getGroup(); CameraConnectUpdateImageFun(i, widget); if (widget != nullptr) { mainLayout->addWidget(widget); m_currentSelectGroup.liGroup.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 = -28; for (Group* w : m_currentSelectGroup.liGroup) { w->setMinimumHeight(minHeight); w->setMaximumWidth(maxWidth); num = num + 272; } container->setMinimumSize(num, 162); container->setLayout(mainLayout); ui->scrollArea->setWidget(container); ui->scrollArea->resize(1062, 177); // 只有一个相机的情况,直接绑定 if (numbers.size() == 1) { Group* pGroup = m_currentSelectGroup.liGroup[0]; connect(pGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0); ST_CURRENT_SELECT_GROUP _curr; _curr.isBond = true; _curr.pSelectGroup = pGroup; _curr.nCurrentCameraId = pGroup->m_nGroupId; _curr.nSelectLeft1 = 1; m_veCurrentSelectGroup.push_back(_curr); UpdataLightJoystickSwitchPage(pGroup); } } } void MainAndSecondaryCamerasWnd::CameraConnectUpdateImageFun(int nIndex, Group* widget) { auto BinCamerasImage = [&](void (MainAndSecondaryCamerasWnd::* pCamerasImage)(const QPixmap& imageData)) { //共用函数 //connect(widget, &Group::send_button_Signal, this, &MainAndSecondaryCamerasWnd::CheckIs); connect(widget, &Group::SetCurrentSelectSig, this, &MainAndSecondaryCamerasWnd::GetCurrentSelectSlots); // 相机图片 connect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots); }; if (nIndex == 0) { BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals0); } else if (nIndex == 1) { BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals1); } else if (nIndex == 2) { BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals2); } else if (nIndex == 3) { BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals3); } else if (nIndex == 4) { BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals4); } } void MainAndSecondaryCamerasWnd::checkSettings() { QSettings settings("YourCompany", "YourApplication_"); int groupId = settings.value("GroupId", 0).toInt(); int index = settings.value("Index", 0).toInt(); if (groupId != lastGroupId || index != lastIndex) { loadSettings(); lastGroupId = groupId; lastIndex = index; } } void MainAndSecondaryCamerasWnd::loadSettings() { QSettings settings("YourCompany", "YourApplication_"); int groupId = settings.value("GroupId", 0).toInt(); int index = settings.value("Index", 0).toInt(); //TODO: 这个地方目前暂停使用 UpdataGroupSettings(groupId, index); } void MainAndSecondaryCamerasWnd::UpdataGroupSettings(int Id, int Index) { //int Id = m_currentSelectGroup.nGroupId; //int Index = m_currentSelectGroup.nSelectLeft1; // isUpdatingSettings = true; 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(); QSettings Last_settings("YourOrganization", "YourApplication"); settings.beginGroup(QString::number(lastGroupId)); QString Last_imagePath1 = settings.value("ImagePath1").toString(); int Last_materialWndType = settings.value("MaterialWndType").toInt(); QStringList Last_textList = settings.value("TextList").toStringList(); settings.endGroup(); QString lastRightImage = settings.value("LastRightImage").toString(); QPixmap newPixmap; QPixmap Last_newPixmap; if (Index == 1) { newPixmap = QPixmap(imagePath); QStringList test = { "1","2" }; ui->viewwidgetgroup_R->updateOperateWidget(newPixmap, test); } if (lastIndex == 1) { Last_newPixmap = QPixmap(imagePath); QStringList test = { "1","2" }; ui->viewwidgetgroup_L->updateOperateWidget(Last_newPixmap, test); } else if (lastIndex == 2) { updateMaterialWidget(last_left,Last_materialWndType, lastGroupId); } if (Index == 2) { updateMaterialWidget(current_right,materialWndType, Id); } QSettings settings2("YourOrganization", "YourApplication_lastWndType"); settings2.setValue("LastWndType", lastIndex); settings2.setValue("LastGroup", lastGroupId); QPixmap scaledPixmap_right = newPixmap.scaled(ui->viewwidgetgroup_R->getOperatewidget()->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); if (isUpdatingSettings) { lastLastRightPixmap = m_lastRightPixmap; lastLasttextList = lasttextList; m_lastRightPixmap = scaledPixmap_right; lasttextList = textList; lastLastIndex = lastIndex; lastLastGroupId = lastGroupId; } } void MainAndSecondaryCamerasWnd::updateMaterialWidget(int side,int materialWndType, int groupId) { if (side == last_left) { switch (materialWndType) { case 1: ui->viewwidgetgroup_L->setWafer(waferMap.value(lastGroupId)); break; case 2: ui->viewwidgetgroup_L->setWaffle(waffleMap.value(lastGroupId)); break; case 3: ui->viewwidgetgroup_L->setMaterialBox(materialBoxMap.value(lastGroupId)); break; } } else if (side == current_right) { switch (materialWndType) { case 1: ui->viewwidgetgroup_R->setWafer(waferMap.value(lastGroupId)); break; case 2: ui->viewwidgetgroup_R->setWaffle(waffleMap.value(lastGroupId)); break; case 3: ui->viewwidgetgroup_R->setMaterialBox(materialBoxMap.value(lastGroupId)); break; } } } void MainAndSecondaryCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind) { m_pMainCameraBind = pCameraBind; initFrom(); m_nTimeShowPos = startTimer(600); ResetIdleTimer(true); } void MainAndSecondaryCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData) { // TODO: 这里需要改动 QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8); ui->viewwidgetgroup_L->getOperatewidget()->setGeometry(ui->viewwidgetgroup_L->getOperatewidget()->pos().x(), ui->viewwidgetgroup_L->getOperatewidget()->pos().y(), ui->viewwidgetgroup_L->getOperatewidget()->width(), ui->viewwidgetgroup_L->getOperatewidget()->height()); //ui->LeftOperatewidget->setPixmap(QPixmap::fromImage(image)); emit UpDataImageShowSignals0(QPixmap::fromImage(image)); } void MainAndSecondaryCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData) { QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8); ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(), ui->viewwidgetgroup_R->getOperatewidget()->pos().y(), ui->viewwidgetgroup_R->getOperatewidget()->width(), ui->viewwidgetgroup_R->getOperatewidget()->height()); //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image)); emit UpDataImageShowSignals1(QPixmap::fromImage(image)); } void MainAndSecondaryCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData) { } void MainAndSecondaryCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData) { } void MainAndSecondaryCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData) { QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8); ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(), ui->viewwidgetgroup_R->getOperatewidget()->pos().y(), ui->viewwidgetgroup_R->getOperatewidget()->width(), ui->viewwidgetgroup_R->getOperatewidget()->height()); //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image)); emit UpDataImageShowSignals4(QPixmap::fromImage(image)); } void MainAndSecondaryCamerasWnd::HideLayout(QHBoxLayout* layout, bool isHide) { for (int i = 0; i < layout->count(); ++i) { QWidget* widget = layout->itemAt(i)->widget(); if (widget) { if (isHide) { widget->hide(); } else { widget->show(); } } } } void MainAndSecondaryCamerasWnd::UpdataLightJoystickSwitchPage(Group* pGroup) { auto Fun = [&](LightJoystickSwitchPage* p, bool bShow) { p->UpdatemPageGroup(pGroup); p->InitMainCameraBind(m_pMainCameraBind, bShow); p->HideOrShowPage(bShow); }; for (int i = 0; i < m_veCurrentSelectGroup.size(); i++) { if (i == 0) { bool bShow = false; if (m_veCurrentSelectGroup[0].nSelectLeft1 == 1) { bShow = true; } Fun(ui->control_L, bShow); } else if (i == 1) { bool bShow = false; if (m_veCurrentSelectGroup[1].nSelectLeft1 == 1) { bShow = true; } Fun(ui->control_L, bShow); } } } void MainAndSecondaryCamerasWnd::timerEvent(QTimerEvent* event) { int nID = event->timerId(); } void MainAndSecondaryCamerasWnd::ResetIdleTimer(bool bStart /*= false*/) { if (bStart) { if (isActiveWindow()) { m_idleTimer = startTimer(3000); } } else { killTimer(m_idleTimer); m_idleTimer = -1; } } void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex) { if (m_pMainCameraBind == nullptr) { return; } // 绑定操作,用来初始化 ST_CURRENT_SELECT_GROUP _curr; _curr.isBond = true; m_currentSelectGroup.nGroupId = groupId; //2. 开始干活 int nOnClickGroupId = groupId - 1; // 这里new 有些是0,有些是1 暂时选择 if (m_pMainCameraBind->m_vecCamera.size() > nOnClickGroupId) { _curr.nCurrentCameraId = m_pMainCameraBind->m_vecCamera[nOnClickGroupId].iCameraId; } else { _curr.nCurrentCameraId = 0; } _curr.nSelectLeft1 = nIndex; // 是否选中窗口 Group* pGroup = m_currentSelectGroup.liGroup[nOnClickGroupId]; _curr.pSelectGroup = pGroup; // 1.判断当前是否存储 if (m_veCurrentSelectGroup.size() >= 2) { if (pGroup == m_veCurrentSelectGroup[1].pSelectGroup && m_veCurrentSelectGroup[1].nSelectLeft1== nIndex) { return; } // 解绑操作,删除第0个 ,, 主要目前为了实现 相机切换 disconnect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0); disconnect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4); disconnect(m_veCurrentSelectGroup[1].pSelectGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0); disconnect(m_veCurrentSelectGroup[1].pSelectGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4); m_veCurrentSelectGroup.erase(m_veCurrentSelectGroup.begin() + 0);// 0个 if (m_veCurrentSelectGroup[0].nSelectLeft1 == 1) { connect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0); // 在绑定 connect(pGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4); } else { // 直接复制图片? if (_curr.nSelectLeft1 == 1) { connect(m_veCurrentSelectGroup[0].pSelectGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4); } else { //loadGroupSettings(groupId, nIndex); } } m_veCurrentSelectGroup.push_back(_curr); UpdataLightJoystickSwitchPage(pGroup); } else { if (m_veCurrentSelectGroup[0].pSelectGroup != _curr.pSelectGroup) { if (m_veCurrentSelectGroup.size() == 1) { connect(pGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4); } else { connect(pGroup, &Group::SetUpDataImageShowSig, this, &MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0); } m_veCurrentSelectGroup.push_back(_curr); UpdataLightJoystickSwitchPage(pGroup); } } } void MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals0(const QPixmap& imageData) { //lastIndex = 1; QSize size_left = ui->viewwidgetgroup_L->getOperatewidget()->size(); QPixmap scaledPixmap_left = m_lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->viewwidgetgroup_L->getOperatewidget()->setPixmap(scaledPixmap_left); m_lastRightPixmap = imageData; //UpdataGroupSettings(imageData); } void MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals1(const QPixmap& imageData) { // lastIndex = 2; //UpdataGroupSettings(imageData); } void MainAndSecondaryCamerasWnd::GetUpDataImageShowSignals4(const QPixmap& imageData) { QSize size_left = ui->viewwidgetgroup_R->getOperatewidget()->size(); QPixmap scaledPixmap_left = imageData.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->viewwidgetgroup_R->getOperatewidget()->setPixmap(scaledPixmap_left); //m_lastRightPixmap = imageData; } void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent *event) { if (ui->viewwidgetgroup_L->getOperatewidget()->rect().contains(ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()))) { mousePos = ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()); if (event->angleDelta().y() > 0) { ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 1.1); // 放大 } else { ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 0.9); // 缩小 } } if (ui->viewwidgetgroup_R->getOperatewidget()->rect().contains(ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()))) { mousePos = ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()); if (event->angleDelta().y() > 0) { ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 1.1); // 放大 } else { ui->viewwidgetgroup_R->updateScale(Right_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); } bool MainAndSecondaryCamerasWnd::eventFilter(QObject* obj, QEvent* event) { // 检测用户活动事件 switch (event->type()) { case QEvent::KeyPress: case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::Wheel: ResetIdleTimer(); ResetIdleTimer(true); break; default: break; } return QMainWindow::eventFilter(obj, event); } void MainAndSecondaryCamerasWnd::showEvent(QShowEvent *event) { isUpdatingSettings = false; QMainWindow::showEvent(event); //loadSettings(); isUpdatingSettings = false; } void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent *event) { isUpdatingSettings = false; QMainWindow::hideEvent(event); } void MainAndSecondaryCamerasWnd::CheckIs() { /*QSettings settings("YourCompany", "YourApplication_Button"); int groupId = settings.value("GroupId_button", 0).toInt(); if (groupId == lastGroupId) { if (lastIndex == 1 ) { if(isShow == true){ isShow = false; } else { isShow = true; } } if (lastLastIndex == 1 && groupId == lastLastGroupId) { if(isShow_L == true){ isShow_L = false; } else { isShow_L = true; } } showAndHide(); showAndHide_L(); } else if (groupId == lastLastGroupId) { if (lastLastIndex == 1) { if(isShow_L == true){ isShow_L = false; } else { isShow_L = true; } } showAndHide_L(); }*/ }