StatusBar.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #pragma execution_character_set("utf-8")
  2. #include "Common.h"
  3. #include "StatusBar.h"
  4. #include "Preferences.h"
  5. StatusBar::StatusBar(QWidget *parent) : QWidget(parent)
  6. {
  7. m_bLineFixedWidth = false;
  8. m_nDay = 0;
  9. m_nHour = 0;
  10. m_nMinute = 0;
  11. m_nSeconds = 0;
  12. m_pLabSystemState = new QLabel;
  13. m_pLabLiveTime = new QLabel;
  14. m_pLabLaveCount = new QLabel;
  15. m_pLabProjectName = new QLabel;
  16. //m_pLabUser = new QLabel;
  17. m_pLabMessage = new QLabel;
  18. //m_pLabDateTime = new QLabel;
  19. m_tTimer = new QTimer(this);
  20. connect(m_tTimer, SIGNAL(timeout()), this, SLOT(showTime()));
  21. }
  22. void StatusBar::paintEvent(QPaintEvent *)
  23. {
  24. //加上此代码让继承类样式起作用
  25. QStyleOption o;
  26. o.initFrom(this);
  27. QPainter p(this);
  28. style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
  29. }
  30. void StatusBar::showTime()
  31. {
  32. m_nSeconds++;
  33. if (m_nSeconds == 60)
  34. {
  35. m_nMinute++;
  36. m_nSeconds = 0;
  37. }
  38. if ( m_nMinute == 60)
  39. {
  40. m_nHour++;
  41. m_nMinute = 0;
  42. }
  43. if ( m_nHour == 24)
  44. {
  45. m_nDay++;
  46. m_nHour = 0;
  47. }
  48. QDateTime now = QDateTime::currentDateTime();
  49. thePrefs.m_strLiveTime = QString("%1天%2时%3分%4秒").arg(m_nDay).arg(m_nHour).arg(m_nMinute).arg(m_nSeconds);
  50. m_pLabLiveTime->setText(QString("已运行: %1").arg(thePrefs.m_strLiveTime));
  51. thePrefs.m_strSystemTime = QString("%1").arg(now.toString("MM月dd日 HH:mm:ss"));
  52. // m_pLabDateTime->setText(thePrefs.m_strSystemTime);
  53. {
  54. if (thePrefs.m_bSystemIsRunning)
  55. {
  56. m_pLabSystemState->setText("Run");
  57. m_pLabSystemState->setStyleSheet("QLabel{background-color:rgb(127,255,170);}"); //设置样式表
  58. }
  59. else
  60. {
  61. m_pLabSystemState->setText("Stop");
  62. m_pLabSystemState->setStyleSheet("QLabel{background-color:rgb(220,20,60);}"); //设置样式表
  63. }
  64. m_pLabLaveCount->setText(QString("运行:%1").arg(thePrefs.m_nRunningCount));
  65. m_pLabProjectName->setText(thePrefs.m_strProjectName);
  66. //m_pLabUser->setText(QString("%1<%2>").arg(thePrefs.m_strCurr_UserName).arg(thePrefs.m_strCurr_UserType));
  67. m_pLabMessage->setText(thePrefs.m_strMessage);
  68. }
  69. }
  70. void StatusBar::setLineFixedWidth(bool lineFixedWidth)
  71. {
  72. this->m_bLineFixedWidth = lineFixedWidth;
  73. }
  74. void StatusBar::start(int interval)
  75. {
  76. //m_pLabDateTime->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  77. showTime();
  78. QFrame *line1 = new QFrame;
  79. line1->setFrameShape(QFrame::VLine);
  80. line1->setFrameShadow(QFrame::Sunken);
  81. QFrame *line2 = new QFrame;
  82. line2->setFrameShape(QFrame::VLine);
  83. line2->setFrameShadow(QFrame::Sunken);
  84. QFrame *line3 = new QFrame;
  85. line3->setFrameShape(QFrame::VLine);
  86. line3->setFrameShadow(QFrame::Sunken);
  87. QFrame *line4 = new QFrame;
  88. line4->setFrameShape(QFrame::VLine);
  89. line4->setFrameShadow(QFrame::Sunken);
  90. QFrame* line5 = new QFrame;
  91. line5->setFrameShape(QFrame::VLine);
  92. line5->setFrameShadow(QFrame::Sunken);
  93. QFrame* line6 = new QFrame;
  94. line6->setFrameShape(QFrame::VLine);
  95. line6->setFrameShadow(QFrame::Sunken);
  96. {
  97. m_pLabSystemState->setText("Stop");
  98. m_pLabLaveCount->setText(QString("运行:%1").arg(thePrefs.m_nRunningCount ));
  99. m_pLabProjectName->setText(thePrefs.m_strProjectName);
  100. //m_pLabUser->setText(QString("%1<%2>").arg(thePrefs.m_strCurr_UserName).arg(thePrefs.m_strCurr_UserType));
  101. m_pLabMessage->setText(thePrefs.m_strMessage);
  102. }
  103. if (m_bLineFixedWidth)
  104. {
  105. line1->setFixedWidth(1);
  106. line2->setFixedWidth(1);
  107. line3->setFixedWidth(1);
  108. line4->setFixedWidth(1);
  109. line5->setFixedWidth(1);
  110. line6->setFixedWidth(1);
  111. }
  112. QHBoxLayout *layout = new QHBoxLayout(this);
  113. layout->setSpacing(20);
  114. layout->setContentsMargins(0, 0, 0, 0);
  115. m_pLabMessage->setMaximumWidth(2000);
  116. layout->addWidget(m_pLabSystemState);
  117. layout->addWidget(line1);
  118. layout->addWidget(m_pLabLiveTime);
  119. layout->addWidget(line2);
  120. layout->addWidget(m_pLabLaveCount);
  121. layout->addWidget(line3);
  122. layout->addWidget(m_pLabProjectName);
  123. layout->addWidget(line4);
  124. //layout->addWidget(m_pLabUser);
  125. //layout->addWidget(line5);
  126. //layout->addWidget(m_pLabDateTime);
  127. //layout->addWidget(line6);
  128. layout->addWidget(m_pLabMessage);
  129. m_tTimer->start(interval);
  130. //TODO: 1、运行状态
  131. //1
  132. //TODO: 2、运行时间
  133. //2
  134. //TODO: 3、运行计数
  135. //3
  136. //TODO: 4、项目名称
  137. //4
  138. //TODO: 5、用户名称(Type)
  139. //5
  140. //TODO: 6、实时消息
  141. //6
  142. //TODO: 7、系统状态(动图)
  143. //7
  144. //TODO: 8、系统时间
  145. }