Allow getting AnimatedIcon frame rate.

This commit is contained in:
John Preston 2023-06-15 20:07:58 +04:00
parent 1e89c19a03
commit 3749f10e7f
2 changed files with 14 additions and 0 deletions

View file

@ -41,6 +41,7 @@ public:
[[nodiscard]] bool valid() const;
[[nodiscard]] QSize size() const;
[[nodiscard]] int framesCount() const;
[[nodiscard]] double frameRate() const;
[[nodiscard]] Frame &frame();
[[nodiscard]] const Frame &frame() const;
@ -67,6 +68,7 @@ private:
base::weak_ptr<AnimatedIcon> _weak;
int _framesCount = 0;
double _frameRate = 0.;
mutable crl::semaphore _semaphore;
mutable bool _ready = false;
@ -88,6 +90,7 @@ void AnimatedIcon::Impl::prepareFromAsync(
return;
}
_framesCount = generator->count();
_frameRate = generator->rate();
_current.generated = generator->renderNext(QImage(), sizeOverride);
if (_current.generated.image.isNull()) {
return;
@ -120,6 +123,11 @@ int AnimatedIcon::Impl::framesCount() const {
return _framesCount;
}
double AnimatedIcon::Impl::frameRate() const {
waitTillPrepared();
return _frameRate;
}
AnimatedIcon::Frame &AnimatedIcon::Impl::frame() {
waitTillPrepared();
return _current;
@ -222,6 +230,10 @@ int AnimatedIcon::framesCount() const {
return _impl->framesCount();
}
double AnimatedIcon::frameRate() const {
return _impl->frameRate();
}
QImage AnimatedIcon::frame(const QColor &textColor) const {
return frame(textColor, QSize(), nullptr).image;
}
@ -356,6 +368,7 @@ int AnimatedIcon::wantedFrameIndex(
const auto next = _animationCurrentStart + duration;
if (frame->generated.last) {
_animation.stop();
if (_repaint) _repaint();
return _animationCurrentIndex;
} else if (now < next) {
return _animationCurrentIndex;

View file

@ -36,6 +36,7 @@ public:
[[nodiscard]] bool valid() const;
[[nodiscard]] int frameIndex() const;
[[nodiscard]] int framesCount() const;
[[nodiscard]] double frameRate() const;
[[nodiscard]] QImage frame(const QColor &textColor) const;
[[nodiscard]] QImage notColorizedFrame() const;
[[nodiscard]] int width() const;