#pragma execution_character_set("utf-8") #include "Common.h" #include "StatusBar.h" #include "Preferences.h" StatusBar::StatusBar(QWidget *parent) : QWidget(parent) { m_bLineFixedWidth = false; m_nDay = 0; m_nHour = 0; m_nMinute = 0; m_nSeconds = 0; m_pLabSystemState = new QLabel; m_pLabLiveTime = new QLabel; m_pLabLaveCount = new QLabel; m_pLabProjectName = new QLabel; //m_pLabUser = new QLabel; m_pLabMessage = new QLabel; //m_pLabDateTime = new QLabel; m_tTimer = new QTimer(this); connect(m_tTimer, SIGNAL(timeout()), this, SLOT(showTime())); } void StatusBar::paintEvent(QPaintEvent *) { //加上此代码让继承类样式起作用 QStyleOption o; o.initFrom(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this); } void StatusBar::showTime() { m_nSeconds++; if (m_nSeconds == 60) { m_nMinute++; m_nSeconds = 0; } if ( m_nMinute == 60) { m_nHour++; m_nMinute = 0; } if ( m_nHour == 24) { m_nDay++; m_nHour = 0; } QDateTime now = QDateTime::currentDateTime(); thePrefs.m_strLiveTime = QString("%1天%2时%3分%4秒").arg(m_nDay).arg(m_nHour).arg(m_nMinute).arg(m_nSeconds); m_pLabLiveTime->setText(QString("已运行: %1").arg(thePrefs.m_strLiveTime)); thePrefs.m_strSystemTime = QString("%1").arg(now.toString("MM月dd日 HH:mm:ss")); // m_pLabDateTime->setText(thePrefs.m_strSystemTime); { if (thePrefs.m_bSystemIsRunning) { m_pLabSystemState->setText("Run"); m_pLabSystemState->setStyleSheet("QLabel{background-color:rgb(127,255,170);}"); //设置样式表 } else { m_pLabSystemState->setText("Stop"); m_pLabSystemState->setStyleSheet("QLabel{background-color:rgb(220,20,60);}"); //设置样式表 } m_pLabLaveCount->setText(QString("运行:%1").arg(thePrefs.m_nRunningCount)); m_pLabProjectName->setText(thePrefs.m_strProjectName); //m_pLabUser->setText(QString("%1<%2>").arg(thePrefs.m_strCurr_UserName).arg(thePrefs.m_strCurr_UserType)); m_pLabMessage->setText(thePrefs.m_strMessage); } } void StatusBar::setLineFixedWidth(bool lineFixedWidth) { this->m_bLineFixedWidth = lineFixedWidth; } void StatusBar::start(int interval) { //m_pLabDateTime->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); showTime(); QFrame *line1 = new QFrame; line1->setFrameShape(QFrame::VLine); line1->setFrameShadow(QFrame::Sunken); QFrame *line2 = new QFrame; line2->setFrameShape(QFrame::VLine); line2->setFrameShadow(QFrame::Sunken); QFrame *line3 = new QFrame; line3->setFrameShape(QFrame::VLine); line3->setFrameShadow(QFrame::Sunken); QFrame *line4 = new QFrame; line4->setFrameShape(QFrame::VLine); line4->setFrameShadow(QFrame::Sunken); QFrame* line5 = new QFrame; line5->setFrameShape(QFrame::VLine); line5->setFrameShadow(QFrame::Sunken); QFrame* line6 = new QFrame; line6->setFrameShape(QFrame::VLine); line6->setFrameShadow(QFrame::Sunken); { m_pLabSystemState->setText("Stop"); m_pLabLaveCount->setText(QString("运行:%1").arg(thePrefs.m_nRunningCount )); m_pLabProjectName->setText(thePrefs.m_strProjectName); //m_pLabUser->setText(QString("%1<%2>").arg(thePrefs.m_strCurr_UserName).arg(thePrefs.m_strCurr_UserType)); m_pLabMessage->setText(thePrefs.m_strMessage); } if (m_bLineFixedWidth) { line1->setFixedWidth(1); line2->setFixedWidth(1); line3->setFixedWidth(1); line4->setFixedWidth(1); line5->setFixedWidth(1); line6->setFixedWidth(1); } QHBoxLayout *layout = new QHBoxLayout(this); layout->setSpacing(20); layout->setContentsMargins(0, 0, 0, 0); m_pLabMessage->setMaximumWidth(2000); layout->addWidget(m_pLabSystemState); layout->addWidget(line1); layout->addWidget(m_pLabLiveTime); layout->addWidget(line2); layout->addWidget(m_pLabLaveCount); layout->addWidget(line3); layout->addWidget(m_pLabProjectName); layout->addWidget(line4); //layout->addWidget(m_pLabUser); //layout->addWidget(line5); //layout->addWidget(m_pLabDateTime); //layout->addWidget(line6); layout->addWidget(m_pLabMessage); m_tTimer->start(interval); //TODO: 1、运行状态 //1 //TODO: 2、运行时间 //2 //TODO: 3、运行计数 //3 //TODO: 4、项目名称 //4 //TODO: 5、用户名称(Type) //5 //TODO: 6、实时消息 //6 //TODO: 7、系统状态(动图) //7 //TODO: 8、系统时间 }