#include "ControlOperationPage.h" #include "ui_ControlOperationPage.h" ControlOperationPage::ControlOperationPage(QWidget* parent) : QWidget(parent) , ui(new Ui::ControlOperationPage) { ui->setupUi(this); HideLayout(false); } ControlOperationPage::~ControlOperationPage() { delete ui; } void ControlOperationPage::updateOperateWidget(const QPixmap& pixmap, const QStringList& textList) { 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%"); ui->DataSources->clear(); ui->DataSources->addItems(textList); m_currentMode = ModeImage; } // 清除大窗口上当前的布局 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) { ui->Operatewidget->clearPixmap(); QVBoxLayout* layout = new QVBoxLayout(ui->Operatewidget); layout->setContentsMargins(0, 0, 0, 0); m_currentMode = ModeView; if (kind == wafer_kind) { m_wafer->initFrom(ui->Operatewidget); layout->addWidget(m_wafer->view); m_currentView = m_wafer->view; } else if (kind == waffle_kind) { m_waffle->initFrom(ui->Operatewidget); layout->addWidget(m_waffle->view); m_currentView = m_waffle->view; } else if (kind == materialbox_kind) { m_materialbox->initFrom(ui->Operatewidget); layout->addWidget(m_materialbox->view); m_currentView = m_materialbox->view; } 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() { { // 后面在做 //if (m_pMainCameraBind != nullptr) //{ // DeduplicationBox(ui->axisComboBox, m_pMainCameraBind->m_vecCAxis, 0); // DeduplicationBox(ui->axisTypeComboBox, m_pMainCameraBind->m_vecCAxis, 1); //} } connect(ui->Operatewidget, &ImageWidget::sendDoubleClicksignal, this, &ControlOperationPage::handleDoubleClick); ui->Operatewidget->setMouseTracking(true); } ImageWidget* ControlOperationPage::getOperatewidget() { return ui->Operatewidget; } void ControlOperationPage::resizeSingleUI() { 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(22, 882, 786, 32)); ui->horizontalLayout->setGeometry(QRect(22, 882, 786, 32)); ui->ZoomUpButton->setGeometry(QRect(25, 882, 138, 32)); ui->layoutWidget->setGeometry(QRect(22, 882, 800, 31)); ui->ZoomOutButton->setGeometry(QRect(163, 882, 112, 32)); ui->RulerButton->setGeometry(QRect(430, 882, 124, 32)); ui->PenButton->setGeometry(QRect(555, 882, 108, 32)); ui->label_Percentage->setGeometry(QRect(275, 882, 135, 32)); ui->BackGround->setGeometry(QRect(16, 68, 794, 794)); } void ControlOperationPage::resizeChartsAndCamerasUI() { } void ControlOperationPage::on_switchJoystickBut_clicked() { ResetIdleTimer(true); } void ControlOperationPage::timerEvent(QTimerEvent* event) { int nID = event->timerId(); if (nID == m_idleTimer) { ResetIdleTimer(false); } } 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); } 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); } } }