• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
SerialTrack.cpp
Go to the documentation of this file.
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 "SerialTrack.h"
12 #include "GeoDataTypes.h"
13 #include "PlaybackFlyToItem.h"
14 #include "PlaybackWaitItem.h"
15 #include "PlaybackTourControlItem.h"
16 #include "GeoDataCamera.h"
17 #include "GeoDataLookAt.h"
18 #include "TourPlayback.h"
19 
20 #include <QTimer>
21 
22 namespace Marble
23 {
24 
25 SerialTrack::SerialTrack(): QObject()
26 {
27  m_currentIndex = 0;
28  m_finishedPosition = 0;
29  m_currentPosition = 0;
30  m_paused = true;
31 }
32 
33 SerialTrack::~SerialTrack()
34 {
35  clear();
36 }
37 
38 void SerialTrack::append(PlaybackItem* item)
39 {
40  connect( item, SIGNAL( progressChanged( double ) ), this, SLOT( changeProgress( double ) ) );
41  connect( item, SIGNAL( centerOn( GeoDataCoordinates ) ), this, SIGNAL( centerOn( GeoDataCoordinates ) ) );
42  connect( item, SIGNAL( finished() ), this, SLOT( handleFinishedItem() ) ) ;
43  connect( item, SIGNAL( paused() ), this, SLOT( pause() ) ) ;
44  m_items.append( item );
45 }
46 
47 void SerialTrack::play()
48 {
49  m_paused = false;
50  m_items[m_currentIndex]->play();
51 }
52 
53 void SerialTrack::pause()
54 {
55  m_paused = true;
56  m_items[m_currentIndex]->pause();
57 }
58 
59 void SerialTrack::stop()
60 {
61  m_paused = true;
62  if( m_items.size() != 0 && m_currentIndex >= 0 && m_currentIndex <= m_items.size() - 1 ){
63  m_items[m_currentIndex]->stop();
64  }
65  m_finishedPosition = 0;
66  emit progressChanged( m_finishedPosition );
67  m_currentIndex = 0;
68 }
69 
70 void SerialTrack::seek( double offset )
71 {
72  m_currentPosition = offset;
73  int index = -1;
74  for( int i = 0; i < m_items.size(); i++ ){
75  if( offset < m_items[i]->duration() ){
76  index = i;
77  break;
78  } else {
79  m_items[i]->stop();
80  offset -= m_items[i]->duration();
81  }
82  }
83 
84  if( index == -1 ){
85  index = m_items.size() - 1;
86  }
87 
88  if( index < m_items.size() - 1 ){
89  for( int i = index + 1; i < m_items.size(); i++ ){
90  m_items[ i ]->stop();
91  }
92  }
93 
94  if( index > m_currentIndex ){
95  for( int i = m_currentIndex; i < index ; i++ ){
96  m_finishedPosition += m_items[ i ]->duration();
97  }
98  }else{
99  for( int i = m_currentIndex - 1; i >= index ; i-- ){
100  m_finishedPosition -= m_items[ i ]->duration();
101  }
102  }
103 
104  if (m_currentIndex != index && !m_paused) {
105  m_items[ index ]->play();
106  }
107 
108  m_currentIndex = index;
109  if ( m_currentIndex != -1 ){
110  double t = offset / m_items[ m_currentIndex ]->duration();
111  Q_ASSERT( t >= 0 && t <= 1 );
112  m_items[ m_currentIndex ]->seek( t );
113  }
114 }
115 
116 double SerialTrack::duration() const
117 {
118  double duration = 0.0;
119  foreach (PlaybackItem* item, m_items) {
120  duration += item->duration();
121  }
122  return duration;
123 }
124 
125 void SerialTrack::clear()
126 {
127  qDeleteAll( m_items );
128  m_items.clear();
129 }
130 
131 void SerialTrack::handleFinishedItem()
132 {
133  if( m_paused ){
134  return;
135  }
136  if ( m_currentIndex + 1 < m_items.size() ) {
137  m_finishedPosition += m_items[m_currentIndex]->duration();
138  m_currentIndex++;
139  m_items[m_currentIndex]->play();
140  } else {
141  emit finished();
142  }
143 }
144 
145 void SerialTrack::changeProgress( double progress )
146 {
147  m_currentPosition = m_finishedPosition + progress;
148  emit progressChanged( m_currentPosition );
149 }
150 
151 int SerialTrack::size() const
152 {
153  return m_items.size();
154 }
155 
156 PlaybackItem* SerialTrack::at( int i )
157 {
158  return m_items.at( i );
159 }
160 
161 
162 }
163 
164 #include "SerialTrack.moc"
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::SerialTrack::play
void play()
Definition: SerialTrack.cpp:47
Marble::SerialTrack::finished
void finished()
Marble::SerialTrack::SerialTrack
SerialTrack()
Definition: SerialTrack.cpp:25
SerialTrack.h
Marble::PlaybackItem::duration
virtual double duration() const =0
Marble::SerialTrack::stop
void stop()
Definition: SerialTrack.cpp:59
GeoDataCamera.h
GeoDataLookAt.h
Marble::SerialTrack::clear
void clear()
Definition: SerialTrack.cpp:125
PlaybackWaitItem.h
Marble::SerialTrack::at
PlaybackItem * at(int i)
Definition: SerialTrack.cpp:156
QObject
Marble::SerialTrack::pause
void pause()
Definition: SerialTrack.cpp:53
TourPlayback.h
PlaybackFlyToItem.h
Marble::SerialTrack::centerOn
void centerOn(const GeoDataCoordinates &coordinates)
Marble::SerialTrack::progressChanged
void progressChanged(double)
Marble::SerialTrack::size
int size() const
Definition: SerialTrack.cpp:151
Marble::PlaybackItem
Definition: PlaybackItem.h:20
Marble::SerialTrack::append
void append(PlaybackItem *item)
Definition: SerialTrack.cpp:38
Marble::SerialTrack::~SerialTrack
~SerialTrack()
Definition: SerialTrack.cpp:33
Marble::SerialTrack::paused
void paused()
PlaybackTourControlItem.h
Marble::SerialTrack::changeProgress
void changeProgress(double)
Definition: SerialTrack.cpp:145
GeoDataTypes.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::SerialTrack::seek
void seek(double position)
Definition: SerialTrack.cpp:70
Marble::SerialTrack::duration
double duration() const
Definition: SerialTrack.cpp:116
Marble::SerialTrack::handleFinishedItem
void handleFinishedItem()
Definition: SerialTrack.cpp:131
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal