2012-01-20 21:27:53 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2012 Olivier Teulière
|
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TIMER_WIDGET_H_
|
|
|
|
#define TIMER_WIDGET_H_
|
|
|
|
|
2013-09-25 22:23:01 +02:00
|
|
|
#include <QLCDNumber>
|
2012-01-20 21:27:53 +01:00
|
|
|
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
|
|
|
|
|
|
class QTimer;
|
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
|
|
|
|
/// Helper class, used to synchronize the various instances of TimerWidget
|
|
|
|
class TimerModel : public QObject
|
2012-01-20 21:27:53 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT;
|
2012-02-18 22:26:52 +01:00
|
|
|
DEFINE_LOGGER();
|
2012-01-20 21:27:53 +01:00
|
|
|
|
|
|
|
public:
|
2012-01-26 20:57:43 +01:00
|
|
|
TimerModel(int iTotalDuration, int iAlertDuration);
|
2012-01-20 21:27:53 +01:00
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
// Accessors
|
|
|
|
int getValue() const { return m_remaining; }
|
|
|
|
void setValue(int iNewValue);
|
2013-01-10 20:56:10 +01:00
|
|
|
int getElapsed() const { return m_totalDuration - m_remaining; }
|
2012-01-20 21:27:53 +01:00
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
int getTotalDuration() const { return m_totalDuration; }
|
2012-01-20 21:27:53 +01:00
|
|
|
void setTotalDuration(int iSeconds);
|
2012-01-21 11:04:04 +01:00
|
|
|
|
|
|
|
int getAlertDuration() const { return m_alertDuration; }
|
2012-01-20 21:27:53 +01:00
|
|
|
void setAlertDuration(int iSeconds);
|
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
bool wasAlertTriggered() const { return m_alertTriggered; }
|
|
|
|
bool isExpired() const { return m_remaining == 0; }
|
|
|
|
|
2013-01-10 01:55:41 +01:00
|
|
|
bool isChronoMode() const { return m_chronoMode; }
|
|
|
|
void setChronoMode(bool iChrono);
|
|
|
|
|
2012-02-21 08:17:29 +01:00
|
|
|
bool isActiveTimer() const;
|
|
|
|
|
|
|
|
public slots:
|
2012-01-21 11:04:04 +01:00
|
|
|
// Timer handling
|
|
|
|
void startTimer();
|
|
|
|
void pauseTimer();
|
|
|
|
void resetTimer();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void valueChanged(int iNewValue);
|
|
|
|
void alert(int iRemainingSeconds);
|
|
|
|
void expired();
|
|
|
|
void timerReset();
|
|
|
|
void newTotalDuration(int iNewTotal);
|
|
|
|
|
2012-01-20 21:27:53 +01:00
|
|
|
private slots:
|
|
|
|
void updateTime();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Total duration of the timer, in seconds
|
|
|
|
int m_totalDuration;
|
|
|
|
|
|
|
|
/// Alert duration of the timer, in seconds (must be lower than the total duration)
|
|
|
|
int m_alertDuration;
|
|
|
|
|
|
|
|
/// Number of remaining seconds
|
|
|
|
int m_remaining;
|
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
/// Indicate whether we triggered an alert
|
|
|
|
bool m_alertTriggered;
|
|
|
|
|
2013-01-10 01:55:41 +01:00
|
|
|
/// Indicate whether to show the remaining time or elapsed time
|
|
|
|
bool m_chronoMode;
|
|
|
|
|
2012-01-20 21:27:53 +01:00
|
|
|
/// Timer used for the countdown
|
|
|
|
QTimer *m_timer;
|
2012-01-21 11:04:04 +01:00
|
|
|
};
|
2012-01-20 21:27:53 +01:00
|
|
|
|
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
class TimerWidget : public QLCDNumber
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
DEFINE_LOGGER();
|
2012-01-20 21:27:53 +01:00
|
|
|
|
2012-01-21 11:04:04 +01:00
|
|
|
public:
|
|
|
|
TimerWidget(QWidget *parent, TimerModel &iTimerModel);
|
|
|
|
|
|
|
|
private slots:
|
2012-01-20 21:27:53 +01:00
|
|
|
/// Format the given time and display it
|
|
|
|
void displayTime(int iSeconds);
|
2012-01-21 11:04:04 +01:00
|
|
|
|
|
|
|
void newTotalDuration(int iNewTotal);
|
|
|
|
void alertTriggered();
|
|
|
|
void timerReset();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Events handling
|
|
|
|
virtual void mousePressEvent(QMouseEvent*);
|
|
|
|
virtual void mouseDoubleClickEvent(QMouseEvent*);
|
|
|
|
/// Define a default size
|
|
|
|
virtual QSize sizeHint() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Model representing the number of remaining seconds
|
|
|
|
TimerModel &m_model;
|
2012-01-20 21:27:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|