diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index f2deb371a8..6b199630d9 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -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 diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 82563e4c56..a103f8ba27 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -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);