File indexing completed on 2024-04-21 03:49:51
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com> 0004 // 0005 0006 #include "PlaybackWaitItem.h" 0007 0008 #include "GeoDataWait.h" 0009 0010 #include <QTimer> 0011 0012 namespace Marble 0013 { 0014 0015 PlaybackWaitItem::PlaybackWaitItem( const GeoDataWait* wait ) 0016 { 0017 m_wait = wait; 0018 m_isPlaying = false; 0019 } 0020 const GeoDataWait* PlaybackWaitItem::wait() const 0021 { 0022 return m_wait; 0023 } 0024 double PlaybackWaitItem::duration() const 0025 { 0026 return m_wait->duration(); 0027 } 0028 0029 void PlaybackWaitItem::play() 0030 { 0031 if( m_isPlaying ){ 0032 return; 0033 } else { 0034 m_isPlaying = true; 0035 if ( !( m_start.isValid() ) ){ 0036 m_start = QDateTime::currentDateTime(); 0037 Q_ASSERT( m_start.isValid() ); 0038 } else { 0039 m_start = m_start.addMSecs( m_pause.msecsTo( QDateTime::currentDateTime() ) ); 0040 } 0041 playNext(); 0042 } 0043 } 0044 0045 void PlaybackWaitItem::playNext() 0046 { 0047 if( !m_start.isValid() ){ 0048 return; 0049 } 0050 double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0; 0051 Q_ASSERT( progress >= 0.0 ); 0052 double const t = progress / m_wait->duration(); 0053 if( t <= 1 ){ 0054 if( m_isPlaying ){ 0055 emit progressChanged( progress ); 0056 QTimer::singleShot( 20, this, SLOT(playNext()) ); 0057 } 0058 } else { 0059 stop(); 0060 emit finished(); 0061 } 0062 } 0063 0064 void PlaybackWaitItem::pause() 0065 { 0066 m_isPlaying = false; 0067 m_pause = QDateTime::currentDateTime(); 0068 } 0069 0070 void PlaybackWaitItem::seek( double t ) 0071 { 0072 m_start = QDateTime::currentDateTime().addMSecs( -t * m_wait->duration() * 1000 ); 0073 m_pause = QDateTime::currentDateTime(); 0074 } 0075 0076 void PlaybackWaitItem::stop() 0077 { 0078 m_isPlaying = false; 0079 m_start = QDateTime(); 0080 m_pause = QDateTime(); 0081 } 0082 0083 } 0084 0085 #include "moc_PlaybackWaitItem.cpp"