Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ui] Make temporal controller's forward, backward and pause
buttons behave as animation state toggle
  • Loading branch information
nirvn committed May 23, 2020
1 parent f676c82 commit ee9dadb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
5 changes: 5 additions & 0 deletions python/gui/auto_generated/qgstemporalcontrollerwidget.sip.in
Expand Up @@ -37,6 +37,11 @@ The dock widget retains ownership of the returned object.
%End


protected:

virtual void keyPressEvent( QKeyEvent *e );


};

/************************************************************************
Expand Down
77 changes: 74 additions & 3 deletions src/gui/qgstemporalcontrollerwidget.cpp
Expand Up @@ -30,11 +30,11 @@ QgsTemporalControllerWidget::QgsTemporalControllerWidget( QWidget *parent )

mNavigationObject = new QgsTemporalNavigationObject( this );

connect( mForwardButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::playForward );
connect( mBackButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::playBackward );
connect( mForwardButton, &QPushButton::clicked, this, &QgsTemporalControllerWidget::togglePlayForward );
connect( mBackButton, &QPushButton::clicked, this, &QgsTemporalControllerWidget::togglePlayBackward );
connect( mStopButton, &QPushButton::clicked, this, &QgsTemporalControllerWidget::togglePause );
connect( mNextButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::next );
connect( mPreviousButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::previous );
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 ); } );
Expand Down Expand Up @@ -136,6 +136,77 @@ QgsTemporalControllerWidget::QgsTemporalControllerWidget( QWidget *parent )
connect( QgsProject::instance(), &QgsProject::cleared, this, &QgsTemporalControllerWidget::onProjectCleared );
}

void QgsTemporalControllerWidget::keyPressEvent( QKeyEvent *e )
{
if ( mSlider->hasFocus() && e->key() == Qt::Key_Space )
{
togglePause();
}
QWidget::keyPressEvent( e );
}

void QgsTemporalControllerWidget::togglePlayForward()
{
mPlayingForward = true;

if ( mNavigationObject->animationState() != QgsTemporalNavigationObject::Forward )
{
mStopButton->setChecked( false );
mBackButton->setChecked( false );
mForwardButton->setChecked( true );
mNavigationObject->playForward();
}
else
{
mBackButton->setChecked( true );
mForwardButton->setChecked( false );
mNavigationObject->pause();
}
}

void QgsTemporalControllerWidget::togglePlayBackward()
{
mPlayingForward = false;

if ( mNavigationObject->animationState() != QgsTemporalNavigationObject::Reverse )
{
mStopButton->setChecked( false );
mBackButton->setChecked( true );
mForwardButton->setChecked( false );
mNavigationObject->playBackward();
}
else
{
mBackButton->setChecked( true );
mBackButton->setChecked( false );
mNavigationObject->pause();
}
}

void QgsTemporalControllerWidget::togglePause()
{
if ( mNavigationObject->animationState() != QgsTemporalNavigationObject::Idle )
{
mStopButton->setChecked( true );
mBackButton->setChecked( false );
mForwardButton->setChecked( false );
mNavigationObject->pause();
}
else
{
mBackButton->setChecked( mPlayingForward ? false : true );
mForwardButton->setChecked( mPlayingForward ? false : true );
if ( mPlayingForward )
{
mNavigationObject->playForward();
}
else
{
mNavigationObject->playBackward();
}
}
}

void QgsTemporalControllerWidget::updateTemporalExtent()
{
QgsDateTimeRange temporalExtent = QgsDateTimeRange( mStartDateTime->dateTime(),
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgstemporalcontrollerwidget.h
Expand Up @@ -63,6 +63,10 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui

#endif

protected:

void keyPressEvent( QKeyEvent *e ) override;

private:

/**
Expand All @@ -82,6 +86,11 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui

bool mHasTemporalLayersLoaded = false;

void togglePlayForward();
void togglePlayBackward();
void togglePause();
bool mPlayingForward = true;

private slots:

/**
Expand Down

0 comments on commit ee9dadb

Please sign in to comment.