#include "MainWnd.h" #include "ui_MainWnd.h" #include "Login.h" #include #include #include "OriginalWnd/OriginalWnd.h" MainWnd::MainWnd(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWnd) ,initialIconSet(false) { ui->setupUi(this); // // 初始化 OriginalWnd m_originalWnd = new OriginalWnd(this); // // 将 OriginalWnd 添加到 stackedWidget_UI ui->stackedWidget_UI->addWidget(m_originalWnd); bool buttonConnected = connect(ui->tabHomeBtn, &QPushButton::clicked, this, &MainWnd::on_tabHomeBtn_clicked); qDebug() << "Connected tabHomeBtn clicked to on_tabHomeBtn_clicked:" << buttonConnected; connect(ui->tabProductionBtn, &QPushButton::clicked, this, &MainWnd::on_tabProductionBtn_clicked); connect(ui->tabDiagnosisBtn, &QPushButton::clicked, this, &MainWnd::on_tabDiagnosisBtn_clicked); connect(ui->tabDispositionBtn, &QPushButton::clicked, this, &MainWnd::on_tabDispositionBtn_clicked); connect(ui->tabModuleBtn, &QPushButton::clicked, this, &MainWnd::on_tabModuleBtn_clicked); connect(ui->tabSystemBtn, &QPushButton::clicked, this, &MainWnd::on_tabSystemBtn_clicked); connect(ui->tabProgramBtn, &QPushButton::clicked, this, &MainWnd::on_tabProgramBtn_clicked); // 设置 OriginalWnd 为当前页面 ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); qDebug() << "OriginalWnd 已设置为 stackedWidget 的当前页面"; initForm(); } MainWnd::~MainWnd() { delete ui; } void MainWnd::on_tabProductionBtn_clicked() { m_originalWnd->switchToProductionConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::on_tabHomeBtn_clicked() { m_originalWnd->switchToHomeConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::on_tabProgramBtn_clicked() { m_originalWnd->switchToProgramConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::on_tabModuleBtn_clicked() { m_originalWnd->switchToModuleConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::on_tabDispositionBtn_clicked() { m_originalWnd->switchToDispositionConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::on_tabDiagnosisBtn_clicked() { m_originalWnd->switchToDiagnosisConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::on_tabSystemBtn_clicked() { m_originalWnd->switchToSystemConfig(); ui->stackedWidget_UI->setCurrentWidget(m_originalWnd); } void MainWnd::initForm() { // 隐藏原生标题栏 setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog); // 窗口背景透明 setAttribute(Qt::WA_TranslucentBackground, true); QPixmap pixmap(":/images/light/logo1.png"); QPixmap scaledPixmap = pixmap.scaled(90, 49, Qt::KeepAspectRatio); ui->label_logo->setPixmap(scaledPixmap); Login *login = new Login; ui->stackedWidget_UI->addWidget(login); ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(login)); //登录监听 ui->label_logo->installEventFilter(this); ui->stackedWidget_UI->installEventFilter(this); //安装监听事件,点击左侧按钮图标变化 ui->tabHomeBtn->installEventFilter(this); ui->tabProductionBtn->installEventFilter(this); ui->tabProgramBtn->installEventFilter(this); ui->tabMessageBtn->installEventFilter(this); ui->tabModuleBtn->installEventFilter(this); ui->tabDispositionBtn->installEventFilter(this); ui->tabDiagnosisBtn->installEventFilter(this); ui->tabSystemBtn->installEventFilter(this); ui->tabHelpBtn->installEventFilter(this); QMouseEvent* pressEvent = new QMouseEvent(QEvent::MouseButtonPress, ui->tabHomeBtn->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QApplication::sendEvent(ui->tabHomeBtn, pressEvent); delete pressEvent; } bool MainWnd::eventFilter(QObject *obj, QEvent *event) { if (obj == this->ui->stackedWidget_UI) { onCurrentWidgetChanged(); } if (obj == this->ui->label_logo) { //判断事件类型是否为鼠标事件 if (event->type() == QEvent::MouseButtonPress) { //转换为鼠标事件 QMouseEvent* mouseenevt = static_cast(event); //判断鼠标左键点击 if (mouseenevt->button() == Qt::LeftButton) { Login *login = new Login; ui->stackedWidget_UI->addWidget(login); ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(login)); return true; } } } switch(event->type()) { case QEvent::MouseButtonPress: { if(obj == ui->tabHomeBtn && ui->tabHomeBtn->isEnabled()) { ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png")); ui->tabHomeBtn->setChecked(true); if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabProductionBtn && ui->tabProductionBtn->isEnabled()) { ui->tabProductionBtn->setIcon(QIcon(":/images/deep/Productionn assistance.png")); ui->tabProductionBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabProgramBtn && ui->tabProgramBtn->isEnabled()) { ui->tabProgramBtn->setIcon(QIcon(":/images/deep/Program.png")); ui->tabProgramBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabMessageBtn && ui->tabMessageBtn->isEnabled()) { ui->tabMessageBtn->setIcon(QIcon(":/images/deep/Message.png")); ui->tabMessageBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabModuleBtn && ui->tabModuleBtn->isEnabled()) { ui->tabModuleBtn->setIcon(QIcon(":/images/deep/Module.png")); ui->tabModuleBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isEnabled()) { ui->tabDispositionBtn->setIcon(QIcon(":/images/deep/Disposition.png")); ui->tabDispositionBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isEnabled()) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/deep/Diagnosis.png")); ui->tabDiagnosisBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabSystemBtn && ui->tabSystemBtn->isEnabled()) { ui->tabSystemBtn->setIcon(QIcon(":/images/deep/System.png")); ui->tabSystemBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabHelpBtn && ui->tabHelpBtn->isEnabled()) { ui->tabHelpBtn->setIcon(QIcon(":/images/deep/Help.png")); ui->tabHelpBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } } break; } case QEvent::HoverEnter: { if(obj == ui->tabHomeBtn && ui->tabHomeBtn->isEnabled()) { ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png")); } if(obj == ui->tabProductionBtn && ui->tabProductionBtn->isEnabled()) { ui->tabProductionBtn->setIcon(QIcon(":/images/deep/Productionn assistance.png")); } if(obj == ui->tabProgramBtn && ui->tabProgramBtn->isEnabled()) { ui->tabProgramBtn->setIcon(QIcon(":/images/deep/Program.png")); } if(obj == ui->tabMessageBtn && ui->tabMessageBtn->isEnabled()) { ui->tabMessageBtn->setIcon(QIcon(":/images/deep/Message.png")); } if(obj == ui->tabModuleBtn && ui->tabModuleBtn->isEnabled()) { ui->tabModuleBtn->setIcon(QIcon(":/images/deep/Module.png")); } if(obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isEnabled()) { ui->tabDispositionBtn->setIcon(QIcon(":/images/deep/Disposition.png")); } if(obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isEnabled()) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/deep/Diagnosis.png")); } if(obj == ui->tabSystemBtn && ui->tabSystemBtn->isEnabled()) { ui->tabSystemBtn->setIcon(QIcon(":/images/deep/System.png")); } if(obj == ui->tabHelpBtn && ui->tabHelpBtn->isEnabled()) { ui->tabHelpBtn->setIcon(QIcon(":/images/deep/Help.png")); } break; } case QEvent::HoverLeave: { if(obj == ui->tabHomeBtn && ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); ui->tabHomeBtn->setChecked(false); } if(obj == ui->tabProductionBtn && ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); ui->tabProductionBtn->setChecked(false); } if(obj == ui->tabProgramBtn && ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); ui->tabProgramBtn->setChecked(false); } if(obj == ui->tabMessageBtn && ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); ui->tabMessageBtn->setChecked(false); } if(obj == ui->tabModuleBtn && ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); ui->tabModuleBtn->setChecked(false); } if(obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); ui->tabDispositionBtn->setChecked(false); } if(obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); ui->tabDiagnosisBtn->setChecked(false); } if(obj == ui->tabSystemBtn && ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); ui->tabSystemBtn->setChecked(false); } if(obj == ui->tabHelpBtn && ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); ui->tabHelpBtn->setChecked(false); } } default: break; } return QWidget::eventFilter(obj, event); } void MainWnd::onCurrentWidgetChanged() { QWidget *currentWidget = ui->stackedWidget_UI->currentWidget(); if (currentWidget) { QString currentWidgetName = currentWidget->objectName(); if (currentWidgetName == "Login") { QString styleSheet = "QToolButton:disabled { color: #808080; background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F8FBFF, stop: 1 #E7ECF3); }"; // 设置禁用状态下的文本颜色为灰色 ui->tabHomeBtn->setDisabled(true); ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); ui->tabHomeBtn->setStyleSheet(styleSheet); ui->tabProductionBtn->setDisabled(true); ui->tabProductionBtn->setStyleSheet(styleSheet); ui->tabProgramBtn->setDisabled(true); ui->tabProgramBtn->setStyleSheet(styleSheet); ui->tabMessageBtn->setDisabled(true); ui->tabMessageBtn->setStyleSheet(styleSheet); ui->tabModuleBtn->setDisabled(true); ui->tabModuleBtn->setStyleSheet(styleSheet); ui->tabDispositionBtn->setDisabled(true); ui->tabDispositionBtn->setStyleSheet(styleSheet); ui->tabDiagnosisBtn->setDisabled(true); ui->tabDiagnosisBtn->setStyleSheet(styleSheet); ui->tabSystemBtn->setDisabled(true); ui->tabSystemBtn->setStyleSheet(styleSheet); ui->tabHelpBtn->setDisabled(true); ui->tabHelpBtn->setStyleSheet(styleSheet); } else { ui->tabHomeBtn->setDisabled(false); if (!initialIconSet) { ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png")); initialIconSet = true; } ui->tabProductionBtn->setDisabled(false); ui->tabProgramBtn->setDisabled(false); ui->tabMessageBtn->setDisabled(false); ui->tabModuleBtn->setDisabled(false); ui->tabDispositionBtn->setDisabled(false); ui->tabDiagnosisBtn->setDisabled(false); ui->tabSystemBtn->setDisabled(false); ui->tabHelpBtn->setDisabled(false); } } } void MainWnd::on_pushButton_clicked() { qApp->quit(); }