7#include "MarbleClock.h"
8#include "MarbleDebug.h"
15class MarbleClockPrivate
26 explicit MarbleClockPrivate( MarbleClock* parent );
31MarbleClockPrivate::MarbleClockPrivate( MarbleClock* parent ) :
34 m_datetime(
QDateTime::currentDateTimeUtc() ),
35 m_lasttime(
QDateTime::currentDateTimeUtc() ),
37 m_updateInterval( 60 )
42void MarbleClockPrivate::timerTimeout()
46 int msecdelta = m_lasttime.msecsTo( curenttime );
47 m_lasttime = curenttime;
50 m_datetime = m_datetime.addMSecs( msecdelta * m_speed );
53 emit q->timeChanged();
56 int sleeptime = ( m_updateInterval * 1000 - (qreal)(m_datetime.time().msec() + m_datetime.time().second() * 1000 ) ) / m_speed;
57 if ( sleeptime < 1000 ) {
61 m_timer.start( sleeptime );
66MarbleClock::MarbleClock(
QObject* parent )
67 :
QObject( parent ), d( new MarbleClockPrivate( this ) )
70 connect( &d->m_timer, SIGNAL(timeout()),
71 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 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)