mirror of https://github.com/procxx/kepka.git
Show download progress in playback controls.
This commit is contained in:
parent
46d8d9f97a
commit
0ce5405eef
|
@ -1485,6 +1485,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_mediaview_date_time" = "{date} at {time}";
|
"lng_mediaview_date_time" = "{date} at {time}";
|
||||||
|
|
||||||
"lng_mediaview_saved" = "Image was saved to your [c]Downloads[/c] folder";
|
"lng_mediaview_saved" = "Image was saved to your [c]Downloads[/c] folder";
|
||||||
|
"lng_mediaview_video_loading" = "Loading - {percent}";
|
||||||
|
|
||||||
"lng_theme_preview_title" = "Theme Preview";
|
"lng_theme_preview_title" = "Theme Preview";
|
||||||
"lng_theme_preview_generating" = "Generating color theme preview...";
|
"lng_theme_preview_generating" = "Generating color theme preview...";
|
||||||
|
|
|
@ -446,12 +446,21 @@ void OverlayWidget::clearLottie() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::documentUpdated(DocumentData *doc) {
|
void OverlayWidget::documentUpdated(DocumentData *doc) {
|
||||||
if (documentBubbleShown() && _doc && _doc == doc) {
|
if (_doc && _doc == doc) {
|
||||||
if ((_doc->loading() && _docCancel->isHidden()) || (!_doc->loading() && !_docCancel->isHidden())) {
|
if (documentBubbleShown()) {
|
||||||
updateControls();
|
if ((_doc->loading() && _docCancel->isHidden()) || (!_doc->loading() && !_docCancel->isHidden())) {
|
||||||
} else if (_doc->loading()) {
|
updateControls();
|
||||||
updateDocSize();
|
} else if (_doc->loading()) {
|
||||||
update(_docRect);
|
updateDocSize();
|
||||||
|
update(_docRect);
|
||||||
|
}
|
||||||
|
} else if (_streamed) {
|
||||||
|
const auto ready = _doc->loaded()
|
||||||
|
? _doc->size
|
||||||
|
: _doc->loading()
|
||||||
|
? std::clamp(_doc->loadOffset(), 0, _doc->size)
|
||||||
|
: 0;
|
||||||
|
_streamed->controls.setLoadingProgress(ready, _doc->size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/continuous_sliders.h"
|
#include "ui/widgets/continuous_sliders.h"
|
||||||
#include "ui/effects/fade_animation.h"
|
#include "ui/effects/fade_animation.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "styles/style_mediaview.h"
|
#include "styles/style_mediaview.h"
|
||||||
|
|
||||||
|
@ -157,6 +158,45 @@ void PlaybackControls::updatePlayback(const Player::TrackState &state) {
|
||||||
updateTimeTexts(state);
|
updateTimeTexts(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaybackControls::setLoadingProgress(int ready, int total) {
|
||||||
|
if (_loadingReady == ready && _loadingTotal == total) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_loadingReady = ready;
|
||||||
|
_loadingTotal = total;
|
||||||
|
if (_loadingReady != 0 && _loadingReady != _loadingTotal) {
|
||||||
|
if (!_downloadProgress) {
|
||||||
|
_downloadProgress.create(this, st::mediaviewPlayProgressLabel);
|
||||||
|
_downloadProgress->setVisible(!_fadeAnimation->animating());
|
||||||
|
_loadingPercent = -1;
|
||||||
|
}
|
||||||
|
const auto progress = total ? (ready / float64(total)) : 0.;
|
||||||
|
const auto percent = int(std::round(progress * 100));
|
||||||
|
if (_loadingPercent != percent) {
|
||||||
|
_loadingPercent = percent;
|
||||||
|
_downloadProgress->setText(lng_mediaview_video_loading(
|
||||||
|
lt_percent,
|
||||||
|
QString::number(percent) + '%'));
|
||||||
|
if (_playbackSlider->width() > _downloadProgress->width()) {
|
||||||
|
const auto left = (_playbackSlider->width() - _downloadProgress->width()) / 2;
|
||||||
|
_downloadProgress->move(_playbackSlider->x() + left, st::mediaviewPlayProgressTop);
|
||||||
|
}
|
||||||
|
refreshFadeCache();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_downloadProgress.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaybackControls::refreshFadeCache() {
|
||||||
|
if (!_fadeAnimation->animating()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startFading([&] {
|
||||||
|
_fadeAnimation->refreshCache();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void PlaybackControls::updatePlayPauseResumeState(const Player::TrackState &state) {
|
void PlaybackControls::updatePlayPauseResumeState(const Player::TrackState &state) {
|
||||||
auto showPause = ShowPauseIcon(state.state) || (_seekPositionMs >= 0);
|
auto showPause = ShowPauseIcon(state.state) || (_seekPositionMs >= 0);
|
||||||
if (showPause != _showPause) {
|
if (showPause != _showPause) {
|
||||||
|
@ -207,9 +247,7 @@ void PlaybackControls::refreshTimeTexts() {
|
||||||
_toPlayLeft->setText(timeLeft, &leftChanged);
|
_toPlayLeft->setText(timeLeft, &leftChanged);
|
||||||
if (alreadyChanged || leftChanged) {
|
if (alreadyChanged || leftChanged) {
|
||||||
resizeEvent(nullptr);
|
resizeEvent(nullptr);
|
||||||
startFading([this]() {
|
refreshFadeCache();
|
||||||
_fadeAnimation->refreshCache();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,6 +276,11 @@ void PlaybackControls::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
||||||
_playedAlready->moveToLeft(st::mediaviewPlayPauseLeft + _playPauseResume->width() + playTop, st::mediaviewPlayProgressTop);
|
_playedAlready->moveToLeft(st::mediaviewPlayPauseLeft + _playPauseResume->width() + playTop, st::mediaviewPlayProgressTop);
|
||||||
_toPlayLeft->moveToRight(width() - (st::mediaviewPlayPauseLeft + _playPauseResume->width() + playTop) - playbackWidth, st::mediaviewPlayProgressTop);
|
_toPlayLeft->moveToRight(width() - (st::mediaviewPlayPauseLeft + _playPauseResume->width() + playTop) - playbackWidth, st::mediaviewPlayProgressTop);
|
||||||
|
|
||||||
|
if (_downloadProgress) {
|
||||||
|
const auto left = (_playbackSlider->width() - _downloadProgress->width()) / 2;
|
||||||
|
_downloadProgress->move(_playbackSlider->x() + left, st::mediaviewPlayProgressTop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackControls::paintEvent(QPaintEvent *e) {
|
void PlaybackControls::paintEvent(QPaintEvent *e) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
void hideAnimated();
|
void hideAnimated();
|
||||||
|
|
||||||
void updatePlayback(const Player::TrackState &state);
|
void updatePlayback(const Player::TrackState &state);
|
||||||
|
void setLoadingProgress(int ready, int total);
|
||||||
void setInFullScreen(bool inFullScreen);
|
void setInFullScreen(bool inFullScreen);
|
||||||
|
|
||||||
~PlaybackControls();
|
~PlaybackControls();
|
||||||
|
@ -62,6 +63,7 @@ private:
|
||||||
void startFading(Callback start);
|
void startFading(Callback start);
|
||||||
void fadeFinished();
|
void fadeFinished();
|
||||||
void fadeUpdated(float64 opacity);
|
void fadeUpdated(float64 opacity);
|
||||||
|
void refreshFadeCache();
|
||||||
|
|
||||||
void updatePlayPauseResumeState(const Player::TrackState &state);
|
void updatePlayPauseResumeState(const Player::TrackState &state);
|
||||||
void updateTimeTexts(const Player::TrackState &state);
|
void updateTimeTexts(const Player::TrackState &state);
|
||||||
|
@ -75,6 +77,9 @@ private:
|
||||||
QString _timeAlready, _timeLeft;
|
QString _timeAlready, _timeLeft;
|
||||||
crl::time _seekPositionMs = -1;
|
crl::time _seekPositionMs = -1;
|
||||||
crl::time _lastDurationMs = 0;
|
crl::time _lastDurationMs = 0;
|
||||||
|
int _loadingReady = 0;
|
||||||
|
int _loadingTotal = 0;
|
||||||
|
int _loadingPercent = 0;
|
||||||
|
|
||||||
object_ptr<Ui::IconButton> _playPauseResume;
|
object_ptr<Ui::IconButton> _playPauseResume;
|
||||||
object_ptr<Ui::MediaSlider> _playbackSlider;
|
object_ptr<Ui::MediaSlider> _playbackSlider;
|
||||||
|
@ -84,6 +89,7 @@ private:
|
||||||
object_ptr<Ui::IconButton> _fullScreenToggle;
|
object_ptr<Ui::IconButton> _fullScreenToggle;
|
||||||
object_ptr<Ui::LabelSimple> _playedAlready;
|
object_ptr<Ui::LabelSimple> _playedAlready;
|
||||||
object_ptr<Ui::LabelSimple> _toPlayLeft;
|
object_ptr<Ui::LabelSimple> _toPlayLeft;
|
||||||
|
object_ptr<Ui::LabelSimple> _downloadProgress = { nullptr };
|
||||||
|
|
||||||
std::unique_ptr<Ui::FadeAnimation> _fadeAnimation;
|
std::unique_ptr<Ui::FadeAnimation> _fadeAnimation;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue