Fix forum userpic button if no userpic is set.

This commit is contained in:
John Preston 2022-12-01 17:43:29 +04:00
parent b561705528
commit 1c44121db7
2 changed files with 22 additions and 29 deletions

View File

@ -395,31 +395,16 @@ void UserpicButton::paintEvent(QPaintEvent *e) {
paintUserpicFrame(p, photoPosition);
}
const auto fillShape = [&](const style::color &color) {
PainterHighQualityEnabler hq(p);
p.setPen(Qt::NoPen);
p.setBrush(color);
if (_peer && _peer->isForum()) {
p.drawRoundedRect(
photoLeft,
photoTop,
_st.photoSize,
_st.photoSize,
st::roundRadiusLarge,
st::roundRadiusLarge);
} else {
p.drawEllipse(
photoLeft,
photoTop,
_st.photoSize,
_st.photoSize);
}
const auto fillTranslatedShape = [&](const style::color &color) {
p.translate(photoLeft, photoTop);
fillShape(p, color);
p.translate(-photoLeft, -photoTop);
};
if (_role == Role::ChangePhoto || _role == Role::ChoosePhoto) {
auto over = isOver() || isDown();
if (over) {
fillShape(_userpicHasImage
fillTranslatedShape(_userpicHasImage
? st::msgDateImgBg
: _st.changeButton.textBgOver);
}
@ -459,7 +444,7 @@ void UserpicButton::paintEvent(QPaintEvent *e) {
_st.photoSize,
barHeight);
p.setClipRect(rect);
fillShape(_st.uploadBg);
fillTranslatedShape(_st.uploadBg);
auto iconLeft = (_st.uploadIconPosition.x() < 0)
? (_st.photoSize - _st.uploadIcon.width()) / 2
: _st.uploadIconPosition.x();
@ -807,17 +792,24 @@ void UserpicButton::setImage(QImage &&image) {
startNewPhotoShowing();
}
void UserpicButton::fillShape(QPainter &p, const style::color &color) const {
PainterHighQualityEnabler hq(p);
p.setPen(Qt::NoPen);
p.setBrush(color);
const auto size = _st.photoSize;
if (_peer && _peer->isForum()) {
const auto radius = st::roundRadiusLarge;
p.drawRoundedRect(0, 0, size, size, radius, radius);
} else {
p.drawEllipse(0, 0, size, size);
}
}
void UserpicButton::prepareUserpicPixmap() {
if (_userpicCustom) {
return;
}
auto size = _st.photoSize;
auto paintButton = [&](QPainter &p, const style::color &color) {
PainterHighQualityEnabler hq(p);
p.setBrush(color);
p.setPen(Qt::NoPen);
p.drawEllipse(0, 0, size, size);
};
_userpicHasImage = _peer
? (_peer->currentUserpic(_userpicView) || _role != Role::ChangePhoto)
: false;
@ -825,7 +817,7 @@ void UserpicButton::prepareUserpicPixmap() {
if (_userpicHasImage) {
_peer->paintUserpic(p, _userpicView, 0, 0, _st.photoSize);
} else {
paintButton(p, _st.changeButton.textBg);
fillShape(p, _st.changeButton.textBg);
}
});
_userpicUniqueKey = _userpicHasImage

View File

@ -132,7 +132,8 @@ private:
void processNewPeerPhoto();
void startNewPhotoShowing();
void prepareUserpicPixmap();
QPoint countPhotoPosition() const;
void fillShape(QPainter &p, const style::color &color) const;
[[nodiscard]] QPoint countPhotoPosition() const;
void startChangeOverlayAnimation();
void updateCursorInChangeOverlay(QPoint localPos);
void setCursorInChangeOverlay(bool inOverlay);