KGameClock Class

Class representing a game clock. More...

Header: #include <KGameClock>
Inherits: QObject

Public Types

enum ClockType { HourMinSec, MinSecOnly, FlexibleHourMinSec, LongMinSec }

Public Functions

KGameClock(QObject *parent = nullptr, KGameClock::ClockType clocktype = HourMinSec)
uint seconds() const
void setTime(const QString &s)
void setTime(uint seconds)
void showTime()
QString timeString() const

Public Slots

virtual void pause()
virtual void restart()
virtual void resume()

Signals

void timeChanged(const QString &)

Protected Slots

virtual void timeoutClock()

Detailed Description

This class represents a game clock.

Member Type Documentation

enum KGameClock::ClockType

Controls the format of the return value of timeString().

FormatExample1Example2
HourMinSec00:04:0501:02:03
MinSecOnly04:0502:03
FlexibleHourMinSec04:0501:02:03
LongMinSec04:0562:03
ConstantValueDescription
KGameClock::HourMinSec0Time in hours, minutes, and seconds.
KGameClock::MinSecOnly1Time in minutes and seconds, minus any hours.
KGameClock::FlexibleHourMinSec (since 22.04)2Time in minutes and seconds, with hours if necessary.
KGameClock::LongMinSec (since 22.04)3Time in total minutes and seconds.

Member Function Documentation

[explicit] KGameClock::KGameClock(QObject *parent = nullptr, KGameClock::ClockType clocktype = HourMinSec)

Constructs a KGameClock with parent, clocktype.

[virtual slot] void KGameClock::pause()

Pauses the clock.

[virtual slot] void KGameClock::restart()

Resets the clock and starts again from zero.

[virtual slot] void KGameClock::resume()

Resumes counting time from the current position.

uint KGameClock::seconds() const

Returns the total number of seconds elapsed.

void KGameClock::setTime(const QString &s)

Sets the time to s, format should be "hh:mm:ss" (or "mm:ss" since 22.04).

void KGameClock::setTime(uint seconds)

Sets the time to seconds.

void KGameClock::showTime()

Refreshes the time by emitting timeChanged.

[signal] void KGameClock::timeChanged(const QString &)

When showTime() is called, emits the value of timeString().

QString KGameClock::timeString() const

Returns the time as a string to be displayed: "mm:ss" or "hh:mm:ss" depending on clock type.

[virtual protected slot] void KGameClock::timeoutClock()