File indexing completed on 2024-05-12 12:03:35
0001 /* 0002 This file is part of the KDE games library 0003 SPDX-FileCopyrightText: 2007 Mauricio Piacentini <mauricio@tabuleiro.com> 0004 Portions reused from KGameLCDClock 0005 SPDX-FileCopyrightText: 2001, 2002, 2003 Nicolas Hadacek <hadacek@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-only 0008 */ 0009 0010 #ifndef __KGAMECLOCK_H 0011 #define __KGAMECLOCK_H 0012 0013 // own 0014 #include "kdegames_export.h" 0015 // Qt 0016 #include <QObject> 0017 // Std 0018 #include <memory> 0019 0020 class KGameClockPrivate; 0021 0022 /** 0023 * \class KGameClock kgameclock.h <KGameClock> 0024 * 0025 * Class representing a game clock 0026 */ 0027 class KDEGAMES_EXPORT KGameClock : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * Controls the format of return value of @ref timeString() 0034 * Format Example1 Example2 0035 * --------------------------------------- 0036 * HourMinSec 00:04:05 01:02:03 0037 * MinSecOnly 04:05 02:03 0038 * FlexibleHourMinSec 04:05 01:02:03 0039 * LongMinSec 04:05 62:03 0040 */ 0041 enum ClockType { 0042 HourMinSec = 0, 0043 MinSecOnly = 1, 0044 FlexibleHourMinSec = 2, ///< @since 22.04 0045 LongMinSec = 3, ///< @since 22.04 0046 }; 0047 0048 /** 0049 * @return Constructor 0050 */ 0051 explicit KGameClock(QObject *parent = nullptr, ClockType clocktype = HourMinSec); 0052 0053 ~KGameClock() override; 0054 0055 /** 0056 * @return the total number of seconds elapsed. 0057 */ 0058 uint seconds() const; 0059 0060 /** 0061 * @return the time as a string to be displayed: "mm:ss" or "hh:mm:ss" depending on clock type. 0062 */ 0063 QString timeString() const; 0064 0065 /** 0066 * Set the time. 0067 */ 0068 void setTime(uint seconds); 0069 0070 /** 0071 * Set the time. Format should be "hh:mm:ss" (or "mm:ss" @since 22.04). 0072 */ 0073 void setTime(const QString &s); 0074 0075 /** 0076 * Refresh 0077 */ 0078 void showTime(); 0079 0080 Q_SIGNALS: 0081 void timeChanged(const QString &); 0082 0083 public Q_SLOTS: 0084 /** 0085 * Reset the clock and start again from zero 0086 */ 0087 virtual void restart(); 0088 0089 /** 0090 * Pause the clock 0091 */ 0092 virtual void pause(); 0093 0094 /** 0095 * Resume counting time from the current position 0096 */ 0097 virtual void resume(); 0098 0099 protected Q_SLOTS: 0100 virtual void timeoutClock(); 0101 0102 private: 0103 friend class KGameClockPrivate; 0104 std::unique_ptr<KGameClockPrivate> const d_ptr; 0105 Q_DECLARE_PRIVATE(KGameClock) 0106 0107 Q_DISABLE_COPY(KGameClock) 0108 }; 0109 0110 #endif