Display a userpic placeholder in the call panel.

This commit is contained in:
John Preston 2017-05-12 17:33:30 +03:00
parent 5fe75fbd5f
commit 7593be4361
3 changed files with 45 additions and 16 deletions

View File

@ -449,27 +449,34 @@ void Panel::refreshUserPhoto() {
_userPhotoFull = true;
createUserpicCache(photo->full);
} else if (_userPhoto.isNull()) {
if (auto userpic = _user->currentUserpic()) {
createUserpicCache(userpic);
}
createUserpicCache(_user->currentUserpic());
}
}
void Panel::createUserpicCache(ImagePtr image) {
auto size = st::callWidth * cIntRetinaFactor();
auto options = _useTransparency ? (Images::Option::RoundedLarge | Images::Option::RoundedTopLeft | Images::Option::RoundedTopRight | Images::Option::Smooth) : Images::Option::None;
auto width = image->width();
auto height = image->height();
if (width > height) {
width = qMax((width * size) / height, 1);
height = size;
if (image) {
auto width = image->width();
auto height = image->height();
if (width > height) {
width = qMax((width * size) / height, 1);
height = size;
} else {
height = qMax((height * size) / width, 1);
width = size;
}
_userPhoto = image->pixNoCache(width, height, options, st::callWidth, st::callWidth);
if (cRetina()) _userPhoto.setDevicePixelRatio(cRetinaFactor());
} else {
height = qMax((height * size) / width, 1);
width = size;
auto filled = QImage(QSize(st::callWidth, st::callWidth) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
{
Painter p(&filled);
EmptyUserpic(_user->colorIndex(), _user->name).paintSquare(p, 0, 0, st::callWidth, st::callWidth);
}
Images::prepareRound(filled, ImageRoundRadius::Large, ImageRoundCorner::TopLeft | ImageRoundCorner::TopRight);
_userPhoto = App::pixmapFromImageInPlace(std::move(filled));
}
_userPhoto = image->pixNoCache(width, height, options, st::callWidth, st::callWidth);
if (cRetina()) _userPhoto.setDevicePixelRatio(cRetinaFactor());
refreshCacheImageUserPhoto();
update();

View File

@ -84,6 +84,7 @@ public:
void paint(Painter &p, int x, int y, int size);
void paintRounded(Painter &p, int x, int y, int size);
void paintSquare(Painter &p, int x, int y, int size);
StorageKey uniqueKey() const;
private:
@ -126,6 +127,12 @@ void EmptyUserpic::Impl::paintRounded(Painter &p, int x, int y, int size) {
});
}
void EmptyUserpic::Impl::paintSquare(Painter &p, int x, int y, int size) {
paint(p, x, y, size, [&p, x, y, size] {
p.fillRect(x, y, size, size, p.brush());
});
}
StorageKey EmptyUserpic::Impl::uniqueKey() const {
auto first = 0xFFFFFFFF00000000ULL | anim::getPremultiplied(_color->c);
auto second = uint64(0);
@ -204,17 +211,22 @@ void EmptyUserpic::clear() {
}
void EmptyUserpic::paint(Painter &p, int x, int y, int outerWidth, int size) const {
t_assert(_impl != nullptr);
Expects(_impl != nullptr);
_impl->paint(p, rtl() ? (outerWidth - x - size) : x, y, size);
}
void EmptyUserpic::paintRounded(Painter &p, int x, int y, int outerWidth, int size) const {
t_assert(_impl != nullptr);
Expects(_impl != nullptr);
_impl->paintRounded(p, rtl() ? (outerWidth - x - size) : x, y, size);
}
void EmptyUserpic::paintSquare(Painter &p, int x, int y, int outerWidth, int size) const {
Expects(_impl != nullptr);
_impl->paintSquare(p, rtl() ? (outerWidth - x - size) : x, y, size);
}
StorageKey EmptyUserpic::uniqueKey() const {
t_assert(_impl != nullptr);
Expects(_impl != nullptr);
return _impl->uniqueKey();
}
@ -328,6 +340,14 @@ void PeerData::paintUserpicRounded(Painter &p, int x, int y, int size) const {
}
}
void PeerData::paintUserpicSquare(Painter &p, int x, int y, int size) const {
if (auto userpic = currentUserpic()) {
p.drawPixmap(x, y, userpic->pix(size, size));
} else {
_userpicEmpty.paintSquare(p, x, y, x + size + x, size);
}
}
StorageKey PeerData::userpicUniqueKey() const {
if (photoLoc.isNull() || !_userpic || !_userpic->loaded()) {
return _userpicEmpty.uniqueKey();

View File

@ -244,6 +244,7 @@ public:
void paint(Painter &p, int x, int y, int outerWidth, int size) const;
void paintRounded(Painter &p, int x, int y, int outerWidth, int size) const;
void paintSquare(Painter &p, int x, int y, int outerWidth, int size) const;
QPixmap generate(int size);
StorageKey uniqueKey() const;
@ -345,6 +346,7 @@ public:
paintUserpic(p, rtl() ? (w - x - size) : x, y, size);
}
void paintUserpicRounded(Painter &p, int x, int y, int size) const;
void paintUserpicSquare(Painter &p, int x, int y, int size) const;
void loadUserpic(bool loadFirst = false, bool prior = true) {
_userpic->load(loadFirst, prior);
}