#include "LightJoystickSwitchPage.h" #include "ui_LightJoystickSwitchPage.h" LightJoystickSwitchPage::LightJoystickSwitchPage(QWidget *parent) : QWidget(parent) , ui(new Ui::LightJoystickSwitchPage) { ui->setupUi(this); InitForm(); } LightJoystickSwitchPage::~LightJoystickSwitchPage() { delete ui; } void LightJoystickSwitchPage::InitForm() { m_nTimeShowPos = startTimer(900); InitLineEdits(); SliderBind(); } void LightJoystickSwitchPage::SliderBind(){ connect(ui->RedLightverticalSlider, &QSlider::valueChanged, ui->RedLightprogressBar, &QProgressBar::setValue); connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar, &QProgressBar::setValue); connect(ui->GreenLightverticalSlider, &QSlider::valueChanged, ui->GreenLightprogressBar, &QProgressBar::setValue); connect(ui->DotLightverticalSlider, &QSlider::valueChanged, ui->DotLightprogressBar, &QProgressBar::setValue); BondSliderAndLineEdit(ui->RedLightverticalSlider, ui->RedLightlineEdit); BondSliderAndLineEdit(ui->GreenLightverticalSlider, ui->GreenLightlineEdit); BondSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit); BondSliderAndLineEdit(ui->DotLightverticalSlider, ui->DotLightlineEdit); } void LightJoystickSwitchPage::InitLineEdits() { ui->switchTabWidget->tabBar()->hide(); QList lineEdits = { ui->RedLightlineEdit, ui->GreenLightlineEdit, ui->BlueLightlineEdit, ui->DotLightlineEdit, }; for (QLineEdit* lineEdit : lineEdits) { QRegExp regExp("^(0|([1-9]\\d?)|(1\\d{2})|(2[0-5]\\d))$"); QRegExpValidator* validator = new QRegExpValidator(regExp, lineEdit); lineEdit->setValidator(validator); lineEdit->setAlignment(Qt::AlignCenter); } } void LightJoystickSwitchPage::BondSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit) { QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit); lineEdit->setValidator(validator); connect(slider, &QSlider::valueChanged, [lineEdit](int value) { lineEdit->setText(QString::number(value)); }); connect(lineEdit, &QLineEdit::textChanged, [&, slider, lineEdit](const QString& text) { bool ok; int value = text.toInt(&ok); if (ok && value >= slider->minimum() && value <= slider->maximum()) { slider->setValue(value); } else if (!text.isEmpty()) { int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum()); slider->setValue(closestValue); } if (m_pPageSwitchGroup) { // 执行匹配灯光 int niD = m_pPageSwitchGroup->m_nGroupId; if (niD == 1) { // 相机窗口 if (m_pCameraBind) { m_pCameraBind->JSetRedLight(niD, MatchSelectedLightIndex(lineEdit), value); } } } }); } void LightJoystickSwitchPage::setLigthValue(int redLight,int greenLight,int blueLight,int dotLight) { setLightWidget(redLight, ui->RedLight, ui->RedLightlineEdit, ui->RedLightverticalSlider, ui->RedLightprogressBar, ui->RedLightlabel); setLightWidget(greenLight, ui->GreenLight, ui->GreenLightlineEdit, ui->GreenLightverticalSlider, ui->GreenLightprogressBar, ui->GreenLightlabel); setLightWidget(blueLight, ui->BlueLight, ui->BlueLightlineEdit, ui->BlueLightverticalSlider, ui->BlueLightprogressBar, ui->BlueLightlabel); setLightWidget(dotLight, ui->DotLight, ui->DotLightlineEdit, ui->DotLightverticalSlider, ui->DotLightprogressBar, ui->DotLightlabel); } void LightJoystickSwitchPage::setLightWidget(int value, QWidget *lightWidget, QLineEdit *lineEdit, QSlider *slider, QProgressBar *progressBar, QLabel *label) { if (0 <= value && value <= 100) { lightWidget->show(); lineEdit->show(); slider->show(); progressBar->show(); label->show(); lineEdit->setText(QString::number(value)); progressBar->setValue(value); slider->setValue(value); } else if (value == -1) { lightWidget->hide(); lineEdit->hide(); slider->hide(); progressBar->hide(); label->hide(); } } void LightJoystickSwitchPage::on_move_Button_clicked() { } void LightJoystickSwitchPage::on_moveTo_Button_clicked() { if (m_pCameraBind) { // m_pCameraBind->YGetAxisPosition(); } } void LightJoystickSwitchPage::on_left_Button_clicked() { m_moveAxisInfo.AxisType = "X"; MoveJoystick(); } void LightJoystickSwitchPage::on_up_Button_clicked() { m_moveAxisInfo.AxisType = "Y"; MoveJoystick(); } void LightJoystickSwitchPage::on_right_Button_clicked() { m_moveAxisInfo.AxisType = "X"; MoveJoystick(); } void LightJoystickSwitchPage::on_down_Button_clicked() { m_moveAxisInfo.AxisType = "Y"; MoveJoystick(); } void LightJoystickSwitchPage::InitMainCameraBind(CameraBind* pCameraBind) { m_pCameraBind.reset(pCameraBind); UpdataLightVal(); } void LightJoystickSwitchPage::UpdatemPageGroup(Group* pGroup) { m_pPageSwitchGroup = pGroup; } void LightJoystickSwitchPage::SwitchJoystickPage(bool bSwitch) { ResetIdleTimer(bSwitch); int newIndex = (ui->switchTabWidget->currentIndex() + 1) % ui->switchTabWidget->count(); ui->switchTabWidget->setCurrentIndex(newIndex); } void LightJoystickSwitchPage::HideOrShowPage(bool isHide) { ui->switchTabWidget->setVisible(isHide); } void LightJoystickSwitchPage::SetMoveJoystickInfo(const ST_MOVE_AXIS& movInfo) { m_moveAxisInfo.ModuleType = movInfo.ModuleType; m_moveAxisInfo.AxisType = movInfo.AxisType; m_moveAxisInfo.pos = movInfo.pos; // 这个距离可能会变动// 根据摇杆区分等级 // 点击摇杆的时候开启定时器,然后3秒关闭 SwitchJoystickPage(true); ui->JTabShowLable->setText(CombiningStr()); } void LightJoystickSwitchPage::timerEvent(QTimerEvent* event) { int nID = event->timerId(); if (m_nTimeShowPos == nID) { RealTimeUpdatesToU(); } else if (m_idleTimer == nID) { SwitchJoystickPage(false); } } QString LightJoystickSwitchPage::CombiningStr(bool isUpdate /*= false*/) { double pos = m_moveAxisInfo.pos; QString strShow = tr("Currently selected mode:", "当前选中模式:"); if (isUpdate) { strShow = tr("Move Pos:","移动点:"); if (m_pCameraBind) { m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, pos); } } strShow += m_moveAxisInfo.ModuleType.c_str(); strShow += " "; strShow += m_moveAxisInfo.AxisType.c_str(); strShow += " "; strShow += QString::number(pos, 'f', 2); return strShow; } void LightJoystickSwitchPage::RealTimeUpdatesToU() { if (m_pCameraBind) { ui->JTabShowLableLoop->setText(CombiningStr(true)); } } void LightJoystickSwitchPage::ResetIdleTimer(bool bStart /*= false*/) { if (bStart) { if (isActiveWindow()) { m_idleTimer = startTimer(3000); } } else { killTimer(m_idleTimer); m_idleTimer = -1; } } void LightJoystickSwitchPage::MoveJoystick() { if (m_pCameraBind) { m_pCameraBind->YGetAxisPosition(m_moveAxisInfo.ModuleType, m_moveAxisInfo.AxisType, m_moveAxisInfo.pos); } } void LightJoystickSwitchPage::UpdataLightVal() { if (m_pPageSwitchGroup) { int niD = m_pPageSwitchGroup->m_nGroupId; //if (niD == 1) { auto Fun = [&](QWidget* pWidget, QSlider* pSlider, int nVal) { if (nVal < 0) { // 设置不可用 pWidget->setEnabled(false); pWidget->hide(); } else { pSlider->setValue(nVal); } }; // 切换灯光 ST_LIGHT_VAL _val = m_pCameraBind->JGetLight(niD); Fun(ui->RedLight, ui->RedLightverticalSlider, _val.redLightValue); Fun(ui->GreenLight, ui->GreenLightverticalSlider, _val.greenLightValue); Fun(ui->BlueLight, ui->BlueLightverticalSlider, _val.blueLightValue); Fun(ui->DotLight, ui->DotLightverticalSlider, _val.pointLightValue); } } } EN_LIGHT_INDEX LightJoystickSwitchPage::MatchSelectedLightIndex(QLineEdit* lineEdit) { EN_LIGHT_INDEX nIndex = EN_LIGHT_INDEX::Red; if (lineEdit == ui->RedLightlineEdit) { nIndex = EN_LIGHT_INDEX::Red; } else if (lineEdit == ui->GreenLightlineEdit) { nIndex = EN_LIGHT_INDEX::Green; } else if (lineEdit == ui->BlueLightlineEdit) { nIndex = EN_LIGHT_INDEX::Blue; } else if (lineEdit == ui->DotLightlineEdit) { nIndex = EN_LIGHT_INDEX::Point; } return nIndex; }