Skip to content

Commit ee9dadb

Browse files
authoredMay 23, 2020
[ui] Make temporal controller's forward, backward and pause
buttons behave as animation state toggle
1 parent f676c82 commit ee9dadb

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed
 

‎python/gui/auto_generated/qgstemporalcontrollerwidget.sip.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ The dock widget retains ownership of the returned object.
3737
%End
3838

3939

40+
protected:
41+
42+
virtual void keyPressEvent( QKeyEvent *e );
43+
44+
4045
};
4146

4247
/************************************************************************

‎src/gui/qgstemporalcontrollerwidget.cpp

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ QgsTemporalControllerWidget::QgsTemporalControllerWidget( QWidget *parent )
3030

3131
mNavigationObject = new QgsTemporalNavigationObject( this );
3232

33-
connect( mForwardButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::playForward );
34-
connect( mBackButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::playBackward );
33+
connect( mForwardButton, &QPushButton::clicked, this, &QgsTemporalControllerWidget::togglePlayForward );
34+
connect( mBackButton, &QPushButton::clicked, this, &QgsTemporalControllerWidget::togglePlayBackward );
35+
connect( mStopButton, &QPushButton::clicked, this, &QgsTemporalControllerWidget::togglePause );
3536
connect( mNextButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::next );
3637
connect( mPreviousButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::previous );
37-
connect( mStopButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::pause );
3838
connect( mFastForwardButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::skipToEnd );
3939
connect( mRewindButton, &QPushButton::clicked, mNavigationObject, &QgsTemporalNavigationObject::rewindToStart );
4040
connect( mLoopingCheckBox, &QCheckBox::toggled, this, [ = ]( bool state ) { mNavigationObject->setLooping( state ); } );
@@ -136,6 +136,77 @@ QgsTemporalControllerWidget::QgsTemporalControllerWidget( QWidget *parent )
136136
connect( QgsProject::instance(), &QgsProject::cleared, this, &QgsTemporalControllerWidget::onProjectCleared );
137137
}
138138

139+
void QgsTemporalControllerWidget::keyPressEvent( QKeyEvent *e )
140+
{
141+
if ( mSlider->hasFocus() && e->key() == Qt::Key_Space )
142+
{
143+
togglePause();
144+
}
145+
QWidget::keyPressEvent( e );
146+
}
147+
148+
void QgsTemporalControllerWidget::togglePlayForward()
149+
{
150+
mPlayingForward = true;
151+
152+
if ( mNavigationObject->animationState() != QgsTemporalNavigationObject::Forward )
153+
{
154+
mStopButton->setChecked( false );
155+
mBackButton->setChecked( false );
156+
mForwardButton->setChecked( true );
157+
mNavigationObject->playForward();
158+
}
159+
else
160+
{
161+
mBackButton->setChecked( true );
162+
mForwardButton->setChecked( false );
163+
mNavigationObject->pause();
164+
}
165+
}
166+
167+
void QgsTemporalControllerWidget::togglePlayBackward()
168+
{
169+
mPlayingForward = false;
170+
171+
if ( mNavigationObject->animationState() != QgsTemporalNavigationObject::Reverse )
172+
{
173+
mStopButton->setChecked( false );
174+
mBackButton->setChecked( true );
175+
mForwardButton->setChecked( false );
176+
mNavigationObject->playBackward();
177+
}
178+
else
179+
{
180+
mBackButton->setChecked( true );
181+
mBackButton->setChecked( false );
182+
mNavigationObject->pause();
183+
}
184+
}
185+
186+
void QgsTemporalControllerWidget::togglePause()
187+
{
188+
if ( mNavigationObject->animationState() != QgsTemporalNavigationObject::Idle )
189+
{
190+
mStopButton->setChecked( true );
191+
mBackButton->setChecked( false );
192+
mForwardButton->setChecked( false );
193+
mNavigationObject->pause();
194+
}
195+
else
196+
{
197+
mBackButton->setChecked( mPlayingForward ? false : true );
198+
mForwardButton->setChecked( mPlayingForward ? false : true );
199+
if ( mPlayingForward )
200+
{
201+
mNavigationObject->playForward();
202+
}
203+
else
204+
{
205+
mNavigationObject->playBackward();
206+
}
207+
}
208+
}
209+
139210
void QgsTemporalControllerWidget::updateTemporalExtent()
140211
{
141212
QgsDateTimeRange temporalExtent = QgsDateTimeRange( mStartDateTime->dateTime(),

‎src/gui/qgstemporalcontrollerwidget.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui
6363

6464
#endif
6565

66+
protected:
67+
68+
void keyPressEvent( QKeyEvent *e ) override;
69+
6670
private:
6771

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

8387
bool mHasTemporalLayersLoaded = false;
8488

89+
void togglePlayForward();
90+
void togglePlayBackward();
91+
void togglePause();
92+
bool mPlayingForward = true;
93+
8594
private slots:
8695

8796
/**

0 commit comments

Comments
 (0)
Please sign in to comment.