Moved Ui::EmptyUserpic to td_ui.

This commit is contained in:
23rd 2022-12-03 20:36:08 +03:00
parent a458c89810
commit b2e9c4ab75
11 changed files with 86 additions and 62 deletions

View File

@ -1273,8 +1273,6 @@ PRIVATE
ui/widgets/level_meter.h
ui/countryinput.cpp
ui/countryinput.h
ui/empty_userpic.cpp
ui/empty_userpic.h
ui/filter_icons.cpp
ui/filter_icons.h
ui/filter_icon_panel.cpp

View File

@ -241,7 +241,7 @@ ConfirmInviteBox::ConfirmInviteBox(
}
} else {
_photoEmpty = std::make_unique<Ui::EmptyUserpic>(
Ui::PeerUserpicColor(0),
Ui::EmptyUserpic::UserpicColor(0),
invite.title);
}
}

View File

@ -197,7 +197,8 @@ void Userpic::createCache(Image *image) {
{
auto p = QPainter(&filled);
Ui::EmptyUserpic(
Ui::PeerUserpicColor(_peer->id),
Ui::EmptyUserpic::UserpicColor(
Data::PeerColorIndex(_peer->id)),
_peer->name()
).paint(p, 0, 0, size, size);
}

View File

@ -59,14 +59,8 @@ using UpdateFlag = Data::PeerUpdate::Flag;
namespace Data {
int PeerColorIndex(BareId bareId) {
const auto index = bareId % 7;
const int map[] = { 0, 7, 4, 1, 6, 3, 5 };
return map[index];
}
int PeerColorIndex(PeerId peerId) {
return PeerColorIndex(peerId.value & PeerId::kChatTypeMask);
return Ui::EmptyUserpic::ColorIndex(peerId.value & PeerId::kChatTypeMask);
}
PeerId FakePeerIdForJustName(const QString &name) {
@ -236,7 +230,7 @@ not_null<Ui::EmptyUserpic*> PeerData::ensureEmptyUserpic() const {
if (!_userpicEmpty) {
const auto user = asUser();
_userpicEmpty = std::make_unique<Ui::EmptyUserpic>(
Ui::PeerUserpicColor(id),
Ui::EmptyUserpic::UserpicColor(Data::PeerColorIndex(id)),
user && user->isInaccessible()
? Ui::EmptyUserpic::InaccessibleName()
: name());

View File

@ -40,7 +40,6 @@ class CloudImageView;
struct ReactionId;
int PeerColorIndex(PeerId peerId);
int PeerColorIndex(BareId bareId);
// Must be used only for PeerColor-s.
PeerId FakePeerIdForJustName(const QString &name);

View File

@ -105,7 +105,7 @@ HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external)
: name(name)
, colorPeerId(Data::FakePeerIdForJustName(name))
, emptyUserpic(
Ui::PeerUserpicColor(colorPeerId),
Ui::EmptyUserpic::UserpicColor(Data::PeerColorIndex(colorPeerId)),
(external
? Ui::EmptyUserpic::ExternalName()
: name)) {

View File

@ -122,9 +122,9 @@ QSize Contact::countOptimalSize() {
} else {
const auto full = _name.toString();
_photoEmpty = std::make_unique<Ui::EmptyUserpic>(
Ui::PeerUserpicColor(_userId
Ui::EmptyUserpic::UserpicColor(Data::PeerColorIndex(_userId
? peerFromUser(_userId)
: Data::FakePeerIdForJustName(full)),
: Data::FakePeerIdForJustName(full))),
full);
}
if (_contact && _contact->isContact()) {

View File

@ -158,7 +158,7 @@ Image *ItemBase::getResultThumb(Data::FileOrigin origin) const {
QPixmap ItemBase::getResultContactAvatar(int width, int height) const {
if (_result->_type == Result::Type::Contact) {
auto result = Ui::EmptyUserpic(
Ui::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))),
Ui::EmptyUserpic::UserpicColor(BareId(qHash(_result->_id))),
_result->getLayoutTitle()
).generate(width);
if (result.height() != height * cIntRetinaFactor()) {

View File

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/empty_userpic.h"
#include "data/data_peer.h"
#include "ui/emoji_config.h"
#include "ui/effects/animation_value.h"
#include "ui/painter.h"
@ -194,12 +193,11 @@ void PaintInaccessibleAccountInner(
}
}
template <typename Callback>
[[nodiscard]] QPixmap Generate(int size, Callback callback) {
[[nodiscard]] QPixmap Generate(int size, Fn<void(QPainter&)> callback) {
auto result = QImage(
QSize(size, size) * cIntRetinaFactor(),
QSize(size, size) * style::DevicePixelRatio(),
QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(cRetinaFactor());
result.setDevicePixelRatio(style::DevicePixelRatio());
result.fill(Qt::transparent);
{
Painter p(&result);
@ -223,15 +221,34 @@ QString EmptyUserpic::InaccessibleName() {
return QChar(0) + u"inaccessible"_q;
}
template <typename Callback>
int EmptyUserpic::ColorIndex(uint64 id) {
const auto index = id % 7;
const int map[] = { 0, 7, 4, 1, 6, 3, 5 };
return map[index];
}
EmptyUserpic::BgColors EmptyUserpic::UserpicColor(int id) {
const EmptyUserpic::BgColors colors[] = {
{ st::historyPeer1UserpicBg, st::historyPeer1UserpicBg2 },
{ st::historyPeer2UserpicBg, st::historyPeer2UserpicBg2 },
{ st::historyPeer3UserpicBg, st::historyPeer3UserpicBg2 },
{ st::historyPeer4UserpicBg, st::historyPeer4UserpicBg2 },
{ st::historyPeer5UserpicBg, st::historyPeer5UserpicBg2 },
{ st::historyPeer6UserpicBg, st::historyPeer6UserpicBg2 },
{ st::historyPeer7UserpicBg, st::historyPeer7UserpicBg2 },
{ st::historyPeer8UserpicBg, st::historyPeer8UserpicBg2 },
};
return colors[id];
}
void EmptyUserpic::paint(
QPainter &p,
int x,
int y,
int outerWidth,
int size,
Callback paintBackground) const {
x = rtl() ? (outerWidth - x - size) : x;
Fn<void()> paintBackground) const {
x = style::RightToLeft() ? (outerWidth - x - size) : x;
const auto fontsize = (size * 13) / 33;
auto font = st::historyPeerUserpicFont->f;
@ -252,7 +269,12 @@ void EmptyUserpic::paint(
if (IsExternal(_string)) {
PaintExternalMessagesInner(p, x, y, size, st::historyPeerUserpicFg);
} else if (IsInaccessible(_string)) {
PaintInaccessibleAccountInner(p, x, y, size, st::historyPeerUserpicFg);
PaintInaccessibleAccountInner(
p,
x,
y,
size,
st::historyPeerUserpicFg);
} else {
p.setFont(font);
p.setBrush(Qt::NoBrush);
@ -290,7 +312,12 @@ void EmptyUserpic::paintRounded(
});
}
void EmptyUserpic::paintSquare(QPainter &p, int x, int y, int outerWidth, int size) const {
void EmptyUserpic::paintSquare(
QPainter &p,
int x,
int y,
int outerWidth,
int size) const {
paint(p, x, y, outerWidth, size, [&] {
p.fillRect(x, y, size, size, p.brush());
});
@ -334,7 +361,7 @@ void EmptyUserpic::PaintSavedMessages(
int size,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p);
p.setBrush(std::move(bg));
@ -352,12 +379,18 @@ void EmptyUserpic::PaintSavedMessagesRounded(
int size,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p);
p.setBrush(std::move(bg));
p.setPen(Qt::NoPen);
p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall);
p.drawRoundedRect(
x,
y,
size,
size,
st::roundRadiusSmall,
st::roundRadiusSmall);
PaintSavedMessagesInner(p, x, y, size, fg);
}
@ -412,7 +445,7 @@ void EmptyUserpic::PaintRepliesMessages(
int size,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p);
p.setBrush(bg);
@ -430,12 +463,18 @@ void EmptyUserpic::PaintRepliesMessagesRounded(
int size,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p);
p.setBrush(bg);
p.setPen(Qt::NoPen);
p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall);
p.drawRoundedRect(
x,
y,
size,
size,
st::roundRadiusSmall,
st::roundRadiusSmall);
PaintRepliesMessagesInner(p, x, y, size, fg);
}
@ -452,17 +491,22 @@ QPixmap EmptyUserpic::GenerateRepliesMessagesRounded(int size) {
});
}
InMemoryKey EmptyUserpic::uniqueKey() const {
std::pair<uint64, uint64> EmptyUserpic::uniqueKey() const {
const auto first = (uint64(0xFFFFFFFFU) << 32)
| anim::getPremultiplied(_colors.color1->c);
auto second = uint64(0);
memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar)));
return InMemoryKey(first, second);
memcpy(
&second,
_string.constData(),
std::min(sizeof(second), size_t(_string.size()) * sizeof(QChar)));
return { first, second };
}
QPixmap EmptyUserpic::generate(int size) {
auto result = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(cRetinaFactor());
auto result = QImage(
QSize(size, size) * style::DevicePixelRatio(),
QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(style::DevicePixelRatio());
result.fill(Qt::transparent);
{
auto p = QPainter(&result);
@ -535,18 +579,4 @@ void EmptyUserpic::fillString(const QString &name) {
EmptyUserpic::~EmptyUserpic() = default;
EmptyUserpic::BgColors PeerUserpicColor(PeerId peerId) {
const EmptyUserpic::BgColors colors[] = {
{ st::historyPeer1UserpicBg, st::historyPeer1UserpicBg2 },
{ st::historyPeer2UserpicBg, st::historyPeer2UserpicBg2 },
{ st::historyPeer3UserpicBg, st::historyPeer3UserpicBg2 },
{ st::historyPeer4UserpicBg, st::historyPeer4UserpicBg2 },
{ st::historyPeer5UserpicBg, st::historyPeer5UserpicBg2 },
{ st::historyPeer6UserpicBg, st::historyPeer6UserpicBg2 },
{ st::historyPeer7UserpicBg, st::historyPeer7UserpicBg2 },
{ st::historyPeer8UserpicBg, st::historyPeer8UserpicBg2 },
};
return colors[Data::PeerColorIndex(peerId)];
}
} // namespace Ui

View File

@ -16,6 +16,9 @@ public:
const style::color color2;
};
[[nodiscard]] static int ColorIndex(uint64 id);
[[nodiscard]] static EmptyUserpic::BgColors UserpicColor(int id);
[[nodiscard]] static QString ExternalName();
[[nodiscard]] static QString InaccessibleName();
@ -40,8 +43,8 @@ public:
int y,
int outerWidth,
int size) const;
QPixmap generate(int size);
InMemoryKey uniqueKey() const;
[[nodiscard]] QPixmap generate(int size);
[[nodiscard]] std::pair<uint64, uint64> uniqueKey() const;
static void PaintSavedMessages(
QPainter &p,
@ -71,8 +74,8 @@ public:
int size,
QBrush bg,
const style::color &fg);
static QPixmap GenerateSavedMessages(int size);
static QPixmap GenerateSavedMessagesRounded(int size);
[[nodiscard]] static QPixmap GenerateSavedMessages(int size);
[[nodiscard]] static QPixmap GenerateSavedMessagesRounded(int size);
static void PaintRepliesMessages(
QPainter &p,
@ -102,20 +105,19 @@ public:
int size,
QBrush bg,
const style::color &fg);
static QPixmap GenerateRepliesMessages(int size);
static QPixmap GenerateRepliesMessagesRounded(int size);
[[nodiscard]] static QPixmap GenerateRepliesMessages(int size);
[[nodiscard]] static QPixmap GenerateRepliesMessagesRounded(int size);
~EmptyUserpic();
private:
template <typename Callback>
void paint(
QPainter &p,
int x,
int y,
int outerWidth,
int size,
Callback paintBackground) const;
Fn<void()> paintBackground) const;
void fillString(const QString &name);
@ -124,6 +126,4 @@ private:
};
[[nodiscard]] EmptyUserpic::BgColors PeerUserpicColor(PeerId peerId);
} // namespace Ui

View File

@ -274,6 +274,8 @@ PRIVATE
ui/color_contrast.h
ui/color_int_conversion.cpp
ui/color_int_conversion.h
ui/empty_userpic.cpp
ui/empty_userpic.h
ui/grouped_layout.cpp
ui/grouped_layout.h
ui/widgets/fields/special_fields.cpp