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"
17SerialTrack::SerialTrack():
QObject()
20 m_finishedPosition = 0;
21 m_currentPosition = 0;
25SerialTrack::~SerialTrack()
30void 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()) ) ;
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 )
45void SerialTrack::play()
48 m_items[m_currentIndex]->play();
51void SerialTrack::pause()
54 m_items[m_currentIndex]->pause();
57void SerialTrack::stop()
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 );
68void 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 );
114double SerialTrack::duration()
const
116 double duration = 0.0;
117 for (PlaybackItem* item: m_items) {
118 duration += item->duration();
123void SerialTrack::clear()
125 qDeleteAll( m_items );
128 m_finishedPosition = 0;
129 m_currentPosition = 0;
133void 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 );
149void SerialTrack::changeProgress(
double progress )
151 m_currentPosition = m_finishedPosition + progress;
152 emit progressChanged( m_currentPosition );
155int SerialTrack::size()
const
157 return m_items.size();
160PlaybackItem* SerialTrack::at(
int i )
162 return m_items.at( i );
165double SerialTrack::currentPosition()
167 return m_currentPosition;
172#include "moc_SerialTrack.cpp"
Q_SCRIPTABLE Q_NOREPLY void pause()
Binds a QML item to a specific geodetic location in screen coordinates.
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)