File indexing completed on 2024-04-28 04:05:21

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jakob Gruber <jakob.gruber@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ELAPSEDTIME_H
0008 #define ELAPSEDTIME_H
0009 
0010 #include <QDateTime>
0011 
0012 class Time
0013 {
0014 public:
0015     Time(int seconds) : m_seconds(seconds) { }
0016     QString toString(const QString &format = QStringLiteral("%1:%2:%3")) const;
0017 
0018 private:
0019     const int m_seconds;
0020 
0021     static const int m_secs_per_minute = 60;
0022     static const int m_secs_per_hour = 60 * 60;
0023 };
0024 
0025 class ElapsedTime
0026 {
0027 public:
0028     ElapsedTime();
0029 
0030     /* start, stop, or (un)pause the timer */
0031     void start();
0032     void pause(bool paused);
0033     void stop();
0034 
0035     /* adds penalty time and increases the next penalty amount */
0036     void addPenaltyTime();
0037 
0038     /* return elapsed seconds since the datetime when start() was called */
0039     int elapsedSecs() const;
0040     QDateTime startDate() const;
0041 
0042 private:
0043     int currentTimesliceSecs() const;
0044 
0045     QDateTime m_start_date;
0046     int m_elapsed;
0047     qint64 m_start;
0048     bool m_paused, m_stopped;
0049 
0050     int m_next_penalty;
0051     const int m_penalty_multiplier;
0052 };
0053 
0054 #endif // ELAPSEDTIME_H