Blame view

app/gui/oven_control/multicooktimebar.cpp 1.45 KB
2f6b55128   김태훈   다중 요리 구현
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include "multicooktimebar.h"
  
  #include <QPainter>
  #include <QTime>
  #include <QDebug>
  
  MultiCookTimeBar::MultiCookTimeBar(QWidget *parent) : QWidget(parent)
  {
      format = "hh:mm";
      timePosition = 0;
  
      checkTimer.start(100);
      connect(&checkTimer, SIGNAL(timeout()), SLOT(check()));
  }
  
  void MultiCookTimeBar::showNow()
  {
      timePosition = 0;
      update();
  }
  
  void MultiCookTimeBar::showPrev()
  {
      timePosition--;
      update();
  }
  
  void MultiCookTimeBar::showNext()
  {
      timePosition++;
      update();
  }
  
  void MultiCookTimeBar::paintEvent(QPaintEvent */*event*/)
  {
      int w = width();
      int h = height();
      int y = h / 2;
  
      QPoint c1(w * 2 / 10, y);
      QPoint c2(w * 5 / 10, y);
      QPoint c3(w * 8 / 10, y);
2f6b55128   김태훈   다중 요리 구현
43
44
45
46
47
48
49
50
51
52
      QRect rect(0, 0, w, h);
  
      QTime t = QTime::currentTime();
  
      QString s1 = t.addSecs(200 * (timePosition + 0)).toString(format);
      QString s2 = t.addSecs(200 * (timePosition + 3)).toString(format);
      QString s3 = t.addSecs(200 * (timePosition + 6)).toString(format);
  
      QPainter painter(this);
      painter.setPen(Qt::white);
2f6b55128   김태훈   다중 요리 구현
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  
      rect.moveCenter(c1);
      painter.drawText(rect, Qt::AlignCenter, s1);
  
      rect.moveCenter(c2);
      painter.drawText(rect, Qt::AlignCenter, s2);
  
      rect.moveCenter(c3);
      painter.drawText(rect, Qt::AlignCenter, s3);
  }
  
  void MultiCookTimeBar::check()
  {
      QString s = QTime::currentTime().toString(format);
      if (lastDraw.isNull() || s != lastDraw)
      {
          update();
          lastDraw = s;
      }
  }