File indexing completed on 2024-04-21 03:49:28

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
0004 //
0005 
0006 #include "AnimatedUpdateTrack.h"
0007 
0008 #include "PlaybackAnimatedUpdateItem.h"
0009 
0010 namespace Marble
0011 {
0012 
0013 AnimatedUpdateTrack::AnimatedUpdateTrack( PlaybackAnimatedUpdateItem* item )
0014 {
0015     m_item = item;
0016     m_progress = 0;
0017     m_delayBeforeTrackStarts = 0;
0018     m_paused = true;
0019     connect( &m_timer, SIGNAL(timeout()), this, SLOT(playSlot()) );
0020     connect( m_item, SIGNAL(balloonHidden()), this, SIGNAL(balloonHidden()) );
0021     connect( m_item, SIGNAL(balloonShown(GeoDataPlacemark*)), this, SIGNAL(balloonShown(GeoDataPlacemark*)) );
0022     connect( m_item, SIGNAL(updated(GeoDataFeature*)), this, SIGNAL(updated(GeoDataFeature*)) );
0023     connect( m_item, SIGNAL(added(GeoDataContainer*,GeoDataFeature*,int)), this, SIGNAL(added(GeoDataContainer*,GeoDataFeature*,int)) );
0024     connect( m_item, SIGNAL(removed(const GeoDataFeature*)), this, SIGNAL(removed(const GeoDataFeature*)) );
0025 }
0026 
0027 void AnimatedUpdateTrack::setDelayBeforeTrackStarts( double delay )
0028 {
0029     m_delayBeforeTrackStarts = delay;
0030     m_timer.setSingleShot( true );
0031     m_timer.setInterval( m_delayBeforeTrackStarts * 1000 );
0032 }
0033 
0034 double AnimatedUpdateTrack::delayBeforeTrackStarts() const
0035 {
0036     return m_delayBeforeTrackStarts;
0037 }
0038 
0039 void AnimatedUpdateTrack::play()
0040 {
0041     m_paused = false;
0042     m_playTime = QDateTime::currentDateTime();
0043     if( m_progress <= m_delayBeforeTrackStarts ){
0044         m_timer.start( ( m_delayBeforeTrackStarts - m_progress ) * 1000 );
0045     } else {
0046         m_item->play();
0047     }
0048 }
0049 
0050 void AnimatedUpdateTrack::playSlot()
0051 {
0052     m_item->play();
0053 }
0054 
0055 void AnimatedUpdateTrack::pause()
0056 {
0057     m_paused = true;
0058     m_pauseTime = QDateTime::currentDateTime();
0059     m_progress += m_playTime.secsTo( m_pauseTime );
0060     if( m_timer.isActive() ){
0061         m_timer.stop();
0062     } else {
0063         m_item->pause();
0064     }
0065 }
0066 
0067 void AnimatedUpdateTrack::seek( double offset )
0068 {
0069     m_timer.stop();
0070     m_progress = offset;
0071     m_playTime = QDateTime::currentDateTime().addMSecs( -offset * 1000 );
0072 
0073     if( offset <= m_delayBeforeTrackStarts ){
0074         if( !m_paused ){
0075             m_pauseTime = QDateTime();
0076             m_item->stop();
0077             m_timer.start( ( m_delayBeforeTrackStarts - m_progress ) * 1000 );
0078         } else {
0079             m_pauseTime = QDateTime::currentDateTime();
0080             m_item->stop();
0081         }
0082     } else {
0083         if( !m_paused ){
0084             m_pauseTime = QDateTime();
0085             m_item->seek( offset - m_delayBeforeTrackStarts );
0086         } else {
0087             m_pauseTime = QDateTime::currentDateTime();
0088             m_item->stop();
0089             m_item->seek( offset - m_delayBeforeTrackStarts );
0090         }
0091     }
0092 }
0093 
0094 void AnimatedUpdateTrack::stop()
0095 {
0096     m_paused = true;
0097     m_item->stop();
0098     m_timer.stop();
0099     m_playTime = QDateTime();
0100     m_pauseTime = QDateTime();
0101     m_progress = 0;
0102 }
0103 
0104 void AnimatedUpdateTrack::setPaused( bool pause )
0105 {
0106     m_paused = pause;
0107 }
0108 
0109 }
0110 
0111 #include "moc_AnimatedUpdateTrack.cpp"