mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/telegramdesktop/tdesktop
synced 2026-09-21 00:23:56 +08:00
979 lines
28 KiB
C++
979 lines
28 KiB
C++
/*
|
|
This file is part of Telegram Desktop,
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
For license and copyright information please follow this link:
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
*/
|
|
#include "dialogs/dialogs_row.h"
|
|
|
|
#include "ui/chat/chat_theme.h" // CountAverageColor.
|
|
#include "ui/color_contrast.h"
|
|
#include "ui/effects/credits_graphics.h"
|
|
#include "ui/effects/outline_segments.h"
|
|
#include "ui/effects/ripple_animation.h"
|
|
#include "ui/effects/ttl_icon.h"
|
|
#include "ui/effects/round_checkbox.h"
|
|
#include "ui/image/image_prepare.h"
|
|
#include "ui/text/custom_emoji_text_badge.h"
|
|
#include "ui/text/format_values.h"
|
|
#include "ui/text/text_options.h"
|
|
#include "ui/text/text_utilities.h"
|
|
#include "ui/painter.h"
|
|
#include "dialogs/dialogs_entry.h"
|
|
#include "dialogs/ui/dialogs_video_userpic.h"
|
|
#include "dialogs/ui/dialogs_layout.h"
|
|
#include "data/data_channel.h"
|
|
#include "data/data_community.h"
|
|
#include "data/data_folder.h"
|
|
#include "data/data_forum.h"
|
|
#include "data/data_session.h"
|
|
#include "data/data_stories.h"
|
|
#include "data/data_peer_values.h"
|
|
#include "data/data_user.h"
|
|
#include "history/history.h"
|
|
#include "history/history_item.h"
|
|
#include "lang/lang_keys.h"
|
|
#include "base/unixtime.h"
|
|
#include "styles/style_dialogs.h"
|
|
|
|
namespace Dialogs {
|
|
namespace {
|
|
|
|
constexpr auto kTopLayer = 3;
|
|
constexpr auto kHiddenLayer = 2;
|
|
constexpr auto kBottomLayer = 1;
|
|
constexpr auto kNoneLayer = 0;
|
|
constexpr auto kBlurRadius = 24;
|
|
|
|
[[nodiscard]] int SubscriptionCutSkip() {
|
|
const auto width = st::dialogsSubscriptionBadgeOutlineTwice / 2.;
|
|
return int(std::ceil(width)) + 1;
|
|
}
|
|
|
|
// Exact squared euclidean distance transform, two separable passes.
|
|
[[nodiscard]] std::vector<float64> SquaredDistances(
|
|
std::vector<float64> grid,
|
|
int side) {
|
|
constexpr auto kFar = 1e12;
|
|
auto values = std::vector<float64>(side);
|
|
auto hulls = std::vector<int>(side);
|
|
auto breaks = std::vector<float64>(side + 1);
|
|
const auto pass = [&](auto read, auto write) {
|
|
for (auto i = 0; i != side; ++i) {
|
|
values[i] = read(i);
|
|
}
|
|
auto last = 0;
|
|
hulls[0] = 0;
|
|
breaks[0] = -kFar;
|
|
breaks[1] = kFar;
|
|
for (auto i = 1; i != side; ++i) {
|
|
auto cross = 0.;
|
|
while (true) {
|
|
const auto hull = hulls[last];
|
|
cross = ((values[i] + float64(i) * i)
|
|
- (values[hull] + float64(hull) * hull))
|
|
/ (2. * i - 2. * hull);
|
|
if (last > 0 && cross <= breaks[last]) {
|
|
--last;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
++last;
|
|
hulls[last] = i;
|
|
breaks[last] = cross;
|
|
breaks[last + 1] = kFar;
|
|
}
|
|
last = 0;
|
|
for (auto i = 0; i != side; ++i) {
|
|
while (breaks[last + 1] < i) {
|
|
++last;
|
|
}
|
|
const auto hull = hulls[last];
|
|
write(i, float64(i - hull) * (i - hull) + values[hull]);
|
|
}
|
|
};
|
|
for (auto x = 0; x != side; ++x) {
|
|
pass(
|
|
[&](int y) { return grid[y * side + x]; },
|
|
[&](int y, float64 value) { grid[y * side + x] = value; });
|
|
}
|
|
for (auto y = 0; y != side; ++y) {
|
|
pass(
|
|
[&](int x) { return grid[y * side + x]; },
|
|
[&](int x, float64 value) { grid[y * side + x] = value; });
|
|
}
|
|
return grid;
|
|
}
|
|
|
|
// Star silhouette grown by outline width in every direction.
|
|
[[nodiscard]] const QImage &SubscriptionCutMask() {
|
|
constexpr auto kSupersample = 4;
|
|
|
|
static auto mask = QImage();
|
|
if (!mask.isNull()) {
|
|
return mask;
|
|
}
|
|
const auto ratio = style::DevicePixelRatio();
|
|
const auto skip = SubscriptionCutSkip();
|
|
const auto size = st::dialogsSubscriptionBadgeSize + 2 * skip;
|
|
const auto star = Ui::GenerateStars(
|
|
st::dialogsSubscriptionBadgeSize,
|
|
1,
|
|
ratio * kSupersample);
|
|
const auto side = size * ratio * kSupersample;
|
|
const auto offset = skip * ratio * kSupersample;
|
|
constexpr auto kFar = 1e12;
|
|
auto grid = std::vector<float64>(side * side, kFar);
|
|
for (auto y = 0; y != star.height(); ++y) {
|
|
const auto line = reinterpret_cast<const QRgb*>(
|
|
star.constScanLine(y));
|
|
for (auto x = 0; x != star.width(); ++x) {
|
|
if (qAlpha(line[x]) > 127) {
|
|
grid[(y + offset) * side + (x + offset)] = 0.;
|
|
}
|
|
}
|
|
}
|
|
const auto squared = SquaredDistances(std::move(grid), side);
|
|
const auto radius = (st::dialogsSubscriptionBadgeOutlineTwice / 2.)
|
|
* ratio
|
|
* kSupersample;
|
|
const auto result = size * ratio;
|
|
mask = QImage(result, result, QImage::Format_ARGB32_Premultiplied);
|
|
mask.setDevicePixelRatio(ratio);
|
|
for (auto y = 0; y != result; ++y) {
|
|
const auto line = reinterpret_cast<QRgb*>(mask.scanLine(y));
|
|
for (auto x = 0; x != result; ++x) {
|
|
auto covered = 0.;
|
|
for (auto inner = 0; inner != kSupersample; ++inner) {
|
|
const auto row = (y * kSupersample + inner) * side
|
|
+ x * kSupersample;
|
|
for (auto i = 0; i != kSupersample; ++i) {
|
|
covered += std::clamp(
|
|
radius + 0.5 - std::sqrt(squared[row + i]),
|
|
0.,
|
|
1.);
|
|
}
|
|
}
|
|
const auto alpha = base::SafeRound(
|
|
255. * covered / (kSupersample * kSupersample));
|
|
line[x] = qRgba(0, 0, 0, int(alpha));
|
|
}
|
|
}
|
|
return mask;
|
|
}
|
|
|
|
[[nodiscard]] const QImage &SubscriptionIcon() {
|
|
static auto starImage = QImage();
|
|
if (!starImage.isNull()) {
|
|
return starImage;
|
|
}
|
|
starImage = Ui::GenerateStars(st::dialogsSubscriptionBadgeSize, 1);
|
|
return starImage;
|
|
}
|
|
|
|
[[nodiscard]] QImage CornerBadgeTTL(
|
|
not_null<PeerData*> peer,
|
|
Ui::PeerUserpicView &view,
|
|
int photoSize) {
|
|
const auto ttl = peer->messagesTTL();
|
|
if (!ttl) {
|
|
return QImage();
|
|
}
|
|
const auto ratio = style::DevicePixelRatio();
|
|
const auto fullSize = photoSize;
|
|
const auto partRect = CornerBadgeTTLRect(fullSize);
|
|
const auto &partSize = partRect.width();
|
|
const auto partSkip = fullSize - partSize;
|
|
auto result = Images::Circle(BlurredDarkenedPart(
|
|
PeerData::GenerateUserpicImage(peer, view, fullSize * ratio, 0),
|
|
QRect(
|
|
QPoint(partSkip, partSkip) * ratio,
|
|
QSize(partSize, partSize) * ratio)));
|
|
result.setDevicePixelRatio(ratio);
|
|
|
|
auto q = QPainter(&result);
|
|
PainterHighQualityEnabler hq(q);
|
|
|
|
const auto innerRect = QRect(QPoint(), partRect.size())
|
|
- st::dialogsTTLBadgeInnerMargins;
|
|
const auto ttlText = Ui::FormatTTLTiny(ttl);
|
|
|
|
Ui::PaintTimerIcon(q, innerRect, ttlText, st::premiumButtonFg->c);
|
|
|
|
return result;
|
|
}
|
|
|
|
[[nodiscard]] QRect CornerBadgeHiddenRect(int photoSize) {
|
|
const auto iconSize = st::dialogsCommunityHiddenBadgeIcon.size();
|
|
const auto padding = st::dialogsCommunityHiddenBadgePadding;
|
|
const auto margins = QMargins(padding, padding, padding, padding);
|
|
const auto badgeSize = iconSize.grownBy(margins);
|
|
return QRect(
|
|
QPoint(
|
|
photoSize - badgeSize.width()
|
|
+ st::dialogsTTLBadgeSkip.x(),
|
|
photoSize - badgeSize.height()
|
|
+ st::dialogsTTLBadgeSkip.y()),
|
|
badgeSize);
|
|
}
|
|
|
|
[[nodiscard]] QImage CornerBadgeHidden(
|
|
not_null<PeerData*> peer,
|
|
Ui::PeerUserpicView &view,
|
|
int photoSize) {
|
|
const auto ratio = style::DevicePixelRatio();
|
|
const auto fullSize = photoSize;
|
|
const auto partSize = CornerBadgeHiddenRect(fullSize).size();
|
|
auto result = Images::Circle(BlurredDarkenedPart(
|
|
PeerData::GenerateUserpicImage(peer, view, fullSize * ratio, 0),
|
|
QRect(
|
|
QPoint(
|
|
fullSize - partSize.width(),
|
|
fullSize - partSize.height()) * ratio,
|
|
partSize * ratio)));
|
|
result.setDevicePixelRatio(ratio);
|
|
|
|
auto q = QPainter(&result);
|
|
PainterHighQualityEnabler hq(q);
|
|
|
|
st::dialogsCommunityHiddenBadgeIcon.paintInCenter(
|
|
q,
|
|
QRect(QPoint(), partSize));
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
QRect CornerBadgeTTLRect(int photoSize) {
|
|
const auto &partSize = st::dialogsTTLBadgeSize;
|
|
return QRect(
|
|
photoSize - partSize + st::dialogsTTLBadgeSkip.x(),
|
|
photoSize - partSize + st::dialogsTTLBadgeSkip.y(),
|
|
partSize,
|
|
partSize);
|
|
}
|
|
|
|
QImage BlurredDarkenedPart(QImage image, QRect part) {
|
|
auto blurred = Images::BlurLargeImage(
|
|
std::move(image),
|
|
kBlurRadius).copy(part);
|
|
|
|
constexpr auto kMinAcceptableContrast = 4.5;
|
|
const auto averageColor = Ui::CountAverageColor(blurred);
|
|
const auto contrast = Ui::CountContrast(
|
|
averageColor,
|
|
st::premiumButtonFg->c);
|
|
if (contrast < kMinAcceptableContrast) {
|
|
constexpr auto kDarkerBy = 0.2;
|
|
auto painterPart = QPainter(&blurred);
|
|
painterPart.setOpacity(kDarkerBy);
|
|
painterPart.fillRect(QRect(QPoint(), part.size()), Qt::black);
|
|
}
|
|
|
|
blurred.setDevicePixelRatio(image.devicePixelRatio());
|
|
return blurred;
|
|
}
|
|
|
|
Row::CornerLayersManager::CornerLayersManager() = default;
|
|
|
|
bool Row::CornerLayersManager::isSameLayer(Layer layer) const {
|
|
return isFinished() && (_nextLayer == layer);
|
|
}
|
|
|
|
void Row::CornerLayersManager::setLayer(
|
|
Layer layer,
|
|
Fn<void()> updateCallback) {
|
|
if (_nextLayer == layer) {
|
|
return;
|
|
}
|
|
_lastFrameShown = false;
|
|
_prevLayer = _nextLayer;
|
|
_nextLayer = layer;
|
|
if (_animation.animating()) {
|
|
_animation.change(
|
|
1.,
|
|
st::dialogsOnlineBadgeDuration * (1. - _animation.value(1.)));
|
|
} else if (updateCallback) {
|
|
_animation.start(
|
|
std::move(updateCallback),
|
|
0.,
|
|
1.,
|
|
st::dialogsOnlineBadgeDuration);
|
|
}
|
|
}
|
|
|
|
float64 Row::CornerLayersManager::progressForLayer(Layer layer) const {
|
|
return (_nextLayer == layer)
|
|
? progress()
|
|
: (_prevLayer == layer)
|
|
? (1. - progress())
|
|
: 0.;
|
|
}
|
|
|
|
float64 Row::CornerLayersManager::progress() const {
|
|
return _animation.value(1.);
|
|
}
|
|
|
|
bool Row::CornerLayersManager::isFinished() const {
|
|
return (progress() == 1.) && _lastFrameShown;
|
|
}
|
|
|
|
void Row::CornerLayersManager::markFrameShown() {
|
|
if (progress() == 1.) {
|
|
_lastFrameShown = true;
|
|
}
|
|
}
|
|
|
|
bool Row::CornerLayersManager::isDisplayedNone() const {
|
|
return (progress() == 1.) && (_nextLayer == 0);
|
|
}
|
|
|
|
BasicRow::BasicRow() = default;
|
|
BasicRow::~BasicRow() = default;
|
|
|
|
void BasicRow::addRipple(
|
|
QPoint origin,
|
|
QSize size,
|
|
Fn<void()> updateCallback) {
|
|
if (!_ripple) {
|
|
addRippleWithMask(
|
|
origin,
|
|
Ui::RippleAnimation::RectMask(size),
|
|
std::move(updateCallback));
|
|
} else {
|
|
_ripple->add(origin);
|
|
}
|
|
}
|
|
|
|
void BasicRow::addRippleWithMask(
|
|
QPoint origin,
|
|
QImage mask,
|
|
Fn<void()> updateCallback) {
|
|
_ripple = std::make_unique<Ui::RippleAnimation>(
|
|
st::dialogsRipple,
|
|
std::move(mask),
|
|
std::move(updateCallback));
|
|
_ripple->add(origin);
|
|
}
|
|
|
|
void BasicRow::clearRipple() {
|
|
_ripple = nullptr;
|
|
}
|
|
|
|
void BasicRow::stopLastRipple() {
|
|
if (_ripple) {
|
|
_ripple->lastStop();
|
|
}
|
|
}
|
|
|
|
void BasicRow::paintRipple(
|
|
QPainter &p,
|
|
int x,
|
|
int y,
|
|
int outerWidth,
|
|
const QColor *colorOverride) const {
|
|
if (_ripple) {
|
|
_ripple->paint(p, x, y, outerWidth, colorOverride);
|
|
if (_ripple->empty()) {
|
|
_ripple.reset();
|
|
}
|
|
}
|
|
}
|
|
|
|
void BasicRow::paintUserpic(
|
|
Painter &p,
|
|
not_null<Entry*> entry,
|
|
PeerData *peer,
|
|
Ui::VideoUserpic *videoUserpic,
|
|
const Ui::PaintContext &context,
|
|
bool hasUnreadBadgesAbove) const {
|
|
PaintUserpic(p, entry, peer, videoUserpic, _userpic, context);
|
|
}
|
|
|
|
Row::Row(Key key, int index, int top) : _id(key), _top(top), _index(index) {
|
|
if (const auto history = key.history()) {
|
|
updateCornerBadgeShown(history->peer);
|
|
}
|
|
}
|
|
|
|
Row::~Row() {
|
|
clearTopicJumpRipple();
|
|
}
|
|
|
|
const style::DialogRow &Row::ComputeSt(
|
|
not_null<const Entry*> entry,
|
|
FilterId filterId) {
|
|
if (const auto history = entry->asHistory()) {
|
|
const auto hasTags = entry->hasChatsFilterTags(filterId);
|
|
const auto wideRow = history->peer->displayAsForum()
|
|
|| history->amMonoforumAdmin();
|
|
return wideRow
|
|
? (hasTags ? st::taggedForumDialogRow : st::forumDialogRow)
|
|
: hasTags
|
|
? st::taggedDialogRow
|
|
: st::defaultDialogRow;
|
|
} else if (entry->asTopic()) {
|
|
return st::forumTopicRow;
|
|
}
|
|
return st::defaultDialogRow;
|
|
}
|
|
|
|
void Row::recountHeight(float64 narrowRatio, FilterId filterId) {
|
|
const auto &st = ComputeSt(_id.entry(), filterId);
|
|
_height = ((&st == &st::defaultDialogRow) || !_id.history())
|
|
? st::defaultDialogRow.height
|
|
: anim::interpolate(
|
|
st.height,
|
|
st::defaultDialogRow.height,
|
|
narrowRatio);
|
|
}
|
|
|
|
uint64 Row::sortKey(FilterId filterId) const {
|
|
return _id.entry()->sortKeyInChatList(filterId);
|
|
}
|
|
|
|
void Row::setCornerBadgeShown(
|
|
CornerLayersManager::Layer nextLayer,
|
|
Fn<void()> updateCallback) const {
|
|
const auto cornerBadgeShown = (nextLayer ? 1 : 0);
|
|
if (_cornerBadgeShown == cornerBadgeShown) {
|
|
if (!cornerBadgeShown) {
|
|
return;
|
|
} else if (_cornerBadgeUserpic
|
|
&& _cornerBadgeUserpic->layersManager.isSameLayer(nextLayer)) {
|
|
return;
|
|
}
|
|
}
|
|
const_cast<Row*>(this)->_cornerBadgeShown = cornerBadgeShown;
|
|
ensureCornerBadgeUserpic();
|
|
_cornerBadgeUserpic->layersManager.setLayer(
|
|
nextLayer,
|
|
std::move(updateCallback));
|
|
if (!_cornerBadgeShown
|
|
&& _cornerBadgeUserpic
|
|
&& _cornerBadgeUserpic->layersManager.isDisplayedNone()) {
|
|
_cornerBadgeUserpic = nullptr;
|
|
}
|
|
}
|
|
|
|
void Row::updateCornerBadgeShown(
|
|
not_null<PeerData*> peer,
|
|
Fn<void()> updateCallback,
|
|
bool hasUnreadBadgesAbove,
|
|
bool insideCommunity,
|
|
bool hidden) const {
|
|
const auto user = peer->asUser();
|
|
const auto now = user ? base::unixtime::now() : TimeId();
|
|
const auto channel = user ? nullptr : peer->asChannel();
|
|
const auto nextLayer = [&] {
|
|
if (hasUnreadBadgesAbove) {
|
|
return kNoneLayer;
|
|
} else if (user
|
|
&& (Data::IsUserOnline(user, now)
|
|
|| (!insideCommunity && user->linkedCommunityId()))) {
|
|
return kTopLayer;
|
|
} else if (channel
|
|
&& (Data::ChannelHasActiveCall(channel)
|
|
|| Data::ChannelHasSubscriptionUntilDate(channel)
|
|
|| (!insideCommunity && channel->linkedCommunityId()))) {
|
|
return kTopLayer;
|
|
} else if (hidden) {
|
|
return kHiddenLayer;
|
|
} else if (peer->messagesTTL()) {
|
|
return kBottomLayer;
|
|
}
|
|
return kNoneLayer;
|
|
}();
|
|
setCornerBadgeShown(nextLayer, std::move(updateCallback));
|
|
if ((nextLayer == kTopLayer) && user) {
|
|
peer->owner().watchForOffline(user, now);
|
|
}
|
|
}
|
|
|
|
void Row::ensureCornerBadgeUserpic() const {
|
|
if (_cornerBadgeUserpic) {
|
|
return;
|
|
}
|
|
_cornerBadgeUserpic = std::make_unique<CornerBadgeUserpic>();
|
|
}
|
|
|
|
void Row::PaintCornerBadgeFrame(
|
|
not_null<CornerBadgeUserpic*> data,
|
|
int framePadding,
|
|
not_null<Entry*> entry,
|
|
PeerData *peer,
|
|
Ui::VideoUserpic *videoUserpic,
|
|
Ui::PeerUserpicView &view,
|
|
const Ui::PaintContext &context,
|
|
bool subscribed,
|
|
bool communityMember,
|
|
bool hidden) {
|
|
data->frame.fill(Qt::transparent);
|
|
|
|
Painter q(&data->frame);
|
|
q.translate(framePadding, framePadding);
|
|
auto hq = std::optional<PainterHighQualityEnabler>();
|
|
const auto photoSize = context.st->photoSize;
|
|
const auto storiesCount = data->storiesCount;
|
|
if (storiesCount) {
|
|
hq.emplace(q);
|
|
const auto line = st::dialogsStoriesFull.lineTwice / 2.;
|
|
const auto skip = line * 3 / 2.;
|
|
const auto scale = 1. - (2 * skip / photoSize);
|
|
const auto center = photoSize / 2.;
|
|
q.save();
|
|
q.translate(center, center);
|
|
q.scale(scale, scale);
|
|
q.translate(-center, -center);
|
|
}
|
|
q.translate(-context.st->padding.left(), -context.st->padding.top());
|
|
PaintUserpic(
|
|
q,
|
|
entry,
|
|
peer,
|
|
videoUserpic,
|
|
view,
|
|
context);
|
|
q.translate(context.st->padding.left(), context.st->padding.top());
|
|
if (storiesCount) {
|
|
q.restore();
|
|
|
|
const auto outline = QRectF(0, 0, photoSize, photoSize);
|
|
const auto storiesUnread = st::dialogsStoriesFull.lineTwice / 2.;
|
|
const auto storiesLine = st::dialogsStoriesFull.lineReadTwice / 2.;
|
|
auto segments = std::vector<Ui::OutlineSegment>();
|
|
if (data->storiesHasVideoStream) {
|
|
const auto storiesVideoStreamBrush = st::attentionButtonFg->b;
|
|
segments.push_back({ storiesVideoStreamBrush, storiesUnread });
|
|
} else {
|
|
const auto storiesUnreadCount = data->storiesUnreadCount;
|
|
const auto storiesUnreadBrush = [&] {
|
|
if (context.active || !storiesUnreadCount) {
|
|
return st::dialogsUnreadBgMutedActive->b;
|
|
}
|
|
auto gradient = Ui::UnreadStoryOutlineGradient(outline);
|
|
return QBrush(gradient);
|
|
}();
|
|
const auto storiesBrush = context.active
|
|
? st::dialogsUnreadBgMutedActive->b
|
|
: st::dialogsUnreadBgMuted->b;
|
|
segments.reserve(storiesCount);
|
|
const auto storiesReadCount = storiesCount - storiesUnreadCount;
|
|
for (auto i = 0; i != storiesReadCount; ++i) {
|
|
segments.push_back({ storiesBrush, storiesLine });
|
|
}
|
|
for (auto i = 0; i != storiesUnreadCount; ++i) {
|
|
segments.push_back({ storiesUnreadBrush, storiesUnread });
|
|
}
|
|
}
|
|
if (peer && (peer->forum() || peer->monoforum())) {
|
|
const auto radius = context.st->photoSize
|
|
* Ui::ForumUserpicRadiusMultiplier();
|
|
Ui::PaintOutlineSegments(q, outline, radius, segments);
|
|
} else {
|
|
Ui::PaintOutlineSegments(q, outline, segments);
|
|
}
|
|
|
|
if (data->storiesHasVideoStream) {
|
|
Ui::PaintLiveBadge(q, 0, 0, photoSize);
|
|
}
|
|
}
|
|
|
|
if (subscribed) {
|
|
// TODO: Unnecessarily repaints on activating peer.
|
|
const auto &s = st::dialogsSubscriptionBadgeSkip;
|
|
const auto x = photoSize - s.x() - st::dialogsSubscriptionBadgeSize;
|
|
const auto y = photoSize - s.y() - st::dialogsSubscriptionBadgeSize;
|
|
const auto skip = SubscriptionCutSkip();
|
|
q.resetTransform();
|
|
q.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
|
q.drawImage(x - skip, y - skip, SubscriptionCutMask());
|
|
q.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
q.drawImage(x, y, SubscriptionIcon());
|
|
return;
|
|
}
|
|
|
|
if (communityMember) {
|
|
if (!hq) {
|
|
hq.emplace(q);
|
|
}
|
|
q.setCompositionMode(QPainter::CompositionMode_Source);
|
|
const auto size = st::dialogsCommunityBadgeSize;
|
|
const auto &skip = st::dialogsCommunityBadgeSkip;
|
|
const auto rect = QRectF(
|
|
photoSize - skip.x() - size,
|
|
photoSize - skip.y() - size,
|
|
size,
|
|
size);
|
|
auto pen = QPen(Qt::transparent);
|
|
pen.setWidthF(st::dialogsCommunityBadgeStroke);
|
|
q.setPen(pen);
|
|
q.setBrush(st::windowFg);
|
|
q.drawEllipse(rect);
|
|
q.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
const auto center = rect.center();
|
|
const auto arm = size / 4.;
|
|
auto arrow = QPen(st::windowBg->c);
|
|
arrow.setWidthF(st::dialogsCommunityBadgeLine);
|
|
arrow.setCapStyle(Qt::RoundCap);
|
|
arrow.setJoinStyle(Qt::MiterJoin);
|
|
q.setPen(arrow);
|
|
q.setBrush(Qt::NoBrush);
|
|
auto path = QPainterPath();
|
|
path.moveTo(center.x() - arm, center.y() - arm / 2.);
|
|
path.lineTo(center.x(), center.y() + arm / 2.);
|
|
path.lineTo(center.x() + arm, center.y() - arm / 2.);
|
|
q.drawPath(path);
|
|
return;
|
|
}
|
|
|
|
const auto &manager = data->layersManager;
|
|
if (const auto p = manager.progressForLayer(kBottomLayer); p > 0.) {
|
|
const auto size = photoSize;
|
|
if (data->cacheTTL.isNull() && peer && 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.);
|
|
}
|
|
if (const auto p = manager.progressForLayer(kHiddenLayer); p > 0.) {
|
|
const auto rect = CornerBadgeHiddenRect(photoSize);
|
|
if (data->cacheHidden.isNull() && peer && hidden) {
|
|
data->cacheHidden = CornerBadgeHidden(peer, view, photoSize);
|
|
}
|
|
if (!data->cacheHidden.isNull()) {
|
|
q.setOpacity(p);
|
|
q.drawImage(rect.topLeft(), data->cacheHidden);
|
|
q.setOpacity(1.);
|
|
if (!hq) {
|
|
hq.emplace(q);
|
|
}
|
|
q.setCompositionMode(QPainter::CompositionMode_Source);
|
|
auto pen = QPen(Qt::transparent);
|
|
pen.setWidthF(st::dialogsOnlineBadgeStroke * p);
|
|
q.setPen(pen);
|
|
q.setBrush(Qt::NoBrush);
|
|
q.drawEllipse(QRectF(rect));
|
|
q.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
}
|
|
}
|
|
const auto topLayerProgress = manager.progressForLayer(kTopLayer);
|
|
if (!topLayerProgress) {
|
|
return;
|
|
}
|
|
|
|
if (!hq) {
|
|
hq.emplace(q);
|
|
}
|
|
q.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
const auto online = peer && peer->isUser();
|
|
const auto size = online
|
|
? st::dialogsOnlineBadgeSize
|
|
: st::dialogsCallBadgeSize;
|
|
const auto stroke = st::dialogsOnlineBadgeStroke;
|
|
const auto skip = online
|
|
? st::dialogsOnlineBadgeSkip
|
|
: st::dialogsCallBadgeSkip;
|
|
const auto shrink = (size / 2) * (1. - topLayerProgress);
|
|
|
|
auto pen = QPen(Qt::transparent);
|
|
pen.setWidthF(stroke * topLayerProgress);
|
|
q.setPen(pen);
|
|
q.setBrush(data->active
|
|
? st::dialogsOnlineBadgeFgActive
|
|
: st::dialogsOnlineBadgeFg);
|
|
q.drawEllipse(QRectF(
|
|
photoSize - skip.x() - size,
|
|
photoSize - skip.y() - size,
|
|
size,
|
|
size
|
|
).marginsRemoved({ shrink, shrink, shrink, shrink }));
|
|
}
|
|
|
|
void Row::paintUserpic(
|
|
Painter &p,
|
|
not_null<Entry*> entry,
|
|
PeerData *peer,
|
|
Ui::VideoUserpic *videoUserpic,
|
|
const Ui::PaintContext &context,
|
|
bool hasUnreadBadgesAbove) const {
|
|
const auto communityChannel = peer ? peer->asChannel() : nullptr;
|
|
if (communityChannel && communityChannel->isCommunity()) {
|
|
if (!_communityUserpicEffect) {
|
|
_communityUserpicEffect
|
|
= std::make_unique<Ui::CommunityUserpicEffect>();
|
|
}
|
|
Ui::PaintCommunityUserpicEffect(
|
|
p,
|
|
*_communityUserpicEffect,
|
|
context.st->padding.left(),
|
|
context.st->padding.top(),
|
|
context.st->photoSize,
|
|
st::windowSubTextFg->c);
|
|
} else if (_communityUserpicEffect) {
|
|
_communityUserpicEffect = nullptr;
|
|
}
|
|
const auto insideCommunity = context.insideCommunity;
|
|
const auto hidden = peer
|
|
&& context.community
|
|
&& context.community->isHidden(peer);
|
|
if (peer) {
|
|
updateCornerBadgeShown(
|
|
peer,
|
|
nullptr,
|
|
hasUnreadBadgesAbove,
|
|
insideCommunity,
|
|
hidden);
|
|
}
|
|
|
|
const auto cornerBadgeShown = !_cornerBadgeUserpic
|
|
? _cornerBadgeShown
|
|
: !_cornerBadgeUserpic->layersManager.isDisplayedNone();
|
|
const auto storiesPeer = peer
|
|
? ((peer->isUser() || peer->isChannel()) ? peer : nullptr)
|
|
: nullptr;
|
|
const auto storiesFolder = peer ? nullptr : _id.folder();
|
|
const auto storiesHas = storiesPeer
|
|
? storiesPeer->hasActiveStories()
|
|
: storiesFolder
|
|
? (storiesFolder->storiesCount() > 0)
|
|
: false;
|
|
if (!cornerBadgeShown && !storiesHas) {
|
|
BasicRow::paintUserpic(p, entry, peer, videoUserpic, context, false);
|
|
if (!peer || !_cornerBadgeShown) {
|
|
_cornerBadgeUserpic = nullptr;
|
|
}
|
|
return;
|
|
}
|
|
ensureCornerBadgeUserpic();
|
|
const auto ratio = style::DevicePixelRatio();
|
|
const auto framePadding = std::max({
|
|
-st::dialogsCallBadgeSkip.x(),
|
|
-st::dialogsCallBadgeSkip.y(),
|
|
st::lineWidth * 2 });
|
|
const auto frameSide = (2 * framePadding + context.st->photoSize)
|
|
* ratio;
|
|
const auto frameSize = QSize(frameSide, frameSide);
|
|
const auto storiesSource = (storiesHas && storiesPeer)
|
|
? storiesPeer->owner().stories().source(storiesPeer->id)
|
|
: nullptr;
|
|
const auto storiesCountReal = storiesSource
|
|
? int(storiesSource->ids.size())
|
|
: storiesFolder
|
|
? storiesFolder->storiesCount()
|
|
: storiesHas
|
|
? 1
|
|
: 0;
|
|
const auto storiesUnreadCountReal = storiesSource
|
|
? storiesSource->unreadCount()
|
|
: storiesFolder
|
|
? storiesFolder->storiesUnreadCount()
|
|
: (storiesPeer && storiesPeer->hasUnreadStories())
|
|
? 1
|
|
: 0;
|
|
const auto storiesHasVideoStream = storiesSource
|
|
? storiesSource->hasVideoStream
|
|
: (storiesPeer && storiesPeer->hasActiveVideoStream())
|
|
? 1
|
|
: 0;
|
|
const auto limit = Ui::kOutlineSegmentsMax;
|
|
const auto storiesCount = std::min(storiesCountReal, limit);
|
|
const auto storiesUnreadCount = std::min(storiesUnreadCountReal, limit);
|
|
if (_cornerBadgeUserpic->frame.size() != frameSize) {
|
|
_cornerBadgeUserpic->frame = QImage(
|
|
frameSize,
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
_cornerBadgeUserpic->frame.setDevicePixelRatio(ratio);
|
|
}
|
|
auto key = peer ? peer->userpicUniqueKey(userpicView()) : InMemoryKey();
|
|
key.first += peer ? peer->messagesTTL() : 0;
|
|
const auto frameIndex = videoUserpic ? videoUserpic->frameIndex() : -1;
|
|
const auto paletteVersionReal = style::PaletteVersion();
|
|
const auto paletteVersion = (paletteVersionReal & ((1 << 17) - 1));
|
|
const auto active = context.active ? 1 : 0;
|
|
const auto keyChanged = (_cornerBadgeUserpic->key != key)
|
|
|| (_cornerBadgeUserpic->paletteVersion != paletteVersion);
|
|
if (keyChanged) {
|
|
_cornerBadgeUserpic->cacheTTL = QImage();
|
|
_cornerBadgeUserpic->cacheHidden = QImage();
|
|
}
|
|
const auto badgeChannel = peer ? peer->asChannel() : nullptr;
|
|
const auto badgeUser = peer ? peer->asUser() : nullptr;
|
|
const auto subscribed = Data::ChannelHasSubscriptionUntilDate(
|
|
badgeChannel);
|
|
const auto communityMember = peer
|
|
&& Data::PeerLinkedCommunityId(peer)
|
|
&& !(badgeChannel && Data::ChannelHasActiveCall(badgeChannel))
|
|
&& !(badgeUser && Data::IsUserOnline(badgeUser))
|
|
&& !subscribed
|
|
&& !insideCommunity;
|
|
if (keyChanged
|
|
|| !_cornerBadgeUserpic->layersManager.isFinished()
|
|
|| _cornerBadgeUserpic->active != active
|
|
|| _cornerBadgeUserpic->hidden != (hidden ? 1 : 0)
|
|
|| _cornerBadgeUserpic->frameIndex != frameIndex
|
|
|| _cornerBadgeUserpic->storiesCount != storiesCount
|
|
|| _cornerBadgeUserpic->storiesUnreadCount != storiesUnreadCount
|
|
|| _cornerBadgeUserpic->storiesHasVideoStream != storiesHasVideoStream
|
|
|| videoUserpic) {
|
|
_cornerBadgeUserpic->key = key;
|
|
_cornerBadgeUserpic->paletteVersion = paletteVersion;
|
|
_cornerBadgeUserpic->active = active;
|
|
_cornerBadgeUserpic->hidden = hidden ? 1 : 0;
|
|
_cornerBadgeUserpic->storiesCount = storiesCount;
|
|
_cornerBadgeUserpic->storiesUnreadCount = storiesUnreadCount;
|
|
_cornerBadgeUserpic->storiesHasVideoStream = storiesHasVideoStream;
|
|
_cornerBadgeUserpic->frameIndex = frameIndex;
|
|
_cornerBadgeUserpic->layersManager.markFrameShown();
|
|
PaintCornerBadgeFrame(
|
|
_cornerBadgeUserpic.get(),
|
|
framePadding,
|
|
_id.entry(),
|
|
peer,
|
|
videoUserpic,
|
|
userpicView(),
|
|
context,
|
|
subscribed,
|
|
communityMember,
|
|
hidden);
|
|
}
|
|
p.drawImage(
|
|
context.st->padding.left() - framePadding,
|
|
context.st->padding.top() - framePadding,
|
|
_cornerBadgeUserpic->frame);
|
|
const auto history = _id.history();
|
|
if (!history
|
|
|| history->peer->isUser()
|
|
|| subscribed
|
|
|| communityMember
|
|
|| (hidden
|
|
&& !(badgeChannel && Data::ChannelHasActiveCall(badgeChannel)))) {
|
|
return;
|
|
}
|
|
const auto actionPainter = history->sendActionPainter();
|
|
const auto bg = context.active
|
|
? st::dialogsBgActive
|
|
: st::dialogsBg;
|
|
const auto size = st::dialogsCallBadgeSize;
|
|
const auto skip = st::dialogsCallBadgeSkip;
|
|
p.setOpacity(
|
|
_cornerBadgeUserpic->layersManager.progressForLayer(kTopLayer));
|
|
p.translate(context.st->padding.left(), context.st->padding.top());
|
|
actionPainter->paintSpeaking(
|
|
p,
|
|
context.st->photoSize - skip.x() - size,
|
|
context.st->photoSize - skip.y() - size,
|
|
context.width,
|
|
bg,
|
|
context.now);
|
|
p.translate(-context.st->padding.left(), -context.st->padding.top());
|
|
p.setOpacity(1.);
|
|
}
|
|
|
|
bool Row::lookupIsInTopicJump(int x, int y) const {
|
|
const auto history = this->history();
|
|
return history && history->lastItemDialogsView().isInTopicJump(x, y);
|
|
}
|
|
|
|
void Row::stopLastRipple() {
|
|
BasicRow::stopLastRipple();
|
|
const auto history = this->history();
|
|
const auto view = history ? &history->lastItemDialogsView() : nullptr;
|
|
if (view) {
|
|
view->stopLastRipple();
|
|
}
|
|
}
|
|
|
|
void Row::clearRipple() {
|
|
BasicRow::clearRipple();
|
|
clearTopicJumpRipple();
|
|
}
|
|
|
|
void Row::addTopicJumpRipple(
|
|
QPoint origin,
|
|
not_null<Ui::TopicJumpCache*> topicJumpCache,
|
|
Fn<void()> updateCallback) {
|
|
const auto history = this->history();
|
|
const auto view = history ? &history->lastItemDialogsView() : nullptr;
|
|
if (view) {
|
|
view->addTopicJumpRipple(
|
|
origin,
|
|
topicJumpCache,
|
|
std::move(updateCallback));
|
|
_topicJumpRipple = 1;
|
|
}
|
|
}
|
|
|
|
void Row::clearTopicJumpRipple() {
|
|
if (!_topicJumpRipple) {
|
|
return;
|
|
}
|
|
const auto history = this->history();
|
|
const auto view = history ? &history->lastItemDialogsView() : nullptr;
|
|
if (view) {
|
|
view->clearRipple();
|
|
}
|
|
_topicJumpRipple = 0;
|
|
}
|
|
|
|
bool Row::topicJumpRipple() const {
|
|
return _topicJumpRipple != 0;
|
|
}
|
|
|
|
FakeRow::FakeRow(
|
|
Key searchInChat,
|
|
not_null<HistoryItem*> item,
|
|
Fn<void()> repaint)
|
|
: _searchInChat(searchInChat)
|
|
, _item(item)
|
|
, _repaint(std::move(repaint)) {
|
|
invalidateTopic();
|
|
}
|
|
|
|
void FakeRow::invalidateTopic() {
|
|
_topic = _item->topic();
|
|
if (_topic) {
|
|
return;
|
|
} else if (const auto rootId = _item->topicRootId()) {
|
|
if (const auto forum = _item->history()->asForum()) {
|
|
if (!forum->topicDeleted(rootId)) {
|
|
forum->requestTopic(rootId, crl::guard(this, [=] {
|
|
_topic = _item->topic();
|
|
if (_topic) {
|
|
_repaint();
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const Ui::Text::String &FakeRow::name() const {
|
|
if (_name.isEmpty()) {
|
|
const auto from = _searchInChat
|
|
? _item->displayFrom()
|
|
: nullptr;
|
|
const auto peer = from ? from : _item->history()->peer.get();
|
|
_name.setText(
|
|
st::semiboldTextStyle,
|
|
peer->name(),
|
|
Ui::NameTextOptions());
|
|
}
|
|
return _name;
|
|
}
|
|
|
|
DateText FakeRow::dateText(
|
|
TimeId date,
|
|
crl::time now) const {
|
|
return ResolveDateText(_dateCache, date, now);
|
|
}
|
|
|
|
} // namespace Dialogs
|