#include "ControlOperationPage.h" #include "ui_ControlOperationPage.h" ControlOperationPage::ControlOperationPage(QWidget* parent) : QWidget(parent) , ui(new Ui::ControlOperationPage) { ui->setupUi(this); InitWnd(); } ControlOperationPage::~ControlOperationPage() { delete ui; } void ControlOperationPage::updateOperateWidget(const QPixmap& pixmap) { QSize size = ui->Operatewidget->size(); QPixmap scaledPixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); clearLayout(); ui->Operatewidget->setPixmap(scaledPixmap); m_currentPixmap = scaledPixmap; m_scaleFactor = 1.0; m_previousScaleFactor = 1.0; ui->label_Percentage->setText("100%"); m_currentMode = ModeImage; } void ControlOperationPage::setDataSources(const QStringList& textList) { ui->DataSources->clear(); ui->DataSources->addItems(textList); } // 清除大窗口上当前的布局 void ControlOperationPage::clearLayout() { // 获取当前布局 QLayout* layout = ui->Operatewidget->layout(); if (layout) { QLayoutItem* child; while ((child = layout->takeAt(0)) != nullptr) { if (child->widget() != nullptr) { delete child->widget(); // 删除控件 } delete child; // 删除布局项 } delete layout; // 删除布局本身 } } void ControlOperationPage::on_ZoomUpButton_clicked() { m_mousePos = ui->Operatewidget->geometry().center(); updateScale(m_scaleFactor * 1.1); } void ControlOperationPage::on_ZoomOutButton_clicked() { m_mousePos = ui->Operatewidget->geometry().center(); updateScale(m_scaleFactor * 0.9); } // 更新缩放比例 void ControlOperationPage::updateScale(double newScaleFactor) { if (newScaleFactor >= 1.0) { m_scaleFactor = newScaleFactor; } else { m_scaleFactor = 1.0; // 最小缩放比例为 1.0 } applyScale(); // 应用缩放 } // 应用缩放 void ControlOperationPage::applyScale() { if (m_currentMode == ModeImage) { // 图片模式:缩放图片 int newWidth = m_currentPixmap.width() * m_scaleFactor; int newHeight = m_currentPixmap.height() * m_scaleFactor; QPixmap scaledImage = m_currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->Operatewidget->setPixmapAndPoint(scaledImage, m_previousScaleFactor, m_scaleFactor, m_mousePos); m_previousScaleFactor = m_scaleFactor; } else if (m_currentMode == ModeView && m_currentView) { // View 模式:缩放 view QTransform transform; transform.scale(m_scaleFactor, m_scaleFactor); m_currentView->setTransform(transform); } // 更新百分比显示 double percentage = m_scaleFactor * 100; QString percentageStr = QString::number((int)percentage); ui->label_Percentage->setText(QString("%1%").arg(percentageStr)); } void ControlOperationPage::handleDoubleClick() { if (m_currentMode == ModeImage) { QPixmap scaledImage = m_currentPixmap.scaled(m_currentPixmap.width(), m_currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->Operatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片 } else if (m_currentMode == ModeView && m_currentView) { QTransform transform; transform.scale(1, 1); m_currentView->setTransform(transform); } m_scaleFactor = 1.0; m_previousScaleFactor = 1.0; ui->label_Percentage->setText("100%"); } void ControlOperationPage::updateMaterialWidget(kinds materialWndType) { clearLayout(); switch (materialWndType) { case wafer_kind: KindsofWidget(wafer_kind); break; case waffle_kind: KindsofWidget(waffle_kind); break; case materialbox_kind: KindsofWidget(materialbox_kind); break; case bond_kind:KindsofWidget(bond_kind); break; } } void ControlOperationPage::KindsofWidget(kinds kind) { bool isRun = false; ui->Operatewidget->clearPixmap(); QVBoxLayout* layout = new QVBoxLayout(ui->Operatewidget); layout->setContentsMargins(0, 0, 0, 0); m_currentMode = ModeView; if (kind == wafer_kind) { if (m_wafer) { isRun = true; m_wafer->initFrom(ui->Operatewidget); layout->addWidget(m_wafer->view); m_currentView = m_wafer->view; } } else if (kind == waffle_kind) { if (m_waffle) { isRun = true; m_waffle->initFrom(ui->Operatewidget); layout->addWidget(m_waffle->view); m_currentView = m_waffle->view; } } else if (kind == materialbox_kind) { if (m_materialbox) { isRun = true; m_materialbox->initFrom(ui->Operatewidget); layout->addWidget(m_materialbox->view); m_currentView = m_materialbox->view; } } if (isRun) { ui->Operatewidget->setLayout(layout); m_currentMode = ModeView; m_scaleFactor = 1.0; applyScale(); } } void ControlOperationPage::setWafer(Wafer* wafer) { m_wafer = wafer; updateMaterialWidget(wafer_kind); } void ControlOperationPage::setWaffle(Waffle* waffle) { m_waffle = waffle; updateMaterialWidget(waffle_kind); } void ControlOperationPage::setMaterialBox(MaterialBox* materialbox) { m_materialbox = materialbox; updateMaterialWidget(materialbox_kind); } //void ControlOperationPage::setBond(Bond *bond){ // m_bond = bond; //} void ControlOperationPage::initForm() { connect(ui->Operatewidget, &ImageWidget::sendDoubleClicksignal, this, &ControlOperationPage::handleDoubleClick); ui->Operatewidget->setMouseTracking(true); } ImageWidget* ControlOperationPage::getOperatewidget() { return ui->Operatewidget; } void ControlOperationPage::resizeSingleUI(bool bMax /*= false*/) { ui->DataSources->setGeometry(QRect(20, 20, 400, 32)); ui->Operatewidget->setGeometry(QRect(5, 5, 786, 786)); //ui->line_2->setGeometry(QRect(826, 20, 1, 953)); ui->LiveButton->setGeometry(QRect(436, 20, 60, 32)); ui->horizontalLayout_2->setGeometry(QRect(12, 882, 786, 32)); ui->layoutWidget->setGeometry(QRect(10, 882, 790, 31)); ui->ZoomUpButton->setGeometry(QRect(25, 882, 120, 32)); ui->ZoomOutButton->setGeometry(QRect(155, 882, 100, 32)); ui->label_Percentage->setGeometry(QRect(265, 882, 120, 32)); ui->RulerButton->setGeometry(QRect(400, 882, 110, 32)); ui->PenButton->setGeometry(QRect(530, 882, 100, 32)); // ui->switchJoystickBut ui->horizontalLayout->setGeometry(QRect(12, 882, 786, 32)); ui->BackGround->setGeometry(QRect(16, 68, 794, 794)); if (bMax) { ui->Operatewidget->m_nSingleCameraOperationWnd = true; } } void ControlOperationPage::resizeChartsAndCamerasUI() { } void ControlOperationPage::UpDateCameraBind(CameraBind* pCameraBind) { m_pCameraBindCopy = pCameraBind; // 有指针了在去刷新 // if (m_pCameraBindCopy != nullptr) // { // DeduplicationBox(ui->moduleTypeComboBox, m_pCameraBindCopy->m_vecCAxis, 0); // DeduplicationBox(ui->axisTypeComboBox, m_pCameraBindCopy->m_vecCAxis, 1); // } } void ControlOperationPage::on_switchJoystickBut_clicked() { m_isUserOnclick = true; ResetIdleTimer(true); } void ControlOperationPage::MouseMovedSlots(const QPoint& delta) { qDebug() << "MouseMovedSlots:" << delta; if (m_pCameraBindCopy) { m_pCameraBindCopy->JCameraMove(0, delta.x(), delta.y()); } } void ControlOperationPage::RequestCursorMoveSlots(const QPoint& pos) { QCursor::setPos(pos); } void ControlOperationPage::timerEvent(QTimerEvent* event) { int nID = event->timerId(); if (nID == m_idleTimer) { ResetIdleTimer(false); m_isUserOnclick = false; } } void ControlOperationPage::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) { LockMouse(true); } else if (event->button() == Qt::RightButton) { LockMouse(false); } } void ControlOperationPage::mouseMoveEvent(QMouseEvent* event) { int a = 10; } bool ControlOperationPage::eventFilter(QObject* obj, QEvent* event) { switch (event->type()) { case QEvent::KeyPress: case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::Wheel: { if (m_isUserOnclick) { ResetIdleTimer(false); ResetIdleTimer(true); } } break; default: break; } return QWidget::eventFilter(obj, event); } void ControlOperationPage::HideLayout(bool bShow) { for (int i = 0; i < ui->horizontalLayout->count(); ++i) { QWidget* widget = ui->horizontalLayout->itemAt(i)->widget(); if (widget) { if (bShow) { widget->show(); } else { widget->hide(); } } } } void ControlOperationPage::ResetIdleTimer(bool bStart /*= false*/) { if (bStart) { if (isActiveWindow()) { m_idleTimer = startTimer(3000); } } else { killTimer(m_idleTimer); m_idleTimer = -1; } HideLayout(bStart); } void ControlOperationPage::InitWnd() { HideLayout(false); this->setMouseTracking(true); this->installEventFilter(this); } void ControlOperationPage::CreateMouseMonitor(bool isStart) { if (isStart) { m_pMousethread = new JMouseMonitorThread(this); connect(m_pMousethread, &JMouseMonitorThread::MouseMovedSlg, this, &ControlOperationPage::MouseMovedSlots); connect(m_pMousethread, &JMouseMonitorThread::RequestCursorMoveSlg, this, &ControlOperationPage::RequestCursorMoveSlots); m_pMousethread->start(); } else { m_pMousethread->stop(); m_pMousethread->wait(); delete m_pMousethread; m_pMousethread = nullptr; } } void ControlOperationPage::LockMouse(bool islockMouse) { if (m_pCameraBindCopy) { if (islockMouse) { if (!m_bMouseRun) { CreateMouseMonitor(true); QPoint center = rect().center(); QPoint globalCenter = mapToGlobal(center); m_pMousethread->setLockCenter(globalCenter); QCursor::setPos(globalCenter); setCursor(Qt::BlankCursor); grabMouse(); m_bMouseRun = true; } } else { if (m_bMouseRun) { if (m_pMousethread) { m_pMousethread->unlock(); releaseMouse(); unsetCursor(); QCursor::setPos(mapToGlobal(rect().center())); CreateMouseMonitor(false); } m_bMouseRun = false; } } } } template void ControlOperationPage::DeduplicationBox(QComboBox* pCom, const T& veTemp, int nIndex) { QStringList items; for (int i = 0; i < pCom->count(); ++i) { items << pCom->itemText(i); } for (auto& a : veTemp) { QString strName; if (nIndex == 0) { strName = a->GetModuleType().c_str(); } else if (nIndex == 1) { strName = a->GetStringAxisType().c_str(); } bool bMa = false; // 是否匹配 for (auto b : items) { if (b == strName) { bMa = true; break; } } if (!bMa) { pCom->addItem(strName); } } } void ControlOperationPage::setEnableControls(bool enable) { ui->LiveButton->setEnabled(enable); ui->DataSources->setEnabled(enable); if (enable == true) { ui->LiveButton->setStyleSheet( "QPushButton:hover {" " background-color: #45a049;" "}" "QPushButton:pressed {" " background-color: #3e8e41;" "}" ); } else { ui->LiveButton->setStyleSheet("background-color: lightgray;"); } }