mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Cached TTL badge in dialogs list.
This commit is contained in:
parent
84de08cad6
commit
d55d383627
2 changed files with 25 additions and 23 deletions
|
@ -35,20 +35,15 @@ constexpr auto kTopLayer = 2;
|
||||||
constexpr auto kBottomLayer = 1;
|
constexpr auto kBottomLayer = 1;
|
||||||
constexpr auto kNoneLayer = 0;
|
constexpr auto kNoneLayer = 0;
|
||||||
|
|
||||||
void PaintCornerBadgeTTLFrame(
|
[[nodiscard]] QImage CornerBadgeTTL(
|
||||||
QPainter &q,
|
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
Ui::PeerUserpicView &view,
|
Ui::PeerUserpicView &view,
|
||||||
float64 progress,
|
|
||||||
int photoSize) {
|
int photoSize) {
|
||||||
const auto ttl = peer->messagesTTL();
|
const auto ttl = peer->messagesTTL();
|
||||||
if (!ttl) {
|
if (!ttl) {
|
||||||
return;
|
return QImage();
|
||||||
}
|
}
|
||||||
constexpr auto kBlurRadius = 24;
|
constexpr auto kBlurRadius = 24;
|
||||||
PainterHighQualityEnabler hq(q);
|
|
||||||
|
|
||||||
q.setOpacity(progress);
|
|
||||||
|
|
||||||
const auto ratio = style::DevicePixelRatio();
|
const auto ratio = style::DevicePixelRatio();
|
||||||
const auto fullSize = photoSize;
|
const auto fullSize = photoSize;
|
||||||
|
@ -57,14 +52,7 @@ void PaintCornerBadgeTTLFrame(
|
||||||
kBlurRadius);
|
kBlurRadius);
|
||||||
const auto partRect = CornerBadgeTTLRect(fullSize);
|
const auto partRect = CornerBadgeTTLRect(fullSize);
|
||||||
const auto &partSize = partRect.width();
|
const auto &partSize = partRect.width();
|
||||||
if (progress <= 1.) {
|
auto result = [&] {
|
||||||
q.save();
|
|
||||||
q.translate(partRect.center());
|
|
||||||
q.scale(progress, progress);
|
|
||||||
q.translate(-partRect.center());
|
|
||||||
q.restore();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto blurredPart = blurredFull.copy(
|
auto blurredPart = blurredFull.copy(
|
||||||
blurredFull.width() - partSize * ratio,
|
blurredFull.width() - partSize * ratio,
|
||||||
blurredFull.height() - partSize * ratio,
|
blurredFull.height() - partSize * ratio,
|
||||||
|
@ -85,11 +73,14 @@ void PaintCornerBadgeTTLFrame(
|
||||||
QRect(QPoint(), partRect.size()),
|
QRect(QPoint(), partRect.size()),
|
||||||
Qt::black);
|
Qt::black);
|
||||||
}
|
}
|
||||||
q.drawImage(
|
return Images::Circle(std::move(blurredPart));
|
||||||
partRect.topLeft(),
|
}();
|
||||||
Images::Circle(std::move(blurredPart)));
|
|
||||||
}
|
auto q = QPainter(&result);
|
||||||
const auto innerRect = partRect - st::dialogsTTLBadgeInnerMargins;
|
PainterHighQualityEnabler hq(q);
|
||||||
|
|
||||||
|
const auto innerRect = QRect(QPoint(), partRect.size())
|
||||||
|
- st::dialogsTTLBadgeInnerMargins;
|
||||||
const auto ttlText = Ui::FormatTTLTiny(ttl);
|
const auto ttlText = Ui::FormatTTLTiny(ttl);
|
||||||
|
|
||||||
q.setFont(st::dialogsScamFont);
|
q.setFont(st::dialogsScamFont);
|
||||||
|
@ -112,12 +103,12 @@ void PaintCornerBadgeTTLFrame(
|
||||||
q.setBrush(Qt::NoBrush);
|
q.setBrush(Qt::NoBrush);
|
||||||
q.drawArc(innerRect, kAngleStart, kAngleSpan);
|
q.drawArc(innerRect, kAngleStart, kAngleSpan);
|
||||||
|
|
||||||
q.setClipRect(partRect - QMargins(partRect.width() / 2, 0, 0, 0));
|
q.setClipRect(innerRect - QMargins(innerRect.width() / 2, 0, 0, 0));
|
||||||
pen.setStyle(Qt::DotLine);
|
pen.setStyle(Qt::DotLine);
|
||||||
q.setPen(pen);
|
q.setPen(pen);
|
||||||
q.drawEllipse(innerRect);
|
q.drawEllipse(innerRect);
|
||||||
|
|
||||||
q.setOpacity(1.);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -355,7 +346,14 @@ void Row::PaintCornerBadgeFrame(
|
||||||
|
|
||||||
const auto &manager = data->layersManager;
|
const auto &manager = data->layersManager;
|
||||||
if (const auto p = manager.progressForLayer(kBottomLayer); p) {
|
if (const auto p = manager.progressForLayer(kBottomLayer); p) {
|
||||||
PaintCornerBadgeTTLFrame(q, peer, view, p, context.st->photoSize);
|
const auto size = context.st->photoSize;
|
||||||
|
if (data->cacheTTL.isNull() && peer->messagesTTL()) {
|
||||||
|
data->cacheTTL = CornerBadgeTTL(peer, view, size);
|
||||||
|
}
|
||||||
|
q.setOpacity(p);
|
||||||
|
const auto point = CornerBadgeTTLRect(size).topLeft();
|
||||||
|
q.drawImage(point, data->cacheTTL);
|
||||||
|
q.setOpacity(1.);
|
||||||
}
|
}
|
||||||
const auto topLayerProgress = manager.progressForLayer(kTopLayer);
|
const auto topLayerProgress = manager.progressForLayer(kTopLayer);
|
||||||
if (!topLayerProgress) {
|
if (!topLayerProgress) {
|
||||||
|
@ -429,6 +427,9 @@ void Row::paintUserpic(
|
||||||
auto key = peer->userpicUniqueKey(userpicView());
|
auto key = peer->userpicUniqueKey(userpicView());
|
||||||
key.first += peer->messagesTTL();
|
key.first += peer->messagesTTL();
|
||||||
const auto frameIndex = videoUserpic ? videoUserpic->frameIndex() : -1;
|
const auto frameIndex = videoUserpic ? videoUserpic->frameIndex() : -1;
|
||||||
|
if (_cornerBadgeUserpic->key != key) {
|
||||||
|
_cornerBadgeUserpic->cacheTTL = QImage();
|
||||||
|
}
|
||||||
if (!_cornerBadgeUserpic->layersManager.isFinished()
|
if (!_cornerBadgeUserpic->layersManager.isFinished()
|
||||||
|| _cornerBadgeUserpic->key != key
|
|| _cornerBadgeUserpic->key != key
|
||||||
|| _cornerBadgeUserpic->active != context.active
|
|| _cornerBadgeUserpic->active != context.active
|
||||||
|
|
|
@ -168,6 +168,7 @@ private:
|
||||||
int frameIndex = -1;
|
int frameIndex = -1;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
QImage frame;
|
QImage frame;
|
||||||
|
QImage cacheTTL;
|
||||||
};
|
};
|
||||||
|
|
||||||
void setCornerBadgeShown(
|
void setCornerBadgeShown(
|
||||||
|
|
Loading…
Add table
Reference in a new issue