2016-06-07 19:59:39 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-07 19:59:39 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-07 19:59:39 +00:00
|
|
|
*/
|
|
|
|
#include "dialogs/dialogs_row.h"
|
|
|
|
|
2022-12-01 10:46:04 +00:00
|
|
|
#include "ui/chat/chat_theme.h" // CountAverageColor.
|
|
|
|
#include "ui/color_contrast.h"
|
2016-12-05 11:01:08 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2022-12-01 10:46:04 +00:00
|
|
|
#include "ui/image/image_prepare.h"
|
|
|
|
#include "ui/text/format_values.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2021-12-25 16:19:00 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "dialogs/dialogs_entry.h"
|
2022-05-16 11:38:35 +00:00
|
|
|
#include "dialogs/ui/dialogs_video_userpic.h"
|
2022-09-29 10:33:17 +00:00
|
|
|
#include "dialogs/ui/dialogs_layout.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "data/data_folder.h"
|
2022-10-26 12:33:58 +00:00
|
|
|
#include "data/data_forum.h"
|
2022-10-24 07:22:26 +00:00
|
|
|
#include "data/data_session.h"
|
2019-06-17 14:37:29 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2023-07-04 16:13:56 +00:00
|
|
|
#include "data/data_user.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "history/history.h"
|
2022-08-09 11:12:19 +00:00
|
|
|
#include "history/history_item.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2022-10-24 07:22:26 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2016-06-07 19:59:39 +00:00
|
|
|
|
|
|
|
namespace Dialogs {
|
2022-12-01 10:46:04 +00:00
|
|
|
namespace {
|
2016-06-07 19:59:39 +00:00
|
|
|
|
2022-12-01 10:46:04 +00:00
|
|
|
constexpr auto kTopLayer = 2;
|
|
|
|
constexpr auto kBottomLayer = 1;
|
2022-12-01 15:11:50 +00:00
|
|
|
constexpr auto kNoneLayer = 0;
|
|
|
|
|
2022-12-05 15:26:27 +00:00
|
|
|
[[nodiscard]] QImage CornerBadgeTTL(
|
2022-12-01 10:46:04 +00:00
|
|
|
not_null<PeerData*> peer,
|
2022-12-05 12:18:10 +00:00
|
|
|
Ui::PeerUserpicView &view,
|
2022-12-01 10:46:04 +00:00
|
|
|
int photoSize) {
|
|
|
|
const auto ttl = peer->messagesTTL();
|
2022-12-05 12:18:10 +00:00
|
|
|
if (!ttl) {
|
2022-12-05 15:26:27 +00:00
|
|
|
return QImage();
|
2022-12-01 10:46:04 +00:00
|
|
|
}
|
|
|
|
constexpr auto kBlurRadius = 24;
|
|
|
|
|
|
|
|
const auto ratio = style::DevicePixelRatio();
|
|
|
|
const auto fullSize = photoSize;
|
|
|
|
const auto blurredFull = Images::BlurLargeImage(
|
2022-12-05 12:18:10 +00:00
|
|
|
peer->generateUserpicImage(view, fullSize * ratio, 0),
|
2022-12-01 10:46:04 +00:00
|
|
|
kBlurRadius);
|
|
|
|
const auto partRect = CornerBadgeTTLRect(fullSize);
|
|
|
|
const auto &partSize = partRect.width();
|
2022-12-05 15:26:27 +00:00
|
|
|
auto result = [&] {
|
2022-12-01 10:46:04 +00:00
|
|
|
auto blurredPart = blurredFull.copy(
|
|
|
|
blurredFull.width() - partSize * ratio,
|
|
|
|
blurredFull.height() - partSize * ratio,
|
|
|
|
partSize * ratio,
|
|
|
|
partSize * ratio);
|
|
|
|
blurredPart.setDevicePixelRatio(ratio);
|
|
|
|
|
|
|
|
constexpr auto kMinAcceptableContrast = 4.5;
|
|
|
|
const auto averageColor = Ui::CountAverageColor(blurredPart);
|
|
|
|
const auto contrast = Ui::CountContrast(
|
|
|
|
averageColor,
|
|
|
|
st::premiumButtonFg->c);
|
|
|
|
if (contrast < kMinAcceptableContrast) {
|
|
|
|
constexpr auto kDarkerBy = 0.2;
|
|
|
|
auto painterPart = QPainter(&blurredPart);
|
|
|
|
painterPart.setOpacity(kDarkerBy);
|
|
|
|
painterPart.fillRect(
|
|
|
|
QRect(QPoint(), partRect.size()),
|
|
|
|
Qt::black);
|
|
|
|
}
|
2022-12-05 15:26:27 +00:00
|
|
|
return Images::Circle(std::move(blurredPart));
|
|
|
|
}();
|
|
|
|
|
|
|
|
auto q = QPainter(&result);
|
|
|
|
PainterHighQualityEnabler hq(q);
|
|
|
|
|
|
|
|
const auto innerRect = QRect(QPoint(), partRect.size())
|
|
|
|
- st::dialogsTTLBadgeInnerMargins;
|
2022-12-01 10:46:04 +00:00
|
|
|
const auto ttlText = Ui::FormatTTLTiny(ttl);
|
|
|
|
|
|
|
|
q.setFont(st::dialogsScamFont);
|
|
|
|
q.setPen(st::premiumButtonFg);
|
|
|
|
q.drawText(
|
|
|
|
innerRect,
|
|
|
|
(ttlText.size() > 2) ? ttlText.mid(0, 2) : ttlText,
|
|
|
|
style::al_center);
|
|
|
|
|
|
|
|
constexpr auto kPenWidth = 1.5;
|
|
|
|
|
2023-01-07 01:53:31 +00:00
|
|
|
const auto penWidth = style::ConvertScaleExact(kPenWidth);
|
2022-12-01 10:46:04 +00:00
|
|
|
auto pen = QPen(st::premiumButtonFg);
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
2023-01-07 01:53:31 +00:00
|
|
|
pen.setWidthF(penWidth);
|
2022-12-01 10:46:04 +00:00
|
|
|
|
|
|
|
q.setPen(pen);
|
|
|
|
q.setBrush(Qt::NoBrush);
|
2023-01-11 04:56:01 +00:00
|
|
|
q.drawArc(innerRect, arc::kQuarterLength, arc::kHalfLength);
|
2022-12-01 10:46:04 +00:00
|
|
|
|
2023-01-07 01:53:31 +00:00
|
|
|
q.setClipRect(innerRect
|
|
|
|
- QMargins(innerRect.width() / 2, 0, -penWidth, -penWidth));
|
2022-12-01 10:46:04 +00:00
|
|
|
pen.setStyle(Qt::DotLine);
|
|
|
|
q.setPen(pen);
|
|
|
|
q.drawEllipse(innerRect);
|
|
|
|
|
2022-12-05 15:26:27 +00:00
|
|
|
return result;
|
2022-12-01 10:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
QRect CornerBadgeTTLRect(int photoSize) {
|
|
|
|
const auto &partSize = st::dialogsTTLBadgeSize;
|
|
|
|
return QRect(
|
|
|
|
photoSize - partSize + st::dialogsTTLBadgeSkip.x(),
|
|
|
|
photoSize - partSize + st::dialogsTTLBadgeSkip.y(),
|
|
|
|
partSize,
|
|
|
|
partSize);
|
|
|
|
}
|
|
|
|
|
2022-12-01 15:11:50 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
BasicRow::BasicRow() = default;
|
|
|
|
BasicRow::~BasicRow() = default;
|
2016-12-05 11:01:08 +00:00
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::addRipple(
|
|
|
|
QPoint origin,
|
|
|
|
QSize size,
|
|
|
|
Fn<void()> updateCallback) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_ripple) {
|
2022-11-14 07:24:31 +00:00
|
|
|
addRippleWithMask(
|
|
|
|
origin,
|
|
|
|
Ui::RippleAnimation::RectMask(size),
|
2019-06-17 14:37:29 +00:00
|
|
|
std::move(updateCallback));
|
2022-11-14 07:24:31 +00:00
|
|
|
} else {
|
|
|
|
_ripple->add(origin);
|
2016-12-05 11:01:08 +00:00
|
|
|
}
|
2022-11-14 07:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasicRow::addRippleWithMask(
|
|
|
|
QPoint origin,
|
|
|
|
QImage mask,
|
|
|
|
Fn<void()> updateCallback) {
|
|
|
|
_ripple = std::make_unique<Ui::RippleAnimation>(
|
|
|
|
st::dialogsRipple,
|
|
|
|
std::move(mask),
|
|
|
|
std::move(updateCallback));
|
2016-12-05 11:01:08 +00:00
|
|
|
_ripple->add(origin);
|
|
|
|
}
|
|
|
|
|
2022-11-14 07:24:31 +00:00
|
|
|
void BasicRow::clearRipple() {
|
|
|
|
_ripple = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::stopLastRipple() {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_ripple) {
|
|
|
|
_ripple->lastStop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::paintRipple(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2019-06-17 14:37:29 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
const QColor *colorOverride) const {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_ripple) {
|
2019-04-02 09:13:30 +00:00
|
|
|
_ripple->paint(p, x, y, outerWidth, colorOverride);
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_ripple->empty()) {
|
|
|
|
_ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:35 +00:00
|
|
|
void BasicRow::paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Ui::VideoUserpic *videoUserpic,
|
|
|
|
History *historyForCornerBadge,
|
2022-09-29 10:33:17 +00:00
|
|
|
const Ui::PaintContext &context) const {
|
2022-05-16 11:38:35 +00:00
|
|
|
PaintUserpic(
|
|
|
|
p,
|
|
|
|
peer,
|
|
|
|
videoUserpic,
|
|
|
|
_userpic,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->padding.left(),
|
|
|
|
context.st->padding.top(),
|
|
|
|
context.width,
|
|
|
|
context.st->photoSize,
|
|
|
|
context.paused);
|
2022-05-16 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 06:23:23 +00:00
|
|
|
Row::Row(Key key, int index, int top) : _id(key), _top(top), _index(index) {
|
2022-05-16 11:38:35 +00:00
|
|
|
if (const auto history = key.history()) {
|
|
|
|
updateCornerBadgeShown(history->peer);
|
2022-11-29 17:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 13:48:33 +00:00
|
|
|
Row::~Row() {
|
|
|
|
clearTopicJumpRipple();
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:36:26 +00:00
|
|
|
void Row::recountHeight(float64 narrowRatio) {
|
2022-11-29 17:36:34 +00:00
|
|
|
if (const auto history = _id.history()) {
|
2022-12-02 14:19:56 +00:00
|
|
|
_height = history->isForum()
|
2022-12-01 17:36:26 +00:00
|
|
|
? anim::interpolate(
|
|
|
|
st::forumDialogRow.height,
|
|
|
|
st::defaultDialogRow.height,
|
|
|
|
narrowRatio)
|
2022-11-11 06:23:23 +00:00
|
|
|
: st::defaultDialogRow.height;
|
2022-11-29 17:36:34 +00:00
|
|
|
} else if (_id.folder()) {
|
2022-11-11 09:24:37 +00:00
|
|
|
_height = st::defaultDialogRow.height;
|
2022-11-11 06:23:23 +00:00
|
|
|
} else {
|
|
|
|
_height = st::forumTopicRow.height;
|
2022-05-16 11:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 Row::sortKey(FilterId filterId) const {
|
|
|
|
return _id.entry()->sortKeyInChatList(filterId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::setCornerBadgeShown(
|
2022-12-01 15:11:50 +00:00
|
|
|
CornerLayersManager::Layer nextLayer,
|
2022-05-16 11:38:35 +00:00
|
|
|
Fn<void()> updateCallback) const {
|
2022-12-01 15:11:50 +00:00
|
|
|
const auto cornerBadgeShown = (nextLayer ? 1 : 0);
|
|
|
|
if (_cornerBadgeShown == cornerBadgeShown) {
|
|
|
|
if (!cornerBadgeShown) {
|
|
|
|
return;
|
|
|
|
} else if (_cornerBadgeUserpic
|
|
|
|
&& _cornerBadgeUserpic->layersManager.isSameLayer(nextLayer)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-16 11:38:35 +00:00
|
|
|
}
|
2022-12-01 15:11:50 +00:00
|
|
|
const_cast<Row*>(this)->_cornerBadgeShown = cornerBadgeShown;
|
|
|
|
ensureCornerBadgeUserpic();
|
|
|
|
_cornerBadgeUserpic->layersManager.setLayer(
|
|
|
|
nextLayer,
|
|
|
|
std::move(updateCallback));
|
2022-05-16 11:38:35 +00:00
|
|
|
if (!_cornerBadgeShown
|
|
|
|
&& _cornerBadgeUserpic
|
2022-12-01 15:11:50 +00:00
|
|
|
&& _cornerBadgeUserpic->layersManager.isDisplayedNone()) {
|
2022-05-16 11:38:35 +00:00
|
|
|
_cornerBadgeUserpic = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::updateCornerBadgeShown(
|
2020-12-02 10:52:19 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Fn<void()> updateCallback) const {
|
2022-10-24 07:22:26 +00:00
|
|
|
const auto user = peer->asUser();
|
|
|
|
const auto now = user ? base::unixtime::now() : TimeId();
|
2022-12-01 15:11:50 +00:00
|
|
|
const auto nextLayer = [&] {
|
|
|
|
if (user && Data::IsUserOnline(user, now)) {
|
|
|
|
return kTopLayer;
|
|
|
|
} else if (peer->isChannel()
|
|
|
|
&& Data::ChannelHasActiveCall(peer->asChannel())) {
|
|
|
|
return kTopLayer;
|
2022-12-01 10:46:04 +00:00
|
|
|
} else if (peer->messagesTTL()) {
|
|
|
|
return kBottomLayer;
|
2020-12-02 10:52:19 +00:00
|
|
|
}
|
2022-12-01 15:11:50 +00:00
|
|
|
return kNoneLayer;
|
2020-12-02 10:52:19 +00:00
|
|
|
}();
|
2022-12-01 15:11:50 +00:00
|
|
|
setCornerBadgeShown(nextLayer, std::move(updateCallback));
|
|
|
|
if ((nextLayer == kTopLayer) && user) {
|
2022-10-24 07:22:26 +00:00
|
|
|
peer->owner().watchForOffline(user, now);
|
|
|
|
}
|
2020-12-02 10:52:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:35 +00:00
|
|
|
void Row::ensureCornerBadgeUserpic() const {
|
2020-12-02 10:52:19 +00:00
|
|
|
if (_cornerBadgeUserpic) {
|
2019-06-17 14:37:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-02 10:52:19 +00:00
|
|
|
_cornerBadgeUserpic = std::make_unique<CornerBadgeUserpic>();
|
2019-06-17 14:37:29 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:35 +00:00
|
|
|
void Row::PaintCornerBadgeFrame(
|
2020-12-02 10:52:19 +00:00
|
|
|
not_null<CornerBadgeUserpic*> data,
|
2023-07-04 16:13:56 +00:00
|
|
|
int framePadding,
|
2020-05-28 14:32:10 +00:00
|
|
|
not_null<PeerData*> peer,
|
2022-05-16 11:38:35 +00:00
|
|
|
Ui::VideoUserpic *videoUserpic,
|
2022-12-05 12:18:10 +00:00
|
|
|
Ui::PeerUserpicView &view,
|
2022-09-29 10:33:17 +00:00
|
|
|
const Ui::PaintContext &context) {
|
2019-06-17 14:37:29 +00:00
|
|
|
data->frame.fill(Qt::transparent);
|
|
|
|
|
|
|
|
Painter q(&data->frame);
|
2023-07-04 16:13:56 +00:00
|
|
|
q.translate(framePadding, framePadding);
|
|
|
|
auto hq = std::optional<PainterHighQualityEnabler>();
|
|
|
|
if (data->storiesShown) {
|
|
|
|
hq.emplace(q);
|
|
|
|
const auto line = st::dialogsStoriesFull.lineTwice / 2.;
|
|
|
|
const auto skip = line * 3 / 2.;
|
|
|
|
const auto scale = 1. - (2 * skip / context.st->photoSize);
|
|
|
|
const auto center = context.st->photoSize / 2.;
|
|
|
|
q.save();
|
|
|
|
q.translate(center, center);
|
|
|
|
q.scale(scale, scale);
|
|
|
|
q.translate(-center, -center);
|
|
|
|
}
|
2022-05-16 11:38:35 +00:00
|
|
|
PaintUserpic(
|
2019-06-17 14:37:29 +00:00
|
|
|
q,
|
2022-05-16 11:38:35 +00:00
|
|
|
peer,
|
|
|
|
videoUserpic,
|
2020-05-28 14:32:10 +00:00
|
|
|
view,
|
2019-06-17 14:37:29 +00:00
|
|
|
0,
|
|
|
|
0,
|
2022-05-16 11:38:35 +00:00
|
|
|
data->frame.width() / data->frame.devicePixelRatio(),
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->photoSize,
|
|
|
|
context.paused);
|
2023-07-04 16:13:56 +00:00
|
|
|
if (data->storiesShown) {
|
|
|
|
q.restore();
|
|
|
|
|
|
|
|
const auto st = context.st;
|
|
|
|
const auto storiesUnreadBrush = [&] {
|
2023-07-05 07:55:16 +00:00
|
|
|
if (context.active) {
|
2023-07-05 08:55:22 +00:00
|
|
|
return st::dialogsUnreadBgMutedActive->b;
|
2023-07-05 07:55:16 +00:00
|
|
|
}
|
2023-07-04 16:13:56 +00:00
|
|
|
const auto left = st->padding.left();
|
|
|
|
const auto top = st->padding.top();
|
|
|
|
auto gradient = QLinearGradient(
|
|
|
|
QPoint(left + st->photoSize, top),
|
|
|
|
QPoint(left, top + st->photoSize));
|
|
|
|
gradient.setStops({
|
|
|
|
{ 0., st::groupCallLive1->c },
|
|
|
|
{ 1., st::groupCallMuted1->c },
|
|
|
|
});
|
|
|
|
return QBrush(gradient);
|
|
|
|
};
|
|
|
|
const auto storiesBrush = data->storiesUnread
|
|
|
|
? storiesUnreadBrush()
|
|
|
|
: context.active
|
|
|
|
? st::dialogsUnreadBgMutedActive->b
|
|
|
|
: st::dialogsUnreadBgMuted->b;
|
|
|
|
const auto storiesLine = data->storiesUnread
|
|
|
|
? (st::dialogsStoriesFull.lineTwice / 2.)
|
|
|
|
: (st::dialogsStoriesFull.lineReadTwice / 2.);
|
|
|
|
const auto pen = QPen(storiesBrush, storiesLine);
|
|
|
|
q.setPen(pen);
|
|
|
|
q.drawEllipse(0, 0, st->photoSize, st->photoSize);
|
|
|
|
}
|
2019-06-17 14:37:29 +00:00
|
|
|
|
2022-12-01 10:46:04 +00:00
|
|
|
const auto &manager = data->layersManager;
|
2023-07-04 16:13:56 +00:00
|
|
|
if (const auto p = manager.progressForLayer(kBottomLayer); p > 0.) {
|
2022-12-05 15:26:27 +00:00
|
|
|
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.);
|
2022-12-01 10:46:04 +00:00
|
|
|
}
|
|
|
|
const auto topLayerProgress = manager.progressForLayer(kTopLayer);
|
|
|
|
if (!topLayerProgress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-04 16:13:56 +00:00
|
|
|
if (!hq) {
|
|
|
|
hq.emplace(q);
|
|
|
|
}
|
2019-06-17 14:37:29 +00:00
|
|
|
q.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
|
2020-12-02 10:52:19 +00:00
|
|
|
const auto size = peer->isUser()
|
|
|
|
? st::dialogsOnlineBadgeSize
|
|
|
|
: st::dialogsCallBadgeSize;
|
2019-06-17 14:37:29 +00:00
|
|
|
const auto stroke = st::dialogsOnlineBadgeStroke;
|
2020-12-02 10:52:19 +00:00
|
|
|
const auto skip = peer->isUser()
|
|
|
|
? st::dialogsOnlineBadgeSkip
|
|
|
|
: st::dialogsCallBadgeSkip;
|
2022-12-01 10:46:04 +00:00
|
|
|
const auto shrink = (size / 2) * (1. - topLayerProgress);
|
2019-06-17 14:37:29 +00:00
|
|
|
|
|
|
|
auto pen = QPen(Qt::transparent);
|
2022-12-01 10:46:04 +00:00
|
|
|
pen.setWidthF(stroke * topLayerProgress);
|
2019-06-17 14:37:29 +00:00
|
|
|
q.setPen(pen);
|
|
|
|
q.setBrush(data->active
|
|
|
|
? st::dialogsOnlineBadgeFgActive
|
|
|
|
: st::dialogsOnlineBadgeFg);
|
|
|
|
q.drawEllipse(QRectF(
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->photoSize - skip.x() - size,
|
|
|
|
context.st->photoSize - skip.y() - size,
|
2019-06-17 14:37:29 +00:00
|
|
|
size,
|
|
|
|
size
|
|
|
|
).marginsRemoved({ shrink, shrink, shrink, shrink }));
|
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:35 +00:00
|
|
|
void Row::paintUserpic(
|
2019-06-17 14:37:29 +00:00
|
|
|
Painter &p,
|
|
|
|
not_null<PeerData*> peer,
|
2022-05-16 11:38:35 +00:00
|
|
|
Ui::VideoUserpic *videoUserpic,
|
2020-12-02 10:52:19 +00:00
|
|
|
History *historyForCornerBadge,
|
2022-09-29 10:33:17 +00:00
|
|
|
const Ui::PaintContext &context) const {
|
2020-12-02 10:52:19 +00:00
|
|
|
updateCornerBadgeShown(peer);
|
2019-06-17 14:37:29 +00:00
|
|
|
|
2022-12-01 15:11:50 +00:00
|
|
|
const auto cornerBadgeShown = !_cornerBadgeUserpic
|
|
|
|
? _cornerBadgeShown
|
|
|
|
: !_cornerBadgeUserpic->layersManager.isDisplayedNone();
|
2023-07-04 16:13:56 +00:00
|
|
|
const auto storiesUser = historyForCornerBadge
|
|
|
|
? historyForCornerBadge->peer->asUser()
|
|
|
|
: nullptr;
|
|
|
|
const auto storiesShown = (storiesUser
|
|
|
|
&& storiesUser->hasActiveStories()) ? 1 : 0;
|
|
|
|
const auto storiesUnread = (storiesShown
|
|
|
|
&& storiesUser->hasUnreadStories()) ? 1 : 0;
|
|
|
|
if (!historyForCornerBadge || (!cornerBadgeShown && !storiesShown)) {
|
2022-05-16 11:38:35 +00:00
|
|
|
BasicRow::paintUserpic(
|
2019-06-17 14:37:29 +00:00
|
|
|
p,
|
2022-05-16 11:38:35 +00:00
|
|
|
peer,
|
|
|
|
videoUserpic,
|
|
|
|
historyForCornerBadge,
|
2022-09-29 10:33:17 +00:00
|
|
|
context);
|
2020-12-02 10:52:19 +00:00
|
|
|
if (!historyForCornerBadge || !_cornerBadgeShown) {
|
|
|
|
_cornerBadgeUserpic = nullptr;
|
2019-06-17 14:37:29 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-12-02 10:52:19 +00:00
|
|
|
ensureCornerBadgeUserpic();
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto ratio = style::DevicePixelRatio();
|
2023-07-04 16:13:56 +00:00
|
|
|
const auto framePadding = std::max({
|
2022-10-28 13:21:11 +00:00
|
|
|
-st::dialogsCallBadgeSkip.x(),
|
|
|
|
-st::dialogsCallBadgeSkip.y(),
|
2023-07-04 16:13:56 +00:00
|
|
|
st::lineWidth * 2 });
|
|
|
|
const auto frameSide = (2 * framePadding + context.st->photoSize)
|
|
|
|
* ratio;
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto frameSize = QSize(frameSide, frameSide);
|
|
|
|
if (_cornerBadgeUserpic->frame.size() != frameSize) {
|
2020-12-02 10:52:19 +00:00
|
|
|
_cornerBadgeUserpic->frame = QImage(
|
2022-09-29 10:33:17 +00:00
|
|
|
frameSize,
|
2019-06-17 14:37:29 +00:00
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
2022-09-29 10:33:17 +00:00
|
|
|
_cornerBadgeUserpic->frame.setDevicePixelRatio(ratio);
|
2019-06-17 14:37:29 +00:00
|
|
|
}
|
2022-12-01 10:46:04 +00:00
|
|
|
auto key = peer->userpicUniqueKey(userpicView());
|
|
|
|
key.first += peer->messagesTTL();
|
2022-05-16 11:38:35 +00:00
|
|
|
const auto frameIndex = videoUserpic ? videoUserpic->frameIndex() : -1;
|
2023-03-17 12:09:23 +00:00
|
|
|
const auto paletteVersion = style::PaletteVersion();
|
2023-07-04 16:13:56 +00:00
|
|
|
const auto active = context.active ? 1 : 0;
|
2023-03-17 12:09:23 +00:00
|
|
|
const auto keyChanged = (_cornerBadgeUserpic->key != key)
|
|
|
|
|| (_cornerBadgeUserpic->paletteVersion != paletteVersion);
|
|
|
|
if (keyChanged) {
|
2022-12-05 15:26:27 +00:00
|
|
|
_cornerBadgeUserpic->cacheTTL = QImage();
|
|
|
|
}
|
2023-03-17 12:09:23 +00:00
|
|
|
if (keyChanged
|
|
|
|
|| !_cornerBadgeUserpic->layersManager.isFinished()
|
2023-07-04 16:13:56 +00:00
|
|
|
|| _cornerBadgeUserpic->active != active
|
2022-05-16 11:38:35 +00:00
|
|
|
|| _cornerBadgeUserpic->frameIndex != frameIndex
|
2023-07-04 16:13:56 +00:00
|
|
|
|| _cornerBadgeUserpic->storiesShown != storiesShown
|
|
|
|
|| _cornerBadgeUserpic->storiesUnread != storiesUnread
|
2022-05-16 11:38:35 +00:00
|
|
|
|| videoUserpic) {
|
2020-12-02 10:52:19 +00:00
|
|
|
_cornerBadgeUserpic->key = key;
|
2023-03-17 12:09:23 +00:00
|
|
|
_cornerBadgeUserpic->paletteVersion = paletteVersion;
|
2023-07-04 16:13:56 +00:00
|
|
|
_cornerBadgeUserpic->active = active;
|
|
|
|
_cornerBadgeUserpic->storiesShown = storiesShown;
|
|
|
|
_cornerBadgeUserpic->storiesUnread = storiesUnread;
|
2022-05-16 11:38:35 +00:00
|
|
|
_cornerBadgeUserpic->frameIndex = frameIndex;
|
2022-12-01 15:11:50 +00:00
|
|
|
_cornerBadgeUserpic->layersManager.markFrameShown();
|
2022-05-16 11:38:35 +00:00
|
|
|
PaintCornerBadgeFrame(
|
|
|
|
_cornerBadgeUserpic.get(),
|
2023-07-04 16:13:56 +00:00
|
|
|
framePadding,
|
2022-05-16 11:38:35 +00:00
|
|
|
peer,
|
|
|
|
videoUserpic,
|
2022-05-16 12:32:24 +00:00
|
|
|
userpicView(),
|
2022-09-29 10:33:17 +00:00
|
|
|
context);
|
2020-12-02 10:52:19 +00:00
|
|
|
}
|
2022-09-29 10:33:17 +00:00
|
|
|
p.drawImage(
|
2023-07-04 16:13:56 +00:00
|
|
|
context.st->padding.left() - framePadding,
|
|
|
|
context.st->padding.top() - framePadding,
|
2022-09-29 10:33:17 +00:00
|
|
|
_cornerBadgeUserpic->frame);
|
2020-12-02 10:52:19 +00:00
|
|
|
if (historyForCornerBadge->peer->isUser()) {
|
|
|
|
return;
|
2019-06-17 14:37:29 +00:00
|
|
|
}
|
2020-12-02 10:52:19 +00:00
|
|
|
const auto actionPainter = historyForCornerBadge->sendActionPainter();
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto bg = context.active
|
2020-12-02 10:52:19 +00:00
|
|
|
? st::dialogsBgActive
|
|
|
|
: st::dialogsBg;
|
|
|
|
const auto size = st::dialogsCallBadgeSize;
|
|
|
|
const auto skip = st::dialogsCallBadgeSkip;
|
2022-12-01 15:11:50 +00:00
|
|
|
p.setOpacity(
|
|
|
|
_cornerBadgeUserpic->layersManager.progressForLayer(kTopLayer));
|
2022-09-29 10:33:17 +00:00
|
|
|
p.translate(context.st->padding.left(), context.st->padding.top());
|
2020-12-02 10:52:19 +00:00
|
|
|
actionPainter->paintSpeaking(
|
|
|
|
p,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->photoSize - skip.x() - size,
|
|
|
|
context.st->photoSize - skip.y() - size,
|
|
|
|
context.width,
|
2020-12-02 10:52:19 +00:00
|
|
|
bg,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.now);
|
|
|
|
p.translate(-context.st->padding.left(), -context.st->padding.top());
|
2020-12-06 13:28:27 +00:00
|
|
|
p.setOpacity(1.);
|
2019-06-17 14:37:29 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 07:24:31 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 13:48:33 +00:00
|
|
|
void Row::clearRipple() {
|
|
|
|
BasicRow::clearRipple();
|
|
|
|
clearTopicJumpRipple();
|
|
|
|
}
|
|
|
|
|
2022-11-14 07:24:31 +00:00
|
|
|
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() {
|
2022-12-29 13:48:33 +00:00
|
|
|
if (!_topicJumpRipple) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto history = this->history();
|
|
|
|
const auto view = history ? &history->lastItemDialogsView() : nullptr;
|
|
|
|
if (view) {
|
|
|
|
view->clearRipple();
|
2022-11-14 07:24:31 +00:00
|
|
|
}
|
2022-12-29 13:48:33 +00:00
|
|
|
_topicJumpRipple = 0;
|
2022-11-14 07:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Row::topicJumpRipple() const {
|
|
|
|
return _topicJumpRipple != 0;
|
|
|
|
}
|
|
|
|
|
2022-08-09 15:53:40 +00:00
|
|
|
FakeRow::FakeRow(
|
|
|
|
Key searchInChat,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
Fn<void()> repaint)
|
2018-02-14 19:38:01 +00:00
|
|
|
: _searchInChat(searchInChat)
|
2022-08-09 15:53:40 +00:00
|
|
|
, _item(item)
|
|
|
|
, _repaint(std::move(repaint)) {
|
2022-10-26 12:33:58 +00:00
|
|
|
invalidateTopic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FakeRow::invalidateTopic() {
|
|
|
|
_topic = _item->topic();
|
|
|
|
if (_topic) {
|
|
|
|
return;
|
|
|
|
} else if (const auto rootId = _item->topicRootId()) {
|
2022-11-01 09:00:17 +00:00
|
|
|
if (const auto forum = _item->history()->asForum()) {
|
2022-10-26 12:33:58 +00:00
|
|
|
if (!forum->topicDeleted(rootId)) {
|
|
|
|
forum->requestTopic(rootId, crl::guard(this, [=] {
|
|
|
|
_topic = _item->topic();
|
|
|
|
if (_topic) {
|
|
|
|
_repaint();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-07 19:59:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 11:12:19 +00:00
|
|
|
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();
|
2022-09-30 07:25:02 +00:00
|
|
|
_name.setText(
|
|
|
|
st::semiboldTextStyle,
|
|
|
|
peer->name(),
|
|
|
|
Ui::NameTextOptions());
|
2022-08-09 11:12:19 +00:00
|
|
|
}
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
2021-12-25 16:19:00 +00:00
|
|
|
} // namespace Dialogs
|