7#include "MarbleClock.h"
8#include "MarbleDebug.h"
16class MarbleClockPrivate
27 explicit MarbleClockPrivate(MarbleClock *parent);
32MarbleClockPrivate::MarbleClockPrivate(MarbleClock *parent)
35 , m_datetime(
QDateTime::currentDateTimeUtc())
36 , m_lasttime(
QDateTime::currentDateTimeUtc())
38 , m_updateInterval(60)
43void MarbleClockPrivate::timerTimeout()
47 int msecdelta = m_lasttime.msecsTo(curenttime);
48 m_lasttime = curenttime;
51 m_datetime = m_datetime.addMSecs(msecdelta * m_speed);
54 Q_EMIT q->timeChanged();
57 int sleeptime = (m_updateInterval * 1000 - (qreal)(m_datetime.time().msec() + m_datetime.time().second() * 1000)) / m_speed;
58 if (sleeptime < 1000) {
62 m_timer.start(sleeptime);
67MarbleClock::MarbleClock(
QObject *parent)
69 , d(new MarbleClockPrivate(this))
72 connect(&d->m_timer, SIGNAL(timeout()),
this, SLOT(timerTimeout()));
76MarbleClock::~MarbleClock()
81qreal MarbleClock::dayFraction()
const
83 qreal fraction = d->m_datetime.time().second();
84 fraction = fraction / 60.0 + d->m_datetime.time().minute();
85 fraction = fraction / 60.0 + d->m_datetime.time().hour();
86 fraction = fraction / 24.0;
90void MarbleClock::setDateTime(
const QDateTime &datetime)
92 d->m_datetime = datetime;
101void MarbleClock::setUpdateInterval(
int seconds)
103 d->m_updateInterval = seconds;
104 Q_EMIT updateIntervalChanged(seconds);
107int MarbleClock::updateInterval()
const
109 return d->m_updateInterval;
112int MarbleClock::speed()
const
117void MarbleClock::setSpeed(
int speed)
123int MarbleClock::timezone()
const
125 return d->m_timezoneInSec;
128void MarbleClock::setTimezone(
int timezoneInSec)
130 d->m_timezoneInSec = timezoneInSec;
135#include "moc_MarbleClock.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
QDateTime currentDateTimeUtc()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)