Show speed control in media viewer only when supported

This commit is contained in:
Ilya Fedin 2023-03-16 03:48:46 +04:00 committed by John Preston
parent fc860a1ef4
commit 77f4256d8d

View file

@ -34,18 +34,21 @@ PlaybackControls::PlaybackControls(
, _playbackProgress(std::make_unique<PlaybackProgress>()) , _playbackProgress(std::make_unique<PlaybackProgress>())
, _volumeToggle(this, st::mediaviewVolumeToggle) , _volumeToggle(this, st::mediaviewVolumeToggle)
, _volumeController(this, st::mediaviewPlayback) , _volumeController(this, st::mediaviewPlayback)
, _speedToggle(this, st::mediaviewSpeedButton) , _speedToggle(Media::Audio::SupportsSpeedControl()
? object_ptr<Player::SpeedButton>(this, st::mediaviewSpeedButton)
: nullptr)
, _fullScreenToggle(this, st::mediaviewFullScreenButton) , _fullScreenToggle(this, st::mediaviewFullScreenButton)
, _pictureInPicture(this, st::mediaviewPipButton) , _pictureInPicture(this, st::mediaviewPipButton)
, _playedAlready(this, st::mediaviewPlayProgressLabel) , _playedAlready(this, st::mediaviewPlayProgressLabel)
, _toPlayLeft(this, st::mediaviewPlayProgressLabel) , _toPlayLeft(this, st::mediaviewPlayProgressLabel)
, _speedController( , _speedController(_speedToggle
std::make_unique<Player::SpeedController>( ? std::make_unique<Player::SpeedController>(
_speedToggle.data(), _speedToggle.data(),
parent, parent,
[=](bool) {}, [=](bool) {},
[=](bool lastNonDefault) { return speedLookup(lastNonDefault); }, [=](bool lastNonDefault) { return speedLookup(lastNonDefault); },
[=](float64 speed) { saveSpeed(speed); })) [=](float64 speed) { saveSpeed(speed); })
: nullptr)
, _fadeAnimation(std::make_unique<Ui::FadeAnimation>(this)) { , _fadeAnimation(std::make_unique<Ui::FadeAnimation>(this)) {
_fadeAnimation->show(); _fadeAnimation->show();
_fadeAnimation->setFinishedCallback([=] { _fadeAnimation->setFinishedCallback([=] {
@ -343,8 +346,10 @@ void PlaybackControls::resizeEvent(QResizeEvent *e) {
st::mediaviewPlayButtonTop); st::mediaviewPlayButtonTop);
auto right = st::mediaviewButtonsRight; auto right = st::mediaviewButtonsRight;
_speedToggle->moveToRight(right, st::mediaviewButtonsTop); if (_speedToggle) {
right += _speedToggle->width() + st::mediaviewPipButtonSkip; _speedToggle->moveToRight(right, st::mediaviewButtonsTop);
right += _speedToggle->width() + st::mediaviewPipButtonSkip;
}
_pictureInPicture->moveToRight(right, st::mediaviewButtonsTop); _pictureInPicture->moveToRight(right, st::mediaviewButtonsTop);
right += _pictureInPicture->width() + st::mediaviewFullScreenButtonSkip; right += _pictureInPicture->width() + st::mediaviewFullScreenButtonSkip;
_fullScreenToggle->moveToRight(right, st::mediaviewButtonsTop); _fullScreenToggle->moveToRight(right, st::mediaviewButtonsTop);
@ -392,7 +397,7 @@ void PlaybackControls::mousePressEvent(QMouseEvent *e) {
} }
bool PlaybackControls::hasMenu() const { bool PlaybackControls::hasMenu() const {
return _speedController->menu() != nullptr; return _speedController && _speedController->menu();
} }
bool PlaybackControls::dragging() const { bool PlaybackControls::dragging() const {
@ -400,7 +405,7 @@ bool PlaybackControls::dragging() const {
|| _playbackSlider->isChanging() || _playbackSlider->isChanging()
|| _playPauseResume->isOver() || _playPauseResume->isOver()
|| _volumeToggle->isOver() || _volumeToggle->isOver()
|| _speedToggle->isOver() || (_speedToggle && _speedToggle->isOver())
|| _fullScreenToggle->isOver() || _fullScreenToggle->isOver()
|| _pictureInPicture->isOver(); || _pictureInPicture->isOver();
} }