-
Notifications
You must be signed in to change notification settings - Fork 0
/
yoshitimer.cpp
307 lines (291 loc) · 11.3 KB
/
yoshitimer.cpp
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include "yoshitimer.h"
#include <QString>
#include <QDebug>
yoshitimer::yoshitimer(QWidget *parent)
: QWidget(parent)
{
//Style Sheet
setStyleSheet("QPushButton { min-width: 300px; min-height: 75px; border-radius: 6px; border: 2px solid #8f8f91; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #dadbde);}");
// Sound
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
Phonon::createPath(mediaObject, audioOutput);
num = new QLCDNumber(this);
num->setNumDigits(8);
num->setSegmentStyle(QLCDNumber::Filled);
num->setStyleSheet("* {border-radius: 12px; border: 4px solid #ffffff; background-color:rgb(80,110,180);color:rgb(255,255,255);}");
currentExercise = new QLCDNumber(this);
currentExercise->setNumDigits(2);
currentExercise->setSegmentStyle(QLCDNumber::Flat);
currentExercise->setStyleSheet("* {border-radius: 6px; border: 2px solid #8f8f91; background-color:rgb(255,255,255);}");
currentSet = new QLCDNumber(this);
currentSet->setNumDigits(2);
currentSet->setSegmentStyle(QLCDNumber::Flat);
currentSet->setStyleSheet("* {border-radius: 6px; border: 2px solid #8f8f91; background-color:rgb(255,255,255);}");
currentSuperSet = new QLCDNumber(this);
currentSuperSet->setNumDigits(2);
currentSuperSet->setSegmentStyle(QLCDNumber::Flat);
currentSuperSet->setStyleSheet("* {border-radius: 6px; border: 2px solid #8f8f91; background-color:rgb(255,255,255);}");
QLabel *labelCurrentExercise = new QLabel(this);
labelCurrentExercise->setText("Current Exercise:");
QLabel *labelCurrentSet = new QLabel(this);
labelCurrentSet->setText("Current Set:");
QLabel *labelCurrentSuperSet = new QLabel(this);
labelCurrentSuperSet->setText("Current Superset:");
timeSet = new QTime();
timeSet->setHMS(0,0,0,0);
//Start Delay timer
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
//Work timer
workTimer = new QTimer(this);
connect(workTimer, SIGNAL(timeout()), this, SLOT(superSets()));
i=0;
exerciseNumber=1;
setNumber=1;
superSetNumber=1;
workFlag = false;
delayFlag = true;
restFlag = false;
QLabel *labelDelay = new QLabel(this);
labelDelay->setText("Start Delay:");
QLabel *labelWork = new QLabel(this);
labelWork->setText("Workout Time:");
QLabel *labelRest = new QLabel(this);
labelRest->setText("Set Rest Time:");
QLabel *labelRestExercise = new QLabel(this);
labelRestExercise->setText("Exercise Rest Time:");
QLabel *labelExercises = new QLabel(this);
labelExercises->setText("Exercises/Set:");
QLabel *labelSets = new QLabel(this);
labelSets->setText("Sets/Superset:");
QLabel *labelSuperSets = new QLabel(this);
labelSuperSets->setText("Number of Supersets:");
timeEditDelay = new QTimeEdit(this);
timeEditDelay->setDisplayFormat("hh:mm:ss");
timeEditDelay->setStyleSheet("* { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #506eb4);}");
timeEditWork = new QTimeEdit(this);
timeEditWork->setDisplayFormat("hh:mm:ss");
timeEditWork->setStyleSheet("* { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #00ff00);}");
timeEditRest = new QTimeEdit(this);
timeEditRest->setDisplayFormat("hh:mm:ss");
timeEditRest->setStyleSheet("* { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #ff0000);}");
timeEditRestExercise = new QTimeEdit(this);
timeEditRestExercise->setDisplayFormat("hh:mm:ss");
timeEditRestExercise->setStyleSheet("* { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #ffff00);}");
spinBoxExercises = new QSpinBox(this);
spinBoxExercises->setValue(1);
spinBoxSets = new QSpinBox(this);
spinBoxSets->setValue(1);
spinBoxSuperSets = new QSpinBox(this);
spinBoxSuperSets->setValue(1);
layout = new QVBoxLayout(this);
hlayout = new QHBoxLayout(this);
qlayout = new QGridLayout(this);
reset = new QPushButton("Reset",this);
start = new QPushButton("&Start",this);
resume = new QPushButton("&Resume",this);
pause = new QPushButton("&Pause",this);
pause->hide();
resume->hide();
QString text = timeSet->toString("hh:mm:ss");
num->display(text);
connect(reset,SIGNAL(clicked()),this,SLOT(resetTime()));
connect(start,SIGNAL(clicked()),this,SLOT(startTime()));
connect(pause,SIGNAL(clicked()),this,SLOT(pauseTime()));
connect(resume,SIGNAL(clicked()),this,SLOT(resumeTime()));
qlayout->addWidget(labelDelay,0,0,Qt::AlignRight);
qlayout->addWidget(timeEditDelay,0,1);
qlayout->addWidget(labelWork,1,0,Qt::AlignRight);
qlayout->addWidget(timeEditWork,1,1);
qlayout->addWidget(labelRest,2,0,Qt::AlignRight);
qlayout->addWidget(timeEditRest,2,1);
qlayout->addWidget(labelRestExercise,3,0,Qt::AlignRight);
qlayout->addWidget(timeEditRestExercise,3,1);
qlayout->addWidget(labelExercises,4,0,Qt::AlignRight);
qlayout->addWidget(spinBoxExercises,4,1);
qlayout->addWidget(labelSets,5,0,Qt::AlignRight);
qlayout->addWidget(spinBoxSets,5,1);
qlayout->addWidget(labelSuperSets,6,0,Qt::AlignRight);
qlayout->addWidget(spinBoxSuperSets,6,1);
qlayout->addWidget(labelCurrentExercise,0,2,2,1,Qt::AlignRight);
qlayout->addWidget(currentExercise,0,3,2,1,Qt::AlignLeft);
qlayout->addWidget(labelCurrentSet,2,2,2,1,Qt::AlignRight);
qlayout->addWidget(currentSet,2,3,2,1,Qt::AlignLeft);
qlayout->addWidget(labelCurrentSuperSet,4,2,2,1,Qt::AlignRight);
qlayout->addWidget(currentSuperSet,4,3,2,1,Qt::AlignLeft);
hlayout->addWidget(start);
hlayout->addWidget(pause);
hlayout->addWidget(resume);
hlayout->addWidget(reset);
qlayout->addLayout(hlayout,7,0,1,4,Qt::AlignCenter);
layout->addWidget(num);
layout->addLayout(qlayout);
setLayout(layout);
resize(800,400);
}
yoshitimer::~yoshitimer()
{
// No need to delete any object that has a parent which is properly deleted.
}
void yoshitimer::showTime()
{
workTimeoutTime = workTimeoutTime-1000;
QTime newtime;
i=i+1;
newtime=timeSet->addSecs(-i);
QString text = newtime.toString("hh:mm:ss");
num->display(text);
}
void yoshitimer::countDown(int hours, int minutes, int seconds, int timeInterval)
{
timeSet->setHMS(0,0,0);
QString text = timeSet->toString("hh:mm:ss");
num->display(text);
i=0;
timeSet->setHMS(hours, minutes, seconds);
timer->start(1000);
workTimer->start(timeInterval * 1000);
workTimeoutTime = workTimer->interval();
}
void yoshitimer::resetTime()
{
timeSet->setHMS(0,0,0);
QString text = timeSet->toString("hh:mm:ss");
num->display(text);
i=0;
pause->hide();
resume->hide();
start->show();
timer->stop();
workTimer->stop();
exerciseNumber=1;
setNumber=1;
superSetNumber=1;
workFlag = false;
restFlag = false;
delayFlag = true;
currentExercise->display(0);
currentSet->display(0);
currentSuperSet->display(0);
num->setStyleSheet("* {border-radius: 12px; border: 4px solid #ffffff; background-color:rgb(80,110,180);color:rgb(255,255,255);}");
}
void yoshitimer::startTime()
{
start->hide();
pause->show();
setValue = spinBoxSets->value();
exerciseValue = spinBoxExercises->value();
superSetValue = spinBoxSuperSets->value();
superSets();
}
void yoshitimer::pauseTime()
{
pause->hide();
start->hide();
resume->show();
timer->stop();
workTimer->stop();
}
void yoshitimer::resumeTime()
{
pause->show();
start->hide();
resume->hide();
timer->start();
workTimer->start(workTimeoutTime);
}
void yoshitimer::superSets()
{
if (superSetNumber <= superSetValue && !delayFlag) {
currentSuperSet->display(superSetNumber);
sets();
} else if (superSetNumber <= superSetValue && delayFlag) {
workFlag = true;
delayFlag = false;
delay();
} else {
resetTime();
mediaObject->setCurrentSource(Phonon::MediaSource("Sounds/youaredoneeverything.wav"));
mediaObject->play();
}
}
void yoshitimer::sets()
{
if (setNumber <= setValue && !restFlag) {
currentSet->display(setNumber);
rounds();
} else if (restFlag){
rest();
restFlag = false;
} else {
delayFlag = true;
setNumber=1;
currentSet->display(0);
superSetNumber++;
superSets();
}
}
void yoshitimer::rounds()
{
if (exerciseNumber <= exerciseValue && !restExerciseFlag) {
currentExercise->display(exerciseNumber);
work();
workFlag = false;
restExerciseFlag = true;
} else if (restExerciseFlag && !workFlag && exerciseNumber < exerciseValue) {
exerciseNumber++;
restExercise();
restExerciseFlag = false;
workFlag = true;
} else {
restExerciseFlag = false;
restFlag = true;
exerciseNumber=1;
currentExercise->display(0);
setNumber++;
sets();
}
}
void yoshitimer::delay()
{
QTime delayTime = timeEditDelay->time();
int delaySeconds = (delayTime.hour() * 3600) + (delayTime.minute() * 60) + delayTime.second();
num->setStyleSheet("* {border-radius: 12px; border: 4px solid #ffffff; background-color:rgb(80,110,180);color:rgb(255,255,255);}");
mediaObject->setCurrentSource(Phonon::MediaSource("Sounds/getready.wav"));
mediaObject->play();
countDown(timeEditDelay->time().hour(), timeEditDelay->time().minute(), timeEditDelay->time().second(), delaySeconds);
}
void yoshitimer::work()
{
timer->stop();
workTimer->stop();
QTime delayTime = timeEditWork->time();
int workSeconds = (delayTime.hour() * 3600) + (delayTime.minute() * 60) + delayTime.second();
num->setStyleSheet("* {border-radius: 12px; border: 4px solid #000000; background-color:rgb(0,255,0);color:rgb(255,255,255);}");
mediaObject->setCurrentSource(Phonon::MediaSource("Sounds/work.wav"));
mediaObject->play();
countDown(timeEditWork->time().hour(), timeEditWork->time().minute(), timeEditWork->time().second(), workSeconds);
}
void yoshitimer::rest()
{
timer->stop();
workTimer->stop();
QTime delayTime = timeEditRest->time();
int restSeconds = (delayTime.hour() * 3600) + (delayTime.minute() * 60) + delayTime.second();
num->setStyleSheet("* {border-radius: 12px; border: 4px solid #000000; background-color:rgb(255,0,0);color:rgb(255,255,255);}");
mediaObject->setCurrentSource(Phonon::MediaSource("Sounds/setcompleted.wav"));
mediaObject->play();
countDown(timeEditRest->time().hour(), timeEditRest->time().minute(), timeEditRest->time().second(), restSeconds);
}
void yoshitimer::restExercise()
{
timer->stop();
workTimer->stop();
QTime delayTime = timeEditRestExercise->time();
int restExerciseSeconds = (delayTime.hour() * 3600) + (delayTime.minute() * 60) + delayTime.second();
num->setStyleSheet("* {border-radius: 12px; border: 4px solid #000000; background-color:rgb(255,255,0);color:rgb(255,255,255);}");
mediaObject->setCurrentSource(Phonon::MediaSource("Sounds/pleaserest.wav"));
mediaObject->play();
countDown(timeEditRestExercise->time().hour(), timeEditRestExercise->time().minute(), timeEditRestExercise->time().second(), restExerciseSeconds);
}