mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Add custom userpic rendering for Saved Messages.
This commit is contained in:
parent
1d85c8a6b6
commit
aebdc2fd94
@ -78,6 +78,87 @@ void EmptyUserpic::paintSquare(Painter &p, int x, int y, int outerWidth, int siz
|
||||
});
|
||||
}
|
||||
|
||||
void EmptyUserpic::PaintSavedMessages(
|
||||
Painter &p,
|
||||
int x,
|
||||
int y,
|
||||
int outerWidth,
|
||||
int size) {
|
||||
x = rtl() ? (outerWidth - x - size) : x;
|
||||
|
||||
PainterHighQualityEnabler hq(p);
|
||||
p.setBrush(st::historyPeer4UserpicBg);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.drawEllipse(x, y, size, size);
|
||||
|
||||
// |<----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 --- ---
|
||||
|
||||
const auto thinkness = std::round(size * 0.055);
|
||||
const auto increment = int(thinkness) % 2 + (size % 2);
|
||||
const auto width = std::round(size * 0.15) * 2 + increment;
|
||||
const auto height = std::round(size * 0.19) * 2 + increment;
|
||||
const auto add = std::round(size * 0.064);
|
||||
|
||||
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 = st::historyPeerUserpicFg->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);
|
||||
}
|
||||
}
|
||||
|
||||
StorageKey EmptyUserpic::uniqueKey() const {
|
||||
auto first = 0xFFFFFFFF00000000ULL | anim::getPremultiplied(_color->c);
|
||||
auto second = uint64(0);
|
||||
|
@ -47,6 +47,13 @@ public:
|
||||
QPixmap generate(int size);
|
||||
StorageKey uniqueKey() const;
|
||||
|
||||
static void PaintSavedMessages(
|
||||
Painter &p,
|
||||
int x,
|
||||
int y,
|
||||
int outerWidth,
|
||||
int size);
|
||||
|
||||
~EmptyUserpic();
|
||||
|
||||
private:
|
||||
|
@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "styles/style_history.h"
|
||||
#include "dialogs/dialogs_layout.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/empty_userpic.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "boxes/photo_crop_box.h"
|
||||
@ -522,11 +523,20 @@ void UserpicButton::paintEvent(QPaintEvent *e) {
|
||||
auto photoTop = photoPosition.y();
|
||||
|
||||
auto ms = getms();
|
||||
if (_a_appearance.animating(ms)) {
|
||||
p.drawPixmapLeft(photoPosition, width(), _oldUserpic);
|
||||
p.setOpacity(_a_appearance.current());
|
||||
if (showSavedMessages()) {
|
||||
Ui::EmptyUserpic::PaintSavedMessages(
|
||||
p,
|
||||
photoPosition.x(),
|
||||
photoPosition.y(),
|
||||
width(),
|
||||
_st.photoSize);
|
||||
} else {
|
||||
if (_a_appearance.animating(ms)) {
|
||||
p.drawPixmapLeft(photoPosition, width(), _oldUserpic);
|
||||
p.setOpacity(_a_appearance.current());
|
||||
}
|
||||
p.drawPixmapLeft(photoPosition, width(), _userpic);
|
||||
}
|
||||
p.drawPixmapLeft(photoPosition, width(), _userpic);
|
||||
|
||||
if (_role == Role::ChangePhoto) {
|
||||
auto over = isOver() || isDown();
|
||||
@ -743,6 +753,17 @@ void UserpicButton::switchChangePhotoOverlay(bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void UserpicButton::showSavedMessagesOnSelf(bool enabled) {
|
||||
if (_showSavedMessagesOnSelf != enabled) {
|
||||
_showSavedMessagesOnSelf = enabled;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
bool UserpicButton::showSavedMessages() const {
|
||||
return _showSavedMessagesOnSelf && _peer && _peer->isSelf();
|
||||
}
|
||||
|
||||
void UserpicButton::startChangeOverlayAnimation() {
|
||||
auto over = isOver() || isDown();
|
||||
_changeOverlayShown.start(
|
||||
|
@ -170,6 +170,7 @@ public:
|
||||
const style::UserpicButton &st);
|
||||
|
||||
void switchChangePhotoOverlay(bool enabled);
|
||||
void showSavedMessagesOnSelf(bool enabled);
|
||||
|
||||
QImage takeResultImage() {
|
||||
return std::move(_result);
|
||||
@ -199,6 +200,7 @@ private:
|
||||
void updateCursorInChangeOverlay(QPoint localPos);
|
||||
void setCursorInChangeOverlay(bool inOverlay);
|
||||
void updateCursor();
|
||||
bool showSavedMessages() const;
|
||||
|
||||
void grabOldUserpic();
|
||||
void setClickHandlerByRole();
|
||||
@ -220,6 +222,7 @@ private:
|
||||
Animation _a_appearance;
|
||||
QImage _result;
|
||||
|
||||
bool _showSavedMessagesOnSelf = false;
|
||||
bool _canOpenPhoto = false;
|
||||
bool _cursorInChangeOverlay = false;
|
||||
bool _changeOverlayEnabled = false;
|
||||
|
Loading…
Reference in New Issue
Block a user