123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- #include "ControlOperationPage.h"
- #include "ui_ControlOperationPage.h"
- #include "JoystickPage.h"
- ControlOperationPage::ControlOperationPage(QWidget* parent)
- : QWidget(parent)
- , ui(new Ui::ControlOperationPage)
- {
- ui->setupUi(this);
- m_isEnable = false;
- InitWnd();
- initForm();
- }
- 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();
- ImageView* customView = new ImageView(ui->Operatewidget);
- customView->setPixmap(scaledPixmap);
- QVBoxLayout* layout = new QVBoxLayout(ui->Operatewidget);
- layout->setContentsMargins(0, 0, 0, 0);
- layout->addWidget(customView);
- ui->Operatewidget->setLayout(layout);
-
- m_currentPixmap = scaledPixmap;
- m_scaleFactor = 1.0;
- m_previousScaleFactor = 1.0;
- ui->label_Percentage->setText("100%");
- //m_currentMode = ModeImage;
- m_currentImageView = customView;
- applyScale();
- }
- 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 && m_currentImageView)
- {
- // 图片模式:缩放图片
- QTransform transform;
- transform.scale(m_scaleFactor, m_scaleFactor);
- m_currentImageView->setTransform(transform);
- }
- 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 && m_currentImageView)
- {
- QTransform transform;
- transform.scale(1, 1);
- m_currentImageView->setTransform(transform);
- }
- 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;
- }
-
- }
- else if (kind == bond_kind)
- {
- if (m_bond)
- {
- isRun = true;
- m_bond->initFrom(ui->Operatewidget);
- layout->addWidget(m_bond->view);
- m_currentView = m_bond->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;
- updateMaterialWidget(bond_kind);
- }
- 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(20, 72, 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() {
- }
- qreal ControlOperationPage::getScaleFactorValue() {
- return m_scaleFactor;
- }
- void ControlOperationPage::setScaleFactorSize(QPixmap scaledImage) {
- //int newWidth = scaledImage.width() * m_scaleFactor;
- //int newHeight = scaledImage.height() * m_scaleFactor;
- //QPixmap curr_scaledImage = scaledImage.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- // ui->Operatewidget->setPixmapAndPoint(curr_scaledImage, m_previousScaleFactor, m_scaleFactor, m_mousePos);
- // ui->Operatewidget->setPixmap(curr_scaledImage);
- if (m_currentImageView == nullptr) {
- updateOperateWidget(scaledImage);
- }
- else
- {
- QSize size = ui->Operatewidget->size();
- QPixmap scaledPixmap = scaledImage.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- m_currentImageView->setCurPixmap(scaledPixmap);
- }
- }
- void ControlOperationPage::UpDateCameraBind(CameraBind* pCameraBind)
- {
- m_pCameraBindCopy = pCameraBind;
- m_isAdd = true;
- // 有指针了在去刷新
- if (m_pCameraBindCopy != nullptr)
- {
- DeduplicationBox(ui->moduleTypeComboBox, m_pCameraBindCopy->m_vecCAxis, 0);
- DeduplicationBox(ui->axisTypeComboBox, m_pCameraBindCopy->m_vecCAxis, 1);
- }
- m_isAdd = false;
- setSwitchJoystickButEnable(true);
- }
- void ControlOperationPage::setSwitchJoystickButEnable(bool isEnable)
- {
- ui->switchJoystickBut->setEnabled(isEnable);
- if (isEnable == false)
- {
- ResetIdleTimer(false);
- m_isUserOnclick = false;
- }
- }
- void ControlOperationPage::on_switchJoystickBut_clicked()
- {
- m_isUserOnclick = true;
- ResetIdleTimer(true);
- UpdataModuleType("aaa", 3);
- ui->switchJoystickBut->setEnabled(false);
- }
- 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::on_moduleTypeComboBox_currentIndexChanged(int index)
- {
- m_isAdd = true;
- QString strMod = ui->moduleTypeComboBox->itemText(index);
- ui->axisTypeComboBox->clear();
- for (auto a: m_pCameraBindCopy->m_vecCAxis)
- {
- // 如果2个相等说明当前模组,与轴匹配
- if (strMod == a->GetModuleType().c_str())
- {
- ui->axisTypeComboBox->addItem(a->GetStringAxisType().c_str());
- }
- }
- m_isAdd = false;
- UpdataModuleType(strMod, 1);
- }
- void ControlOperationPage::on_axisTypeComboBox_currentIndexChanged(int index)
- {
- if (!m_isAdd)
- {
- UpdataModuleType(ui->axisTypeComboBox->itemText(index), 2);
- }
- }
- //void ControlOperationPage::timerEvent(QTimerEvent* event)
- //{
- // int nID = event->timerId();
- // if (nID == m_idleTimer)
- // {
- // ResetIdleTimer(false);
- // m_isUserOnclick = false;
- // ui->switchJoystickBut->setEnabled(true);
- // }
- //}
- //
- //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::wheelEvent(QWheelEvent* event) {
- if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
- m_mousePos = ui->Operatewidget->mapFromGlobal(event->globalPos());
- if (event->angleDelta().y() > 0) {
- updateScale(m_scaleFactor * 1.1); // 放大
- }
- else {
- updateScale(m_scaleFactor * 0.9); // 缩小
- }
- }
- }
- 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(g_unnSuspensionWaitingTime);
- }
- }
- else
- {
- killTimer(m_idleTimer);
- m_idleTimer = -1;
- }
- HideLayout(bStart);
- }
- void ControlOperationPage::InitWnd()
- {
- HideLayout(false);
-
- /* connect(ui->widgetPage, &JoystickPage::PositionChangedSignals, [&](qreal x, qreal y) {
- ui->showLabel->setText(QString("摇杆位置: (%1, %2)").arg(x, 0, 'f', 2).arg(y, 0, 'f', 2));
- });*/
- 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;
- }
- }
- }
- }
- void ControlOperationPage::UpdataModuleType(const QString& strMode, int nIndex)
- {
- if (nIndex == 1)
- {
- m_currentSelectRunAxis.ModuleType = strMode.toStdString();
- }
- else if (nIndex == 2)
- {
- m_currentSelectRunAxis.AxisType = strMode.toStdString();
- }
-
- if (m_isAdd == false)
- {
- m_currentSelectRunAxis.isSwitch = true;
- emit SendModuleTypeSignals(m_currentSelectRunAxis);
- m_currentSelectRunAxis.isSwitch = false;
- }
- }
- template<class T>
- void ControlOperationPage::DeduplicationBox(QComboBox* pCom, const T& veTemp, int nIndex)
- {
- for (auto& a : veTemp)
- {
- QString strName;
- if (nIndex == 0)
- {
- strName = a->GetModuleType().c_str();
- }
- else if (nIndex == 1)
- {
- strName = a->GetStringAxisType().c_str();
- }
- QStringList items;
- for (int i = 0; i < pCom->count(); ++i)
- {
- items << pCom->itemText(i);
- }
- 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;");
- }
-
- }
- void ControlOperationPage::setBlueBord() {
- ui->BackGround->setStyleSheet(QString::fromUtf8("border: 4px solid blue;"));
- }
- void ControlOperationPage::on_RulerButton_clicked()
- {
- if (m_currentMode == ModeImage) {
- if (m_currentImageView->rulerVisibale()) {
- m_currentImageView->endRuler();
- }
- else {
- m_currentImageView->startRuler();
- }
- }
- }
- void ControlOperationPage::on_PenButton_clicked() {
- m_isEnable = !m_isEnable;
- if (m_isEnable) {
- //ui->Operatewidget->setIsDrawing(true);
- m_currentImageView->setIsDrawing(true);
- ui->PenButton->setStyleSheet("QPushButton { background-color: #808FFF; }");
- }
- else {
- //ui->Operatewidget->setIsDrawing(false);
- m_currentImageView->setIsDrawing(false);
- ui->PenButton->setStyleSheet("QPushButton { background-color: none; }");
- }
- }
- void ControlOperationPage::SaveNewImage()
- {
- //// 捕获 ui->Operatewidget 的当前显示内容
- //QPixmap pixmap = ui->Operatewidget->grab();
- //// 使用当前时间生成默认文件名
- //QString defaultFileName = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss") + ".png";
- //// 弹出文件对话框,让用户选择保存路径和文件名
- //QString filePath = QFileDialog::getSaveFileName(
- // this,
- // tr("保存图片"),
- // QDir::homePath() + "/" + defaultFileName, // 默认路径为用户目录,文件名为当前时间
- // tr("PNG 文件 (*.png);;JPEG 文件 (*.jpg);;所有文件 (*)")
- //);
- //// 如果用户取消保存,则退出函数
- //if (filePath.isEmpty()) {
- // return;
- //}
- //if (!pixmap.save(filePath)) {
- // QMessageBox::warning(this, tr("保存失败"), tr("无法保存图片到指定路径。"));
- //}
- //else {
- // QMessageBox::information(this, tr("保存成功"), tr("图片已成功保存到:") + filePath);
- //}
- }
|