QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
19 : QWidget{parent}
20{
21 setupUi( this );
22
23 mPauseButton->setChecked( true );
24
25 mForwardButton->setToolTip( tr( "Play" ) );
26 mBackButton->setToolTip( tr( "Reverse" ) );
27 mNextButton->setToolTip( tr( "Go to next frame" ) );
28 mPreviousButton->setToolTip( tr( "Go to previous frame" ) );
29 mPauseButton->setToolTip( tr( "Pause" ) );
30 mRewindButton->setToolTip( tr( "Rewind to start" ) );
31 mFastForwardButton->setToolTip( tr( "Fast forward to end" ) );
32
33 connect( mForwardButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::togglePlayForward );
34 connect( mBackButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::togglePlayBackward );
35 connect( mPauseButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::pause );
36 connect( mNextButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::next );
37 connect( mPreviousButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::previous );
38 connect( mFastForwardButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::skipToEnd );
39 connect( mRewindButton, &QPushButton::clicked, this, &QgsPlaybackControllerWidget::rewindToStart );
40}
41
43{
44 switch ( operation )
45 {
47 return mRewindButton;
49 return mPreviousButton;
51 return mBackButton;
53 return mPauseButton;
55 return mForwardButton;
57 return mNextButton;
59 return mFastForwardButton;
60 }
62}
63
65{
66 if ( state == mAnimationState )
67 return;
68
69 mAnimationState = state;
70 whileBlocking( mForwardButton )->setChecked( mAnimationState == Qgis::AnimationState::Forward );
71 whileBlocking( mBackButton )->setChecked( mAnimationState == Qgis::AnimationState::Reverse );
72 whileBlocking( mPauseButton )->setChecked( mAnimationState == Qgis::AnimationState::Idle );
73
74 switch ( mAnimationState )
75 {
78 break;
81 break;
84 break;
85 }
86}
87
101
102void QgsPlaybackControllerWidget::togglePlayForward()
103{
104 mPlayingForward = true;
105
106 if ( mAnimationState != Qgis::AnimationState::Forward )
107 {
108 mPauseButton->setChecked( false );
109 mBackButton->setChecked( false );
110 mForwardButton->setChecked( true );
111
112 mAnimationState = Qgis::AnimationState::Forward;
114 }
115 else
116 {
117 mPauseButton->setChecked( true );
118 mForwardButton->setChecked( false );
119
120 mAnimationState = Qgis::AnimationState::Idle;
122 }
123}
124
125void QgsPlaybackControllerWidget::togglePlayBackward()
126{
127 mPlayingForward = false;
128
129 if ( mAnimationState != Qgis::AnimationState::Reverse )
130 {
131 mPauseButton->setChecked( false );
132 mBackButton->setChecked( true );
133 mForwardButton->setChecked( false );
134
135 mAnimationState = Qgis::AnimationState::Reverse;
137 }
138 else
139 {
140 mPauseButton->setChecked( true );
141 mBackButton->setChecked( false );
142
143 mAnimationState = Qgis::AnimationState::Idle;
145 }
146}
147
148void QgsPlaybackControllerWidget::pause()
149{
150 if ( mAnimationState != Qgis::AnimationState::Idle )
151 {
152 mPauseButton->setChecked( true );
153 mBackButton->setChecked( false );
154 mForwardButton->setChecked( false );
155
156 mAnimationState = Qgis::AnimationState::Idle;
158 }
159 else
160 {
161 mBackButton->setChecked( !mPlayingForward );
162 mForwardButton->setChecked( mPlayingForward );
163 mAnimationState = mPlayingForward ? Qgis::AnimationState::Forward : Qgis::AnimationState::Reverse;
164 if ( mPlayingForward )
165 {
167 }
168 else
169 {
171 }
172 }
173}
174
175void QgsPlaybackControllerWidget::next()
176{
178}
179
180void QgsPlaybackControllerWidget::previous()
181{
183}
184
185void QgsPlaybackControllerWidget::skipToEnd()
186{
188}
189
190void QgsPlaybackControllerWidget::rewindToStart()
191{
193}
PlaybackOperation
Media playback operations.
Definition qgis.h:2395
@ 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:2382
@ 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:6571
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5821