/***************************************************************************
 *   Copyright (C) 2004 by Kraschinski Arnold                              *
 *   arnold.kra67@gmx.de                                                   *
 *                                                                         *
 *   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 Steet, Fifth Floor, Boston, MA 02110-1301, USA.           *
 ***************************************************************************/
#ifndef QTIMERVIEW_H
#define QTIMERVIEW_H

#include <QWidget>
#include <QPixmap>
#include <QSize>

class QTimer;

/** The class belongs to the set of classes which give a feedback to the
    learning person. The timer can be used in two modes. First he can count
    the time the person is learning. That means he is counting upwards. Or
    he can start at with some time and count the remaining time downwards. At
    the end the class emits a signal that the time has expired.
    
    If the time is running the QTimerView has a QTimer in the member timer.
    If the time isn't running the member timer is 0
  
  @author Arnold Kraschinski
  */
class QTimerView : public QWidget
{
Q_OBJECT
public:
    QTimerView(QWidget *parent = 0);

    ~QTimerView();
    
    virtual QSize sizeHint() const { return QSize(TIMER_WIDTH, TIMER_HEIGHT); };
    
    /** Starts the timer. This is not a restart. m_seconds will be resetted.
     */
    void startExercise(bool up = true, int seconds = 0);
    
    /** Returns the number of the seconds until the timeout or from the
      * beginning of the exercise depending on the direction m_up
      */
    int getSeconds() { return m_seconds; };
    int getTotalSeconds() { return m_totalSeconds; };
    
    /** Returns if the timer is running
      */
    bool isRunning() { return (m_timer != 0); };
    
public slots:
    /** Starts the timer. This can be a restart, too.
     */
    void slotStartTimer();
    /** Stops the timer but doesn't reset it. So the timer can make a break
     * if a new file with tasks or another picture for the puzzle has to
     * be selected.
     */
    void slotStopTimer();

protected:
    /** A clock is painted and the time that has elapsed is
      * shown as a segment of a circle
      */
    virtual void paintEvent(QPaintEvent* e);

private slots:
    /** This slot is connected with the timer object m_timer.
      */
    void slotTimeout();

signals:
    /** The signal will be emitted when the timer starts. This signal
      * can be connected to all the objects that need to know when the 
      * timer starts
      */
    void signalTimerStarted();
    
    /** The signal will be emitted when the timer stops. This signal
      * can be connected to all the objects that need to know when the
      * timer stops
      */
    void signalTimerStoped();
    
    /** The signal indicates that the timer has counted downwards until 0.
      */
    void signalTimeout();

private:
    /** the timer sends every second a signal to this class */
    QTimer*                 m_timer;
    /** the seconds that the timerview is counting for the running exercise */
    int                     m_seconds;
    /** the seconds that the timerview was used since it was created */
    int                     m_totalSeconds;
    /** if m_up is true the timer is counting the time upwards, otherwise it is
      * counting down until it reaches 0.
      */
    bool                    m_up;
    /** The picture for the clock */
    QPixmap                 m_clock;
    /** The width for the timer widget */
    static const int        TIMER_WIDTH;
    /** The height for the timer widget */
    static const int        TIMER_HEIGHT;
};

#endif
