~ubuntu-branches/ubuntu/wily/marble/wily-proposed

« back to all changes in this revision

Viewing changes to src/lib/marble/PlaybackFlyToItem.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark, Jonathan Riddell, Scarlett Clark
  • Date: 2014-07-24 23:38:32 UTC
  • mfrom: (1.5.2)
  • Revision ID: package-import@ubuntu.com-20140724233832-7v4421t4khrhw487
Tags: 4:4.13.90-0ubuntu1
[ Jonathan Riddell ]
* Switch to libmarblewidget19 for new soversion

[ Scarlett Clark ]
* New upstream beta release
* Update: do_not_install_private_headers. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// This file is part of the Marble Virtual Globe.
 
3
//
 
4
// This program is free software licensed under the GNU LGPL. You can
 
5
// find a copy of this license in LICENSE.txt in the top directory of
 
6
// the source code.
 
7
//
 
8
// Copyright 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
 
9
//
 
10
 
 
11
#include "PlaybackFlyToItem.h"
 
12
 
 
13
#include "GeoDataTypes.h"
 
14
#include "GeoDataLookAt.h"
 
15
#include "GeoDataCamera.h"
 
16
#include "Quaternion.h"
 
17
 
 
18
#include <QTimer>
 
19
 
 
20
namespace Marble
 
21
{
 
22
PlaybackFlyToItem::PlaybackFlyToItem( const GeoDataFlyTo* flyTo ):
 
23
        m_flyTo( flyTo ),
 
24
        m_before( 0 ),
 
25
        m_next( 0 ),
 
26
        m_duration( flyTo->duration() ),
 
27
        m_isPlaying( false )
 
28
{
 
29
    //do nothing
 
30
}
 
31
 
 
32
const GeoDataFlyTo* PlaybackFlyToItem::flyTo() const
 
33
{
 
34
    return m_flyTo;
 
35
}
 
36
 
 
37
double PlaybackFlyToItem::duration() const
 
38
{
 
39
    return m_flyTo->duration();
 
40
}
 
41
 
 
42
void PlaybackFlyToItem::play()
 
43
{
 
44
    if( m_isPlaying ){
 
45
        return;
 
46
    } else {
 
47
        m_isPlaying = true;
 
48
        if ( !( m_start.isValid() ) ){
 
49
            m_start = QDateTime::currentDateTime();
 
50
            Q_ASSERT( m_start.isValid() );
 
51
        } else {
 
52
            m_start = m_start.addMSecs( m_pause.msecsTo( QDateTime::currentDateTime() ) );
 
53
        }
 
54
        playNext();
 
55
    }
 
56
}
 
57
 
 
58
void PlaybackFlyToItem::playNext()
 
59
{
 
60
    if( !m_start.isValid() ){
 
61
        return;
 
62
    }
 
63
    double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0;
 
64
    Q_ASSERT( progress >= 0.0 );
 
65
    double const t = progress / m_duration;
 
66
    if( t <= 1 ){
 
67
        if( m_isPlaying ){
 
68
            center( t );
 
69
            emit progressChanged( progress );
 
70
            QTimer::singleShot( 5, this, SLOT( playNext() ) );
 
71
        }
 
72
    } else {
 
73
        center( 1.0 );
 
74
        emit finished();
 
75
        stop();
 
76
    }
 
77
}
 
78
 
 
79
void PlaybackFlyToItem::pause()
 
80
{
 
81
    m_isPlaying = false;
 
82
    m_pause = QDateTime::currentDateTime();
 
83
}
 
84
 
 
85
void PlaybackFlyToItem::seek( double t )
 
86
{
 
87
    m_start = QDateTime::currentDateTime().addMSecs( -t * m_duration * 1000 );
 
88
    m_pause = QDateTime::currentDateTime();
 
89
    center( t );
 
90
}
 
91
 
 
92
void PlaybackFlyToItem::stop()
 
93
{
 
94
    m_isPlaying = false;
 
95
    m_start = QDateTime();
 
96
    m_pause = QDateTime();
 
97
}
 
98
 
 
99
void PlaybackFlyToItem::center( double t )
 
100
{
 
101
    Q_ASSERT( t >= 0.0 && t <= 1.0 );
 
102
    Q_ASSERT( m_before );
 
103
    if ( m_flyTo->flyToMode() == GeoDataFlyTo::Bounce || !m_before->m_before || !m_next ) {
 
104
        GeoDataCoordinates const a = m_before->m_flyTo->view()->coordinates();
 
105
        GeoDataCoordinates const b = m_flyTo->view()->coordinates();
 
106
        emit centerOn( a.interpolate( b, t ) );
 
107
    } else {
 
108
        Q_ASSERT( m_flyTo->flyToMode() == GeoDataFlyTo::Smooth );
 
109
        GeoDataCoordinates const a = m_before->m_before->m_flyTo->view()->coordinates();
 
110
        GeoDataCoordinates const b = m_before->m_flyTo->view()->coordinates();
 
111
        GeoDataCoordinates const c = m_flyTo->view()->coordinates();
 
112
        GeoDataCoordinates const d = m_next->m_flyTo->view()->coordinates();
 
113
        emit centerOn( b.interpolate( a, c, d, t ) );
 
114
    }
 
115
}
 
116
 
 
117
void PlaybackFlyToItem::setBefore( PlaybackFlyToItem *before )
 
118
{
 
119
    m_before = before;
 
120
}
 
121
 
 
122
void PlaybackFlyToItem::setNext( PlaybackFlyToItem *next )
 
123
{
 
124
    m_next = next;
 
125
}
 
126
 
 
127
}
 
128
 
 
129
#include "PlaybackFlyToItem.moc"