-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivitysequence.cpp
More file actions
61 lines (47 loc) · 1.53 KB
/
activitysequence.cpp
File metadata and controls
61 lines (47 loc) · 1.53 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
#include "activitysequence.h"
#include "activity.h"
#include <QTimer>
#include <QDebug>
ActivitySequence::ActivitySequence(QObject *parent) : QObject(parent) {
activityTimer = new QTimer();
activityTimer->setSingleShot(true);
connect(activityTimer, SIGNAL(timeout()), this, SLOT(gotoNextActivity()));
this->currentActivityIndex = 0;
}
void ActivitySequence::setActivities(const QList<Activity*> activities) {
this->activities = activities;
this->currentActivityIndex = 0;
}
void ActivitySequence::gotoNextActivity() {
// Fetch next activity
int nextIndex = (currentActivityIndex < activities.size() - 1) ? currentActivityIndex + 1 : 0;
Activity* newActivity = activities.at(nextIndex);
// Set new activity active
activityTimer->start(newActivity->getDuration() * TIME_BASE);
currentActivityIndex = nextIndex;
activityTriggered(newActivity);
}
void ActivitySequence::start() {
if (activities.size() > 0) {
gotoNextActivity();
}
}
Activity* ActivitySequence::getCurrentActivity() {
if (currentActivityIndex < activities.size()) {
return activities.at(currentActivityIndex);
} else {
return NULL;
}
}
float ActivitySequence::getCurrentActivityProgress() {
if (!activityTimer->isActive()) {
return 0;
}
Activity* currentActivity = getCurrentActivity();
if (currentActivity == NULL) {
return 0;
}
float remaining = (float) (activityTimer->remainingTime());
float total = (float) (currentActivity->getDuration() * TIME_BASE);
return (total - remaining) / total;
}