Show radial progress in PeerShortInfoBox video.

This commit is contained in:
John Preston 2021-10-22 13:45:04 +04:00
parent 9f21da8bde
commit d73d5724d8
3 changed files with 54 additions and 2 deletions

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/peers/peer_short_info_box.h"
#include "ui/effects/radial_animation.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/vertical_layout.h"
@ -36,6 +37,17 @@ struct PeerShortInfoBox::CustomLabelStyle {
float64 opacity = 1.;
};
struct PeerShortInfoBox::Radial {
explicit Radial(Fn<void()> &&callback);
Ui::RadialAnimation radial;
base::Timer removeTimer;
};
PeerShortInfoBox::Radial::Radial(Fn<void()> &&callback)
: radial(callback) {
}
PeerShortInfoBox::CustomLabelStyle::CustomLabelStyle(
const style::FlatLabel &original)
: textFg([=, c = original.textFg]{
@ -259,6 +271,7 @@ void PeerShortInfoBox::paintCover(QPainter &p) {
paintCoverImage(p, frame.isNull() ? _userpicImage : frame);
paintBars(p);
paintShadow(p);
paintRadial(p);
if (_videoInstance && _videoInstance->ready() && !paused) {
_videoInstance->markFrameShown();
}
@ -437,6 +450,31 @@ void PeerShortInfoBox::paintShadow(QPainter &p) {
p.setOpacity(1.);
}
void PeerShortInfoBox::paintRadial(QPainter &p) {
const auto radial = radialRect();
if (_videoInstance && _videoInstance->waitingShown()) {
const auto line = st::shortInfoRadialAnimation.thickness;
const auto arc = radial.marginsRemoved(
{ line, line, line, line });
p.setOpacity(_videoInstance->waitingOpacity());
p.setPen(Qt::NoPen);
p.setBrush(st::radialBg);
{
PainterHighQualityEnabler hq(p);
p.drawEllipse(radial);
}
p.setOpacity(1.);
Ui::InfiniteRadialAnimation::Draw(
p,
_videoInstance->waitingState(),
arc.topLeft(),
arc.size(),
st::shortInfoWidth,
st::radialFg,
line);
}
}
QImage PeerShortInfoBox::currentVideoFrame() const {
const auto coverSize = st::shortInfoWidth;
const auto size = QSize(coverSize, coverSize);
@ -631,11 +669,16 @@ void PeerShortInfoBox::refreshBarImages() {
QRect PeerShortInfoBox::radialRect() const {
const auto cover = _cover->rect();
return cover;
const auto size = st::boxLoadingSize;
return QRect(
cover.x() + (cover.width() - size) / 2,
cover.y() + (cover.height() - size) / 2,
size,
size);
}
void PeerShortInfoBox::videoWaiting() {
if (!anim::Disabled()) {
update(radialRect());
_cover->update(radialRect());
}
}

View File

@ -63,6 +63,7 @@ public:
private:
struct CustomLabelStyle;
struct Radial;
void prepare() override;
void prepareRows();
@ -74,6 +75,7 @@ private:
void paintCoverImage(QPainter &p, const QImage &image);
void paintBars(QPainter &p);
void paintShadow(QPainter &p);
void paintRadial(QPainter &p);
void refreshRoundedTopImage(const QColor &color);
int fillRoundedTopHeight();
@ -132,6 +134,8 @@ private:
Fn<bool()> _videoPaused;
QImage _shadowBottom;
std::unique_ptr<Radial> _radial;
rpl::event_stream<> _openRequests;
rpl::event_stream<int> _moveRequests;

View File

@ -984,3 +984,8 @@ shortInfoScroll: ScrollArea(defaultScrollArea) {
duration: 150;
hiding: 1000;
}
shortInfoRadialAnimation: InfiniteRadialAnimation(defaultInfiniteRadialAnimation) {
color: radialFg;
thickness: 2px;
}