Marble

PlaybackWaitItem.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <[email protected]>
4 //
5 
6 #include "PlaybackWaitItem.h"
7 
8 #include "GeoDataWait.h"
9 
10 #include <QTimer>
11 
12 namespace Marble
13 {
14 
15 PlaybackWaitItem::PlaybackWaitItem( const GeoDataWait* wait )
16 {
17  m_wait = wait;
18  m_isPlaying = false;
19 }
20 const GeoDataWait* PlaybackWaitItem::wait() const
21 {
22  return m_wait;
23 }
24 double PlaybackWaitItem::duration() const
25 {
26  return m_wait->duration();
27 }
28 
29 void PlaybackWaitItem::play()
30 {
31  if( m_isPlaying ){
32  return;
33  } else {
34  m_isPlaying = true;
35  if ( !( m_start.isValid() ) ){
36  m_start = QDateTime::currentDateTime();
37  Q_ASSERT( m_start.isValid() );
38  } else {
39  m_start = m_start.addMSecs( m_pause.msecsTo( QDateTime::currentDateTime() ) );
40  }
41  playNext();
42  }
43 }
44 
45 void PlaybackWaitItem::playNext()
46 {
47  if( !m_start.isValid() ){
48  return;
49  }
50  double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0;
51  Q_ASSERT( progress >= 0.0 );
52  double const t = progress / m_wait->duration();
53  if( t <= 1 ){
54  if( m_isPlaying ){
55  emit progressChanged( progress );
56  QTimer::singleShot( 20, this, SLOT(playNext()) );
57  }
58  } else {
59  stop();
60  emit finished();
61  }
62 }
63 
65 {
66  m_isPlaying = false;
67  m_pause = QDateTime::currentDateTime();
68 }
69 
70 void PlaybackWaitItem::seek( double t )
71 {
72  m_start = QDateTime::currentDateTime().addMSecs( -t * m_wait->duration() * 1000 );
73  m_pause = QDateTime::currentDateTime();
74 }
75 
77 {
78  m_isPlaying = false;
79  m_start = QDateTime();
80  m_pause = QDateTime();
81 }
82 
83 }
84 
85 #include "moc_PlaybackWaitItem.cpp"
QDateTime addMSecs(qint64 msecs) const const
void stop(Ekos::AlignState mode)
QDateTime currentDateTime()
Q_SCRIPTABLE Q_NOREPLY void pause()
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.