stringer.cpp
6.74 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#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;
}
enum RealTimeFormat { Hour12, Hour24 };
RealTimeFormat realTimeFormat()
{
Define::config_item item = Config::getInstance()->getConfigValue(Define::config_time_type);
switch (item.d32)
{
case Define::time_type_12h:
return Hour12;
case Define::time_type_24h:
default:
return Hour24;
}
}
}
QString Stringer::remainingTime(int msecs)
{
switch (::remainingTime())
{
case RemainingTime:
msecs /= 1000;
if (msecs >= 3600)
return QCoreApplication::tr("%1시간 %2분").arg(msecs / 3600).arg((msecs % 3600) / 60, 2, 10, QLatin1Char('0'));
if (msecs >= 60)
return QCoreApplication::tr("%1분 %2초").arg(msecs / 60).arg(msecs % 60, 2, 10, QLatin1Char('0'));
return QCoreApplication::tr("%1초").arg(msecs);
case FinishTime:
QDateTime dateTime = QDateTime::currentDateTime().addMSecs(msecs);
switch (realTimeFormat())
{
case Hour12:
return dateTime.toString("A hh:mm:ss");
case Hour24:
return dateTime.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(QCoreApplication::tr("시간"));
QString min = heavySpan.arg((msecs % 3600) / 60, 2, 10, QLatin1Char('0')) + lightSpan.arg(QCoreApplication::tr("분"));
return style + QString("%1 %2").arg(hour).arg(min);
}
if (msecs >= 60)
{
QString min = heavySpan.arg(msecs / 60) + lightSpan.arg(QCoreApplication::tr("분"));
QString sec = heavySpan.arg(msecs % 60, 2, 10, QLatin1Char('0')) + lightSpan.arg(QCoreApplication::tr("초"));
return style + QString("%1 %2").arg(min).arg(sec);
}
return style + heavySpan.arg(msecs) + lightSpan.arg(QCoreApplication::tr("초"));
case FinishTime:
QDateTime dateTime = QDateTime::currentDateTime().addMSecs(msecs);
switch (realTimeFormat())
{
case Hour12:
return heavySpan.arg(dateTime.toString("A hh:mm:ss"));
case Hour24:
return heavySpan.arg(dateTime.toString("HH:mm:ss"));
}
}
return QString();
}
QString Stringer::remainingTime(qint64 msecs)
{
switch (::remainingTime())
{
case RemainingTime:
msecs /= 1000;
if (msecs >= 3600)
return QCoreApplication::tr("%1시간 %2분").arg(msecs / 3600).arg((msecs % 3600) / 60, 2, 10, QLatin1Char('0'));
if (msecs >= 60)
return QCoreApplication::tr("%1분 %2초").arg(msecs / 60).arg(msecs % 60, 2, 10, QLatin1Char('0'));
return QCoreApplication::tr("%1초").arg(msecs);
case FinishTime:
QDateTime dateTime = QDateTime::currentDateTime().addMSecs(msecs);
switch (realTimeFormat())
{
case Hour12:
return dateTime.toString("A hh:mm:ss");
case Hour24:
return dateTime.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("℃");
}
}
QString Stringer::dateTime(const QDateTime &dateTime, DateTimeType type)
{
Define::config_item item = Config::getInstance()->getConfigValue(Define::config_time_type);
switch(item.d32)
{
case Define::time_type_12h:
if (type == OneLine)
return dateTime.toString("yy-MM-dd a hh:mm");
else
return dateTime.toString("yy-MM-dd\na hh:mm");
case Define::time_type_24h:
default:
if (type == OneLine)
return dateTime.toString("yy-MM-dd HH:mm");
else
return dateTime.toString("yy-MM-dd\nHH:mm");
}
}
QString Stringer::time(int msecs)
{
int t = qCeil(msecs / 1000.0);
int h = t / (60*60);
int m = (t/60) % 60;
int s = t % 60;
return QString("%1:%2:%3")
.arg(h, 2, 10, QLatin1Char('0'))
.arg(m, 2, 10, QLatin1Char('0'))
.arg(s, 2, 10, QLatin1Char('0'));
}