FotoBox
countdown.h
Go to the documentation of this file.
1 /* countdown.h
2  *
3  * Copyright (c) 2019 Thomas Kais
4  *
5  * This file is subject to the terms and conditions defined in
6  * file 'COPYING', which is part of this source code package.
7  */
8 #ifndef COUNTDOWN_H
9 #define COUNTDOWN_H
10 
11 #include <QObject>
12 #include <QTimer>
13 
14 namespace FotoBox {
15 
20 class Countdown : public QObject
21 {
22  Q_OBJECT
23 
24 public:
30  explicit Countdown(QObject *parent = nullptr, unsigned int i_seconds = 0);
31 
35  ~Countdown() override = default;
36 
40  Countdown(const Countdown &other) = delete;
41 
45  Countdown &operator=(const Countdown &other) = delete;
46 
50  Countdown(Countdown &&other) = delete;
51 
55  Countdown &operator=(Countdown &&other) = delete;
56 
61  void setStartTime(unsigned int i_seconds);
62 
67  auto isActive() const -> bool;
68 
74  auto start() -> bool;
75 
80  auto stop() -> bool;
81 
87  auto reset() -> bool;
88 
89 Q_SIGNALS:
93  void update(unsigned int /*_t1*/);
94 
99  void elapsed();
100 
101 private:
106  void updateTimeLeft();
107 
109  QTimer m_timer;
110 
112  unsigned int m_startTime;
113 
115  unsigned int m_timeLeft;
116 
118  bool m_isActive{false};
119 
121  static constexpr int ONE_SECOND = 1000;
122 };
123 
124 } // end namespace FotoBox
125 
126 #endif // COUNTDOWN_H
The Countdown class.
Definition: countdown.h:21
void setStartTime(unsigned int i_seconds)
Set the countdown start time.
Definition: countdown.cpp:46
static constexpr int ONE_SECOND
Definition: countdown.h:121
auto reset() -> bool
Reset countdown (reset.
Definition: countdown.cpp:88
~Countdown() override=default
Countdown default destructor.
auto start() -> bool
Start countdown.
Definition: countdown.cpp:57
unsigned int m_startTime
Definition: countdown.h:112
Countdown(Countdown &&other)=delete
Countdown default move constructor.
void elapsed()
Countdown elapsed.
auto stop() -> bool
Stop countdown and check.
Definition: countdown.cpp:78
void updateTimeLeft()
Start the timer until there is no time left, means.
Definition: countdown.cpp:25
Countdown(QObject *parent=nullptr, unsigned int i_seconds=0)
Countdown constructor.
Definition: countdown.cpp:12
auto isActive() const -> bool
Show countdown status.
Definition: countdown.cpp:52
Countdown & operator=(Countdown &&other)=delete
Countdown default move assignment.
Countdown & operator=(const Countdown &other)=delete
Countdown default copy assignment.
void update(unsigned int)
Update countdown.
unsigned int m_timeLeft
Definition: countdown.h:115
Countdown(const Countdown &other)=delete
Countdown default copy constructor.