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/widgets/level_meter.h
ui/countryinput.cpp ui/countryinput.cpp
ui/countryinput.h ui/countryinput.h
ui/empty_userpic.cpp
ui/empty_userpic.h
ui/filter_icons.cpp ui/filter_icons.cpp
ui/filter_icons.h ui/filter_icons.h
ui/filter_icon_panel.cpp ui/filter_icon_panel.cpp

View file

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

View file

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

View file

@ -59,14 +59,8 @@ using UpdateFlag = Data::PeerUpdate::Flag;
namespace Data { 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) { int PeerColorIndex(PeerId peerId) {
return PeerColorIndex(peerId.value & PeerId::kChatTypeMask); return Ui::EmptyUserpic::ColorIndex(peerId.value & PeerId::kChatTypeMask);
} }
PeerId FakePeerIdForJustName(const QString &name) { PeerId FakePeerIdForJustName(const QString &name) {
@ -236,7 +230,7 @@ not_null<Ui::EmptyUserpic*> PeerData::ensureEmptyUserpic() const {
if (!_userpicEmpty) { if (!_userpicEmpty) {
const auto user = asUser(); const auto user = asUser();
_userpicEmpty = std::make_unique<Ui::EmptyUserpic>( _userpicEmpty = std::make_unique<Ui::EmptyUserpic>(
Ui::PeerUserpicColor(id), Ui::EmptyUserpic::UserpicColor(Data::PeerColorIndex(id)),
user && user->isInaccessible() user && user->isInaccessible()
? Ui::EmptyUserpic::InaccessibleName() ? Ui::EmptyUserpic::InaccessibleName()
: name()); : name());

View file

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

View file

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

View file

@ -122,9 +122,9 @@ QSize Contact::countOptimalSize() {
} else { } else {
const auto full = _name.toString(); const auto full = _name.toString();
_photoEmpty = std::make_unique<Ui::EmptyUserpic>( _photoEmpty = std::make_unique<Ui::EmptyUserpic>(
Ui::PeerUserpicColor(_userId Ui::EmptyUserpic::UserpicColor(Data::PeerColorIndex(_userId
? peerFromUser(_userId) ? peerFromUser(_userId)
: Data::FakePeerIdForJustName(full)), : Data::FakePeerIdForJustName(full))),
full); full);
} }
if (_contact && _contact->isContact()) { 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 { QPixmap ItemBase::getResultContactAvatar(int width, int height) const {
if (_result->_type == Result::Type::Contact) { if (_result->_type == Result::Type::Contact) {
auto result = Ui::EmptyUserpic( auto result = Ui::EmptyUserpic(
Ui::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))), Ui::EmptyUserpic::UserpicColor(BareId(qHash(_result->_id))),
_result->getLayoutTitle() _result->getLayoutTitle()
).generate(width); ).generate(width);
if (result.height() != height * cIntRetinaFactor()) { 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 "ui/empty_userpic.h"
#include "data/data_peer.h"
#include "ui/emoji_config.h" #include "ui/emoji_config.h"
#include "ui/effects/animation_value.h" #include "ui/effects/animation_value.h"
#include "ui/painter.h" #include "ui/painter.h"
@ -194,12 +193,11 @@ void PaintInaccessibleAccountInner(
} }
} }
template <typename Callback> [[nodiscard]] QPixmap Generate(int size, Fn<void(QPainter&)> callback) {
[[nodiscard]] QPixmap Generate(int size, Callback callback) {
auto result = QImage( auto result = QImage(
QSize(size, size) * cIntRetinaFactor(), QSize(size, size) * style::DevicePixelRatio(),
QImage::Format_ARGB32_Premultiplied); QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(cRetinaFactor()); result.setDevicePixelRatio(style::DevicePixelRatio());
result.fill(Qt::transparent); result.fill(Qt::transparent);
{ {
Painter p(&result); Painter p(&result);
@ -223,15 +221,34 @@ QString EmptyUserpic::InaccessibleName() {
return QChar(0) + u"inaccessible"_q; 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( void EmptyUserpic::paint(
QPainter &p, QPainter &p,
int x, int x,
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
Callback paintBackground) const { Fn<void()> paintBackground) const {
x = rtl() ? (outerWidth - x - size) : x; x = style::RightToLeft() ? (outerWidth - x - size) : x;
const auto fontsize = (size * 13) / 33; const auto fontsize = (size * 13) / 33;
auto font = st::historyPeerUserpicFont->f; auto font = st::historyPeerUserpicFont->f;
@ -252,7 +269,12 @@ void EmptyUserpic::paint(
if (IsExternal(_string)) { if (IsExternal(_string)) {
PaintExternalMessagesInner(p, x, y, size, st::historyPeerUserpicFg); PaintExternalMessagesInner(p, x, y, size, st::historyPeerUserpicFg);
} else if (IsInaccessible(_string)) { } else if (IsInaccessible(_string)) {
PaintInaccessibleAccountInner(p, x, y, size, st::historyPeerUserpicFg); PaintInaccessibleAccountInner(
p,
x,
y,
size,
st::historyPeerUserpicFg);
} else { } else {
p.setFont(font); p.setFont(font);
p.setBrush(Qt::NoBrush); 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, [&] { paint(p, x, y, outerWidth, size, [&] {
p.fillRect(x, y, size, size, p.brush()); p.fillRect(x, y, size, size, p.brush());
}); });
@ -334,7 +361,7 @@ void EmptyUserpic::PaintSavedMessages(
int size, int size,
QBrush bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(std::move(bg)); p.setBrush(std::move(bg));
@ -352,12 +379,18 @@ void EmptyUserpic::PaintSavedMessagesRounded(
int size, int size,
QBrush bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(std::move(bg)); p.setBrush(std::move(bg));
p.setPen(Qt::NoPen); 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); PaintSavedMessagesInner(p, x, y, size, fg);
} }
@ -412,7 +445,7 @@ void EmptyUserpic::PaintRepliesMessages(
int size, int size,
QBrush bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(bg); p.setBrush(bg);
@ -430,12 +463,18 @@ void EmptyUserpic::PaintRepliesMessagesRounded(
int size, int size,
QBrush bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = style::RightToLeft() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(bg); p.setBrush(bg);
p.setPen(Qt::NoPen); 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); 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) const auto first = (uint64(0xFFFFFFFFU) << 32)
| anim::getPremultiplied(_colors.color1->c); | anim::getPremultiplied(_colors.color1->c);
auto second = uint64(0); auto second = uint64(0);
memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar))); memcpy(
return InMemoryKey(first, second); &second,
_string.constData(),
std::min(sizeof(second), size_t(_string.size()) * sizeof(QChar)));
return { first, second };
} }
QPixmap EmptyUserpic::generate(int size) { QPixmap EmptyUserpic::generate(int size) {
auto result = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); auto result = QImage(
result.setDevicePixelRatio(cRetinaFactor()); QSize(size, size) * style::DevicePixelRatio(),
QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(style::DevicePixelRatio());
result.fill(Qt::transparent); result.fill(Qt::transparent);
{ {
auto p = QPainter(&result); auto p = QPainter(&result);
@ -535,18 +579,4 @@ void EmptyUserpic::fillString(const QString &name) {
EmptyUserpic::~EmptyUserpic() = default; 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 } // namespace Ui

View file

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

View file

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