QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsplaybackcontrollerwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsplaybackcontrollerwidget.cpp
3 --------------------------------------
4 begin : November 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
17#include "moc_qgsplaybackcontrollerwidget.cpp"
18
20 : QWidget { parent }
21{
22 setupUi( this );
23
24 mPauseButton->setChecked( true );
25
26 mForwardButton->setToolTip( tr( "Play" ) );
27 mBackButton->setToolTip( tr( "Reverse" ) );
28 mNextButton->setToolTip( tr( "Go to next frame" ) );
29 mPreviousButton->setToolTip( tr( "Go to previous frame" ) );
30 mPauseButton->setToolTip( tr( "Pause" ) );
31 mRewindButton->setToolTip( tr( "Rewind to start" ) );
32 mFastForwardButton->setToolTip( tr( "Fast forward to end" ) );
33
34 connect( mForwardButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::togglePlayForward );
35 connect( mBackButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::togglePlayBackward );
36 connect( mPauseButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::pause );
37 connect( mNextButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::next );
38 connect( mPreviousButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::previous );
39 connect( mFastForwardButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::skipToEnd );
40 connect( mRewindButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::rewindToStart );
41}
42
44{
45 switch ( operation )
46 {
48 return mRewindButton;
50 return mPreviousButton;
52 return mBackButton;
54 return mPauseButton;
56 return mForwardButton;
58 return mNextButton;
60 return mFastForwardButton;
61 }
63}
64
66{
67 if ( state == mAnimationState )
68 return;
69
70 mAnimationState = state;
71 whileBlocking( mForwardButton )->setChecked( mAnimationState == Qgis::AnimationState::Forward );
72 whileBlocking( mBackButton )->setChecked( mAnimationState == Qgis::AnimationState::Reverse );
73 whileBlocking( mPauseButton )->setChecked( mAnimationState == Qgis::AnimationState::Idle );
74
75 switch ( mAnimationState )
76 {
79 break;
82 break;
85 break;
86 }
87}
88
102
103void QgsPlaybackControllerWidget::togglePlayForward()
104{
105 mPlayingForward = true;
106
107 if ( mAnimationState != Qgis::AnimationState::Forward )
108 {
109 mPauseButton->setChecked( false );
110 mBackButton->setChecked( false );
111 mForwardButton->setChecked( true );
112
113 mAnimationState = Qgis::AnimationState::Forward;
115 }
116 else
117 {
118 mPauseButton->setChecked( true );
119 mForwardButton->setChecked( false );
120
121 mAnimationState = Qgis::AnimationState::Idle;
123 }
124}
125
126void QgsPlaybackControllerWidget::togglePlayBackward()
127{
128 mPlayingForward = false;
129
130 if ( mAnimationState != Qgis::AnimationState::Reverse )
131 {
132 mPauseButton->setChecked( false );
133 mBackButton->setChecked( true );
134 mForwardButton->setChecked( false );
135
136 mAnimationState = Qgis::AnimationState::Reverse;
138 }
139 else
140 {
141 mPauseButton->setChecked( true );
142 mBackButton->setChecked( false );
143
144 mAnimationState = Qgis::AnimationState::Idle;
146 }
147}
148
149void QgsPlaybackControllerWidget::pause()
150{
151 if ( mAnimationState != Qgis::AnimationState::Idle )
152 {
153 mPauseButton->setChecked( true );
154 mBackButton->setChecked( false );
155 mForwardButton->setChecked( false );
156
157 mAnimationState = Qgis::AnimationState::Idle;
159 }
160 else
161 {
162 mBackButton->setChecked( !mPlayingForward );
163 mForwardButton->setChecked( mPlayingForward );
164 mAnimationState = mPlayingForward ? Qgis::AnimationState::Forward : Qgis::AnimationState::Reverse;
165 if ( mPlayingForward )
166 {
168 }
169 else
170 {
172 }
173 }
174}
175
176void QgsPlaybackControllerWidget::next()
177{
179}
180
181void QgsPlaybackControllerWidget::previous()
182{
184}
185
186void QgsPlaybackControllerWidget::skipToEnd()
187{
189}
190
191void QgsPlaybackControllerWidget::rewindToStart()
192{
194}
PlaybackOperation
Media playback operations.
Definition qgis.h:2440
@ Pause
Pause playback.
@ PlayReverse
Play in reverse.
@ PlayForward
Play forward.
@ SkipToStart
Jump to start of playback.
@ PreviousFrame
Step to previous frame.
@ SkipToEnd
Jump to end of playback.
@ NextFrame
Step to next frame.
AnimationState
Animation states.
Definition qgis.h:2427
@ Forward
Animation is playing forward.
@ Reverse
Animation is playing in reverse.
@ Idle
Animation is paused.
void operationTriggered(Qgis::PlaybackOperation operation)
Emitted when a playback operation is triggered.
void setState(Qgis::AnimationState state)
Sets the current animation state for the widget.
QgsPlaybackControllerWidget(QWidget *parent=nullptr)
Constructor for QgsPlaybackControllerWidget, with the specified parent widget.
void togglePause()
Toggles the pause state on or off.
QPushButton * button(Qgis::PlaybackOperation operation)
Returns the button associated with the specified playback operation.
#define BUILTIN_UNREACHABLE
Definition qgis.h:6678
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5928