mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix new forum userpic rounding.
This commit is contained in:
parent
7db2acc742
commit
86ed2745e3
2 changed files with 29 additions and 17 deletions
|
@ -55,6 +55,7 @@ void CameraBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<Window::Controller*> controller,
|
not_null<Window::Controller*> controller,
|
||||||
PeerData *peer,
|
PeerData *peer,
|
||||||
|
bool forceForumShape,
|
||||||
Fn<void(QImage &&image)> &&doneCallback) {
|
Fn<void(QImage &&image)> &&doneCallback) {
|
||||||
using namespace Webrtc;
|
using namespace Webrtc;
|
||||||
|
|
||||||
|
@ -79,12 +80,14 @@ void CameraBox(
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
done(std::move(image));
|
done(std::move(image));
|
||||||
};
|
};
|
||||||
|
const auto useForumShape = forceForumShape
|
||||||
|
|| (peer && peer->isForum());
|
||||||
PrepareProfilePhoto(
|
PrepareProfilePhoto(
|
||||||
box,
|
box,
|
||||||
controller,
|
controller,
|
||||||
{
|
{
|
||||||
.confirm = tr::lng_profile_set_photo_button(tr::now),
|
.confirm = tr::lng_profile_set_photo_button(tr::now),
|
||||||
.cropType = ((peer && peer->isForum())
|
.cropType = (useForumShape
|
||||||
? EditorData::CropType::RoundedRect
|
? EditorData::CropType::RoundedRect
|
||||||
: EditorData::CropType::Ellipse),
|
: EditorData::CropType::Ellipse),
|
||||||
.keepAspectRatio = true,
|
.keepAspectRatio = true,
|
||||||
|
@ -141,11 +144,13 @@ UserpicButton::UserpicButton(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
Role role,
|
Role role,
|
||||||
const style::UserpicButton &st)
|
const style::UserpicButton &st,
|
||||||
|
bool forceForumShape)
|
||||||
: RippleButton(parent, st.changeButton.ripple)
|
: RippleButton(parent, st.changeButton.ripple)
|
||||||
, _st(st)
|
, _st(st)
|
||||||
, _controller(window->sessionController())
|
, _controller(window->sessionController())
|
||||||
, _window(window)
|
, _window(window)
|
||||||
|
, _forceForumShape(forceForumShape)
|
||||||
, _role(role) {
|
, _role(role) {
|
||||||
Expects(_role == Role::ChangePhoto || _role == Role::ChoosePhoto);
|
Expects(_role == Role::ChangePhoto || _role == Role::ChoosePhoto);
|
||||||
|
|
||||||
|
@ -295,7 +300,7 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
.confirm = ((type == ChosenType::Suggest)
|
.confirm = ((type == ChosenType::Suggest)
|
||||||
? tr::lng_profile_suggest_button(tr::now)
|
? tr::lng_profile_suggest_button(tr::now)
|
||||||
: tr::lng_profile_set_photo_button(tr::now)),
|
: tr::lng_profile_set_photo_button(tr::now)),
|
||||||
.cropType = ((_peer && _peer->isForum())
|
.cropType = (useForumShape()
|
||||||
? EditorData::CropType::RoundedRect
|
? EditorData::CropType::RoundedRect
|
||||||
: EditorData::CropType::Ellipse),
|
: EditorData::CropType::Ellipse),
|
||||||
.keepAspectRatio = true,
|
.keepAspectRatio = true,
|
||||||
|
@ -333,6 +338,7 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
CameraBox,
|
CameraBox,
|
||||||
_window,
|
_window,
|
||||||
_peer,
|
_peer,
|
||||||
|
_forceForumShape,
|
||||||
callback(ChosenType::Set)));
|
callback(ChosenType::Set)));
|
||||||
}, &st::menuIconPhotoSet);
|
}, &st::menuIconPhotoSet);
|
||||||
}
|
}
|
||||||
|
@ -546,8 +552,7 @@ void UserpicButton::paintUserpicFrame(Painter &p, QPoint photoPosition) {
|
||||||
auto size = QSize{ _st.photoSize, _st.photoSize };
|
auto size = QSize{ _st.photoSize, _st.photoSize };
|
||||||
const auto ratio = style::DevicePixelRatio();
|
const auto ratio = style::DevicePixelRatio();
|
||||||
request.outer = request.resize = size * ratio;
|
request.outer = request.resize = size * ratio;
|
||||||
const auto forum = _peer && _peer->isForum();
|
if (useForumShape()) {
|
||||||
if (forum) {
|
|
||||||
const auto radius = int(_st.photoSize
|
const auto radius = int(_st.photoSize
|
||||||
* Ui::ForumUserpicRadiusMultiplier());
|
* Ui::ForumUserpicRadiusMultiplier());
|
||||||
if (_roundingCorners[0].width() != radius * ratio) {
|
if (_roundingCorners[0].width() != radius * ratio) {
|
||||||
|
@ -789,6 +794,10 @@ void UserpicButton::processNewPeerPhoto() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UserpicButton::useForumShape() const {
|
||||||
|
return _forceForumShape || (_peer && _peer->isForum());
|
||||||
|
}
|
||||||
|
|
||||||
void UserpicButton::grabOldUserpic() {
|
void UserpicButton::grabOldUserpic() {
|
||||||
auto photoRect = QRect(
|
auto photoRect = QRect(
|
||||||
countPhotoPosition(),
|
countPhotoPosition(),
|
||||||
|
@ -893,9 +902,11 @@ void UserpicButton::showCustom(QImage &&image) {
|
||||||
size * cIntRetinaFactor(),
|
size * cIntRetinaFactor(),
|
||||||
Qt::IgnoreAspectRatio,
|
Qt::IgnoreAspectRatio,
|
||||||
Qt::SmoothTransformation);
|
Qt::SmoothTransformation);
|
||||||
const auto forum = _peer && _peer->isForum();
|
_userpic = Ui::PixmapFromImage(useForumShape()
|
||||||
_userpic = Ui::PixmapFromImage(forum
|
? Images::Round(
|
||||||
? Images::Round(std::move(small), Images::Option::RoundLarge)
|
std::move(small),
|
||||||
|
Images::CornersMask(_st.photoSize
|
||||||
|
* Ui::ForumUserpicRadiusMultiplier()))
|
||||||
: Images::Circle(std::move(small)));
|
: Images::Circle(std::move(small)));
|
||||||
} else {
|
} else {
|
||||||
_userpic = CreateSquarePixmap(_st.photoSize, [&](Painter &p) {
|
_userpic = CreateSquarePixmap(_st.photoSize, [&](Painter &p) {
|
||||||
|
@ -945,7 +956,7 @@ void UserpicButton::fillShape(QPainter &p, const style::color &color) const {
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
p.setBrush(color);
|
p.setBrush(color);
|
||||||
const auto size = _st.photoSize;
|
const auto size = _st.photoSize;
|
||||||
if (_peer && _peer->isForum()) {
|
if (useForumShape()) {
|
||||||
const auto radius = size * Ui::ForumUserpicRadiusMultiplier();
|
const auto radius = size * Ui::ForumUserpicRadiusMultiplier();
|
||||||
p.drawRoundedRect(0, 0, size, size, radius, radius);
|
p.drawRoundedRect(0, 0, size, size, radius, radius);
|
||||||
} else {
|
} else {
|
||||||
|
@ -977,14 +988,12 @@ void UserpicButton::prepareUserpicPixmap() {
|
||||||
QSize(size, size) * ratio,
|
QSize(size, size) * ratio,
|
||||||
Qt::IgnoreAspectRatio,
|
Qt::IgnoreAspectRatio,
|
||||||
Qt::SmoothTransformation);
|
Qt::SmoothTransformation);
|
||||||
if (_peer->isForum()) {
|
image = useForumShape()
|
||||||
image = Images::Round(
|
? Images::Round(
|
||||||
std::move(image),
|
std::move(image),
|
||||||
Images::CornersMask(size
|
Images::CornersMask(size
|
||||||
* Ui::ForumUserpicRadiusMultiplier()));
|
* Ui::ForumUserpicRadiusMultiplier()))
|
||||||
} else {
|
: Images::Circle(std::move(image));
|
||||||
image = Images::Circle(std::move(image));
|
|
||||||
}
|
|
||||||
image.setDevicePixelRatio(style::DevicePixelRatio());
|
image.setDevicePixelRatio(style::DevicePixelRatio());
|
||||||
p.drawImage(0, 0, image);
|
p.drawImage(0, 0, image);
|
||||||
}
|
}
|
||||||
|
@ -996,7 +1005,7 @@ void UserpicButton::prepareUserpicPixmap() {
|
||||||
((user && user->isInaccessible())
|
((user && user->isInaccessible())
|
||||||
? Ui::EmptyUserpic::InaccessibleName()
|
? Ui::EmptyUserpic::InaccessibleName()
|
||||||
: _peer->name()));
|
: _peer->name()));
|
||||||
if (_peer->isForum()) {
|
if (useForumShape()) {
|
||||||
empty.paintRounded(
|
empty.paintRounded(
|
||||||
p,
|
p,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -61,7 +61,8 @@ public:
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<::Window::Controller*> window,
|
not_null<::Window::Controller*> window,
|
||||||
Role role,
|
Role role,
|
||||||
const style::UserpicButton &st);
|
const style::UserpicButton &st,
|
||||||
|
bool forceForumShape = false);
|
||||||
UserpicButton(
|
UserpicButton(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<::Window::SessionController*> controller,
|
not_null<::Window::SessionController*> controller,
|
||||||
|
@ -140,6 +141,7 @@ private:
|
||||||
void streamingReady(Media::Streaming::Information &&info);
|
void streamingReady(Media::Streaming::Information &&info);
|
||||||
void paintUserpicFrame(Painter &p, QPoint photoPosition);
|
void paintUserpicFrame(Painter &p, QPoint photoPosition);
|
||||||
|
|
||||||
|
[[nodiscard]] bool useForumShape() const;
|
||||||
void grabOldUserpic();
|
void grabOldUserpic();
|
||||||
void setClickHandlerByRole();
|
void setClickHandlerByRole();
|
||||||
void requestSuggestAvailability();
|
void requestSuggestAvailability();
|
||||||
|
@ -154,6 +156,7 @@ private:
|
||||||
::Window::SessionController *_controller = nullptr;
|
::Window::SessionController *_controller = nullptr;
|
||||||
::Window::Controller *_window = nullptr;
|
::Window::Controller *_window = nullptr;
|
||||||
PeerData *_peer = nullptr;
|
PeerData *_peer = nullptr;
|
||||||
|
bool _forceForumShape = false;
|
||||||
PeerUserpicView _userpicView;
|
PeerUserpicView _userpicView;
|
||||||
std::shared_ptr<Data::PhotoMedia> _nonPersonalView;
|
std::shared_ptr<Data::PhotoMedia> _nonPersonalView;
|
||||||
Role _role = Role::ChangePhoto;
|
Role _role = Role::ChangePhoto;
|
||||||
|
|
Loading…
Add table
Reference in a new issue