#include "TimeShowWidget.h" TimeShowWidget::TimeShowWidget(QWidget *parent): QWidget(parent), basicEventHandler(){ m_bWorkingStatus = TSW_NO_STATUS; m_iLogoIndex = 0; m_iLogoStage = 0; m_iLogoSize = 40; //setStyleSheet(QStringLiteral("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 128), stop:1 rgba(255, 255, 255, 255));")); /* m_pGreenPixmap = new QPixmap("resources/pictures/status/green-80.png"); m_pRedPixmap = new QPixmap("resources/pictures/status/guard-80-t0_0.png"); m_pGrayPixmap = new QPixmap("resources/pictures/status/gray-80.png"); m_pBluePixmap = new QPixmap("resources/pictures/status/blue-80.png"); */ m_pGreenPixmap = new QPixmap(":pictures/status/green-40.png"); m_pRedPixmap = new QPixmap(":pictures/status/guard-40-t0_0.png"); m_pGrayPixmap = new QPixmap(":pictures/status/gray-40.png"); m_pBluePixmap = new QPixmap(":pictures/status/blue-40.png"); for (int index = 0; index < 10; index++){ char Buffer[200]; sprintf(Buffer, ":pictures/status/guard-%d-t1_%d.png", m_iLogoSize,index); m_pArmedPixmap[index] = new QPixmap(Buffer); sprintf(Buffer, ":pictures/status/guard-%d-t0_%d.png", m_iLogoSize,index); m_pPreArmedPixmap[index] = new QPixmap(Buffer); if (index < 6) { sprintf(Buffer, ":pictures/status/guard-%d-t2_%d.png", m_iLogoSize, index); m_pAlarmedPixmap[index] = new QPixmap(Buffer); }; }; QHBoxLayout *mLayout; mLayout = new QHBoxLayout(this); mLayout->setSpacing(0); mLayout->setContentsMargins(0, 0, 10, 0); QLabel *mlabel1, *mlabel2, *mlabel3, *mlabel4; m_pLogoLabel = new QLabel(this); m_pLogoLabel->setText(QStringLiteral("")); m_pLogoLabel->setPixmap(*m_pRedPixmap); //m_pLogoLabel->setStyleSheet(QStringLiteral("")); m_pLogoLabel->setFixedSize(m_iLogoSize, m_iLogoSize); mLayout->addWidget(m_pLogoLabel); QSpacerItem *mSpacer; mSpacer = new QSpacerItem(20, 40, QSizePolicy::Expanding, QSizePolicy::Minimum); mLayout->addItem(mSpacer); QFont mFont; mFont.setPointSize(24); mFont.setBold(false); mFont.setWeight(50); m_pDayNumber = new QLCDNumber(); m_pDayNumber->setFixedSize(43, 40); m_pDayNumber->setFrameShape(QFrame::NoFrame); m_pDayNumber->setSmallDecimalPoint(false); m_pDayNumber->setDigitCount(2); m_pDayNumber->setMode(QLCDNumber::Dec); m_pDayNumber->setSegmentStyle(QLCDNumber::Flat); m_pDayNumber->setProperty("intValue", QVariant(88)); m_pDayNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); mLayout->addWidget(m_pDayNumber); mlabel1 = new QLabel(this); mlabel1->setFixedSize(5, 40); mlabel1->setFont(mFont); mlabel1->setText(QStringLiteral("/")); mLayout->addWidget(mlabel1); m_pMonthNumber = new QLCDNumber(); m_pMonthNumber->setFixedSize(43, 40); m_pMonthNumber->setFrameShape(QFrame::NoFrame); m_pMonthNumber->setSmallDecimalPoint(false); m_pMonthNumber->setDigitCount(2); m_pMonthNumber->setMode(QLCDNumber::Dec); m_pMonthNumber->setSegmentStyle(QLCDNumber::Flat); m_pMonthNumber->setProperty("intValue", QVariant(88)); m_pMonthNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); mLayout->addWidget(m_pMonthNumber); mlabel2 = new QLabel(this); mlabel2->setFixedSize(5, 40); mlabel2->setFont(mFont); mlabel2->setText(QStringLiteral("/")); mLayout->addWidget(mlabel2); m_pYearNumber = new QLCDNumber(); m_pYearNumber->setFixedSize(81, 40); m_pYearNumber->setFrameShape(QFrame::NoFrame); m_pYearNumber->setSmallDecimalPoint(false); m_pYearNumber->setDigitCount(4); m_pYearNumber->setMode(QLCDNumber::Dec); m_pYearNumber->setSegmentStyle(QLCDNumber::Flat); m_pYearNumber->setProperty("intValue", QVariant(8888)); m_pYearNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); mLayout->addWidget(m_pYearNumber); QSpacerItem *mSpacer2; mSpacer2 = new QSpacerItem(50, 40, QSizePolicy::Fixed, QSizePolicy::Fixed); mLayout->addItem(mSpacer2); m_pHourNumber = new QLCDNumber(); m_pHourNumber->setFixedSize(43, 40); m_pHourNumber->setFrameShape(QFrame::NoFrame); m_pHourNumber->setSmallDecimalPoint(false); m_pHourNumber->setDigitCount(2); m_pHourNumber->setMode(QLCDNumber::Dec); m_pHourNumber->setSegmentStyle(QLCDNumber::Flat); m_pHourNumber->setProperty("intValue", QVariant(88)); m_pHourNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); mLayout->addWidget(m_pHourNumber); mlabel3 = new QLabel(this); mlabel3->setFixedSize(5, 40); mlabel3->setFont(mFont); mlabel3->setText(QStringLiteral(":")); mLayout->addWidget(mlabel3); m_pMinutesNumber = new QLCDNumber(); m_pMinutesNumber->setFixedSize(43, 40); m_pMinutesNumber->setFrameShape(QFrame::NoFrame); m_pMinutesNumber->setSmallDecimalPoint(false); m_pMinutesNumber->setDigitCount(2); m_pMinutesNumber->setMode(QLCDNumber::Dec); m_pMinutesNumber->setSegmentStyle(QLCDNumber::Flat); m_pMinutesNumber->setProperty("intValue", QVariant(88)); m_pMinutesNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); mLayout->addWidget(m_pMinutesNumber); mlabel4 = new QLabel(this); mlabel4->setFixedSize(5, 40); mlabel4->setFont(mFont); mlabel4->setText(QStringLiteral(":")); mLayout->addWidget(mlabel4); m_pSecondsNumber = new QLCDNumber(); m_pSecondsNumber->setFixedSize(43, 40); m_pSecondsNumber->setFrameShape(QFrame::NoFrame); m_pSecondsNumber->setSmallDecimalPoint(false); m_pSecondsNumber->setDigitCount(2); m_pSecondsNumber->setMode(QLCDNumber::Dec); m_pSecondsNumber->setSegmentStyle(QLCDNumber::Flat); m_pSecondsNumber->setProperty("intValue", QVariant(88)); m_pSecondsNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); mLayout->addWidget(m_pSecondsNumber); setLayout(mLayout); setFixedHeight(m_iLogoSize); m_pClockTimer = new QTimer(); if (m_pClockTimer != NULL){ connect(m_pClockTimer, &QTimer::timeout, this, &TimeShowWidget::updateClock); m_pClockTimer->start(1000); }; m_pLogoTimer = new QTimer(); if (m_pLogoTimer != NULL){ connect(m_pLogoTimer, &QTimer::timeout, this, &TimeShowWidget::updateLogo); m_pLogoTimer->start(50); }; updateClock(); } TimeShowWidget::~TimeShowWidget(){ delete m_pLogoTimer; delete m_pClockTimer; }; void TimeShowWidget::updateLogo(){ switch (m_bWorkingStatus){ case TSW_NO_STATUS: m_pLogoLabel->setPixmap(*m_pRedPixmap); break; case TSW_NO_CONNECTION: m_pLogoLabel->setPixmap(*m_pGrayPixmap); break; case TSW_LEARNING: m_pLogoLabel->setPixmap(*m_pGreenPixmap); break; case TSW_ARMING: m_pLogoLabel->setPixmap(*m_pPreArmedPixmap[m_iLogoIndex]); if (m_iLogoIndex < 9){ m_iLogoIndex++; } else { m_bWorkingStatus = TSW_ARMED; m_iLogoIndex = 0; m_iLogoStage = 0; }; break; case TSW_ARMED: m_pLogoLabel->setPixmap(*m_pArmedPixmap[m_iLogoIndex]); if (m_iLogoStage == 0){ if (m_iLogoIndex < 9){ m_iLogoIndex++; } else { m_iLogoStage=1; }; } else { if (m_iLogoIndex > 0 ){ m_iLogoIndex--; } else { m_iLogoStage=0; }; } break; case TSW_ALARMING: if(m_iLogoIndex > 5) m_iLogoIndex = 5; m_pLogoLabel->setPixmap(*m_pAlarmedPixmap[m_iLogoIndex]); if (m_iLogoStage == 0){ if (m_iLogoIndex < 5){ m_iLogoIndex++; } else { m_iLogoStage = 1; }; } else { if (m_iLogoIndex > 0){ m_iLogoIndex--; } else { m_iLogoStage = 0; }; } break; case TSW_ALARMED: m_pLogoLabel->setPixmap(*m_pArmedPixmap[m_iLogoIndex]); if (m_iLogoIndex < 9){ m_iLogoIndex++; } else { m_iLogoIndex = 0; }; break; case TSW_DEARMING:break; }; }; void TimeShowWidget::setLogoSize(int Z){ m_iLogoSize = Z; for (int index = 0; index < 10; index++){ char Buffer[200]; sprintf(Buffer, ":pictures/guard-%d-t1_%d.png", m_iLogoSize, index); m_pArmedPixmap[index]->load(Buffer); sprintf(Buffer, ":pictures/guard-%d-t0_%d.png", m_iLogoSize, index); m_pPreArmedPixmap[index]->load(Buffer); sprintf(Buffer, ":pictures/guard-%d-t2_%d.png", m_iLogoSize, index); m_pAlarmedPixmap[index]->load(Buffer); }; }; void TimeShowWidget::updateClock(){ time_t t = time(NULL); struct tm tm = *localtime(&t); if (tm.tm_mday > 9){ m_pDayNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); }else{ m_pDayNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);")); }; m_pDayNumber->display(tm.tm_mday); if (tm.tm_mon > 8){ m_pMonthNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); } else{ m_pMonthNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);")); }; m_pMonthNumber->display(tm.tm_mon + 1); m_pYearNumber->display(tm.tm_year + 1900); if (tm.tm_hour > 9){ m_pHourNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); } else{ m_pHourNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);")); }; m_pHourNumber->display(tm.tm_hour); if (tm.tm_min > 9){ m_pMinutesNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); } else{ m_pMinutesNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);")); }; m_pMinutesNumber->display(tm.tm_min); if (tm.tm_sec > 9){ m_pSecondsNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);")); } else{ m_pSecondsNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);")); }; m_pSecondsNumber->display(tm.tm_sec); this->repaint(); //printf("now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); }; void TimeShowWidget::dispatchEvent(basicEvent *Evt){ if (Evt == NULL) return; if (Evt->m_eClass != EVT_CLASS_SYSTEM && Evt->m_eClass != EVT_CLASS_SENSOR) return; switch (Evt->m_eType){ case EVT_BUSY: m_bWorkingStatus = TSW_DEARMING; break; case EVT_STUDY: m_bWorkingStatus = TSW_LEARNING; break; case EVT_READY: m_bWorkingStatus = TSW_ARMING; break; case EVT_TARGET_WHITE: case EVT_TARGET_BLACK: case EVT_TARGET: case EVT_ALARM: m_bWorkingStatus = TSW_ALARMING; break; case EVT_NOINIT: case EVT_ERROR: m_bWorkingStatus = TSW_NO_CONNECTION; break; }; };