[ui] Make temporal controller's forward, backward and pause

buttons behave as animation state toggle
This commit is contained in:
Mathieu Pellerin 2020-05-23 09:35:18 +07:00 committed by GitHub
parent f676c821d9
commit ee9dadbd64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 3 deletions

View File

@ -37,6 +37,11 @@ The dock widget retains ownership of the returned object.
%End
protected:
virtual void keyPressEvent( QKeyEvent *e );
};
/************************************************************************

View File

@ -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 ); } );
@ -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(),

View File

@ -63,6 +63,10 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui
#endif
protected:
void keyPressEvent( QKeyEvent *e ) override;
private:
/**
@ -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:
/**