Marble

PlaybackWaitItem.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
4//
5
6#include "PlaybackWaitItem.h"
7
8#include "GeoDataWait.h"
9
10#include <QTimer>
11
12namespace Marble
13{
14
15PlaybackWaitItem::PlaybackWaitItem(const GeoDataWait *wait)
16{
17 m_wait = wait;
18 m_isPlaying = false;
19}
20const GeoDataWait *PlaybackWaitItem::wait() const
21{
22 return m_wait;
23}
24double PlaybackWaitItem::duration() const
25{
26 return m_wait->duration();
27}
28
29void PlaybackWaitItem::play()
30{
31 if (m_isPlaying) {
32 return;
33 } else {
34 m_isPlaying = true;
35 if (!(m_start.isValid())) {
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
45void 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 Q_EMIT progressChanged(progress);
56 QTimer::singleShot(20, this, SLOT(playNext()));
57 }
58 } else {
59 stop();
60 Q_EMIT finished();
61 }
62}
63
64void PlaybackWaitItem::pause()
65{
66 m_isPlaying = false;
68}
69
70void PlaybackWaitItem::seek(double t)
71{
72 m_start = QDateTime::currentDateTime().addMSecs(-t * m_wait->duration() * 1000);
74}
75
76void PlaybackWaitItem::stop()
77{
78 m_isPlaying = false;
79 m_start = QDateTime();
80 m_pause = QDateTime();
81}
82
83}
84
85#include "moc_PlaybackWaitItem.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
QDateTime addMSecs(qint64 msecs) const const
QDateTime currentDateTime()
bool isValid() const const
qint64 msecsTo(const QDateTime &other) const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.