[Marble-commits] KDE/kdeedu/marble/src/lib
Bernhard Beschow
bbeschow at cs.tu-berlin.de
Sat Dec 11 19:02:40 CET 2010
SVN commit 1205589 by beschow:
implement all animation code inside MarblePhysics
M +25 -12 MarblePhysics.cpp
M +11 -25 MarblePhysics.h
M +4 -21 MarbleWidget.cpp
M +0 -12 MarbleWidget.h
--- trunk/KDE/kdeedu/marble/src/lib/MarblePhysics.cpp #1205588:1205589
@@ -11,6 +11,7 @@
#include "MarblePhysics.h"
#include "Quaternion.h"
+#include "MarbleWidget.h"
#include "MarbleDebug.h"
#include "GeoDataLineString.h"
#include "ViewportParams.h"
@@ -23,6 +24,8 @@
class MarblePhysicsPrivate {
public:
+ MarbleWidget *const m_widget;
+
GeoDataLookAt m_source;
GeoDataLookAt m_target;
@@ -33,7 +36,10 @@
qreal m_planetRadius;
- MarblePhysicsPrivate() : m_mode(Instant), m_planetRadius(EARTH_RADIUS)
+ MarblePhysicsPrivate( MarbleWidget *widget )
+ : m_widget( widget ),
+ m_mode( Instant ),
+ m_planetRadius( EARTH_RADIUS )
{
m_timeline.setDuration(2000);
m_timeline.setCurveShape( QTimeLine::EaseInOutCurve );
@@ -101,13 +107,14 @@
};
-MarblePhysics::MarblePhysics( QObject * parent )
- : QObject( parent ), d(new MarblePhysicsPrivate)
+MarblePhysics::MarblePhysics( MarbleWidget *widget )
+ : QObject( widget ),
+ d( new MarblePhysicsPrivate( widget ) )
{
connect( &d->m_timeline, SIGNAL( valueChanged( qreal ) ),
this, SLOT( updateProgress( qreal ) ) );
connect( &d->m_timeline, SIGNAL( finished() ),
- this, SIGNAL( finished() ) );
+ this, SLOT( startStillMode() ) );
}
MarblePhysics::~MarblePhysics()
@@ -115,12 +122,12 @@
delete d;
}
-void MarblePhysics::flyTo( const GeoDataLookAt &source, const GeoDataLookAt &target,
- ViewportParams *viewport, FlyToMode mode )
+void MarblePhysics::flyTo( const GeoDataLookAt &target, FlyToMode mode )
{
d->m_timeline.stop();
- d->m_source = source;
+ d->m_source = d->m_widget->lookAt();
d->m_target = target;
+ const ViewportParams *viewport = d->m_widget->viewport();
FlyToMode effectiveMode = mode;
qreal x(0), y(0);
@@ -133,7 +140,7 @@
if (effectiveMode == Automatic)
{
- bool zoom = qAbs(source.range()-target.range()) > 10;
+ bool zoom = qAbs(d->m_source.range()-target.range()) > 10;
if ( (invisible || zoom) ) {
effectiveMode = Jump;
@@ -147,8 +154,7 @@
switch(effectiveMode)
{
case Instant:
- emit positionReached(target);
- emit finished();
+ d->m_widget->flyTo( target, Instant );
return;
break;
case Linear:
@@ -177,7 +183,8 @@
if (progress >= 1.0)
{
- emit positionReached(d->m_target);
+ d->m_widget->flyTo( d->m_target, Instant );
+ d->m_widget->setViewContext( Marble::Still );
return;
}
@@ -192,9 +199,15 @@
intermediate.setAltitude(0.0);
intermediate.setRange(range);
- emit positionReached(intermediate);
+ d->m_widget->setViewContext( Marble::Animation );
+ d->m_widget->flyTo( intermediate, Instant );
}
+void MarblePhysics::startStillMode()
+{
+ d->m_widget->setViewContext( Marble::Still );
}
+}
+
#include "MarblePhysics.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarblePhysics.h #1205588:1205589
@@ -19,7 +19,7 @@
{
class MarblePhysicsPrivate;
-class ViewportParams;
+class MarbleWidget;
class MarblePhysics : public QObject
{
@@ -28,9 +28,9 @@
public:
/**
* @brief Constructor
- * parent Pointer to the parent object
+ * @param widget the MarbleWidget that is being animated
*/
- explicit MarblePhysics( QObject * parent = 0);
+ explicit MarblePhysics( MarbleWidget *widget );
/**
* @brief Destructor
@@ -38,34 +38,20 @@
~MarblePhysics();
/**
- * @brief Calculate an interpolation between source and target according
- * to the given mode
- * @param source Camera position indicating the start point of the interpolation
- * @param target Camera position indicating the target point of the interpolation
- * @param mode Interpolation (animation) mode. Instant means no interpolation.
- * @see positionReached
+ * @brief Initiate an animation to the target according to the given mode.
+ * @param target camera position indicating the target of the animation
+ * @param mode animation mode; @code Instant @endcode means no animation
*/
- void flyTo( const GeoDataLookAt &source, const GeoDataLookAt &target,
- ViewportParams *viewport, FlyToMode mode = Instant );
+ void flyTo( const GeoDataLookAt &target, FlyToMode mode = Instant );
- Q_SIGNALS:
- /**
- * Emitted for each interpolation point between source and target after
- * flyTo was called.
- * @param position Interpolated or final camera position
- * @see flyTo
- */
- void positionReached( const GeoDataLookAt position );
+private Q_SLOTS:
+ void updateProgress(qreal progress);
/**
- * The target was reached.
- * @see flyTo
+ * @brief Switch to still mode when an animation is finished
*/
- void finished();
+ void startStillMode();
-private Q_SLOTS:
- void updateProgress(qreal progress);
-
private:
Q_DISABLE_COPY( MarblePhysics )
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidget.cpp #1205588:1205589
@@ -236,12 +236,6 @@
m_widget->connect( m_model->sunLocator(), SIGNAL( updateStars() ),
m_widget, SLOT( update() ) );
- m_widget->connect( m_physics, SIGNAL( positionReached( GeoDataLookAt ) ),
- m_widget, SLOT( updateAnimation( GeoDataLookAt ) ) );
-
- m_widget->connect( m_physics, SIGNAL( finished() ),
- m_widget, SLOT( startStillMode() ) );
-
m_widget->connect( m_model->sunLocator(), SIGNAL( centerSun() ),
m_widget, SLOT( centerSun() ) );
@@ -1131,6 +1125,9 @@
void MarbleWidget::setViewContext( ViewContext viewContext )
{
+ if ( d->m_viewContext == viewContext )
+ return;
+
d->m_viewContext = viewContext;
if ( viewContext == Still )
@@ -1319,8 +1316,7 @@
d->repaint();
}
else {
- setViewContext( Marble::Animation );
- d->m_physics->flyTo( lookAt(), newLookAt, viewport(), mode );
+ d->m_physics->flyTo( newLookAt, mode );
}
}
@@ -1334,19 +1330,6 @@
d->m_map->downloadRegion( sourceDir, pyramid );
}
-void MarbleWidget::updateAnimation( const GeoDataLookAt &lookAt )
-{
- setViewContext( Marble::Animation );
- d->m_map->flyTo( lookAt );
- d->repaint();
-}
-
-void MarbleWidget::startStillMode()
-{
- setViewContext( Marble::Still );
- d->repaint();
-}
-
GeoDataLookAt MarbleWidget::lookAt() const
{
return d->m_map->lookAt();
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidget.h #1205588:1205589
@@ -1058,18 +1058,6 @@
*/
void changeEvent( QEvent * event );
-private Q_SLOTS:
- /**
- * @brief Switch to still mode when an animation is finished
- */
- void startStillMode();
-
- /**
- * @brief Updates zoom and position during animations
- * @see flyTo
- */
- void updateAnimation( const GeoDataLookAt &lookAt );
-
private:
Q_DISABLE_COPY( MarbleWidget )
MarbleWidgetPrivate * const d;
More information about the Marble-commits
mailing list