#include "ControlOperationPage.h" #include "ui_ControlOperationPage.h" ControlOperationPage::ControlOperationPage(QWidget *parent) : QWidget(parent) , ui(new Ui::ControlOperationPage) { ui->setupUi(this); } 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; }else{ } 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; }