implemented playback controls

This commit is contained in:
itsmattkc
2019-09-06 13:06:23 +10:00
parent 9fe8c102b7
commit a5fb8693d0
11 changed files with 177 additions and 30 deletions
+20
View File
@@ -47,6 +47,26 @@ void PanelWidget::ZoomOut()
{
}
void PanelWidget::GoToStart()
{
}
void PanelWidget::PrevFrame()
{
}
void PanelWidget::PlayPause()
{
}
void PanelWidget::NextFrame()
{
}
void PanelWidget::GoToEnd()
{
}
void PanelWidget::SetTitle(const QString &t)
{
title_ = t;
+17
View File
@@ -62,6 +62,23 @@ public:
* no-op.
*/
virtual void ZoomOut();
virtual void GoToStart();
virtual void PrevFrame();
/**
* @brief Called whenever this panel is focused and user uses "Play/Pause" (either in menus or as a keyboard shortcut)
*
* This function is up to the Panel's interpretation of what the user intends to zoom out of. Default behavior is a
* no-op.
*/
virtual void PlayPause();
virtual void NextFrame();
virtual void GoToEnd();
protected:
/**
* @brief Set panel's title
@@ -82,13 +82,11 @@ PlaybackControls::PlaybackControls(QWidget *parent) :
play_btn_->setIcon(olive::icon::Play);
playpause_stack_->addWidget(play_btn_);
connect(play_btn_, SIGNAL(clicked(bool)), this, SIGNAL(PlayClicked()));
connect(play_btn_, SIGNAL(clicked(bool)), this, SLOT(PlayPauseClickedInternal()));
pause_btn_ = new QPushButton();
pause_btn_->setIcon(olive::icon::Pause);
playpause_stack_->addWidget(pause_btn_);
connect(pause_btn_, SIGNAL(clicked(bool)), this, SIGNAL(PauseClicked()));
connect(pause_btn_, SIGNAL(clicked(bool)), this, SLOT(PlayPauseClickedInternal()));
// Default to showing play button
playpause_stack_->setCurrentWidget(play_btn_);
@@ -141,12 +139,13 @@ void PlaybackControls::SetTime(const int64_t &r)
cur_tc_lbl_->setText(olive::timestamp_to_timecode(r, time_base_, kTimecodeDisplay));
}
void PlaybackControls::PlayPauseClickedInternal()
void PlaybackControls::ShowPauseButton()
{
if (sender() == play_btn_) {
// Play was clicked, toggle to pause
playpause_stack_->setCurrentWidget(pause_btn_);
} else {
playpause_stack_->setCurrentWidget(play_btn_);
}
// Play was clicked, toggle to pause
playpause_stack_->setCurrentWidget(pause_btn_);
}
void PlaybackControls::ShowPlayButton()
{
playpause_stack_->setCurrentWidget(play_btn_);
}
@@ -49,6 +49,10 @@ public:
public slots:
void SetTime(const int64_t &r);
void ShowPauseButton();
void ShowPlayButton();
signals:
/**
* @brief Signal emitted when "Go to Start" is clicked
@@ -95,7 +99,7 @@ private:
QStackedWidget* playpause_stack_;
private slots:
void PlayPauseClickedInternal();
};
+3
View File
@@ -56,6 +56,9 @@ protected:
virtual void mouseMoveEvent(QMouseEvent *event) override;
signals:
/**
* @brief Signal emitted whenever the time changes on this ruler, either by user or programatically
*/
void TimeChanged(int64_t);
private:
+27 -2
View File
@@ -99,7 +99,21 @@ void ViewerWidget::SetScale(const double &scale_)
void ViewerWidget::SetTime(const int64_t &time)
{
ruler_->SetTime(time);
RulerTimeChange(time);
UpdateTimeInternal(time);
}
void ViewerWidget::TogglePlayPause()
{
if (IsPlaying()) {
Pause();
} else {
Play();
}
}
bool ViewerWidget::IsPlaying()
{
return playback_timer_.isActive();
}
void ViewerWidget::SetTexture(GLuint tex)
@@ -107,7 +121,7 @@ void ViewerWidget::SetTexture(GLuint tex)
gl_widget_->SetTexture(tex);
}
void ViewerWidget::RulerTimeChange(int64_t i)
void ViewerWidget::UpdateTimeInternal(int64_t i)
{
rational time_set = rational(i) * time_base_;
@@ -116,6 +130,13 @@ void ViewerWidget::RulerTimeChange(int64_t i)
emit TimeChanged(time_set);
}
void ViewerWidget::RulerTimeChange(int64_t i)
{
Pause();
UpdateTimeInternal(i);
}
void ViewerWidget::Play()
{
if (time_base_.isNull()) {
@@ -127,11 +148,15 @@ void ViewerWidget::Play()
start_timestamp_ = ruler_->Time();
playback_timer_.start();
controls_->ShowPauseButton();
}
void ViewerWidget::Pause()
{
playback_timer_.stop();
controls_->ShowPlayButton();
}
void ViewerWidget::GoToStart()
+19 -13
View File
@@ -53,6 +53,10 @@ public:
void SetTime(const int64_t& time);
void TogglePlayPause();
bool IsPlaying();
public slots:
/**
* @brief Set the texture to draw and draw it
@@ -63,6 +67,18 @@ public slots:
*/
void SetTexture(GLuint tex);
void GoToStart();
void PrevFrame();
void Play();
void Pause();
void NextFrame();
void GoToEnd();
signals:
void TimeChanged(const rational&);
@@ -70,6 +86,8 @@ protected:
virtual void resizeEvent(QResizeEvent *event) override;
private:
void UpdateTimeInternal(int64_t i);
ViewerGLWidget* gl_widget_;
PlaybackControls* controls_;
@@ -88,19 +106,7 @@ private:
int64_t start_timestamp_;
private slots:
void RulerTimeChange(int64_t i);
void Play();
void Pause();
void GoToStart();
void PrevFrame();
void NextFrame();
void GoToEnd();
void RulerTimeChange(int64_t);
void PlaybackTimerUpdate();