KDEGames

kgameclock.h
1/*
2 This file is part of the KDE games library
3 SPDX-FileCopyrightText: 2007 Mauricio Piacentini <mauricio@tabuleiro.com>
4 Portions reused from KGameLCDClock
5 SPDX-FileCopyrightText: 2001, 2002, 2003 Nicolas Hadacek <hadacek@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-only
8*/
9
10#ifndef __KGAMECLOCK_H
11#define __KGAMECLOCK_H
12
13// own
14#include "kdegames_export.h"
15// Qt
16#include <QObject>
17// Std
18#include <memory>
19
20class KGameClockPrivate;
21
22/**
23 * \class KGameClock kgameclock.h <KGameClock>
24 *
25 * Class representing a game clock
26 */
27class KDEGAMES_EXPORT KGameClock : public QObject
28{
29 Q_OBJECT
30
31public:
32 /**
33 * Controls the format of return value of @ref timeString()
34 * Format Example1 Example2
35 * ---------------------------------------
36 * HourMinSec 00:04:05 01:02:03
37 * MinSecOnly 04:05 02:03
38 * FlexibleHourMinSec 04:05 01:02:03
39 * LongMinSec 04:05 62:03
40 */
41 enum ClockType {
42 HourMinSec = 0,
43 MinSecOnly = 1,
44 FlexibleHourMinSec = 2, ///< @since 22.04
45 LongMinSec = 3, ///< @since 22.04
46 };
47
48 /**
49 * @return Constructor
50 */
51 explicit KGameClock(QObject *parent = nullptr, ClockType clocktype = HourMinSec);
52
53 ~KGameClock() override;
54
55 /**
56 * @return the total number of seconds elapsed.
57 */
58 uint seconds() const;
59
60 /**
61 * @return the time as a string to be displayed: "mm:ss" or "hh:mm:ss" depending on clock type.
62 */
63 QString timeString() const;
64
65 /**
66 * Set the time.
67 */
68 void setTime(uint seconds);
69
70 /**
71 * Set the time. Format should be "hh:mm:ss" (or "mm:ss" @since 22.04).
72 */
73 void setTime(const QString &s);
74
75 /**
76 * Refresh
77 */
78 void showTime();
79
81 void timeChanged(const QString &);
82
83public Q_SLOTS:
84 /**
85 * Reset the clock and start again from zero
86 */
87 virtual void restart();
88
89 /**
90 * Pause the clock
91 */
92 virtual void pause();
93
94 /**
95 * Resume counting time from the current position
96 */
97 virtual void resume();
98
99protected Q_SLOTS:
100 virtual void timeoutClock();
101
102private:
103 friend class KGameClockPrivate;
104 std::unique_ptr<KGameClockPrivate> const d_ptr;
105 Q_DECLARE_PRIVATE(KGameClock)
106
107 Q_DISABLE_COPY(KGameClock)
108};
109
110#endif
Class representing a game clock.
Definition kgameclock.h:28
ClockType
Controls the format of return value of timeString()
Definition kgameclock.h:41
Q_SCRIPTABLE Q_NOREPLY void pause()
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.