#include "mainwidget.h" #include "ui_mainwidget.h" #include #include "global.h" #define MaxStack 3 const QString strName[]={ "系统信息","通道信息","告警信息","运行日志" }; MainWidget::MainWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MainWidget) { ui->setupUi(this); InitWidget(); } MainWidget::~MainWidget() { delete ui; } void MainWidget::InitWidget() { //图片设置 QString strPath=QCoreApplication::applicationDirPath() + QDir::separator()+"image_qt" + QDir::separator(); QImage rgbImage=QImage(strPath+"Home.png"); QImage bgrImage = rgbImage.rgbSwapped(); ui->toolButton->setIcon(QIcon(QPixmap::fromImage(bgrImage))); rgbImage=QImage(strPath+"T.png"); bgrImage = rgbImage.rgbSwapped(); ui->label_5->setPixmap(QPixmap::fromImage(bgrImage)); rgbImage=QImage(strPath+"humidity.png"); bgrImage = rgbImage.rgbSwapped(); ui->label_6->setPixmap(QPixmap::fromImage(bgrImage)); rgbImage=QImage(strPath+"error.png"); bgrImage = rgbImage.rgbSwapped(); ui->label_12->setPixmap(QPixmap::fromImage(bgrImage)); rgbImage=QImage(strPath+"warning-fill.png"); bgrImage = rgbImage.rgbSwapped(); ui->label_10->setPixmap(QPixmap::fromImage(bgrImage)); rgbImage=QImage(strPath+"log.png"); bgrImage = rgbImage.rgbSwapped(); ui->label_14->setPixmap(QPixmap::fromImage(bgrImage)); m_pTimer=new QTimer(this); connect(m_pTimer,SIGNAL(timeout()),this,SLOT(slot_TimerUpdate())); m_pTimer->start(1000); m_pHome = new HomeWidget(this); m_pCH=new RunChWiget(this); m_pThreshold=new ThresholdListWidget(this); m_pLogWidget=new RunLogWidget(); ui->stackedWidget->addWidget(m_pHome); ui->stackedWidget->addWidget(m_pCH); ui->stackedWidget->addWidget(m_pThreshold); ui->stackedWidget->addWidget(m_pLogWidget); nIndex=0; connect(ui->toolButton,SIGNAL(clicked()),this,SLOT(slot_BtnHome())); connect(m_pHome,SIGNAL(signal_setPage(int)),this,SLOT(slot_SwitchWnd(int))); // // connect(ui->pushButton_DownPage,SIGNAL(clicked()),this,SLOT(slot_BtnDown())); } void MainWidget::UpdateTemp(QString strT, QString strH) { ui->label_Temp->setText(strT); ui->label_Temp2->setText(strH); update(); } void MainWidget::slot_TimerUpdate() { QDateTime currentTime = QDateTime::currentDateTime(); QString strDate=currentTime.toString("yyyy.MM.dd"); QString strTime=currentTime.toString("HH:mm:ss"); if(ui) { ui->label_Date->setText(strDate); ui->label_Time->setText(strTime); } slot_UpdateData(); } void MainWidget::slot_BtnHome() { //ui->label_2->setText(strName[0]); ui->stackedWidget->setCurrentIndex(0); slot_UpdateData(); } void MainWidget::slot_BtnUp() { if(nIndex==0) { nIndex=MaxStack; }else { nIndex-=1; } //ui->label_2->setText(strName[nIndex]); ui->stackedWidget->setCurrentIndex(nIndex); } void MainWidget::slot_BtnDown() { if(nIndex==MaxStack) { nIndex=0; }else { nIndex+=1; } //ui->label_2->setText(strName[nIndex]); ui->stackedWidget->setCurrentIndex(nIndex); } void MainWidget::slot_SwitchWnd(int nIndex) { ui->stackedWidget->setCurrentIndex(nIndex); if(m_pThreshold&&ui->stackedWidget->currentWidget()==m_pThreshold) { m_pThreshold->ReadSqlData(); }else if(m_pLogWidget&&ui->stackedWidget->currentWidget()==m_pLogWidget) { m_pLogWidget->UpdateLog(); } slot_UpdateData(); } void MainWidget::slot_UpdateData() { if(m_pHome&&ui->stackedWidget->currentWidget()==m_pHome) { m_pHome->UpdateCHData(); } else if(m_pCH&&ui->stackedWidget->currentWidget()==m_pCH) { m_pCH->UpdateAllCh(); } else if(m_pThreshold&&ui->stackedWidget->currentWidget()==m_pThreshold) { m_pThreshold->UpdateTreshold(); } }