Marble

PlaybackFlyToItem.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
4//
5
6#include "PlaybackFlyToItem.h"
7
8#include "GeoDataLookAt.h"
9#include "GeoDataCamera.h"
10#include "GeoDataFlyTo.h"
11#include "Quaternion.h"
12
13#include <QTimer>
14
15namespace Marble
16{
17PlaybackFlyToItem::PlaybackFlyToItem( const GeoDataFlyTo* flyTo ):
18 m_flyTo( flyTo ),
19 m_before( nullptr ),
20 m_next( nullptr ),
21 m_isPlaying( false ),
22 m_isFirst( false )
23{
24 //do nothing
25}
26
27const GeoDataFlyTo* PlaybackFlyToItem::flyTo() const
28{
29 return m_flyTo;
30}
31
32double PlaybackFlyToItem::duration() const
33{
34 // We use duration 0 for first FlyTo for instantly flight to it.
35 return m_isFirst ? 0 : m_flyTo->duration();
36}
37
38void PlaybackFlyToItem::play()
39{
40 if( m_isPlaying ){
41 return;
42 } else {
43 m_isPlaying = true;
44 if ( !( m_start.isValid() ) ){
46 Q_ASSERT( m_start.isValid() );
47 } else {
48 m_start = m_start.addMSecs( m_pause.msecsTo( QDateTime::currentDateTime() ) );
49 }
50 playNext();
51 }
52}
53
54void PlaybackFlyToItem::playNext()
55{
56 if( !m_start.isValid() ){
57 return;
58 }
59 double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0;
60 Q_ASSERT( progress >= 0.0 );
61 double const t = progress / duration();
62 if( t <= 1 ){
63 if( m_isPlaying ){
64 center( t );
65 emit progressChanged( progress );
66 QTimer::singleShot( 5, this, SLOT(playNext()) );
67 }
68 } else {
69 center( 1.0 );
70 emit finished();
71 stop();
72 }
73}
74
75void PlaybackFlyToItem::pause()
76{
77 m_isPlaying = false;
79}
80
81void PlaybackFlyToItem::seek( double t )
82{
83 m_start = QDateTime::currentDateTime().addMSecs( -t * duration() * 1000 );
85 center( t );
86}
87
88void PlaybackFlyToItem::stop()
89{
90 m_isPlaying = false;
91 m_start = QDateTime();
92 m_pause = QDateTime();
93}
94
95void PlaybackFlyToItem::center( double t )
96{
97 Q_ASSERT( t >= 0.0 && t <= 1.0 );
98 Q_ASSERT( m_before );
99 if ( m_flyTo->flyToMode() == GeoDataFlyTo::Bounce || !m_before->m_before || !m_next ) {
100 GeoDataCoordinates const a = m_before->m_flyTo->view()->coordinates();
101 GeoDataCoordinates const b = m_flyTo->view()->coordinates();
102 emit centerOn( a.interpolate( b, t ) );
103 } else {
104 Q_ASSERT( m_flyTo->flyToMode() == GeoDataFlyTo::Smooth );
105 GeoDataCoordinates const a = m_before->m_before->m_flyTo->view()->coordinates();
106 GeoDataCoordinates const b = m_before->m_flyTo->view()->coordinates();
107 GeoDataCoordinates const c = m_flyTo->view()->coordinates();
108 GeoDataCoordinates const d = m_next->m_flyTo->view()->coordinates();
109 emit centerOn( b.interpolate( a, c, d, t ) );
110 }
111}
112
113void PlaybackFlyToItem::setBefore( PlaybackFlyToItem *before )
114{
115 m_before = before;
116}
117
118void PlaybackFlyToItem::setNext( PlaybackFlyToItem *next )
119{
120 m_next = next;
121}
122
123void PlaybackFlyToItem::setFirst(bool isFirst)
124{
125 m_isFirst = isFirst;
126}
127
128}
129
130#include "moc_PlaybackFlyToItem.cpp"
void stop(Ekos::AlignState mode)
QAction * next(const QObject *recvr, const char *slot, QObject *parent)
Binds a QML item to a specific geodetic location in screen coordinates.
QDateTime addMSecs(qint64 msecs) const const
QDateTime currentDateTime()
QTextStream & center(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:57:57 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.