Blame view

app/gui/oven_control/stringer.cpp 4.21 KB
2bfd3a050   김태훈   환경 설정 대응
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  #include "stringer.h"
  
  #include "config.h"
  
  namespace {
  QString heavySpan("<span class=\"heavy\">%1</span>");
  QString lightSpan("<span class=\"light\">%1</span>");
  QString lightestSpan("<span class=\"lightest\">%1</span>");
  
  enum RemainingTimeFormat { RemainingTime, FinishTime };
  RemainingTimeFormat remainingTime()
  {
      Define::config_item item = Config::getInstance()->getConfigValue(Define::config_resttime_format);
      switch (item.d32)
      {
      case Define::rest_time_target:
          return FinishTime;
      case Define::rest_time_rest:
      default:
          return RemainingTime;
      }
  }
  
  enum TemperatureFormat { Celsius, Fahrenheit };
  TemperatureFormat temperatureFormat()
  {
      Define::config_item item = Config::getInstance()->getConfigValue(Define::config_temptype);
      switch (item.d32)
      {
      case Define::temp_type_f:
          return Fahrenheit;
      case Define::temp_type_c:
      default:
          return Celsius;
      }
  }
  
  int toFahrenheit(int celsius)
  {
      return celsius * 1.8 + 32;
  }
  }
  
  QString Stringer::remainingTime(int msecs)
  {
      switch (::remainingTime())
      {
      case RemainingTime:
          msecs /= 1000;
          if (msecs >= 3600)
              return QString("%1시간 %2분").arg(msecs / 3600).arg((msecs % 3600) / 60, 2, 10, QLatin1Char('0'));
          if (msecs >= 60)
              return QString("%1분 %2초").arg(msecs / 60).arg(msecs % 60, 2, 10, QLatin1Char('0'));
  
          return QString("%1초").arg(msecs);
      case FinishTime:
          return QDateTime::currentDateTime().addMSecs(msecs).toString("HH:mm:ss");
      }
  
      return QString();
  }
  
  QString Stringer::remainingTime(int msecs, QString style)
  {
      switch (::remainingTime())
      {
      case RemainingTime:
          msecs /= 1000;
          if (msecs >= 3600)
          {
              QString hour = heavySpan.arg(msecs / 3600) + lightSpan.arg("시간");
              QString min = heavySpan.arg((msecs % 3600) / 60, 2, 10, QLatin1Char('0')) + lightSpan.arg("분");
  
              return style + QString("%1 %2").arg(hour).arg(min);
          }
          if (msecs >= 60)
          {
              QString min = heavySpan.arg(msecs / 60) + lightSpan.arg("분");
              QString sec = heavySpan.arg(msecs % 60, 2, 10, QLatin1Char('0')) + lightSpan.arg("초");
  
              return style + QString("%1 %2").arg(min).arg(sec);
          }
  
          return style + heavySpan.arg(msecs) + lightSpan.arg("초");
      case FinishTime:
          return heavySpan.arg(QDateTime::currentDateTime().addMSecs(msecs).toString("HH:mm:ss"));
      }
  
      return QString();
  }
  
  QString Stringer::temperature(int celsius)
  {
      switch (temperatureFormat())
      {
      case Fahrenheit:
          return QString("%1℉").arg(toFahrenheit(celsius));
      case Celsius:
      default:
          return QString("%1℃").arg(celsius);
      }
  }
  
  QString Stringer::temperature(int celsius, QString style)
  {
      switch (temperatureFormat())
      {
      case Fahrenheit:
          return style + heavySpan.arg(toFahrenheit(celsius)) + lightSpan.arg("℉");
      case Celsius:
      default:
          return style + heavySpan.arg(celsius) + lightSpan.arg("℃");
      }
  }
  
  QString Stringer::temperature(int current, int target)
  {
      switch (temperatureFormat())
      {
      case Fahrenheit:
          return QString("%1℉ / %2℉").arg(toFahrenheit(current)).arg(toFahrenheit(target));
      case Celsius:
      default:
          return QString("%1℃ / %2℃").arg(current).arg(target);
      }
  }
  
  QString Stringer::temperature(int current, int target, QString style)
  {
      switch (temperatureFormat())
      {
      case Fahrenheit:
          return style + heavySpan.arg(toFahrenheit(current)) + lightSpan.arg(QString("℉ / %1").arg(toFahrenheit(target))) + lightestSpan.arg("℉");
      case Celsius:
      default:
          return style + heavySpan.arg(current) + lightSpan.arg(QString("℃ / %1").arg(target)) + lightestSpan.arg("℃");
      }
  }
  
  QString Stringer::unusedTemperature()
  {
      switch (temperatureFormat())
      {
      case Fahrenheit:
          return QString("℉");
      case Celsius:
      default:
          return QString("℃");
      }
  }
  
  QString Stringer::unusedTemperature(QString style)
  {
      switch (temperatureFormat())
      {
      case Fahrenheit:
          return style + lightSpan.arg("℉");
      case Celsius:
      default:
          return style + lightSpan.arg("℃");
      }
  }