2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Support different row styles in chats list.

This commit is contained in:
John Preston
2022-09-29 14:33:17 +04:00
parent 1401b19994
commit 405d8c327d
20 changed files with 369 additions and 324 deletions

View File

@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#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_folder.h"
#include "data/data_peer_values.h"
#include "history/history.h"
@@ -126,20 +127,17 @@ void BasicRow::paintUserpic(
not_null<PeerData*> peer,
Ui::VideoUserpic *videoUserpic,
History *historyForCornerBadge,
crl::time now,
bool active,
int fullWidth,
bool paused) const {
const Ui::PaintContext &context) const {
PaintUserpic(
p,
peer,
videoUserpic,
_userpic,
st::dialogsPadding.x(),
st::dialogsPadding.y(),
fullWidth,
st::dialogsPhotoSize,
paused);
context.st->padding.left(),
context.st->padding.top(),
context.width,
context.st->photoSize,
context.paused);
}
Row::Row(Key key, int pos) : _id(key), _pos(pos) {
@@ -221,7 +219,7 @@ void Row::PaintCornerBadgeFrame(
not_null<PeerData*> peer,
Ui::VideoUserpic *videoUserpic,
std::shared_ptr<Data::CloudImageView> &view,
bool paused) {
const Ui::PaintContext &context) {
data->frame.fill(Qt::transparent);
Painter q(&data->frame);
@@ -233,8 +231,8 @@ void Row::PaintCornerBadgeFrame(
0,
0,
data->frame.width() / data->frame.devicePixelRatio(),
st::dialogsPhotoSize,
paused);
context.st->photoSize,
context.paused);
PainterHighQualityEnabler hq(q);
q.setCompositionMode(QPainter::CompositionMode_Source);
@@ -255,8 +253,8 @@ void Row::PaintCornerBadgeFrame(
? st::dialogsOnlineBadgeFgActive
: st::dialogsOnlineBadgeFg);
q.drawEllipse(QRectF(
st::dialogsPhotoSize - skip.x() - size,
st::dialogsPhotoSize - skip.y() - size,
context.st->photoSize - skip.x() - size,
context.st->photoSize - skip.y() - size,
size,
size
).marginsRemoved({ shrink, shrink, shrink, shrink }));
@@ -267,10 +265,7 @@ void Row::paintUserpic(
not_null<PeerData*> peer,
Ui::VideoUserpic *videoUserpic,
History *historyForCornerBadge,
crl::time now,
bool active,
int fullWidth,
bool paused) const {
const Ui::PaintContext &context) const {
updateCornerBadgeShown(peer);
const auto shown = _cornerBadgeUserpic
@@ -282,61 +277,63 @@ void Row::paintUserpic(
peer,
videoUserpic,
historyForCornerBadge,
now,
active,
fullWidth,
paused);
context);
if (!historyForCornerBadge || !_cornerBadgeShown) {
_cornerBadgeUserpic = nullptr;
}
return;
}
ensureCornerBadgeUserpic();
if (_cornerBadgeUserpic->frame.isNull()) {
const auto ratio = style::DevicePixelRatio();
const auto frameSide = context.st->photoSize * style::DevicePixelRatio();
const auto frameSize = QSize(frameSide, frameSide);
if (_cornerBadgeUserpic->frame.size() != frameSize) {
_cornerBadgeUserpic->frame = QImage(
st::dialogsPhotoSize * cRetinaFactor(),
st::dialogsPhotoSize * cRetinaFactor(),
frameSize,
QImage::Format_ARGB32_Premultiplied);
_cornerBadgeUserpic->frame.setDevicePixelRatio(cRetinaFactor());
_cornerBadgeUserpic->frame.setDevicePixelRatio(ratio);
}
const auto key = peer->userpicUniqueKey(userpicView());
const auto frameIndex = videoUserpic ? videoUserpic->frameIndex() : -1;
if (_cornerBadgeUserpic->shown != shown
|| _cornerBadgeUserpic->key != key
|| _cornerBadgeUserpic->active != active
|| _cornerBadgeUserpic->active != context.active
|| _cornerBadgeUserpic->frameIndex != frameIndex
|| videoUserpic) {
_cornerBadgeUserpic->shown = shown;
_cornerBadgeUserpic->key = key;
_cornerBadgeUserpic->active = active;
_cornerBadgeUserpic->active = context.active;
_cornerBadgeUserpic->frameIndex = frameIndex;
PaintCornerBadgeFrame(
_cornerBadgeUserpic.get(),
peer,
videoUserpic,
userpicView(),
paused);
context);
}
p.drawImage(st::dialogsPadding, _cornerBadgeUserpic->frame);
p.drawImage(
context.st->padding.left(),
context.st->padding.top(),
_cornerBadgeUserpic->frame);
if (historyForCornerBadge->peer->isUser()) {
return;
}
const auto actionPainter = historyForCornerBadge->sendActionPainter();
const auto bg = active
const auto bg = context.active
? st::dialogsBgActive
: st::dialogsBg;
const auto size = st::dialogsCallBadgeSize;
const auto skip = st::dialogsCallBadgeSkip;
p.setOpacity(shown);
p.translate(st::dialogsPadding);
p.translate(context.st->padding.left(), context.st->padding.top());
actionPainter->paintSpeaking(
p,
st::dialogsPhotoSize - skip.x() - size,
st::dialogsPhotoSize - skip.y() - size,
fullWidth,
context.st->photoSize - skip.x() - size,
context.st->photoSize - skip.y() - size,
context.width,
bg,
now);
p.translate(-st::dialogsPadding);
context.now);
p.translate(-context.st->padding.left(), -context.st->padding.top());
p.setOpacity(1.);
}