Skip to content
Permalink
Browse files

Add an option to loop animations

  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent 2328902 commit 05fa67a819048096ef8583b4518b1d1ab9981c61
@@ -137,6 +137,20 @@ a playing animation will advance to the next frame.
long long totalFrameCount();
%Docstring
Returns the total number of frames for the navigation.
%End

bool isLooping() const;
%Docstring
Returns ``True`` if the animation should loop after hitting the end or start frame.

.. seealso:: :py:func:`setLooping`
%End

void setLooping( bool loop );
%Docstring
Sets whether the animation should ``loop`` after hitting the end or start frame.

.. seealso:: :py:func:`looping`
%End

signals:
@@ -34,13 +34,23 @@ void QgsTemporalNavigationObject::timerTimeout()
case AnimationState::Forward:
next();
if ( mCurrentFrameNumber >= totalFrameCount() - 1 )
pause();
{
if ( mLoopAnimation )
mCurrentFrameNumber = -1; // we don't jump immediately to frame 0, instead we delay that till the next timeout
else
pause();
}
break;

case AnimationState::Reverse:
previous();
if ( mCurrentFrameNumber <= 0 )
pause();
{
if ( mLoopAnimation )
mCurrentFrameNumber = totalFrameCount(); // we don't jump immediately to real last frame..., instead we delay that till the next timeout
else
pause();
}
break;

case AnimationState::Idle:
@@ -49,6 +59,16 @@ void QgsTemporalNavigationObject::timerTimeout()
}
}

bool QgsTemporalNavigationObject::isLooping() const
{
return mLoopAnimation;
}

void QgsTemporalNavigationObject::setLooping( bool loopAnimation )
{
mLoopAnimation = loopAnimation;
}

QgsDateTimeRange QgsTemporalNavigationObject::dateTimeRangeForFrameNumber( long long frame ) const
{
QDateTime start = mTemporalExtents.begin();
@@ -152,6 +152,20 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController
*/
long long totalFrameCount();

/**
* Returns TRUE if the animation should loop after hitting the end or start frame.
*
* \see setLooping()
*/
bool isLooping() const;

/**
* Sets whether the animation should \a loop after hitting the end or start frame.
*
* \see looping()
*/
void setLooping( bool loop );

signals:

/**
@@ -239,6 +253,8 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController
//! Navigation playback mode member
AnimationState mPlayBackMode = Idle;

bool mLoopAnimation = false;

};

#endif // QGSTEMPORALNAVIGATIONOBJECT_H
@@ -39,6 +39,7 @@ QgsTemporalControllerDockWidget::QgsTemporalControllerDockWidget( const QString
connect( mStopButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::pause );
connect( mFastForwardButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::skipToEnd );
connect( mRewindButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::rewindToStart );
connect( mLoopingCheckBox, &QCheckBox::toggled, this, [ = ]( bool state ) { mNavigationObject->setLooping( state ); } );

connect( mNavigationObject, &QgsTemporalNavigationObject::stateChanged, this, [ = ]( QgsTemporalNavigationObject::AnimationState state )
{
@@ -138,6 +138,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mLoopingCheckBox">
<property name="toolTip">
<string>Automatically reset and repeat the animation endlessly</string>
</property>
<property name="text">
<string>Loop</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">

0 comments on commit 05fa67a

Please sign in to comment.
You can’t perform that action at this time.