-
Notifications
You must be signed in to change notification settings - Fork 4
/
Alarm.h
159 lines (132 loc) · 4.08 KB
/
Alarm.h
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
/*
File: Alarm.h
Created on: 04/07/2015
Author: Felix de las Pozas Alvarez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ALARM_H_
#define ALARM_H_
// Qt
#include <QTimer>
#include <QTime>
/** \class Alarm
* \brief Holds alarm timer and sends the progression signals.
*
*/
class Alarm
: public QObject
{
Q_OBJECT
public:
/** \brief AlarmTime struct holds the time information.
*
*/
struct AlarmTime
{
int days;
int hours;
int minutes;
int seconds;
explicit AlarmTime(int d, int h, int m, int s): days{d}, hours{h}, minutes{m}, seconds{s} {};
QString text() const;
};
/** \brief Alarm class constructor.
* \param[in] seconds duration of the alarm in seconds.
* \param[in] loop true to loop the alarm.
* \param[in] parent raw pointer of the QObject parent of this one.
*
*/
explicit Alarm(AlarmTime time, bool loop);
/** \brief Alarm class virtual destructor.
*
*/
virtual ~Alarm()
{};
/** \brief Starts the alarm.
*
*/
void start();
/** \brief Stops the alarm.
*
*/
void stop();
/** \brief Pauses/resumes the alarm.
* \param[in] paused true to pause and false otherwise.
*
*/
void pause(bool paused);
/** \brief Returns true if the timer is active.
*
*/
bool isRunning() const;
/** \brief Returns the progress of the alarm in the range [0-100].
*
*/
unsigned int progress() const;
/** \brief Returns the progress of the alarm in the range [0.0-100.0].
*
*/
double precisionProgress() const;
/** \brief Returns the number of completed 1/8th intervals of the alarm completed.
*
*/
unsigned int completedIntervals() const;
/** \brief Returns the remaining time of the alarm.
*
*/
const AlarmTime remainingTime() const;
/** \brief Returns the duration of the alarm.
*
*/
const AlarmTime time() const;
/** \brief Returns the remaining time as a QString.
*
*/
QString remainingTimeText() const;
signals:
/** \brief Signal launched every second.
*
*/
void tic();
/** \brief Signal launched every completed interval. (1/8 th of the duration of the alarm).
* \param[out] value completed intervals in range [1,8].
*
*/
void interval(int value);
/** \brief Signal launched at the end of the alarm.
*
*/
void timeout();
/** \brief Signals the progress of the alarm in a range [0-100]
* \param[out] value progress value in range [0-100].
*
*/
void progress(int value);
private slots:
/** \brief Updates the alarm internal values.
*
*/
void second();
private:
/** \brief computes progress and completed intervals.
*
*/
void computeProgressValues();
AlarmTime m_time; /** duration of the timer/clock. */
AlarmTime m_remainingTime; /** remaining time of the timer/clock */
bool m_loop; /** true to restart the alarm once it finishes. */
unsigned int m_intervals; /** number of completed intervals. */
int m_progress; /** completed time of the alarm. */
double m_dProgress; /** completed time of the alarm with decimals. */
QTimer m_timer; /** timer object. */
};
#endif // ALARM_H_