2017-12-05 08:43:18 +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.
|
2017-12-05 08:43:18 +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
|
2017-12-05 08:43:18 +00:00
|
|
|
*/
|
|
|
|
#include "ui/empty_userpic.h"
|
|
|
|
|
|
|
|
#include "data/data_peer.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "ui/effects/animation_value.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2021-05-07 14:33:53 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2020-09-15 11:47:42 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2021-01-20 14:09:45 +00:00
|
|
|
#include "styles/style_widgets.h" // style::IconButton
|
|
|
|
#include "styles/style_info.h" // st::topBarCall
|
2017-12-05 08:43:18 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
2019-08-28 18:20:49 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
[[nodiscard]] bool IsExternal(const QString &name) {
|
|
|
|
return !name.isEmpty()
|
|
|
|
&& (name.front() == QChar(0))
|
2022-11-11 06:40:33 +00:00
|
|
|
&& QStringView(name).mid(1) == u"external"_q;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsInaccessible(const QString &name) {
|
|
|
|
return !name.isEmpty()
|
|
|
|
&& (name.front() == QChar(0))
|
|
|
|
&& QStringView(name).mid(1) == u"inaccessible"_q;
|
2021-01-20 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
void PaintSavedMessagesInner(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2019-08-28 18:20:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
const style::color &fg) {
|
|
|
|
// |<----width----->|
|
|
|
|
//
|
|
|
|
// XXXXXXXXXXXXXXXXXX ---
|
|
|
|
// X X |
|
|
|
|
// X X |
|
|
|
|
// X X |
|
|
|
|
// X X height
|
|
|
|
// X XX X | ---
|
|
|
|
// X XX XX X | |
|
|
|
|
// X XX XX X | add
|
|
|
|
// X XX XX X | |
|
|
|
|
// XX XX --- ---
|
|
|
|
|
2021-09-27 08:13:57 +00:00
|
|
|
const auto thinkness = base::SafeRound(size * 0.055);
|
2019-08-28 18:20:49 +00:00
|
|
|
const auto increment = int(thinkness) % 2 + (size % 2);
|
2021-09-27 08:13:57 +00:00
|
|
|
const auto width = base::SafeRound(size * 0.15) * 2 + increment;
|
|
|
|
const auto height = base::SafeRound(size * 0.19) * 2 + increment;
|
|
|
|
const auto add = base::SafeRound(size * 0.064);
|
2019-08-28 18:20:49 +00:00
|
|
|
|
|
|
|
const auto left = x + (size - width) / 2;
|
|
|
|
const auto top = y + (size - height) / 2;
|
|
|
|
const auto right = left + width;
|
|
|
|
const auto bottom = top + height;
|
|
|
|
const auto middle = (left + right) / 2;
|
|
|
|
const auto half = (top + bottom) / 2;
|
|
|
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
auto pen = fg->p;
|
|
|
|
pen.setWidthF(thinkness);
|
|
|
|
pen.setCapStyle(Qt::FlatCap);
|
|
|
|
|
|
|
|
{
|
|
|
|
// XXXXXXXXXXXXXXXXXX
|
|
|
|
// X X
|
|
|
|
// X X
|
|
|
|
// X X
|
|
|
|
// X X
|
|
|
|
// X X
|
|
|
|
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
p.setPen(pen);
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(left, half);
|
|
|
|
path.lineTo(left, top);
|
|
|
|
path.lineTo(right, top);
|
|
|
|
path.lineTo(right, half);
|
|
|
|
p.drawPath(path);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// X X
|
|
|
|
// X XX X
|
|
|
|
// X XX XX X
|
|
|
|
// X XX XX X
|
|
|
|
// X XX XX X
|
|
|
|
// XX XX
|
|
|
|
|
|
|
|
pen.setJoinStyle(Qt::MiterJoin);
|
|
|
|
p.setPen(pen);
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(left, half);
|
|
|
|
path.lineTo(left, bottom);
|
|
|
|
path.lineTo(middle, bottom - add);
|
|
|
|
path.lineTo(right, bottom);
|
|
|
|
path.lineTo(right, half);
|
|
|
|
p.drawPath(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
void PaintIconInner(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2020-09-11 15:33:26 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
2021-01-20 14:09:45 +00:00
|
|
|
int defaultSize,
|
|
|
|
const style::icon &icon,
|
2020-09-11 15:33:26 +00:00
|
|
|
const style::color &fg) {
|
2021-01-20 14:09:45 +00:00
|
|
|
if (size == defaultSize) {
|
2020-09-15 11:47:42 +00:00
|
|
|
const auto rect = QRect{ x, y, size, size };
|
2021-01-20 14:09:45 +00:00
|
|
|
icon.paintInCenter(
|
2020-09-15 11:47:42 +00:00
|
|
|
p,
|
|
|
|
rect,
|
|
|
|
fg->c);
|
|
|
|
} else {
|
|
|
|
p.save();
|
2021-01-20 14:09:45 +00:00
|
|
|
const auto ratio = size / float64(defaultSize);
|
2020-09-15 11:47:42 +00:00
|
|
|
p.translate(x + size / 2., y + size / 2.);
|
|
|
|
p.scale(ratio, ratio);
|
2021-01-20 14:09:45 +00:00
|
|
|
const auto skip = defaultSize;
|
2020-09-15 11:47:42 +00:00
|
|
|
const auto rect = QRect{ -skip, -skip, 2 * skip, 2 * skip };
|
2021-01-20 14:09:45 +00:00
|
|
|
icon.paintInCenter(
|
2020-09-15 11:47:42 +00:00
|
|
|
p,
|
|
|
|
rect,
|
|
|
|
fg->c);
|
|
|
|
p.restore();
|
2020-09-11 16:55:28 +00:00
|
|
|
}
|
2020-09-11 15:33:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
void PaintRepliesMessagesInner(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2021-01-20 14:09:45 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
const style::color &fg) {
|
|
|
|
PaintIconInner(
|
|
|
|
p,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
size,
|
2022-09-29 10:33:17 +00:00
|
|
|
st::defaultDialogRow.photoSize,
|
2021-01-20 14:09:45 +00:00
|
|
|
st::dialogsRepliesUserpic,
|
|
|
|
fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaintExternalMessagesInner(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2021-01-20 14:09:45 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
const style::color &fg) {
|
|
|
|
PaintIconInner(
|
|
|
|
p,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
size,
|
|
|
|
st::msgPhotoSize,
|
|
|
|
st::topBarCall.icon,
|
|
|
|
fg);
|
|
|
|
}
|
|
|
|
|
2022-11-11 06:40:33 +00:00
|
|
|
void PaintInaccessibleAccountInner(
|
|
|
|
QPainter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
const style::color &fg) {
|
|
|
|
if (size > st::defaultDialogRow.photoSize) {
|
|
|
|
PaintIconInner(
|
|
|
|
p,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
size,
|
|
|
|
st::infoProfilePhotoInnerSize,
|
|
|
|
st::infoProfileInaccessibleUserpic,
|
|
|
|
fg);
|
|
|
|
} else {
|
|
|
|
PaintIconInner(
|
|
|
|
p,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
size,
|
|
|
|
st::defaultDialogRow.photoSize,
|
|
|
|
st::dialogsInaccessibleUserpic,
|
|
|
|
fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
template <typename Callback>
|
|
|
|
[[nodiscard]] QPixmap Generate(int size, Callback callback) {
|
|
|
|
auto result = QImage(
|
|
|
|
QSize(size, size) * cIntRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&result);
|
|
|
|
callback(p);
|
|
|
|
}
|
2021-05-07 14:33:53 +00:00
|
|
|
return Ui::PixmapFromImage(std::move(result));
|
2019-08-28 18:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2017-12-05 08:43:18 +00:00
|
|
|
|
|
|
|
EmptyUserpic::EmptyUserpic(const style::color &color, const QString &name)
|
|
|
|
: _color(color) {
|
|
|
|
fillString(name);
|
|
|
|
}
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
QString EmptyUserpic::ExternalName() {
|
|
|
|
return QChar(0) + u"external"_q;
|
|
|
|
}
|
|
|
|
|
2022-11-11 06:40:33 +00:00
|
|
|
QString EmptyUserpic::InaccessibleName() {
|
|
|
|
return QChar(0) + u"inaccessible"_q;
|
|
|
|
}
|
|
|
|
|
2017-12-05 08:43:18 +00:00
|
|
|
template <typename Callback>
|
|
|
|
void EmptyUserpic::paint(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2017-12-05 08:43:18 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size,
|
|
|
|
Callback paintBackground) const {
|
|
|
|
x = rtl() ? (outerWidth - x - size) : x;
|
|
|
|
|
|
|
|
const auto fontsize = (size * 13) / 33;
|
|
|
|
auto font = st::historyPeerUserpicFont->f;
|
|
|
|
font.setPixelSize(fontsize);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setBrush(_color);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
paintBackground();
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
if (IsExternal(_string)) {
|
|
|
|
PaintExternalMessagesInner(p, x, y, size, st::historyPeerUserpicFg);
|
2022-11-11 06:40:33 +00:00
|
|
|
} else if (IsInaccessible(_string)) {
|
|
|
|
PaintInaccessibleAccountInner(p, x, y, size, st::historyPeerUserpicFg);
|
2021-01-20 14:09:45 +00:00
|
|
|
} else {
|
|
|
|
p.setFont(font);
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
p.setPen(st::historyPeerUserpicFg);
|
|
|
|
p.drawText(
|
|
|
|
QRect(x, y, size, size),
|
|
|
|
_string,
|
|
|
|
QTextOption(style::al_center));
|
|
|
|
}
|
2017-12-05 08:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyUserpic::paint(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2017-12-05 08:43:18 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size) const {
|
2022-10-14 13:25:05 +00:00
|
|
|
paint(p, x, y, outerWidth, size, [&] {
|
2017-12-05 08:43:18 +00:00
|
|
|
p.drawEllipse(x, y, size, size);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
void EmptyUserpic::paintRounded(
|
|
|
|
QPainter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size,
|
|
|
|
int radius) const {
|
|
|
|
if (!radius) {
|
|
|
|
radius = st::roundRadiusSmall;
|
|
|
|
}
|
|
|
|
paint(p, x, y, outerWidth, size, [&] {
|
|
|
|
p.drawRoundedRect(x, y, size, size, radius, radius);
|
2017-12-05 08:43:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-16 20:23:27 +00:00
|
|
|
void EmptyUserpic::paintSquare(QPainter &p, int x, int y, int outerWidth, int size) const {
|
2022-10-14 13:25:05 +00:00
|
|
|
paint(p, x, y, outerWidth, size, [&] {
|
2017-12-05 08:43:18 +00:00
|
|
|
p.fillRect(x, y, size, size, p.brush());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-05 11:50:32 +00:00
|
|
|
void EmptyUserpic::PaintSavedMessages(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2017-12-05 11:50:32 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size) {
|
2017-12-08 09:22:58 +00:00
|
|
|
const auto &bg = st::historyPeerSavedMessagesBg;
|
2017-12-05 16:48:03 +00:00
|
|
|
const auto &fg = st::historyPeerUserpicFg;
|
|
|
|
PaintSavedMessages(p, x, y, outerWidth, size, bg, fg);
|
|
|
|
}
|
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
void EmptyUserpic::PaintSavedMessagesRounded(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2019-08-28 18:20:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size) {
|
|
|
|
const auto &bg = st::historyPeerSavedMessagesBg;
|
|
|
|
const auto &fg = st::historyPeerUserpicFg;
|
|
|
|
PaintSavedMessagesRounded(p, x, y, outerWidth, size, bg, fg);
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:48:03 +00:00
|
|
|
void EmptyUserpic::PaintSavedMessages(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2017-12-05 16:48:03 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size,
|
|
|
|
const style::color &bg,
|
|
|
|
const style::color &fg) {
|
2017-12-05 11:50:32 +00:00
|
|
|
x = rtl() ? (outerWidth - x - size) : x;
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2017-12-05 16:48:03 +00:00
|
|
|
p.setBrush(bg);
|
2017-12-05 11:50:32 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(x, y, size, size);
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
PaintSavedMessagesInner(p, x, y, size, fg);
|
2019-08-28 18:20:49 +00:00
|
|
|
}
|
2017-12-05 11:50:32 +00:00
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
void EmptyUserpic::PaintSavedMessagesRounded(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2019-08-28 18:20:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size,
|
|
|
|
const style::color &bg,
|
|
|
|
const style::color &fg) {
|
|
|
|
x = rtl() ? (outerWidth - x - size) : x;
|
2017-12-05 11:50:32 +00:00
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setBrush(bg);
|
|
|
|
p.setPen(Qt::NoPen);
|
2020-12-08 07:19:23 +00:00
|
|
|
p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall);
|
2017-12-05 11:50:32 +00:00
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
PaintSavedMessagesInner(p, x, y, size, fg);
|
2019-08-28 18:20:49 +00:00
|
|
|
}
|
2017-12-05 11:50:32 +00:00
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
QPixmap EmptyUserpic::GenerateSavedMessages(int size) {
|
2022-09-16 20:23:27 +00:00
|
|
|
return Generate(size, [&](QPainter &p) {
|
2019-08-28 18:20:49 +00:00
|
|
|
PaintSavedMessages(p, 0, 0, size, size);
|
|
|
|
});
|
|
|
|
}
|
2017-12-05 11:50:32 +00:00
|
|
|
|
2019-08-28 18:20:49 +00:00
|
|
|
QPixmap EmptyUserpic::GenerateSavedMessagesRounded(int size) {
|
2022-09-16 20:23:27 +00:00
|
|
|
return Generate(size, [&](QPainter &p) {
|
2019-08-28 18:20:49 +00:00
|
|
|
PaintSavedMessagesRounded(p, 0, 0, size, size);
|
2020-09-11 15:33:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyUserpic::PaintRepliesMessages(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2020-09-11 15:33:26 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size) {
|
|
|
|
const auto &bg = st::historyPeerSavedMessagesBg;
|
|
|
|
const auto &fg = st::historyPeerUserpicFg;
|
|
|
|
PaintRepliesMessages(p, x, y, outerWidth, size, bg, fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyUserpic::PaintRepliesMessagesRounded(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2020-09-11 15:33:26 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size) {
|
|
|
|
const auto &bg = st::historyPeerSavedMessagesBg;
|
|
|
|
const auto &fg = st::historyPeerUserpicFg;
|
|
|
|
PaintRepliesMessagesRounded(p, x, y, outerWidth, size, bg, fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyUserpic::PaintRepliesMessages(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2020-09-11 15:33:26 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size,
|
|
|
|
const style::color &bg,
|
|
|
|
const style::color &fg) {
|
|
|
|
x = rtl() ? (outerWidth - x - size) : x;
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setBrush(bg);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(x, y, size, size);
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
PaintRepliesMessagesInner(p, x, y, size, fg);
|
2020-09-11 15:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyUserpic::PaintRepliesMessagesRounded(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2020-09-11 15:33:26 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size,
|
|
|
|
const style::color &bg,
|
|
|
|
const style::color &fg) {
|
|
|
|
x = rtl() ? (outerWidth - x - size) : x;
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setBrush(bg);
|
|
|
|
p.setPen(Qt::NoPen);
|
2020-12-08 07:19:23 +00:00
|
|
|
p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall);
|
2020-09-11 15:33:26 +00:00
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
PaintRepliesMessagesInner(p, x, y, size, fg);
|
2020-09-11 15:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap EmptyUserpic::GenerateRepliesMessages(int size) {
|
2022-09-16 20:23:27 +00:00
|
|
|
return Generate(size, [&](QPainter &p) {
|
2020-09-11 15:33:26 +00:00
|
|
|
PaintRepliesMessages(p, 0, 0, size, size);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap EmptyUserpic::GenerateRepliesMessagesRounded(int size) {
|
2022-09-16 20:23:27 +00:00
|
|
|
return Generate(size, [&](QPainter &p) {
|
2020-09-11 15:33:26 +00:00
|
|
|
PaintRepliesMessagesRounded(p, 0, 0, size, size);
|
2019-08-28 18:20:49 +00:00
|
|
|
});
|
2017-12-05 11:50:32 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
InMemoryKey EmptyUserpic::uniqueKey() const {
|
|
|
|
const auto first = (uint64(0xFFFFFFFFU) << 32)
|
|
|
|
| anim::getPremultiplied(_color->c);
|
2017-12-05 08:43:18 +00:00
|
|
|
auto second = uint64(0);
|
|
|
|
memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar)));
|
2019-03-22 13:43:34 +00:00
|
|
|
return InMemoryKey(first, second);
|
2017-12-05 08:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap EmptyUserpic::generate(int size) {
|
|
|
|
auto result = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
{
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(&result);
|
2017-12-05 08:43:18 +00:00
|
|
|
paint(p, 0, 0, size, size);
|
|
|
|
}
|
2021-05-07 14:33:53 +00:00
|
|
|
return Ui::PixmapFromImage(std::move(result));
|
2017-12-05 08:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyUserpic::fillString(const QString &name) {
|
2022-11-11 06:40:33 +00:00
|
|
|
if (IsExternal(name) || IsInaccessible(name)) {
|
2021-01-20 14:09:45 +00:00
|
|
|
_string = name;
|
|
|
|
return;
|
|
|
|
}
|
2017-12-05 08:43:18 +00:00
|
|
|
QList<QString> letters;
|
|
|
|
QList<int> levels;
|
|
|
|
|
|
|
|
auto level = 0;
|
|
|
|
auto letterFound = false;
|
|
|
|
auto ch = name.constData(), end = ch + name.size();
|
|
|
|
while (ch != end) {
|
|
|
|
auto emojiLength = 0;
|
2021-07-13 22:16:03 +00:00
|
|
|
if (Ui::Emoji::Find(ch, end, &emojiLength)) {
|
2017-12-05 08:43:18 +00:00
|
|
|
ch += emojiLength;
|
|
|
|
} else if (ch->isHighSurrogate()) {
|
|
|
|
++ch;
|
|
|
|
if (ch != end && ch->isLowSurrogate()) {
|
|
|
|
++ch;
|
|
|
|
}
|
|
|
|
} else if (!letterFound && ch->isLetterOrNumber()) {
|
|
|
|
letterFound = true;
|
2020-06-04 06:53:59 +00:00
|
|
|
if (ch + 1 != end && Ui::Text::IsDiac(*(ch + 1))) {
|
2017-12-05 08:43:18 +00:00
|
|
|
letters.push_back(QString(ch, 2));
|
|
|
|
levels.push_back(level);
|
|
|
|
++ch;
|
|
|
|
} else {
|
|
|
|
letters.push_back(QString(ch, 1));
|
|
|
|
levels.push_back(level);
|
|
|
|
}
|
|
|
|
++ch;
|
|
|
|
} else {
|
|
|
|
if (*ch == ' ') {
|
|
|
|
level = 0;
|
|
|
|
letterFound = false;
|
|
|
|
} else if (letterFound && *ch == '-') {
|
|
|
|
level = 1;
|
|
|
|
letterFound = true;
|
|
|
|
}
|
|
|
|
++ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We prefer the second letter to be after ' ', but it can also be after '-'.
|
|
|
|
_string = QString();
|
|
|
|
if (!letters.isEmpty()) {
|
|
|
|
_string += letters.front();
|
|
|
|
auto bestIndex = 0;
|
|
|
|
auto bestLevel = 2;
|
|
|
|
for (auto i = letters.size(); i != 1;) {
|
|
|
|
if (levels[--i] < bestLevel) {
|
|
|
|
bestIndex = i;
|
|
|
|
bestLevel = levels[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bestIndex > 0) {
|
|
|
|
_string += letters[bestIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_string = _string.toUpper();
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyUserpic::~EmptyUserpic() = default;
|
|
|
|
|
|
|
|
} // namespace Ui
|