6 #include "SerialTrack.h"
7 #include "PlaybackFlyToItem.h"
8 #include "PlaybackWaitItem.h"
9 #include "PlaybackTourControlItem.h"
10 #include "GeoDataCamera.h"
11 #include "GeoDataLookAt.h"
12 #include "TourPlayback.h"
17 SerialTrack::SerialTrack():
QObject()
20 m_finishedPosition = 0;
21 m_currentPosition = 0;
25 SerialTrack::~SerialTrack()
30 void SerialTrack::append(PlaybackItem* item)
32 connect( item, SIGNAL(progressChanged(
double)),
this, SLOT(changeProgress(
double)) );
33 connect( item, SIGNAL(centerOn(GeoDataCoordinates)),
this, SIGNAL(centerOn(GeoDataCoordinates)) );
34 connect( item, SIGNAL(finished()),
this, SLOT(handleFinishedItem()) ) ;
35 connect( item, SIGNAL(paused()),
this, SLOT(
pause()) ) ;
36 m_items.append( item );
37 if( m_items.size() == 1 ) {
38 PlaybackFlyToItem *flyTo =
dynamic_cast<PlaybackFlyToItem*
>( item );
39 if( flyTo !=
nullptr ) {
40 flyTo->setFirst(
true )
45 void SerialTrack::play()
48 m_items[m_currentIndex]->play();
54 m_items[m_currentIndex]->pause();
60 if( m_items.size() != 0 && m_currentIndex >= 0 && m_currentIndex <= m_items.size() - 1 ){
61 m_items[m_currentIndex]->stop();
63 m_finishedPosition = 0;
64 emit progressChanged( m_finishedPosition );
68 void SerialTrack::seek(
double offset )
70 m_currentPosition = offset;
72 for(
int i = 0; i < m_items.size(); i++ ){
73 if( offset < m_items[i]->duration() ){
78 offset -= m_items[i]->duration();
83 index = m_items.size() - 1;
86 if( index < m_items.size() - 1 ){
87 for(
int i = index + 1; i < m_items.size(); i++ ){
92 if( index > m_currentIndex ){
93 for(
int i = m_currentIndex; i < index ; i++ ){
94 m_finishedPosition += m_items[ i ]->duration();
97 for(
int i = m_currentIndex - 1; i >= index && i >= 0; i-- ){
98 m_finishedPosition -= m_items[ i ]->duration();
102 if (m_currentIndex != index && !m_paused) {
103 m_items[ index ]->play();
106 m_currentIndex = index;
107 if ( m_currentIndex != -1 ){
108 double t = offset / m_items[ m_currentIndex ]->duration();
109 Q_ASSERT( t >= 0 && t <= 1 );
110 m_items[ m_currentIndex ]->seek( t );
114 double SerialTrack::duration()
const
116 double duration = 0.0;
117 for (PlaybackItem* item: m_items) {
118 duration += item->duration();
123 void SerialTrack::clear()
125 qDeleteAll( m_items );
128 m_finishedPosition = 0;
129 m_currentPosition = 0;
133 void SerialTrack::handleFinishedItem()
138 if ( m_currentIndex + 1 < m_items.size() ) {
139 m_finishedPosition += m_items[m_currentIndex]->duration();
141 m_items[m_currentIndex]->play();
142 emit itemFinished( m_currentIndex + 1 );
149 void SerialTrack::changeProgress(
double progress )
151 m_currentPosition = m_finishedPosition + progress;
152 emit progressChanged( m_currentPosition );
155 int SerialTrack::size()
const
157 return m_items.size();
160 PlaybackItem* SerialTrack::at(
int i )
162 return m_items.at( i );
165 double SerialTrack::currentPosition()
167 return m_currentPosition;
172 #include "moc_SerialTrack.cpp"