mainwidget.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #include "mainwidget.h"
  2. #include "ui_mainwidget.h"
  3. #include <QDateTime>
  4. #include "global.h"
  5. #define MaxStack 3
  6. const QString strName[]={
  7. "系统信息","通道信息","告警信息","运行日志"
  8. };
  9. MainWidget::MainWidget(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::MainWidget)
  12. {
  13. ui->setupUi(this);
  14. InitWidget();
  15. }
  16. MainWidget::~MainWidget()
  17. {
  18. delete ui;
  19. }
  20. void MainWidget::InitWidget()
  21. {
  22. //图片设置
  23. QString strPath=QCoreApplication::applicationDirPath() + QDir::separator()+"image_qt" + QDir::separator();
  24. QImage rgbImage=QImage(strPath+"Home.png");
  25. QImage bgrImage = rgbImage.rgbSwapped();
  26. ui->toolButton->setIcon(QIcon(QPixmap::fromImage(bgrImage)));
  27. rgbImage=QImage(strPath+"T.png");
  28. bgrImage = rgbImage.rgbSwapped();
  29. ui->label_5->setPixmap(QPixmap::fromImage(bgrImage));
  30. rgbImage=QImage(strPath+"humidity.png");
  31. bgrImage = rgbImage.rgbSwapped();
  32. ui->label_6->setPixmap(QPixmap::fromImage(bgrImage));
  33. rgbImage=QImage(strPath+"error.png");
  34. bgrImage = rgbImage.rgbSwapped();
  35. ui->label_12->setPixmap(QPixmap::fromImage(bgrImage));
  36. rgbImage=QImage(strPath+"warning-fill.png");
  37. bgrImage = rgbImage.rgbSwapped();
  38. ui->label_10->setPixmap(QPixmap::fromImage(bgrImage));
  39. rgbImage=QImage(strPath+"log.png");
  40. bgrImage = rgbImage.rgbSwapped();
  41. ui->label_14->setPixmap(QPixmap::fromImage(bgrImage));
  42. m_pTimer=new QTimer(this);
  43. connect(m_pTimer,SIGNAL(timeout()),this,SLOT(slot_TimerUpdate()));
  44. m_pTimer->start(1000);
  45. m_pHome = new HomeWidget(this);
  46. m_pCH=new RunChWiget(this);
  47. m_pThreshold=new ThresholdListWidget(this);
  48. m_pLogWidget=new RunLogWidget();
  49. ui->stackedWidget->addWidget(m_pHome);
  50. ui->stackedWidget->addWidget(m_pCH);
  51. ui->stackedWidget->addWidget(m_pThreshold);
  52. ui->stackedWidget->addWidget(m_pLogWidget);
  53. nIndex=0;
  54. connect(ui->toolButton,SIGNAL(clicked()),this,SLOT(slot_BtnHome()));
  55. connect(m_pHome,SIGNAL(signal_setPage(int)),this,SLOT(slot_SwitchWnd(int)));
  56. //
  57. // connect(ui->pushButton_DownPage,SIGNAL(clicked()),this,SLOT(slot_BtnDown()));
  58. }
  59. void MainWidget::UpdateTemp(QString strT, QString strH)
  60. {
  61. ui->label_Temp->setText(strT);
  62. ui->label_Temp2->setText(strH);
  63. update();
  64. }
  65. void MainWidget::slot_TimerUpdate()
  66. {
  67. QDateTime currentTime = QDateTime::currentDateTime();
  68. QString strDate=currentTime.toString("yyyy.MM.dd");
  69. QString strTime=currentTime.toString("HH:mm:ss");
  70. if(ui)
  71. {
  72. ui->label_Date->setText(strDate);
  73. ui->label_Time->setText(strTime);
  74. }
  75. slot_UpdateData();
  76. }
  77. void MainWidget::slot_BtnHome()
  78. {
  79. //ui->label_2->setText(strName[0]);
  80. ui->stackedWidget->setCurrentIndex(0);
  81. slot_UpdateData();
  82. }
  83. void MainWidget::slot_BtnUp()
  84. {
  85. if(nIndex==0)
  86. {
  87. nIndex=MaxStack;
  88. }else
  89. {
  90. nIndex-=1;
  91. }
  92. //ui->label_2->setText(strName[nIndex]);
  93. ui->stackedWidget->setCurrentIndex(nIndex);
  94. }
  95. void MainWidget::slot_BtnDown()
  96. {
  97. if(nIndex==MaxStack)
  98. {
  99. nIndex=0;
  100. }else
  101. {
  102. nIndex+=1;
  103. }
  104. //ui->label_2->setText(strName[nIndex]);
  105. ui->stackedWidget->setCurrentIndex(nIndex);
  106. }
  107. void MainWidget::slot_SwitchWnd(int nIndex)
  108. {
  109. ui->stackedWidget->setCurrentIndex(nIndex);
  110. if(m_pThreshold&&ui->stackedWidget->currentWidget()==m_pThreshold)
  111. {
  112. m_pThreshold->ReadSqlData();
  113. }else if(m_pLogWidget&&ui->stackedWidget->currentWidget()==m_pLogWidget)
  114. {
  115. m_pLogWidget->UpdateLog();
  116. }
  117. slot_UpdateData();
  118. }
  119. void MainWidget::slot_UpdateData()
  120. {
  121. if(m_pHome&&ui->stackedWidget->currentWidget()==m_pHome)
  122. {
  123. m_pHome->UpdateCHData();
  124. }
  125. else if(m_pCH&&ui->stackedWidget->currentWidget()==m_pCH)
  126. {
  127. m_pCH->UpdateAllCh();
  128. }
  129. else if(m_pThreshold&&ui->stackedWidget->currentWidget()==m_pThreshold)
  130. {
  131. m_pThreshold->UpdateTreshold();
  132. }
  133. }