1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
4 //
5
6 #include "AnimatedUpdateTrack.h"
7
8 #include "PlaybackAnimatedUpdateItem.h"
9
10 namespace Marble
11 {
12
AnimatedUpdateTrack(PlaybackAnimatedUpdateItem * item)13 AnimatedUpdateTrack::AnimatedUpdateTrack( PlaybackAnimatedUpdateItem* item )
14 {
15 m_item = item;
16 m_progress = 0;
17 m_delayBeforeTrackStarts = 0;
18 m_paused = true;
19 connect( &m_timer, SIGNAL(timeout()), this, SLOT(playSlot()) );
20 connect( m_item, SIGNAL(balloonHidden()), this, SIGNAL(balloonHidden()) );
21 connect( m_item, SIGNAL(balloonShown(GeoDataPlacemark*)), this, SIGNAL(balloonShown(GeoDataPlacemark*)) );
22 connect( m_item, SIGNAL(updated(GeoDataFeature*)), this, SIGNAL(updated(GeoDataFeature*)) );
23 connect( m_item, SIGNAL(added(GeoDataContainer*,GeoDataFeature*,int)), this, SIGNAL(added(GeoDataContainer*,GeoDataFeature*,int)) );
24 connect( m_item, SIGNAL(removed(const GeoDataFeature*)), this, SIGNAL(removed(const GeoDataFeature*)) );
25 }
26
setDelayBeforeTrackStarts(double delay)27 void AnimatedUpdateTrack::setDelayBeforeTrackStarts( double delay )
28 {
29 m_delayBeforeTrackStarts = delay;
30 m_timer.setSingleShot( true );
31 m_timer.setInterval( m_delayBeforeTrackStarts * 1000 );
32 }
33
delayBeforeTrackStarts() const34 double AnimatedUpdateTrack::delayBeforeTrackStarts() const
35 {
36 return m_delayBeforeTrackStarts;
37 }
38
play()39 void AnimatedUpdateTrack::play()
40 {
41 m_paused = false;
42 m_playTime = QDateTime::currentDateTime();
43 if( m_progress <= m_delayBeforeTrackStarts ){
44 m_timer.start( ( m_delayBeforeTrackStarts - m_progress ) * 1000 );
45 } else {
46 m_item->play();
47 }
48 }
49
playSlot()50 void AnimatedUpdateTrack::playSlot()
51 {
52 m_item->play();
53 }
54
pause()55 void AnimatedUpdateTrack::pause()
56 {
57 m_paused = true;
58 m_pauseTime = QDateTime::currentDateTime();
59 m_progress += m_playTime.secsTo( m_pauseTime );
60 if( m_timer.isActive() ){
61 m_timer.stop();
62 } else {
63 m_item->pause();
64 }
65 }
66
seek(double offset)67 void AnimatedUpdateTrack::seek( double offset )
68 {
69 m_timer.stop();
70 m_progress = offset;
71 m_playTime = QDateTime::currentDateTime().addMSecs( -offset * 1000 );
72
73 if( offset <= m_delayBeforeTrackStarts ){
74 if( !m_paused ){
75 m_pauseTime = QDateTime();
76 m_item->stop();
77 m_timer.start( ( m_delayBeforeTrackStarts - m_progress ) * 1000 );
78 } else {
79 m_pauseTime = QDateTime::currentDateTime();
80 m_item->stop();
81 }
82 } else {
83 if( !m_paused ){
84 m_pauseTime = QDateTime();
85 m_item->seek( offset - m_delayBeforeTrackStarts );
86 } else {
87 m_pauseTime = QDateTime::currentDateTime();
88 m_item->stop();
89 m_item->seek( offset - m_delayBeforeTrackStarts );
90 }
91 }
92 }
93
stop()94 void AnimatedUpdateTrack::stop()
95 {
96 m_paused = true;
97 m_item->stop();
98 m_timer.stop();
99 m_playTime = QDateTime();
100 m_pauseTime = QDateTime();
101 m_progress = 0;
102 }
103
setPaused(bool pause)104 void AnimatedUpdateTrack::setPaused( bool pause )
105 {
106 m_paused = pause;
107 }
108
109 }
110
111 #include "moc_AnimatedUpdateTrack.cpp"
112