Marble

AnimatedUpdateTrack.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
4//
5
6#include "AnimatedUpdateTrack.h"
7
8#include "PlaybackAnimatedUpdateItem.h"
9
10namespace Marble
11{
12
13AnimatedUpdateTrack::AnimatedUpdateTrack( PlaybackAnimatedUpdateItem* item )
14{
15 m_item = item;
16 m_progress = 0;
17 m_delayBeforeTrackStarts = 0;
18 m_paused = true;
19 connect( &m_timer, SIGNAL(timeout()), this, SLOT(playSlot()) );
20 connect( m_item, SIGNAL(balloonHidden()), this, SIGNAL(balloonHidden()) );
21 connect( m_item, SIGNAL(balloonShown(GeoDataPlacemark*)), this, SIGNAL(balloonShown(GeoDataPlacemark*)) );
22 connect( m_item, SIGNAL(updated(GeoDataFeature*)), this, SIGNAL(updated(GeoDataFeature*)) );
23 connect( m_item, SIGNAL(added(GeoDataContainer*,GeoDataFeature*,int)), this, SIGNAL(added(GeoDataContainer*,GeoDataFeature*,int)) );
24 connect( m_item, SIGNAL(removed(const GeoDataFeature*)), this, SIGNAL(removed(const GeoDataFeature*)) );
25}
26
27void AnimatedUpdateTrack::setDelayBeforeTrackStarts( double delay )
28{
29 m_delayBeforeTrackStarts = delay;
30 m_timer.setSingleShot( true );
31 m_timer.setInterval( m_delayBeforeTrackStarts * 1000 );
32}
33
34double AnimatedUpdateTrack::delayBeforeTrackStarts() const
35{
36 return m_delayBeforeTrackStarts;
37}
38
39void AnimatedUpdateTrack::play()
40{
41 m_paused = false;
42 m_playTime = QDateTime::currentDateTime();
43 if( m_progress <= m_delayBeforeTrackStarts ){
44 m_timer.start( ( m_delayBeforeTrackStarts - m_progress ) * 1000 );
45 } else {
46 m_item->play();
47 }
48}
49
50void AnimatedUpdateTrack::playSlot()
51{
52 m_item->play();
53}
54
55void AnimatedUpdateTrack::pause()
56{
57 m_paused = true;
58 m_pauseTime = QDateTime::currentDateTime();
59 m_progress += m_playTime.secsTo( m_pauseTime );
60 if( m_timer.isActive() ){
61 m_timer.stop();
62 } else {
63 m_item->pause();
64 }
65}
66
67void AnimatedUpdateTrack::seek( double offset )
68{
69 m_timer.stop();
70 m_progress = offset;
71 m_playTime = QDateTime::currentDateTime().addMSecs( -offset * 1000 );
72
73 if( offset <= m_delayBeforeTrackStarts ){
74 if( !m_paused ){
75 m_pauseTime = QDateTime();
76 m_item->stop();
77 m_timer.start( ( m_delayBeforeTrackStarts - m_progress ) * 1000 );
78 } else {
79 m_pauseTime = QDateTime::currentDateTime();
80 m_item->stop();
81 }
82 } else {
83 if( !m_paused ){
84 m_pauseTime = QDateTime();
85 m_item->seek( offset - m_delayBeforeTrackStarts );
86 } else {
87 m_pauseTime = QDateTime::currentDateTime();
88 m_item->stop();
89 m_item->seek( offset - m_delayBeforeTrackStarts );
90 }
91 }
92}
93
94void AnimatedUpdateTrack::stop()
95{
96 m_paused = true;
97 m_item->stop();
98 m_timer.stop();
99 m_playTime = QDateTime();
100 m_pauseTime = QDateTime();
101 m_progress = 0;
102}
103
104void AnimatedUpdateTrack::setPaused( bool pause )
105{
106 m_paused = pause;
107}
108
109}
110
111#include "moc_AnimatedUpdateTrack.cpp"
Q_SCRIPTABLE Q_NOREPLY void pause()
Binds a QML item to a specific geodetic location in screen coordinates.
QDateTime addMSecs(qint64 msecs) const const
QDateTime currentDateTime()
qint64 secsTo(const QDateTime &other) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
void setInterval(int msec)
bool isActive() const const
void setSingleShot(bool singleShot)
void start()
void stop()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.