#include "OriginalWnd.h" #include "Login.h" #include "ui_OriginalWnd.h" #include "OriginalWnd/ChartsAndCamerasWnd.h" #include "OriginalWnd/MainAndSecondaryCamerasWnd.h" #include "OriginalWnd/SingleCameraOperationWnd.h" #include "OriginalWnd/treeviewmanager.h" #include #include #include #include #include #include #include #include #include OriginalWnd::OriginalWnd(QWidget *parent) : QMainWindow(parent) , ui(new Ui::OriginalWnd) { ui->setupUi(this); // 初始化 TreeViewManager treeViewManager = new TreeViewManager(this, ui->widget_2); if (!treeViewManager) { qWarning() << "TreeViewManager 初始化失败"; return; } // // 获取应用程序目录 // QString appDir = QCoreApplication::applicationDirPath(); // QDir configDir(appDir); // // 切换到config目录 // if (!configDir.cd("config")) { // qDebug() << "无法切换到config目录:" << configDir.absolutePath(); // return ; // } // // 外部路径 // QStringList configPaths; // configPaths << configDir.filePath("Home_config.json") // << configDir.filePath("Production_config.json") // << configDir.filePath("Diagnosis_config.json") // << configDir.filePath("Module_config.json") // << configDir.filePath("Program_config.json") // << configDir.filePath("Disposition_config.json") // << configDir.filePath("System_config.json"); // // 定义需要预加载的配置路径 QStringList configPaths; configPaths << ":/config/Home_config.json" << ":/config/Production_config.json" << ":/config/Diagnosis_config.json" << ":/config/Module_config.json" << ":/config/Program_config.json" << ":/config/Disposition_config.json" << ":/config/System_config.json"; // 让 TreeViewManager 把文件都读到内存 treeViewManager->preloadAllConfigs(configPaths); // 一启动就显示 home_config.json treeViewManager->switchConfig("Home_config.json"); qDebug() << "UI 初始化完成"; initForm(); } OriginalWnd::~OriginalWnd() { delete ui; } QWidget* OriginalWnd::getWidgetLeft() const { return ui->widget; } void OriginalWnd::switchToHomeConfig() { if (treeViewManager) { treeViewManager->switchConfig("Home_config.json"); } } void OriginalWnd::switchToProductionConfig() { if (treeViewManager) { treeViewManager->switchConfig("Production_config.json"); } } void OriginalWnd::switchToSystemConfig() { if (treeViewManager) { treeViewManager->switchConfig("System_config.json"); } } void OriginalWnd::switchToProgramConfig() { if (treeViewManager) { treeViewManager->switchConfig("Program_config.json"); } } void OriginalWnd::switchToModuleConfig() { if (treeViewManager) { treeViewManager->switchConfig("Module_config.json"); } } void OriginalWnd::switchToDispositionConfig() { if (treeViewManager) { treeViewManager->switchConfig("Disposition_config.json"); } } void OriginalWnd::switchToDiagnosisConfig() { if (treeViewManager) { treeViewManager->switchConfig("Diagnosis_config.json"); } } void OriginalWnd::initForm() { QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &OriginalWnd::updateTime); timer->start(100); ui->toolButton->setIcon(QIcon(":/images/light/stop.png")); ui->toolButton_2->setIcon(QIcon(":/images/light/start.png")); ui->toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); ui->toolButton_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); ui->label_userlogo->setPixmap(QPixmap(":/images/light/user.png").scaled(20, 20, Qt::KeepAspectRatio)); QSettings settings("OrganizationName__", "ApplicationName__"); int lastSavedIndex = settings.value("lastIndex", 1).toInt(); if (lastSavedIndex == 1) { ChartsAndCamerasWnd *chartsAndCamerasWnd = new ChartsAndCamerasWnd; ui->switchShowPageUI->addWidget(chartsAndCamerasWnd); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(chartsAndCamerasWnd)); // ui->ChartButton->setStyleSheet("background-color: #A9B4FF;"); } if (lastSavedIndex == 2) { MainAndSecondaryCamerasWnd *mainAndSecondaryCamerasWnd = new MainAndSecondaryCamerasWnd; ui->switchShowPageUI->addWidget(mainAndSecondaryCamerasWnd); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(mainAndSecondaryCamerasWnd)); // ui->DoubleImageButton->setStyleSheet("background-color: #A9B4FF;"); } if (lastSavedIndex == 3) { SingleCameraOperationWnd *singleCameraOperationWnd = new SingleCameraOperationWnd; ui->switchShowPageUI->addWidget(singleCameraOperationWnd); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(singleCameraOperationWnd)); // ui->SingleImageButton->setStyleSheet("background-color: #A9B4FF;"); } 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); } 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::on_ChartButton_clicked() { ChartsAndCamerasWnd *demo001_1 = new ChartsAndCamerasWnd; ui->switchShowPageUI->addWidget(demo001_1); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1)); QSettings settings("OrganizationName__", "ApplicationName__"); settings.setValue("lastIndex", 1); } void OriginalWnd::on_DoubleImageButton_clicked() { MainAndSecondaryCamerasWnd *demo001_2 = new MainAndSecondaryCamerasWnd; ui->switchShowPageUI->addWidget(demo001_2); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2)); QSettings settings("OrganizationName__", "ApplicationName__"); settings.setValue("lastIndex", 2); } void OriginalWnd::on_SingleImageButton_clicked() { SingleCameraOperationWnd *demo001_3 = new SingleCameraOperationWnd; ui->switchShowPageUI->addWidget(demo001_3); ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3)); QSettings settings("OrganizationName__", "ApplicationName__"); settings.setValue("lastIndex", 3); }