You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
10 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "TimeShowWidget.h"
  2. TimeShowWidget::TimeShowWidget(QWidget *parent): QWidget(parent), basicEventHandler(){
  3. m_bWorkingStatus = TSW_NO_STATUS;
  4. m_iLogoIndex = 0;
  5. m_iLogoStage = 0;
  6. m_iLogoSize = 40;
  7. //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));"));
  8. /*
  9. m_pGreenPixmap = new QPixmap("resources/pictures/status/green-80.png");
  10. m_pRedPixmap = new QPixmap("resources/pictures/status/guard-80-t0_0.png");
  11. m_pGrayPixmap = new QPixmap("resources/pictures/status/gray-80.png");
  12. m_pBluePixmap = new QPixmap("resources/pictures/status/blue-80.png");
  13. */
  14. m_pGreenPixmap = new QPixmap(":pictures/status/green-40.png");
  15. m_pRedPixmap = new QPixmap(":pictures/status/guard-40-t0_0.png");
  16. m_pGrayPixmap = new QPixmap(":pictures/status/gray-40.png");
  17. m_pBluePixmap = new QPixmap(":pictures/status/blue-40.png");
  18. for (int index = 0; index < 10; index++){
  19. char Buffer[200];
  20. sprintf(Buffer, ":pictures/status/guard-%d-t1_%d.png", m_iLogoSize,index);
  21. m_pArmedPixmap[index] = new QPixmap(Buffer);
  22. sprintf(Buffer, ":pictures/status/guard-%d-t0_%d.png", m_iLogoSize,index);
  23. m_pPreArmedPixmap[index] = new QPixmap(Buffer);
  24. if (index < 6) {
  25. sprintf(Buffer, ":pictures/status/guard-%d-t2_%d.png", m_iLogoSize, index);
  26. m_pAlarmedPixmap[index] = new QPixmap(Buffer);
  27. };
  28. };
  29. QHBoxLayout *mLayout;
  30. mLayout = new QHBoxLayout(this);
  31. mLayout->setSpacing(0);
  32. mLayout->setContentsMargins(0, 0, 10, 0);
  33. QLabel *mlabel1, *mlabel2, *mlabel3, *mlabel4;
  34. m_pLogoLabel = new QLabel(this);
  35. m_pLogoLabel->setText(QStringLiteral(""));
  36. m_pLogoLabel->setPixmap(*m_pRedPixmap);
  37. //m_pLogoLabel->setStyleSheet(QStringLiteral(""));
  38. m_pLogoLabel->setFixedSize(m_iLogoSize, m_iLogoSize);
  39. mLayout->addWidget(m_pLogoLabel);
  40. QSpacerItem *mSpacer;
  41. mSpacer = new QSpacerItem(20, 40, QSizePolicy::Expanding, QSizePolicy::Minimum);
  42. mLayout->addItem(mSpacer);
  43. QFont mFont;
  44. mFont.setPointSize(24);
  45. mFont.setBold(false);
  46. mFont.setWeight(50);
  47. m_pDayNumber = new QLCDNumber();
  48. m_pDayNumber->setFixedSize(43, 40);
  49. m_pDayNumber->setFrameShape(QFrame::NoFrame);
  50. m_pDayNumber->setSmallDecimalPoint(false);
  51. m_pDayNumber->setDigitCount(2);
  52. m_pDayNumber->setMode(QLCDNumber::Dec);
  53. m_pDayNumber->setSegmentStyle(QLCDNumber::Flat);
  54. m_pDayNumber->setProperty("intValue", QVariant(88));
  55. m_pDayNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  56. mLayout->addWidget(m_pDayNumber);
  57. mlabel1 = new QLabel(this);
  58. mlabel1->setFixedSize(5, 40);
  59. mlabel1->setFont(mFont);
  60. mlabel1->setText(QStringLiteral("/"));
  61. mLayout->addWidget(mlabel1);
  62. m_pMonthNumber = new QLCDNumber();
  63. m_pMonthNumber->setFixedSize(43, 40);
  64. m_pMonthNumber->setFrameShape(QFrame::NoFrame);
  65. m_pMonthNumber->setSmallDecimalPoint(false);
  66. m_pMonthNumber->setDigitCount(2);
  67. m_pMonthNumber->setMode(QLCDNumber::Dec);
  68. m_pMonthNumber->setSegmentStyle(QLCDNumber::Flat);
  69. m_pMonthNumber->setProperty("intValue", QVariant(88));
  70. m_pMonthNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  71. mLayout->addWidget(m_pMonthNumber);
  72. mlabel2 = new QLabel(this);
  73. mlabel2->setFixedSize(5, 40);
  74. mlabel2->setFont(mFont);
  75. mlabel2->setText(QStringLiteral("/"));
  76. mLayout->addWidget(mlabel2);
  77. m_pYearNumber = new QLCDNumber();
  78. m_pYearNumber->setFixedSize(81, 40);
  79. m_pYearNumber->setFrameShape(QFrame::NoFrame);
  80. m_pYearNumber->setSmallDecimalPoint(false);
  81. m_pYearNumber->setDigitCount(4);
  82. m_pYearNumber->setMode(QLCDNumber::Dec);
  83. m_pYearNumber->setSegmentStyle(QLCDNumber::Flat);
  84. m_pYearNumber->setProperty("intValue", QVariant(8888));
  85. m_pYearNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  86. mLayout->addWidget(m_pYearNumber);
  87. QSpacerItem *mSpacer2;
  88. mSpacer2 = new QSpacerItem(50, 40, QSizePolicy::Fixed, QSizePolicy::Fixed);
  89. mLayout->addItem(mSpacer2);
  90. m_pHourNumber = new QLCDNumber();
  91. m_pHourNumber->setFixedSize(43, 40);
  92. m_pHourNumber->setFrameShape(QFrame::NoFrame);
  93. m_pHourNumber->setSmallDecimalPoint(false);
  94. m_pHourNumber->setDigitCount(2);
  95. m_pHourNumber->setMode(QLCDNumber::Dec);
  96. m_pHourNumber->setSegmentStyle(QLCDNumber::Flat);
  97. m_pHourNumber->setProperty("intValue", QVariant(88));
  98. m_pHourNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  99. mLayout->addWidget(m_pHourNumber);
  100. mlabel3 = new QLabel(this);
  101. mlabel3->setFixedSize(5, 40);
  102. mlabel3->setFont(mFont);
  103. mlabel3->setText(QStringLiteral(":"));
  104. mLayout->addWidget(mlabel3);
  105. m_pMinutesNumber = new QLCDNumber();
  106. m_pMinutesNumber->setFixedSize(43, 40);
  107. m_pMinutesNumber->setFrameShape(QFrame::NoFrame);
  108. m_pMinutesNumber->setSmallDecimalPoint(false);
  109. m_pMinutesNumber->setDigitCount(2);
  110. m_pMinutesNumber->setMode(QLCDNumber::Dec);
  111. m_pMinutesNumber->setSegmentStyle(QLCDNumber::Flat);
  112. m_pMinutesNumber->setProperty("intValue", QVariant(88));
  113. m_pMinutesNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  114. mLayout->addWidget(m_pMinutesNumber);
  115. mlabel4 = new QLabel(this);
  116. mlabel4->setFixedSize(5, 40);
  117. mlabel4->setFont(mFont);
  118. mlabel4->setText(QStringLiteral(":"));
  119. mLayout->addWidget(mlabel4);
  120. m_pSecondsNumber = new QLCDNumber();
  121. m_pSecondsNumber->setFixedSize(43, 40);
  122. m_pSecondsNumber->setFrameShape(QFrame::NoFrame);
  123. m_pSecondsNumber->setSmallDecimalPoint(false);
  124. m_pSecondsNumber->setDigitCount(2);
  125. m_pSecondsNumber->setMode(QLCDNumber::Dec);
  126. m_pSecondsNumber->setSegmentStyle(QLCDNumber::Flat);
  127. m_pSecondsNumber->setProperty("intValue", QVariant(88));
  128. m_pSecondsNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  129. mLayout->addWidget(m_pSecondsNumber);
  130. setLayout(mLayout);
  131. setFixedHeight(m_iLogoSize);
  132. m_pClockTimer = new QTimer();
  133. if (m_pClockTimer != NULL){
  134. connect(m_pClockTimer,
  135. &QTimer::timeout,
  136. this,
  137. &TimeShowWidget::updateClock);
  138. m_pClockTimer->start(1000);
  139. };
  140. m_pLogoTimer = new QTimer();
  141. if (m_pLogoTimer != NULL){
  142. connect(m_pLogoTimer,
  143. &QTimer::timeout,
  144. this,
  145. &TimeShowWidget::updateLogo);
  146. m_pLogoTimer->start(50);
  147. };
  148. updateClock();
  149. }
  150. TimeShowWidget::~TimeShowWidget(){
  151. delete m_pLogoTimer;
  152. delete m_pClockTimer;
  153. };
  154. void TimeShowWidget::updateLogo(){
  155. switch (m_bWorkingStatus){
  156. case TSW_NO_STATUS: m_pLogoLabel->setPixmap(*m_pRedPixmap); break;
  157. case TSW_NO_CONNECTION: m_pLogoLabel->setPixmap(*m_pGrayPixmap); break;
  158. case TSW_LEARNING: m_pLogoLabel->setPixmap(*m_pGreenPixmap); break;
  159. case TSW_ARMING:
  160. m_pLogoLabel->setPixmap(*m_pPreArmedPixmap[m_iLogoIndex]);
  161. if (m_iLogoIndex < 9){
  162. m_iLogoIndex++;
  163. } else {
  164. m_bWorkingStatus = TSW_ARMED;
  165. m_iLogoIndex = 0;
  166. m_iLogoStage = 0;
  167. };
  168. break;
  169. case TSW_ARMED:
  170. m_pLogoLabel->setPixmap(*m_pArmedPixmap[m_iLogoIndex]);
  171. if (m_iLogoStage == 0){
  172. if (m_iLogoIndex < 9){
  173. m_iLogoIndex++;
  174. } else {
  175. m_iLogoStage=1;
  176. };
  177. } else {
  178. if (m_iLogoIndex > 0 ){
  179. m_iLogoIndex--;
  180. } else {
  181. m_iLogoStage=0;
  182. };
  183. }
  184. break;
  185. case TSW_ALARMING:
  186. if(m_iLogoIndex > 5) m_iLogoIndex = 5;
  187. m_pLogoLabel->setPixmap(*m_pAlarmedPixmap[m_iLogoIndex]);
  188. if (m_iLogoStage == 0){
  189. if (m_iLogoIndex < 5){
  190. m_iLogoIndex++;
  191. } else {
  192. m_iLogoStage = 1;
  193. };
  194. } else {
  195. if (m_iLogoIndex > 0){
  196. m_iLogoIndex--;
  197. } else {
  198. m_iLogoStage = 0;
  199. };
  200. }
  201. break;
  202. case TSW_ALARMED:
  203. m_pLogoLabel->setPixmap(*m_pArmedPixmap[m_iLogoIndex]);
  204. if (m_iLogoIndex < 9){
  205. m_iLogoIndex++;
  206. }
  207. else {
  208. m_iLogoIndex = 0;
  209. };
  210. break;
  211. case TSW_DEARMING:break;
  212. };
  213. };
  214. void TimeShowWidget::setLogoSize(int Z){
  215. m_iLogoSize = Z;
  216. for (int index = 0; index < 10; index++){
  217. char Buffer[200];
  218. sprintf(Buffer, ":pictures/guard-%d-t1_%d.png", m_iLogoSize, index);
  219. m_pArmedPixmap[index]->load(Buffer);
  220. sprintf(Buffer, ":pictures/guard-%d-t0_%d.png", m_iLogoSize, index);
  221. m_pPreArmedPixmap[index]->load(Buffer);
  222. sprintf(Buffer, ":pictures/guard-%d-t2_%d.png", m_iLogoSize, index);
  223. m_pAlarmedPixmap[index]->load(Buffer);
  224. };
  225. };
  226. void TimeShowWidget::updateClock(){
  227. time_t t = time(NULL);
  228. struct tm tm = *localtime(&t);
  229. if (tm.tm_mday > 9){
  230. m_pDayNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  231. }else{
  232. m_pDayNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);"));
  233. };
  234. m_pDayNumber->display(tm.tm_mday);
  235. if (tm.tm_mon > 8){
  236. m_pMonthNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  237. }
  238. else{
  239. m_pMonthNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);"));
  240. };
  241. m_pMonthNumber->display(tm.tm_mon + 1);
  242. m_pYearNumber->display(tm.tm_year + 1900);
  243. if (tm.tm_hour > 9){
  244. m_pHourNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  245. }
  246. else{
  247. m_pHourNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);"));
  248. };
  249. m_pHourNumber->display(tm.tm_hour);
  250. if (tm.tm_min > 9){
  251. m_pMinutesNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  252. }
  253. else{
  254. m_pMinutesNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);"));
  255. };
  256. m_pMinutesNumber->display(tm.tm_min);
  257. if (tm.tm_sec > 9){
  258. m_pSecondsNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_bg.png);"));
  259. }
  260. else{
  261. m_pSecondsNumber->setStyleSheet(QStringLiteral("background-image: url(:pictures/lcd_0bg.png);"));
  262. };
  263. m_pSecondsNumber->display(tm.tm_sec);
  264. this->repaint();
  265. //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);
  266. };
  267. void TimeShowWidget::dispatchEvent(basicEvent *Evt){
  268. if (Evt == NULL) return;
  269. if (Evt->m_eClass != EVT_CLASS_SYSTEM && Evt->m_eClass != EVT_CLASS_SENSOR) return;
  270. switch (Evt->m_eType){
  271. case EVT_BUSY:
  272. m_bWorkingStatus = TSW_DEARMING;
  273. break;
  274. case EVT_STUDY:
  275. m_bWorkingStatus = TSW_LEARNING;
  276. break;
  277. case EVT_READY:
  278. m_bWorkingStatus = TSW_ARMING;
  279. break;
  280. case EVT_TARGET_WHITE:
  281. case EVT_TARGET_BLACK:
  282. case EVT_TARGET:
  283. case EVT_ALARM:
  284. m_bWorkingStatus = TSW_ALARMING;
  285. break;
  286. case EVT_NOINIT:
  287. case EVT_ERROR:
  288. m_bWorkingStatus = TSW_NO_CONNECTION;
  289. break;
  290. };
  291. };