1/*
2 This file is part of the KDE games library
3 Copyright (C) 2007 Mauricio Piacentini (mauricio@tabuleiro.com)
4 Portions reused from KGameLCDClock
5 Copyright (C) 2001,2002,2003 Nicolas Hadacek (hadacek@kde.org)
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef __KGAMECLOCK_H
23#define __KGAMECLOCK_H
24
25#include <QtCore/QObject>
26#include <libkdegames_export.h>
27
28class KGameClockPrivate;
29
30/**
31 * \class KGameClock kgameclock.h <KGameClock>
32 *
33 * Class representing a game clock, wraps after 24 hours
34 */
35class KDEGAMES_EXPORT KGameClock : public QObject
36{
37 Q_OBJECT
38public:
39 enum ClockType { HourMinSec = 0, MinSecOnly };
40
41 /**
42 * @return Constructor
43 */
44 explicit KGameClock(QObject *parent = 0, ClockType clocktype = HourMinSec);
45
46 virtual ~KGameClock();
47
48 /**
49 * @return the total number of seconds elapsed.
50 */
51 uint seconds() const;
52
53 /**
54 * @return the time as a string to be displayed: "mm:ss" or "hh:mm:ss" depending on clock type.
55 */
56 QString timeString() const;
57
58 /**
59 * Set the time.
60 */
61 void setTime(uint seconds);
62
63 /**
64 * Set the time (format should be "hh:mm:ss").
65 */
66 void setTime(const QString &s);
67
68 /**
69 * Refresh
70 */
71 void showTime();
72
73Q_SIGNALS:
74 void timeChanged(const QString &);
75
76public Q_SLOTS:
77 /**
78 * Reset the clock and start again from zero
79 */
80 virtual void restart();
81
82 /**
83 * Pause the clock
84 */
85 virtual void pause();
86
87 /**
88 * Resume counting time from the current position
89 */
90 virtual void resume();
91
92protected Q_SLOTS:
93 virtual void timeoutClock();
94
95private:
96 friend class KGameClockPrivate;
97 KGameClockPrivate *const d;
98
99 Q_DISABLE_COPY(KGameClock)
100};
101
102#endif
103