123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #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 <QDebug>
- #include <QJsonDocument>
- #include <QFile>
- #include <QFileDialog>
- #include <QDateTime>
- #include <QTimer>
- #include <QSettings>
- #include <QMouseEvent>
- #include <QDir>
- 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 *demo001_1 = new ChartsAndCamerasWnd;
- ui->switchShowPageUI->addWidget(demo001_1);
- ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
- }
- if (lastSavedIndex == 2) {
- MainAndSecondaryCamerasWnd *demo001_2 = new MainAndSecondaryCamerasWnd;
- ui->switchShowPageUI->addWidget(demo001_2);
- ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
- }
- if (lastSavedIndex == 3) {
- SingleCameraOperationWnd *demo001_3 = new SingleCameraOperationWnd;
- ui->switchShowPageUI->addWidget(demo001_3);
- ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
- }
- 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<QMouseEvent*>(event);
- //判断鼠标左键点击
- if (mouseenevt->button() == Qt::LeftButton)
- {
- if (QStackedWidget *parent = qobject_cast<QStackedWidget*>(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);
- }
|