#include "OriginalWnd.h" #include "Login.h" #include "ui_OriginalWnd.h" #include "OriginalWnd/ChartsAndCamerasWnd.h" #include "OriginalWnd/MainAndSecondaryCamerasWnd.h" #include "OriginalWnd/SingleCameraOperationWnd.h" #include "OriginalWnd/DbTreeViewManager.h" #include "Src/Sql/SqlOperation.h" #include #include #include #include #include #include #include #include #include OriginalWnd::OriginalWnd(QWidget* parent, CameraBind* pCameraBind) : QMainWindow(parent) , ui(new Ui::OriginalWnd) { ui->setupUi(this); m_pCameraBind.reset(pCameraBind); m_pCameraDistribute = CameraDistribute::GetInstance(); RegFun(); if (gen_if.getLanguageValue() == 0) { } else { setChineseMode(this); } // 确保 ui->widget_2 已经初始化 if (!ui->widget_2) { qWarning() << "ui->widget_2 未初始化"; } // 初始化 DbTreeViewManager,传递两个参数 m_pdbTreeViewManager.reset(new DbTreeViewManager(this, ui->widget_2, this)); connect(m_pdbTreeViewManager.get(), &DbTreeViewManager::RunFunSignals, this, &OriginalWnd::JRunFunSlots); // 将 DbTreeViewManager 添加到 UI // 假设 ui->widget_2 是你原来放 TreeViewManager 的地方 QVBoxLayout* layout = new QVBoxLayout(ui->widget_2); layout->addWidget(m_pdbTreeViewManager.get()); ui->widget_2->setLayout(layout); // 初始化界面 InitForm(); SwitchToConfig("Home", 1, 0, false); } OriginalWnd::~OriginalWnd() { Del(); delete ui; } void OriginalWnd::CameraBindInit(CameraBind* pCameraBind) { m_pCameraBind.reset(pCameraBind); } void OriginalWnd::RegFun() { qRegisterMetaType("CAxis::AXIS_TYPE"); qRegisterMetaType("ns_module::ST_BUTTON_FUN"); } QWidget* OriginalWnd::getWidgetLeft() const { return ui->widget; } void OriginalWnd::SwitchToConfig(const QString& name, int configId, int menuArrayIndex, bool isMenuArray /*= true*/) { int userPrivilege = 0x1; // 初始设为 1,后续通过登录获取 m_pdbTreeViewManager->initializeTree(name, userPrivilege); m_pdbTreeViewManager->currentMenuId = configId; if (isMenuArray) { if (m_pdbTreeViewManager->menuArray[menuArrayIndex].isthird == true) { m_pdbTreeViewManager->loadpage(configId); } } } void OriginalWnd::switchToHomeConfig() { SwitchToConfig("Home", 1, 0, false); } void OriginalWnd::switchToProductionConfig() { SwitchToConfig("ProductionAssist", 2, 0); } void OriginalWnd::switchToDiagnosisConfig() { SwitchToConfig("Diagnosis", 2, 0); } void OriginalWnd::switchToDispositionConfig() { SwitchToConfig("Calibration", 6, 4); } void OriginalWnd::switchToModuleConfig() { SwitchToConfig("ModuleConfig", 4, 3); } void OriginalWnd::switchToProgramConfig() { SwitchToConfig("Programme", 5, 1); } void OriginalWnd::setChineseMode(QMainWindow* OriginalWnd) { OriginalWnd->setWindowTitle(QCoreApplication::translate("OriginalWnd", "主界面", nullptr)); ui->stopButton->setText(QCoreApplication::translate("OriginalWnd", "停止", nullptr)); ui->startButton->setText(QCoreApplication::translate("OriginalWnd", "启动", nullptr)); ui->ChartButton->setText(QString()); ui->DoubleImageButton->setText(QString()); ui->SingleImageButton->setText(QString()); // ui->pushButton_18->setText(QCoreApplication::translate("OriginalWnd", "PushButton", nullptr)); ui->label_name->setText(QCoreApplication::translate("OriginalWnd", "姓名001", nullptr)); ui->RegistrationNumber->setText(QCoreApplication::translate("OriginalWnd", "注册号码 001", nullptr)); ui->CalibrationButton->setText(QCoreApplication::translate("OriginalWnd", "校准", nullptr)); ui->ProductIotNumber->setText(QCoreApplication::translate("OriginalWnd", "xxx生产编号", nullptr)); ui->pushButton_2->setText(QString()); ui->pushButton_3->setText(QString()); ui->label_time->setText(QString()); ui->label_username->setText(QString()); ui->label_userlogo->setText(QString()); } void OriginalWnd::switchToSystemConfig() { QString name = "SystemInfor"; int configId = 7; // System_config.json 对应的 ConfigId int userPrivilege = 0x1; // 初始设为 1,后续通过登录获取 m_pdbTreeViewManager->initializeTree(name, userPrivilege); } void OriginalWnd::InitForm() { m_nTimerID = startTimer(100); //给stopbutton加样式 QString stopButton_styleSheet = "QToolButton:hover { background: #cc0000; }" "QToolButton:pressed { background: #990000; }"; ui->stopButton->setStyleSheet(stopButton_styleSheet); ui->stopButton->setIcon(QIcon(":/images/light/stop.png")); ui->startButton->setIcon(QIcon(":/images/light/start.png")); ui->label_userlogo->setPixmap(QPixmap(":/images/TopStatusBar/user.png").scaled(20, 20, Qt::KeepAspectRatio)); ui->label_username->setText(tr("SBT_QQ", "SBT_QQ")); ui->label_username->setStyleSheet("QLabel { color : White; }" "QLabel:hover { color : red; }"); CreateSwitchMainPage(); ui->label_userlogo->installEventFilter(this); ui->label_username->installEventFilter(this); } void OriginalWnd::UpdateTime() { QDateTime currentDateTime = QDateTime::currentDateTime(); QString timeStr = currentDateTime.toString("yyyy-MM-dd HH:mm:ss"); ui->label_time->setText(timeStr); //// 用户也要放到注册表? //QSettings settings("YourCompany_2", "YourAppName_2"); //QString userName = settings.value("userName", "???").toString(); //ui->label_username->setText(userName); } void OriginalWnd::Del() { killTimer(m_nTimerID); } void OriginalWnd::RunOrStopSwitch() { // 目前样式切换需要调整 if (m_isDisabled) { // 当按钮处于禁用状态时,执行停止操作并启用按钮 QString styleSheet = "QToolButton { background: #4AB832; color: #FFFFFF; }" "QToolButton:hover { background: #00FF00; }"; ui->startButton->setDisabled(m_isDisabled); ui->stopButton->setDisabled(!m_isDisabled); ui->startButton->setStyleSheet(styleSheet); m_pCameraBind->JRunAutoBond(); } else { // 当按钮处于启用状态时,执行开始操作并禁用按钮 QString styleSheet = "QToolButton:disabled { color: #808080; background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F8FBFF, stop: 1 #E7ECF3); }"; ui->startButton->setDisabled(m_isDisabled); ui->stopButton->setDisabled(!m_isDisabled); ui->stopButton->setStyleSheet(styleSheet); m_pCameraBind->JRunStop(); } m_isDisabled = !m_isDisabled; // 切换状态 } bool OriginalWnd::eventFilter(QObject* obj, QEvent* event) { if (obj == this->ui->label_userlogo || obj == this->ui->label_username) { //判断事件类型是否为鼠标事件 if (event->type() == QEvent::MouseButtonPress) { //转换为鼠标事件 QMouseEvent* mouseenevt = static_cast(event); //判断鼠标左键点击 if (mouseenevt->button() == Qt::LeftButton) { if (QStackedWidget* parent = qobject_cast(this->parentWidget())) { Login* loginWnd = new Login(this); parent->addWidget(loginWnd); parent->setCurrentIndex(parent->indexOf(loginWnd)); } } } } return QWidget::eventFilter(obj, event); } void OriginalWnd::timerEvent(QTimerEvent* event) { if (m_nTimerID == event->timerId()) { UpdateTime(); } } void OriginalWnd::on_ChartButton_clicked() { CreateSwitchMainPage(EN_WND_SWITCH::ChartsAnd); } void OriginalWnd::on_DoubleImageButton_clicked() { CreateSwitchMainPage(EN_WND_SWITCH::MainAndSecondary); } void OriginalWnd::on_SingleImageButton_clicked() { CreateSwitchMainPage(EN_WND_SWITCH::SingleCameraOperation); } void OriginalWnd::on_startButton_clicked() { RunOrStopSwitch(); } void OriginalWnd::on_stopButton_clicked() { RunOrStopSwitch(); } void OriginalWnd::SwitchMainPage(JOriginalMainWnd* pWnd, QToolButton* tooBut) { if (m_pCameraBind == nullptr) { RegFun(); } m_pCameraBind->SetImageWnd(pWnd); pWnd->InitMainCameraBind(m_pCameraBind.get()); ui->switchShowPageUI->addWidget(pWnd); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(pWnd)); // ui->DoubleImageButton->setStyleSheet("background-color: #A9B4FF;"); tooBut->setChecked(true); m_pJOriginalMainWnd = pWnd; } void OriginalWnd::CreateSwitchMainPage(int nlastIndex /*= -1*/) { QSettings settings("OrganizationName__", "ApplicationName__"); if (nlastIndex <= 0) { nlastIndex = settings.value("lastIndex", 1).toInt(); } else { settings.setValue("lastIndex", nlastIndex); } // 切换窗口 switch (nlastIndex) { case EN_WND_SWITCH::ChartsAnd: { ChartsAndCamerasWnd* chartsAndCamerasWnd = new ChartsAndCamerasWnd; SwitchMainPage(chartsAndCamerasWnd, ui->ChartButton); } break; case EN_WND_SWITCH::MainAndSecondary: { MainAndSecondaryCamerasWnd* mainAndSecondaryCamerasWnd = new MainAndSecondaryCamerasWnd; SwitchMainPage(mainAndSecondaryCamerasWnd, ui->DoubleImageButton); } break; case EN_WND_SWITCH::SingleCameraOperation: { SingleCameraOperationWnd* singleCameraOperationWnd = new SingleCameraOperationWnd; SwitchMainPage(singleCameraOperationWnd, ui->SingleImageButton); } break; default: break; } } void OriginalWnd::onHandleLanguageSignal(const int& data) { if (data == 0) { ui->retranslateUi(this); } else { setChineseMode(this); } } void OriginalWnd::JRunFunSlots(ns_module::ST_BUTTON_FUN pra) { m_pCameraBind->JRunButton(pra); }