From acbaf834426f07d56d8e06d0e0af404641a429ad Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 30 Sep 2016 21:10:54 +0300 Subject: [PATCH] Disabling playback seeking in new media player when loading audio. --- .../SourceFiles/media/player/media_player_cover.cpp | 2 ++ .../SourceFiles/media/view/media_clip_playback.h | 3 +++ Telegram/SourceFiles/ui/widgets/media_slider.cpp | 12 ++++++++++-- Telegram/SourceFiles/ui/widgets/media_slider.h | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/media/player/media_player_cover.cpp b/Telegram/SourceFiles/media/player/media_player_cover.cpp index 4f50aa848..a2c6da7bd 100644 --- a/Telegram/SourceFiles/media/player/media_player_cover.cpp +++ b/Telegram/SourceFiles/media/player/media_player_cover.cpp @@ -195,10 +195,12 @@ void CoverWidget::updateTimeText(const AudioMsgId &audioId, const AudioPlaybackS if (duration || !audioId.audio()->loading()) { display = display / frequency; _time = formatDurationText(display); + _playback->setDisabled(false); } else { auto loaded = audioId.audio()->loadOffset(); auto loadProgress = snap(float64(loaded) / qMax(audioId.audio()->size, 1), 0., 1.); _time = QString::number(qRound(loadProgress * 100)) + '%'; + _playback->setDisabled(true); } if (_seekPositionMs < 0) { updateTimeLabel(); diff --git a/Telegram/SourceFiles/media/view/media_clip_playback.h b/Telegram/SourceFiles/media/view/media_clip_playback.h index 2538a80be..32cb2ffe5 100644 --- a/Telegram/SourceFiles/media/view/media_clip_playback.h +++ b/Telegram/SourceFiles/media/view/media_clip_playback.h @@ -63,6 +63,9 @@ public: void resize(int w, int h) { _slider->resize(w, h); } + void setDisabled(bool disabled) { + _slider->setDisabled(disabled); + } private: Ui::MediaSlider *_slider; diff --git a/Telegram/SourceFiles/ui/widgets/media_slider.cpp b/Telegram/SourceFiles/ui/widgets/media_slider.cpp index 51d85cf5b..a4a3db825 100644 --- a/Telegram/SourceFiles/ui/widgets/media_slider.cpp +++ b/Telegram/SourceFiles/ui/widgets/media_slider.cpp @@ -35,6 +35,14 @@ float64 MediaSlider::value() const { return a_value.current(); } +void MediaSlider::setDisabled(bool disabled) { + if (_disabled != disabled) { + _disabled = disabled; + setCursor(_disabled ? style::cur_default : style::cur_pointer); + update(); + } +} + void MediaSlider::setValue(float64 value, bool animated) { if (animated) { a_value.start(value); @@ -84,7 +92,7 @@ void MediaSlider::paintEvent(QPaintEvent *e) { int skip = lineLeft(); int length = lineWidth(); float64 prg = _mouseDown ? _downValue : a_value.current(); - int32 from = skip, mid = qRound(from + prg * length), end = from + length; + int32 from = skip, mid = _disabled ? 0 : qRound(from + prg * length), end = from + length; if (mid > from) { p.setClipRect(0, 0, mid, height()); p.setOpacity(_fadeOpacity * (over * _st.activeOpacity + (1. - over) * _st.inactiveOpacity)); @@ -97,7 +105,7 @@ void MediaSlider::paintEvent(QPaintEvent *e) { p.setBrush(_st.inactiveFg); p.drawRoundedRect(mid - radius, (height() - _st.width) / 2, end - (mid - radius), _st.width, radius, radius); } - if (over > 0) { + if (!_disabled && over > 0) { int x = mid - skip; p.setClipRect(rect()); p.setOpacity(_fadeOpacity * _st.activeOpacity); diff --git a/Telegram/SourceFiles/ui/widgets/media_slider.h b/Telegram/SourceFiles/ui/widgets/media_slider.h index 27cf74278..3b4433c02 100644 --- a/Telegram/SourceFiles/ui/widgets/media_slider.h +++ b/Telegram/SourceFiles/ui/widgets/media_slider.h @@ -33,6 +33,7 @@ public: float64 value() const; void setValue(float64 value, bool animated); void setFadeOpacity(float64 opacity); + void setDisabled(bool disabled); using Callback = base::lambda_unique; void setChangeProgressCallback(Callback &&callback) { @@ -60,6 +61,8 @@ private: const style::MediaSlider &_st; + bool _disabled = false; + Callback _changeProgressCallback; Callback _changeFinishedCallback;